diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml index 9778ecc..d31bbea 100644 --- a/.github/workflows/gitleaks.yml +++ b/.github/workflows/gitleaks.yml @@ -124,6 +124,31 @@ jobs: regexes = ['''^\n?export TF_VAR_dagster_app_password_rotation[=]2026-09-01-dagster-v1$'''] TOML fi + # Two historical pipelines findings, bound to the exact commit and path that + # added them, so the same path or value in any other commit still fails. + # The sign-in webhook was reviewed and kept by its owner (ai-brain-platform#1601). + # The tracing-guard value is a fake test key in a since-removed test. + if [[ "${REPOSITORY:-}" == '60xAI/ai-brain-pipelines' ]]; then + cat >> "$config" <<'TOML' + [[allowlists]] + description = "Reviewed sign-in webhook added by the pipelines seed commit" + condition = "AND" + targetRules = ["slack-webhook-url"] + commits = ["874c2f2814df6febaa0f3e2ac656cef02a84cfe8"] + paths = ['''^backend/app/api/routes/auth\.py$'''] + [[allowlists]] + description = "Fake LangSmith key in the removed tracing-guard test" + condition = "AND" + targetRules = ["generic-api-key"] + # The test commit, then the two merges that carried it into development. + commits = [ + "93e97b5ed28e929ea9a070be57baaa3bd78bb155", + "db676a8a993e97f42634b12d359f649052dbc544", + "6b7dcbf2ee692e8877339b8e588c064e08b863f6", + ] + paths = ['''^backend/tests/test_tracing_guard\.py$'''] + TOML + fi log_opts='--all --diff-merges=first-parent' if [[ "$FULL_HISTORY" != true ]]; then [[ "$BASE_SHA" =~ ^[a-f0-9]{40}$ && "$HEAD_SHA" =~ ^[a-f0-9]{40}$ ]] || { echo 'Missing valid scan range'; exit 2; } diff --git a/tests/test_secret_scan.py b/tests/test_secret_scan.py index cdce6f5..37d479c 100644 --- a/tests/test_secret_scan.py +++ b/tests/test_secret_scan.py @@ -146,6 +146,37 @@ def test_rotation_marker_exception_preserves_same_path_credentials(self): self.assertEqual(report, []) self.assertFalse((scratch/'gitleaks-redacted.json').exists()) + def test_pipelines_history_exceptions_only_cover_their_own_commits(self): + # The pipelines exceptions are bound to exact historical commits, so a new + # commit on the same path must still be blocked. Synthetic, unissued values. + webhook = 'https://hooks.slack.com/services/' + 'T0SYNTHETIC/B0SYNTHETIC/' + 'abcdefghijklmnopqrstuvwx' + key = 'lsv2_' + 'Q7mZp3Lx9KvR2tYwB8nC' + cases = [ + ('backend/app/api/routes/auth.py', f'URL = "{webhook}"', 'slack-webhook-url'), + ('backend/tests/test_tracing_guard.py', f'API_KEY = "{key}"', 'generic-api-key'), + ] + for filename, line, rule in cases: + with self.subTest(filename), tempfile.TemporaryDirectory() as tmp: + repo = Path(tmp, 'repo'); repo.mkdir() + scratch = Path(tmp, 'runner'); scratch.mkdir() + for args in [('init', '-q'), ('config', 'user.name', 'Security Test'), + ('config', 'user.email', 'test@example.invalid')]: + self.assertEqual(run('git', *args, cwd=repo).returncode, 0) + target = repo / filename + target.parent.mkdir(parents=True) + target.write_text(line + '\n') + self.commit(repo, 'Synthetic credential on an excepted path') + env = os.environ | {'RUNNER_TEMP': str(scratch), + 'GITHUB_STEP_SUMMARY': str(scratch/'summary'), + 'GITHUB_OUTPUT': str(scratch/'output'), + 'FULL_HISTORY': 'true', 'BASE_SHA': '', 'HEAD_SHA': '', + 'REPOSITORY': '60xAI/ai-brain-pipelines'} + result = run('bash', '-c', scan_script(), cwd=repo, env=env) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn('result=10', (scratch/'output').read_text()) + report = json.loads((scratch/'gitleaks-findings.json').read_text()) + self.assertIn({'path': filename, 'rule_id': rule}, report) + def commit(self, repo, message): self.assertEqual(run('git', 'add', '.', cwd=repo).returncode, 0) self.assertEqual(run('git', 'commit', '-qm', message, cwd=repo).returncode, 0)