Skip to content

Commit

Permalink
refactor(checks): migrate AWS iam to Rego
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Pivkin <[email protected]>
  • Loading branch information
nikpivkin committed Jun 28, 2024
1 parent 9968cc8 commit ded4bd8
Show file tree
Hide file tree
Showing 105 changed files with 1,781 additions and 2,261 deletions.
5 changes: 3 additions & 2 deletions avd_docs/aws/iam/AVD-AWS-0056/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

IAM account password policies should prevent the reuse of passwords.
IAM account password policies should prevent the reuse of passwords.

The account password policy should be set to prevent using any of the last five used passwords.


### Impact
Password reuse increase the risk of compromised passwords being abused
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
3 changes: 2 additions & 1 deletion avd_docs/aws/iam/AVD-AWS-0057/docs.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

You should use the principle of least privilege when defining your IAM policies. This means you should specify each exact permission required without using wildcards, as this could cause the granting of access to certain undesired actions, resources and principals.


### Impact
Overly permissive policies may grant access to sensitive resources
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
3 changes: 2 additions & 1 deletion avd_docs/aws/iam/AVD-AWS-0058/docs.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

IAM account password policies should ensure that passwords content including at least one lowercase character.


### Impact
Short, simple passwords are easier to compromise
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
3 changes: 2 additions & 1 deletion avd_docs/aws/iam/AVD-AWS-0059/docs.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

IAM account password policies should ensure that passwords content including at least one number.


### Impact
Short, simple passwords are easier to compromise
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
3 changes: 2 additions & 1 deletion avd_docs/aws/iam/AVD-AWS-0060/docs.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

IAM account password policies should ensure that passwords content including a symbol.


### Impact
Short, simple passwords are easier to compromise
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
4 changes: 3 additions & 1 deletion avd_docs/aws/iam/AVD-AWS-0061/docs.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

,

IAM account password policies should ensure that passwords content including at least one uppercase character.


### Impact
Short, simple passwords are easier to compromise
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
7 changes: 4 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0062/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

IAM account password policies should have a maximum age specified.
IAM account password policies should have a maximum age specified.

The account password policy should be set to expire passwords after 90 days or less.


### Impact
Long life password increase the likelihood of a password eventually being compromised
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 3 additions & 2 deletions avd_docs/aws/iam/AVD-AWS-0063/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

IAM account password policies should ensure that passwords have a minimum length.
IAM account password policies should ensure that passwords have a minimum length.

The account password policy should be set to enforce minimum password length of at least 14 characters.


### Impact
Short, simple passwords are easier to compromise
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
91 changes: 0 additions & 91 deletions avd_docs/aws/iam/AVD-AWS-0123/Terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,97 +28,6 @@ resource "aws_iam_group_policy" "mfa" {
EOF
}
```
```hcl
resource "aws_iam_group" "support" {
name = "support"
}
resource "aws_iam_policy" "mfa" {
name = "something"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Action": "ec2:*",
"Resource": "*",
"Condition": {
"Bool": {
"aws:MultiFactorAuthPresent": ["true"]
}
}
}
]
}
EOF
}
resource "aws_iam_group_policy_attachment" "attach" {
group = aws_iam_group.support.name
policy_arn = aws_iam_policy.mfa.id
}
```
```hcl
resource "aws_iam_group" "support" {
name = "support"
}
resource "aws_iam_group_policy" "mfa" {
group = aws_iam_group.support.name
policy = data.aws_iam_policy_document.combined.json
}
data "aws_iam_policy_document" "policy_override" {
statement {
sid = "main"
effect = "Allow"
actions = ["s3:*"]
resources = ["*"]
condition {
test = "Bool"
variable = "aws:MultiFactorAuthPresent"
values = ["true"]
}
}
}
data "aws_iam_policy_document" "policy_source" {
statement {
sid = "main"
effect = "Allow"
actions = ["iam:*"]
resources = ["*"]
}
}
data "aws_iam_policy_document" "policy_misc" {
statement {
sid = "misc"
effect = "Deny"
actions = ["logs:*"]
resources = ["*"]
}
}
data "aws_iam_policy_document" "combined" {
source_json = <<EOF
{
"Id": "base"
}
EOF
source_policy_documents = [
data.aws_iam_policy_document.policy_source.json
]
override_policy_documents = [
data.aws_iam_policy_document.policy_override.json,
data.aws_iam_policy_document.policy_misc.json
]
statement {
sid = "whatever"
effect = "Deny"
actions = ["*"]
resources = ["*"]
}
}
```

#### Remediation Links
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0123/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


IAM groups should be protected with multi factor authentication to add safe guards to password compromise.


### Impact
IAM groups are more vulnerable to compromise without multi factor authentication activated
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0140/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


The root user has unrestricted access to all services and resources in an AWS account. We highly recommend that you avoid using the root user for daily tasks. Minimizing the use of the root user and adopting the principle of least privilege for access management reduce the risk of accidental changes and unintended disclosure of highly privileged credentials.


### Impact
Compromise of the root account compromises the entire AWS account and all resources within it.
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0141/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


CIS recommends that all access keys be associated with the root user be removed. Removing access keys associated with the root user limits vectors that the account can be compromised by. Removing the root user access keys also encourages the creation and use of role-based accounts that are least privileged.


### Impact
Compromise of the root account compromises the entire AWS account and all resources within it.
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0142/docs.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@


MFA adds an extra layer of protection on top of a user name and password. With MFA enabled, when a user signs in to an AWS website, they're prompted for their user name and password and for an authentication code from their AWS MFA device.

When you use virtual MFA for the root user, CIS recommends that the device used is not a personal device. Instead, use a dedicated mobile device (tablet or phone) that you manage to keep charged and secured independent of any individual personal devices. This lessens the risks of losing access to the MFA due to device loss, device trade-in, or if the individual owning the device is no longer employed at the company.


### Impact
Compromise of the root account compromises the entire AWS account and all resources within it.
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0143/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


CIS recommends that you apply IAM policies directly to groups and roles but not users. Assigning privileges at the group or role level reduces the complexity of access management as the number of users grow. Reducing access management complexity might in turn reduce opportunity for a principal to inadvertently receive or retain excessive privileges.


### Impact
Complex access control is difficult to manage and maintain.
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0144/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


CIS recommends that you remove or deactivate all credentials that have been unused in 90 days or more. Disabling or removing unnecessary credentials reduces the window of opportunity for credentials associated with a compromised or abandoned account to be used.


### Impact
Leaving unused credentials active widens the scope for compromise.
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0145/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


IAM user accounts should be protected with multi factor authentication to add safe guards to password compromise.


### Impact
User accounts are more vulnerable to compromise without multi factor authentication activated
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0146/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


Regularly rotating your IAM credentials helps prevent a compromised set of IAM access keys from accessing components in your AWS account.


### Impact
Compromised keys are more likely to be used to compromise the account
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0165/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


Hardware MFA adds an extra layer of protection on top of a user name and password. With MFA enabled, when a user signs in to an AWS website, they're prompted for their user name and password and for an authentication code from their AWS MFA device.


### Impact
Compromise of the root account compromises the entire AWS account and all resources within it.
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0166/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

AWS IAM users can access AWS resources using different types of credentials, such as passwords or access keys. It is recommended that all credentials that have been unused in45 or greater days be deactivated or removed.

Disabling or removing unnecessary credentials will reduce the window of opportunity for credentials associated with a compromised or abandoned account to be used.


### Impact
Leaving unused credentials active widens the scope for compromise.
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
5 changes: 2 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0167/docs.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


Multiple active access keys widens the scope for compromise.


### Impact
Widened scope for compromise.
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
8 changes: 5 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0168/docs.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@


Removing expired SSL/TLS certificates eliminates the risk that an invalid certificate will be

deployed accidentally to a resource such as AWS Elastic Load Balancer (ELB), which can

damage the credibility of the application/website behind the ELB. As a best practice, it is

recommended to delete expired certificates.


### Impact
Risk of misconfiguration and damage to credibility
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
6 changes: 3 additions & 3 deletions avd_docs/aws/iam/AVD-AWS-0169/docs.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


By implementing least privilege for access control, an IAM Role will require an appropriate

IAM Policy to allow Support Center Access in order to manage Incidents with AWS Support.


### Impact
Incident management is not possible without a support role.
<!-- Add Impact here -->

<!-- DO NOT CHANGE -->
{{ remediationActions }}
Expand Down
3 changes: 2 additions & 1 deletion checks/cloud/aws/iam/disable_unused_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ CIS recommends that you remove or deactivate all credentials that have been unus
Links: []string{
"https://console.aws.amazon.com/iam/",
},
Severity: severity.Medium,
Severity: severity.Medium,
Deprecated: true,
},
func(s *state.State) (results scan.Results) {

Expand Down
Loading

0 comments on commit ded4bd8

Please sign in to comment.