Skip to content

Commit 5d6f64d

Browse files
peppescgkantord
andauthored
Talisman pre-commit hook secrets scanning (#233)
* Talisman pre-commit hook secrets scanning * refactor description * add test * talisman hooks field check * fix rule description Co-authored-by: Dániel Kántor <kd@stacklok.com> --------- Co-authored-by: Dániel Kántor <kd@stacklok.com>
1 parent 5fbd7c1 commit 5d6f64d

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests:
2+
- name: "Should have Talisman pre-commit hook configured"
3+
def: {}
4+
params: {}
5+
expect: "pass"
6+
git:
7+
repo_base: correct
8+
- name: "Should fail Talisman pre-commit hook is not configured"
9+
def: {}
10+
params: {}
11+
expect: "fail"
12+
git:
13+
repo_base: misconfigured
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
args: ['--maxkb=600']
10+
- repo: https://github.com/thoughtworks/talisman
11+
rev: 'v1.28.0' # Update me!
12+
hooks:
13+
# both pre-commit and pre-push supported
14+
# - id: talisman-push
15+
- id: talisman-commit
16+
entry: cmd --githook pre-commit
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
args: ['--maxkb=600']
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
version: v1
3+
release_phase: alpha
4+
type: rule-type
5+
name: talisman_secrets_scanning
6+
display_name: Enable Talisman Pre-commit hooks for detecting secrets
7+
short_failure_message: Talisman Pre-commit hook is not configured for the repository
8+
severity:
9+
value: medium
10+
context: {}
11+
description: |
12+
Verifies that Talisman Pre-commit hook is configured via a GitHub action for the repository
13+
guidance: |
14+
Ensure that Talisman is configured pre-commit hook for the repository.
15+
Talisman validates the outgoing changeset for things that look suspicious — such as tokens, passwords, and private keys.
16+
For more information, see the [GitHub Talisman Pre-commit](https://github.com/thoughtworks/talisman?tab=readme-ov-file#pre-commit) documentation.
17+
def:
18+
in_entity: repository
19+
rule_schema:
20+
type: object
21+
properties: {}
22+
ingest:
23+
type: git
24+
git: {}
25+
eval:
26+
type: rego
27+
rego:
28+
type: deny-by-default
29+
def: |
30+
package minder
31+
import future.keywords.if
32+
import future.keywords.every
33+
34+
default message := "Talisman pre-commit hook is not configured for the repository"
35+
default allow := false
36+
37+
38+
# pre-commit hook
39+
precommit := file.read(".pre-commit-config.yaml")
40+
41+
parsed_data := parse_yaml(precommit)
42+
43+
allow if {
44+
some repo_id, hook_id
45+
repo_data := parsed_data.repos[repo_id]
46+
endswith(repo_data["repo"], "https://github.com/thoughtworks/talisman")
47+
talisman_hooks = repo_data["hooks"]
48+
talisman_hooks[hook_id].id == "talisman-commit"
49+
talisman_hooks[hook_id].entry == "cmd --githook pre-commit"
50+
}
51+
52+
message := "" if allow
53+
alert:
54+
type: security_advisory
55+
security_advisory: {}

0 commit comments

Comments
 (0)