-
Notifications
You must be signed in to change notification settings - Fork 368
feat(query): iam role without permission boundary #8020
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
Open
balaakasam
wants to merge
15
commits into
Checkmarx:master
Choose a base branch
from
balaakasam:feat/iam-role-without-permission-boundary
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
aed3edb
feat(query): add IAM Role Without Permission Boundary query metadata
balaakasam fef914a
feat(query): add IAM Role Without Permission Boundary query logic
balaakasam fda2bb1
feat(query): add IAM Role Without Permission Boundary positive test case
balaakasam a430b8f
feat(query): add IAM Role Without Permission Boundary negative test case
balaakasam 85f898b
feat(query): add IAM Role Without Permission Boundary expected test r…
balaakasam 0a98e03
add missing riskScore field to IAM Role Without Permission Boundary m…
balaakasam f565633
Merge branch 'master' into feat/iam-role-without-permission-boundary
cx-artur-ribeiro d240796
fix(query): update category to Access Control and fix riskScore format
balaakasam cb50fbc
fix(query): fix negative test case to include permissions_boundary at…
balaakasam f8b523f
fix(query): update positive expected result to include fileName
balaakasam 66e2b2b
Merge branch 'master' into feat/iam-role-without-permission-boundary
balaakasam 11693cc
Merge branch 'master' into feat/iam-role-without-permission-boundary
cx-artur-ribeiro b77ace3
Merge branch 'master' into feat/iam-role-without-permission-boundary
balaakasam a02d802
Update assets/queries/terraform/aws/iam_role_without_permission_bound…
balaakasam 0104610
Merge branch 'master' into feat/iam-role-without-permission-boundary
balaakasam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
assets/queries/terraform/aws/iam_role_without_permission_boundary/metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "id": "a4d32b6e-9c7f-4b2a-8e5d-1f3c9a0e7b42", | ||
| "queryName": "IAM Role Without Permission Boundary", | ||
| "severity": "MEDIUM", | ||
| "category": "Access Control", | ||
| "descriptionText": "IAM roles should have a permissions boundary defined to limit the maximum permissions that can be granted. Without a permission boundary, IAM roles can potentially be exploited to escalate privileges beyond intended scope.", | ||
| "descriptionUrl": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role#permissions_boundary", | ||
| "platform": "Terraform", | ||
| "descriptionID": "a4d32b6e", | ||
| "cloudProvider": "aws", | ||
| "cwe": "269", | ||
| "riskScore": 3.0 | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
assets/queries/terraform/aws/iam_role_without_permission_boundary/query.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package Cx | ||
|
|
||
| import data.generic.common as common_lib | ||
| import data.generic.terraform as tf_lib | ||
|
|
||
| CxPolicy[result] { | ||
| resource := input.document[i].resource.aws_iam_role[name] | ||
| not common_lib.valid_key(resource, "permissions_boundary") | ||
|
|
||
| result := { | ||
| "documentId": input.document[i].id, | ||
| "resourceType": "aws_iam_role", | ||
| "resourceName": tf_lib.get_resource_name(resource, name), | ||
| "searchKey": sprintf("resource.aws_iam_role[%s]", [name]), | ||
| "issueType": "MissingAttribute", | ||
| "keyExpectedValue": sprintf("aws_iam_role[%s].permissions_boundary is defined", [name]), | ||
| "keyActualValue": sprintf("aws_iam_role[%s].permissions_boundary is undefined", [name]), | ||
| "searchLine": common_lib.build_search_line(["resource", "aws_iam_role", name], []), | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
assets/queries/terraform/aws/iam_role_without_permission_boundary/test/negative1.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # This should NOT trigger the query - permissions_boundary is defined | ||
| resource "aws_iam_role" "negative1" { | ||
| name = "negative_role" | ||
|
|
||
| assume_role_policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Action = "sts:AssumeRole" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| Service = "ec2.amazonaws.com" | ||
| } | ||
| } | ||
| ] | ||
| }) | ||
|
|
||
| permissions_boundary = "arn:aws:iam::123456789012:policy/BoundaryPolicy" | ||
| } |
17 changes: 17 additions & 0 deletions
17
assets/queries/terraform/aws/iam_role_without_permission_boundary/test/positive1.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # This should trigger the query - no permissions_boundary defined | ||
| resource "aws_iam_role" "positive1" { | ||
| name = "positive_role" | ||
|
|
||
| assume_role_policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Action = "sts:AssumeRole" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| Service = "ec2.amazonaws.com" | ||
| } | ||
| } | ||
| ] | ||
| }) | ||
| } |
8 changes: 8 additions & 0 deletions
8
...ies/terraform/aws/iam_role_without_permission_boundary/test/positive_expected_result.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [ | ||
| { | ||
| "queryName": "IAM Role Without Permission Boundary", | ||
| "severity": "MEDIUM", | ||
| "line": 2, | ||
| "fileName": "positive1.tf" | ||
| } | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.