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

fix(terraform): fix policy document retrieval #6276

Merged
merged 3 commits into from
Mar 12, 2024

Conversation

nikpivkin
Copy link
Contributor

@nikpivkin nikpivkin commented Mar 5, 2024

Description

If a policy, such as aws_iam_policy or aws_iam_policy_document, uses a for-each loop to reference policy document resources, those resources are not detected. In the case where a policy references document resources in a condition, only the first resource was selected. It is necessary to search for policy document resources by identifiers (id) rather than by references to fix this.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@nikpivkin nikpivkin marked this pull request as ready for review March 6, 2024 11:55
@nikpivkin nikpivkin requested a review from simar7 as a code owner March 6, 2024 11:55
Comment on lines 211 to 212
policyDoc, err := modules.GetBlockById(policyDocID)
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
policyDoc, err := modules.GetBlockById(policyDocID)
if err == nil {
if policyDoc, err := modules.GetBlockById(policyDocID); err == nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 9058054

Comment on lines 213 to 214
document, err := ConvertTerraformDocument(modules, policyDoc)
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
document, err := ConvertTerraformDocument(modules, policyDoc)
if err == nil {
if document, err := ConvertTerraformDocument(modules, policyDoc); err == nil {

Comment on lines 218 to 219
parsed, err := iamgo.Parse([]byte(unescapeVars(policyDocID)))
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
parsed, err := iamgo.Parse([]byte(unescapeVars(policyDocID)))
if err == nil {
if parsed, err := iamgo.Parse([]byte(unescapeVars(policyDocID))); err == nil {

Comment on lines +205 to +207
if !attr.IsIterable() {
return documents
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 9058054

@nikpivkin nikpivkin requested a review from simar7 March 11, 2024 13:59
@simar7 simar7 added this pull request to the merge queue Mar 12, 2024
Merged via the queue into aquasecurity:main with commit 102b6df Mar 12, 2024
12 checks passed
@nikpivkin nikpivkin deleted the tf-policy-docs branch March 13, 2024 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(misconf): Resolve attributes depending on conditions irrespective of placement
2 participants