Skip to content

Commit

Permalink
fix(secrets): filter secrets that have vault: in them (#6565)
Browse files Browse the repository at this point in the history
* filter vault

* fix

* add test and small fix

* small fix

* small fix2
  • Loading branch information
RabeaZr authored Jul 11, 2024
1 parent 2966084 commit bbfc595
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions checkov/secrets/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
MAX_FILE_SIZE = int(os.getenv('CHECKOV_MAX_FILE_SIZE', '5000000')) # 5 MB is default limit


def should_filter_vault_secret(secret_value: str, check_id: str) -> bool:
return 'vault:' in secret_value.lower() and check_id in ENTROPY_CHECK_IDS


class Runner(BaseRunner[None, None, None]):
check_type = CheckType.SECRETS # noqa: CCE003 # a static attribute

Expand Down Expand Up @@ -229,6 +233,9 @@ def run(
if not check_id:
logging.debug(f'Secret was filtered - no check_id for line_number {secret.line_number}')
continue
if secret.secret_value and should_filter_vault_secret(secret.secret_value, check_id):
logging.debug(f'Secret was filtered - this is a vault reference: {secret.secret_value}')
continue
secret_key = f'{key}_{secret.line_number}_{secret.secret_hash}'
# secret history
added_commit_hash, removed_commit_hash, code_line, added_by, removed_date, added_date = '', '', '', '', '', ''
Expand Down
21 changes: 21 additions & 0 deletions tests/secrets/test_vault_secrets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from checkov.secrets.runner import should_filter_vault_secret

HIGH_ENTROPY_CHECK_ID = 'CKV_SECRET_80'

def test_vault_secrets_false_positives():
fp_secrets = [
'DB_RBMQ_PASSWORD: vault: secret/data/product-web/mcrp-qwr-v2/mabbot#PASSWORD',
'WEB_PASSWORD: vault: secret/data/product/fwrp-qe-v3/parme3#PASSWORD',
'PASS: vault: secret/sr/dt/pro/fwrtq1#2/weg#PASSWORD'
]
for fp_secret in fp_secrets:
assert should_filter_vault_secret(fp_secret, HIGH_ENTROPY_CHECK_ID)

def test_secrets_without_vault():
real_secrets = [
'ldap_pwd = k%udk423u4%P8=H_',
'password = J6T4ww+##14m',
'PS = 1r4#Gf2FDF$343r3m2me3r%'
]
for real_secret in real_secrets:
assert not should_filter_vault_secret(real_secret, HIGH_ENTROPY_CHECK_ID)

0 comments on commit bbfc595

Please sign in to comment.