-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: add support for awscc provider secrets check #6647
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
Closed
quixoticmonk
wants to merge
23
commits into
bridgecrewio:main
from
quixoticmonk:feat/awscc-provider-support
Closed
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a78979e
feat: add support for awscc provider secrets check
quixoticmonk c9b5da9
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk bc11407
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 1fa191e
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 6ee63ad
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 107cc8f
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 7a88b4a
fix: update service provider reference
quixoticmonk 6673fea
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk d7e4343
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk b01ef3d
fix: tests based on framework
quixoticmonk fc75111
fix: use len than static values
quixoticmonk 4296cda
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 670b48b
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 2479587
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 872e982
Merge branch 'main' into feat/awscc-provider-support
tsmithv11 a555a9b
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 469230b
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 73c9bb3
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 1d52775
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 96490d6
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk b7dd903
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 0191a66
Merge branch 'main' into feat/awscc-provider-support
quixoticmonk 318d404
Merge branch 'main' into feat/awscc-provider-support
pazbechor 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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from checkov.terraform.checks.provider.aws import * # noqa | ||
from checkov.terraform.checks.provider.linode import * # noqa | ||
from checkov.terraform.checks.provider.awscc import * # noqa | ||
from checkov.terraform.checks.provider.bridgecrew import * # noqa | ||
from checkov.terraform.checks.provider.linode import * # noqa | ||
from checkov.terraform.checks.provider.oci import * # noqa | ||
from checkov.terraform.checks.provider.openstack import * # noqa | ||
from checkov.terraform.checks.provider.panos import * # noqa |
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,5 @@ | ||
from os.path import dirname, basename, isfile, join | ||
import glob | ||
|
||
modules = glob.glob(join(dirname(__file__), "*.py")) | ||
__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith("__init__.py")] |
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,37 @@ | ||
import re | ||
from typing import Any, Dict, List | ||
|
||
from checkov.common.models.consts import access_key_pattern, secret_key_pattern | ||
from checkov.common.models.enums import CheckCategories, CheckResult | ||
from checkov.terraform.checks.provider.base_check import BaseProviderCheck | ||
|
||
|
||
class AWSCCCredentials(BaseProviderCheck): | ||
def __init__(self) -> None: | ||
name = "Ensure no hard coded AWS access key and secret key exists in provider" | ||
id = "CKV_AWSCC_41" | ||
supported_provider = ["awscc"] | ||
quixoticmonk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
categories = [CheckCategories.SECRETS] | ||
super().__init__(name=name, id=id, categories=categories, supported_provider=supported_provider) | ||
|
||
def scan_provider_conf(self, conf: Dict[str, List[Any]]) -> CheckResult: | ||
""" | ||
see: https://registry.terraform.io/providers/hashicorp/awscc/latest/docs#authentication | ||
""" | ||
result = CheckResult.PASSED | ||
if self.secret_found(conf, "access_key", access_key_pattern): | ||
result = CheckResult.FAILED | ||
if self.secret_found(conf, "secret_key", secret_key_pattern): | ||
result = CheckResult.FAILED | ||
return result | ||
|
||
def secret_found(self, conf: Dict[str, List[Any]], field: str, pattern: str) -> bool: | ||
if field in conf.keys(): | ||
value = conf[field][0] | ||
if isinstance(value, str) and re.match(pattern, value) is not None: | ||
conf[f'{self.id}_secret_{field}'] = value | ||
return True | ||
return False | ||
|
||
|
||
check = AWSCCCredentials() |
Empty file.
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,74 @@ | ||
import unittest | ||
|
||
import hcl2 | ||
|
||
from checkov.terraform.checks.provider.awscc.credentials import check | ||
from checkov.common.models.enums import CheckResult | ||
|
||
|
||
class TestCredentials(unittest.TestCase): | ||
def test_success_empty(self): | ||
quixoticmonk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
hcl_res = hcl2.loads( | ||
""" | ||
provider "awscc" {} | ||
""" | ||
) | ||
provider_conf = hcl_res["provider"][0]["awscc"] | ||
scan_result = check.scan_provider_conf(conf=provider_conf) | ||
self.assertEqual(CheckResult.PASSED, scan_result) | ||
|
||
def test_success_region(self): | ||
hcl_res = hcl2.loads( | ||
""" | ||
provider "awscc" { | ||
region = "us-west-2" | ||
} | ||
""" | ||
) | ||
provider_conf = hcl_res["provider"][0]["awscc"] | ||
scan_result = check.scan_provider_conf(conf=provider_conf) | ||
self.assertEqual(CheckResult.PASSED, scan_result) | ||
|
||
def test_failure_both_keys(self): | ||
hcl_res = hcl2.loads( | ||
""" | ||
provider "awscc" { | ||
region = "us-west-2" | ||
access_key = "AKIAIOSFODNN7EXAMPLE" | ||
secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | ||
} | ||
""" | ||
) | ||
provider_conf = hcl_res["provider"][0]["awscc"] | ||
scan_result = check.scan_provider_conf(conf=provider_conf) | ||
self.assertEqual(CheckResult.FAILED, scan_result) | ||
|
||
def test_failure_access_key(self): | ||
hcl_res = hcl2.loads( | ||
""" | ||
provider "awscc" { | ||
region = "us-west-2" | ||
access_key = "AKIAIOSFODNN7EXAMPLE" | ||
} | ||
""" | ||
) | ||
provider_conf = hcl_res["provider"][0]["awscc"] | ||
scan_result = check.scan_provider_conf(conf=provider_conf) | ||
self.assertEqual(CheckResult.FAILED, scan_result) | ||
|
||
def test_failure_secret_key(self): | ||
hcl_res = hcl2.loads( | ||
""" | ||
provider "awscc" { | ||
region = "us-west-2" | ||
secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | ||
} | ||
""" | ||
) | ||
provider_conf = hcl_res["provider"][0]["awscc"] | ||
scan_result = check.scan_provider_conf(conf=provider_conf) | ||
self.assertEqual(CheckResult.FAILED, scan_result) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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.