Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: Revert AVD-AWS-0342 policy (#1309)" #1355

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions avd_docs/aws/iam/AVD-AWS-0342/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

In iam:PassRole the service carrying out the actions is "provided" a role by the calling principal and implicitly takes on that role to carry out the actions (instead of executing sts:AssumeRole).
The privileges attached to the role are distinct from those of the primary ordering the action and may even be larger and can cause security issues.


### Impact
Compromise on security of aws resources.

<!-- DO NOT CHANGE -->
{{ remediationActions }}

### Links
- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html


38 changes: 38 additions & 0 deletions rules/cloud/policies/aws/iam/filter_iam_pass_role.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# METADATA
# title: "IAM Pass Role Filtering"
# description: "Ensures any IAM pass role attched to roles are flagged and warned."
# scope: package
# schemas:
# - input: schema["cloud"]
# related_resources:
# - https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html
# custom:
# avd_id: AVD-AWS-0342
# provider: aws
# service: iam
# severity: MEDIUM
# short_code: filer-passrole-access
# recommended_action: "Resolve permission escalations by denying pass role'"
# input:
# selector:
# - type: cloud
# subtypes:
# - service: iam
# provider: aws
package builtin.aws.iam.aws0342

allows_permission(statements, permission, effect) {
statement := statements[_]
statement.Effect == effect
action = statement.Action[_]
action == permission
}

deny[res] {
policy := input.aws.iam.policies[_]
value = json.unmarshal(policy.document.value)
statements = value.Statement
not allows_permission(statements, "iam:PassRole", "Deny")
allows_permission(statements, "iam:PassRole", "Allow")
res = result.new("IAM policy allows 'iam:PassRole' action", policy.document)
}
28 changes: 28 additions & 0 deletions rules/cloud/policies/aws/iam/filter_iam_pass_role_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package builtin.aws.iam.aws0342

test_with_allow_iam_pass_role {
policies := [{
"name": "policy_with_iam_pass_role",
"document": {"value": "{\"Version\":\"2012-10-17\",\"Id\":\"\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{},\"NotPrincipal\":{},\"Action\":[\"iam:PassRole\"],\"NotAction\":null,\"Resource\":[\"arn:aws:iam::193063503752:role/atc-node\"],\"NotResource\":null,\"Condition\":{}}]}"},
}]
r := deny with input as {"aws": {"iam": {"policies": policies}}}
count(r) == 1
}

test_with_deny_iam_pass_role {
policies := [{
"name": "policy_with_iam_pass_role",
"document": {"value": "{\"Version\":\"2012-10-17\",\"Id\":\"\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Deny\",\"Principal\":{},\"NotPrincipal\":{},\"Action\":[\"iam:PassRole\"],\"NotAction\":null,\"Resource\":[\"arn:aws:iam::193063503752:role/atc-node\"],\"NotResource\":null,\"Condition\":{}}]}"},
}]
r := deny with input as {"aws": {"iam": {"policies": policies}}}
count(r) == 0
}

test_with_no_iam_pass_role {
policies := [{
"name": "policy_without_iam_pass_role",
"document": {"value": "{\"Version\":\"2012-10-17\",\"Id\":\"\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{},\"NotPrincipal\":{},\"Action\":[\"s3:GetObject\"],\"NotAction\":null,\"Resource\":[\"arn:aws:s3:::examplebucket/*\"],\"NotResource\":null,\"Condition\":{}}]}"},
}]
r := deny with input as {"aws": {"iam": {"policies": policies}}}
count(r) == 0
}