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

feat(terraform): add module check for commit hash revision usage #5261

Merged
merged 3 commits into from
Jun 27, 2023

Conversation

gruebel
Copy link
Contributor

@gruebel gruebel commented Jun 26, 2023

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

  • adding the first module check 🍻
  • instead of using a tag to reference the version of a module, it is recommend to use the actual git URL + commit hash revision to pin it to an immutable state

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@gruebel gruebel temporarily deployed to scan-security June 26, 2023 21:04 — with GitHub Actions Inactive
checkov/common/goget/github/get_git.py Dismissed Show resolved Hide resolved
Co-authored-by: Taylor <[email protected]>
@gruebel gruebel temporarily deployed to scan-security June 27, 2023 07:04 — with GitHub Actions Inactive
@gruebel gruebel merged commit 0444171 into bridgecrewio:main Jun 27, 2023
32 checks passed
@tobias-netacea
Copy link

Question on this one. Seems checks for the ref= does not take local modules into account e.g.

module "my_module" {
  source = "../modules/foo"
}

Any chance this can be improved to only apply when the source is a URL and not a local path?

@gruebel gruebel deleted the add-commit-hash-module-check branch June 27, 2023 10:57
@gruebel
Copy link
Contributor Author

gruebel commented Jun 27, 2023

hey @tobias-netacea ,

you are right 🙈 I don't know, why I forgot to test the new check against local modules. Will create a fix for it.

JamesWoolfenden pushed a commit that referenced this pull request Jun 27, 2023
* add module check for commit hash revision usage

* fix lint and tests

* adjust check name

Co-authored-by: Taylor <[email protected]>

---------

Co-authored-by: Taylor <[email protected]>
JamesWoolfenden pushed a commit that referenced this pull request Jun 27, 2023
* add module check for commit hash revision usage

* fix lint and tests

* adjust check name

Co-authored-by: Taylor <[email protected]>

---------

Co-authored-by: Taylor <[email protected]>
@richardgavel-ordinaryexperts

#5267

@benedekmol
Copy link

benedekmol commented Jun 29, 2023

Hi,
We referenced a tag like this:
git::ssh://[email protected]/gitrepo//.?ref=0.25.0

And this feature broke it beacuse the regex doesn't allow . characters.

@tomcsi
Copy link

tomcsi commented Jun 29, 2023

I have same issue

from checkov.common.models.enums import CheckResult, CheckCategories
from checkov.terraform.checks.module.base_module_check import BaseModuleCheck

COMMIT_ID_PATTERN = re.compile(r"\?(ref=)(?P<commit_id>([0-9a-f]{5,40}))")

Choose a reason for hiding this comment

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

Using the general git source. This broke the tag reference.

@gruebel
Copy link
Contributor Author

gruebel commented Jun 29, 2023

@tomcsi @benedekmol feel free to read this comment, then you understand the reasoning of this new check #5265 (comment)

@rajaganeshej
Copy link

Hi , I am also facing this issue. so if only commit hash then only I can use this?.. I am referring some feature branch and it's requesting the commit hash.

Could you please help me on this?

@JamesWoolfenden
Copy link
Contributor

Hi , I am also facing this issue. so if only commit hash then only I can use this?.. I am referring some feature branch and it's requesting the commit hash.

Could you please help me on this?

The feature branch should still have a commit hash.

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.

9 participants