-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Open
quixoticmonk
wants to merge
22
commits into
bridgecrewio:main
Choose a base branch
from
quixoticmonk:feat/awscc-provider-support
base: main
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 all commits
Commits
Show all changes
22 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 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_AWS_41" | ||
supported_provider = ["awscc"] | ||
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.
23 changes: 23 additions & 0 deletions
23
tests/terraform/checks/provider/awscc/example_Credentials/main.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,23 @@ | ||
provider "awscc" { | ||
alias = "pass" | ||
region = "us-west-2" | ||
} | ||
|
||
provider "awscc" { | ||
alias = "fail" | ||
region = "us-west-2" | ||
access_key = "AKIAIOSFODNN7EXAMPLE" | ||
secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | ||
} | ||
|
||
provider "awscc" { | ||
alias = "fail2" | ||
region = "us-west-2" | ||
access_key = "AKIAIOSFODNN7EXAMPLE" | ||
} | ||
|
||
provider "awscc" { | ||
alias = "fail3" | ||
region = "us-west-2" | ||
secret_key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | ||
} |
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,40 @@ | ||
import os | ||
import unittest | ||
|
||
from checkov.runner_filter import RunnerFilter | ||
from checkov.terraform.checks.provider.awscc.credentials import check | ||
from checkov.terraform.runner import Runner | ||
|
||
|
||
class TestAWSCCCredentials(unittest.TestCase): | ||
def test(self): | ||
runner = Runner() | ||
current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
test_files_dir = current_dir + "/example_Credentials" | ||
report = runner.run(root_folder=test_files_dir, runner_filter=RunnerFilter(checks=[check.id])) | ||
summary = report.get_summary() | ||
|
||
passing_resources = { | ||
"provider.awscc.pass" | ||
} | ||
failing_resources = { | ||
"provider.awscc.fail", | ||
"provider.awscc.fail2", | ||
"provider.awscc.fail3", | ||
} | ||
|
||
passed_check_resources = set([c.resource for c in report.passed_checks]) | ||
failed_check_resources = set([c.resource for c in report.failed_checks]) | ||
|
||
self.assertEqual(summary["passed"], len(passing_resources)) | ||
self.assertEqual(summary["failed"], len(failing_resources)) | ||
self.assertEqual(summary["skipped"], 0) | ||
self.assertEqual(summary["parsing_errors"], 0) | ||
|
||
self.assertEqual(passing_resources, passed_check_resources) | ||
self.assertEqual(failing_resources, failed_check_resources) | ||
|
||
|
||
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.