8000 feat(security-suite): single source of truth for scanner configs (phase 1: betterleaks base + pinact dedup) by dkastl · Pull Request #102 · geolonia/.github · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .betterleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Canonical org-wide betterleaks config for the Security Suite. SINGLE SOURCE
# OF TRUTH: this is the one betterleaks ruleset the org maintains.
#
# How it is used:
# * Per-PR secret-leak gate (reusable-secret-leak-check.yml): fetched as the
# centralized fallback when a caller repo ships no .betterleaks.toml. Every
# detector stays on (useDefault = true); the allowlist below only removes
# universal, non-secret false-positive patterns (doc placeholders and
# generated build artifacts).
# * Weekly org-wide audit (geolonia-operations/secret-leak-audit.yml): extends
# THIS file and additionally disables generic-api-key, which is dominated by
# history noise across full-history scans. That is a one-line delta, not a
# separate ruleset, so the rules and allowlist live here only.
# * A repo overrides everything by committing its own .betterleaks.toml.
#
# Editing rules:
# * Keep useDefault = true. This file holds ONLY universal, non-secret
# false-positive patterns: unmistakable documentation placeholders and
# generated build artifacts. Never allowlist a real secret; rotate and
# remove it instead.
# * Do NOT add project-specific token exceptions here, not even public,
# client-side tokens (for example a Mapbox pk. token). Those are a
# repo-level decision: the owning repo commits its own .betterleaks.toml so
# its maintainers own the exception and it is not granted org-wide. This
# file is public, so an org-wide token exception would also expose that
# decision (and often the value) to everyone.
# * Allowlists match against the captured Secret value unless regexTarget is
# set, so a regex should describe just the literal placeholder.

title = "Geolonia organization betterleaks baseline"

[extend]
useDefault = true

[[allowlists]]
description = "YOUR_API_KEY / YOUR-API-KEY / YOUR_TOKEN family (API docs templates)"
regexes = [
'''(?i)\bYOUR[-_](API[-_]?KEY|TOKEN|SECRET|CLIENT[-_]?(ID|SECRET))\b''',
]

[[allowlists]]
description = "Angle-bracket placeholders: <your-token>, <api-key>, <endpoint-url> (incl. Japanese)"
regexes = [
# Inner-char ranges: ASCII letter | Hiragana | Katakana | CJK Unified Ideographs
'''<[A-Za-z\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{4E00}-\x{9FFF}][^>]{1,60}>''',
]

[[allowlists]]
description = "Famous example UUIDs used in API docs"
regexes = [
'''(?i)550e8400-e29b-41d4-a716-446655440000''',
'''00000000-0000-0000-0000-000000000000''',
'''(?i)deadbeef-dead-beef-dead-beefdeadbeef''',
]

[[allowlists]]
description = "Standard placeholder words: REPLACE_ME / EXAMPLE / PLACEHOLDER / CHANGEME"
regexes = [
'''(?i)\b(REPLACE[-_]?ME|CHANGE[-_]?ME|PLACEHOLDER|EXAMPLE[-_]?(KEY|TOKEN|SECRET)?|FAKE[-_]?(KEY|TOKEN|SECRET)?|SAMPLE[-_]?(KEY|TOKEN|SECRET)?)\b''',
]

[[allowlists]]
description = "Obvious dev / test scaffold tokens (must include credential context)"
regexes = [
'''(?i)\bdev[-_]?local[-_]?token[-_]?please[-_]?change\b''',
'''(?i)\b(test|sample|dummy|dev|stub)[-_]?(token|key|secret|password)[-_]?(here|value)?\b''',
]

[[allowlists]]
description = "Truncated JWT placeholder in docs (eyJ... ending in literal '...' ellipsis)"
regexes = [
# Matches the docs convention of showing a JWT prefix followed by a
# literal three-dot ellipsis. Real JWTs are never written that way.
'''eyJ[A-Za-z0-9_\-]{8,}\.\.\.''',
]

[[allowlists]]
description = "Basic-auth label pair literal: client_id:client_secret"
regexes = [
# Appears in OAuth docs and test fixtures across the org as the
# `-u "client_id:client_secret"` curl flag or
# `Buffer.from('client-id:client-secret').toString('base64')` in
# tests. Real Basic-auth credentials are never the words themselves.
'''(?i)\bclient[-_]id:client[-_]secret\b''',
]

[[allowlists]]
description = "Minified bundles, source maps, and webpack bundle-stats output"
paths = [
# Content hashes inside generated build output get flagged as
# high-entropy tokens (sourcegraph-access-token in particular fires
# on 40-char hex SHA1s, which is exactly what webpack emits as
# content-addressing identifiers). We never hand-edit these files,
# so anything they contain is by definition not a hand-typed
# credential.
'''\.min\.js$''',
'''\.min\.js\.map$''',
'''\.min\.css$''',
'''\.min\.css\.map$''',
'''(?:^|/)bundle-stats\.json$''',
]
71 changes: 69 additions & 2 deletions .github/workflows/reusable-secret-leak-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ name: "[REUSABLE] Secret Leak Check"
# which catches what is already in main history. This reusable
# prevents new commits with secrets from getting in.
#
# Config resolution (centralized, mirrors reusable-pinact-check.yml):
# betterleaks reads its ruleset from a .betterleaks.toml. This workflow
# resolves one in priority order:
# 1. the `config-path` input, when a caller passes it explicitly;
# 2. a .betterleaks.toml (or .github/.betterleaks.toml) committed in the
# caller repo, auto-detected on the scanned ref;
# 3. the centralized baseline fetched from `config-repo` (default
# geolonia/.github), so org-wide allowlists live in ONE place;
# 4. betterleaks' built-in default ruleset, when none of the above apply.
# A repo customizes by committing its own file; it inherits org policy by
# committing nothing. This is the only per-repo knob that works when the
# suite is enforced by ruleset, since callers cannot pass workflow inputs then.
#
# Consumer wrapper (in any repo):
#
# name: Secret Leak Check
Expand All @@ -30,10 +43,20 @@ on:
required: false
default: true
config-path:
description: "Optional path to a .betterleaks.toml in the caller repo. When unset, the scan uses betterleaks' built-in default ruleset (every detector on). When set, the workflow passes it directly as --config. Use this to suppress documented false positives at the repo level."
description: "Highest-precedence config override: an explicit path to a .betterleaks.toml in the caller repo, passed directly as --config. Usually left unset; prefer committing a repo-root .betterleaks.toml (auto-detected) or inheriting the centralized baseline. See the config-resolution note in the header."
type: string
required: false
default: ""
config-repo:
description: "owner/repo to fetch the centralized .betterleaks.toml from when the caller repo ships none. Set empty to disable the fallback (betterleaks then uses its built-in defaults)."
type: string
required: false
default: "geolonia/.github"
config-ref:
description: "Git ref of the centralized .betterleaks.toml. Defaults to main so a policy change applies everywhere without bumping callers."
type: string
required: false
default: "main"
base-ref:
description: "Git ref to diff against. Defaults to the PR base. Override only when calling from a non-pull_request trigger."
type: string
Expand Down Expand Up @@ -104,14 +127,58 @@ jobs:
docker pull "${BETTERLEAKS_IMAGE}"
docker run --rm "${BETTERLEAKS_IMAGE}" version

- name: Resolve betterleaks config
id: config
env:
GH_TOKEN: ${{ github.token }}
CONFIG_PATH: ${{ inputs.config-path }}
CONFIG_REPO: ${{ inputs.config-repo }}
CONFIG_REF: ${{ inputs.config-ref }}
run: |
# Priority order (see the config-resolution note in the header):
# 1. explicit config-path input
# 2. repo-local .betterleaks.toml / .github/.betterleaks.toml
# 3. centralized baseline fetched from config-repo
# 4. betterleaks built-in defaults (no --config)
# The centralized file is written into the checkout so the scan's
# bind mount picks it up. It stays untracked, so it never appears in
# the PR diff the scan walks.
if [ -n "${CONFIG_PATH}" ]; then
if [ ! -f "${CONFIG_PATH}" ]; then
echo "::error::config-path '${CONFIG_PATH}' was set but no such file exists on the scanned ref."
exit 1
fi
echo "path=${CONFIG_PATH}" >> "$GITHUB_OUTPUT"
echo "::notice::Using caller-provided betterleaks config: ${CONFIG_PATH}"
elif [ -f .betterleaks.toml ]; then
echo "path=.betterleaks.toml" >> "$GITHUB_OUTPUT"
echo "::notice::Using this repo's own .betterleaks.toml."
elif [ -f .github/.betterleaks.toml ]; then
echo "path=.github/.betterleaks.toml" >> "$GITHUB_OUTPUT"
echo "::notice::Using this repo's own .github/.betterleaks.toml."
elif [ -n "${CONFIG_REPO}" ]; then
if gh api "repos/${CONFIG_REPO}/contents/.betterleaks.toml?ref=${CONFIG_REF}" \
-H "Accept: application/vnd.github.raw" > .betterleaks.toml 2>/dev/null && [ -s .betterleaks.toml ]; then
echo "path=.betterleaks.toml" >> "$GITHUB_OUTPUT"
echo "::notice::No .betterleaks.toml in this repo; using the centralized baseline from ${CONFIG_REPO}@${CONFIG_REF}."
else
rm -f .betterleaks.toml
echo "path=" >> "$GITHUB_OUTPUT"
echo "::warning::Could not fetch the centralized .betterleaks.toml from ${CONFIG_REPO}@${CONFIG_REF}; betterleaks will use built-in defaults."
fi
else
echo "path=" >> "$GITHUB_OUTPUT"
echo "::warning::No betterleaks config in this repo and the centralized fallback is disabled; betterleaks will use built-in defaults."
fi

- name: Run betterleaks on PR diff
id: scan
continue-on-error: true
env:
BETTERLEAKS_IMAGE: ${{ inputs.betterleaks-image }}
BASE_REF: ${{ steps.refs.outputs.base }}
HEAD_REF: ${{ steps.refs.outputs.head }}
CONFIG_PATH: ${{ inputs.config-path }}
CONFIG_PATH: ${{ steps.config.outputs.path }}
VALIDATE_SECRETS: ${{ inputs.validate-secrets }}
run: |
# Limit the scan to commits in the PR via --log-opts. The
Expand Down
20 changes: 13 additions & 7 deletions docs/github-actions-pinning.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ floor, so the extra day guarantees Dependabot PRs pass the check on arrival.
New repos created from the Backstage scaffolder get everything below out of the
box. For an existing repo:

1. Copy the canonical config from this repository's
[`pinact/`](https://github.com/geolonia/.github/tree/main/pinact) directory:
- `pinact/.pinact.yml` to your repo root as `.pinact.yml`
- `pinact/dependabot.yml` to `.github/dependabot.yml` (merge the
`github-actions` entry if you already have one)
1. Copy the canonical files from this repository:
- the repo-root
[`.pinact.yml`](https://github.com/geolonia/.github/blob/main/.pinact.yml)
to your repo root as `.pinact.yml`. This is optional: the Action Pinning
Check fetches this same file as its fallback when your repo has none, so
copy it only if you want to pin a local override.
- [`pinact/dependabot.yml`](https://github.com/geolonia/.github/blob/main/pinact/dependabot.yml)
to `.github/dependabot.yml` (merge the `github-actions` entry if you
already have one). This one is required: Dependabot only reads it in-repo.
- optional: `pinact/.pre-commit-config.example.yaml` to your repo root as
`.pre-commit-config.yaml` (auto-pins on every commit)
2. Add the **Action Pinning Check** workflow, either way:
Expand All @@ -75,7 +79,9 @@ box. For an existing repo:
## See also

- [Action Pinning Check reusable workflow](workflows/pinact-check.md)
- Canonical config to copy:
- Canonical config: the repo-root
[`.pinact.yml`](https://github.com/geolonia/.github/blob/main/.pinact.yml),
fetched as the Action Pinning Check fallback. Per-repo helpers live in
[`pinact/`](https://github.com/geolonia/.github/tree/main/pinact)
(`.pinact.yml`, `dependabot.yml`, `.pre-commit-config.example.yaml`).
(`dependabot.yml`, `.pre-commit-config.example.yaml`).
- [pinact](https://github.com/suzuki-shunsuke/pinact) upstream documentation.
31 changes: 18 additions & 13 deletions docs/workflows/pinact-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@ jobs:
uses: geolonia/.github/.github/workflows/reusable-pinact-check.yml@v1
```

## Required files
## Configuration files

Two files at the repo root, both copyable from `geolonia/.github`:
One file is required in the repo; the other is optional:

1. **`.pinact.yml`** (copy `pinact/.pinact.yml`): sets the minimum
release age (org default: 7 days, `min_age.value: 7`, `always: true`).
This is the GitHub Actions analog of pnpm's `minimumReleaseAge`: a new
tag is not adopted until it has survived a week, the window when a
hijacked-tag attack is most likely to still be live. The canonical
file exempts `geolonia/*` from the cooldown (we author our own
releases; the window guards against third-party tag hijacks) and is
still SHA-pinned.
2. **`.github/dependabot.yml`** (copy `pinact/dependabot.yml`) with a
1. **`.github/dependabot.yml`** (required, copy `pinact/dependabot.yml`) with a
`github-actions` ecosystem entry,
`cooldown: { default-days: 8 }`, and a `groups` block batching
minor/patch bumps into one PR while majors arrive individually.
Expand All @@ -50,7 +42,19 @@ Two files at the repo root, both copyable from `geolonia/.github`:
`min_age` of 7: Dependabot counts whole calendar days while pinact
enforces an exact 168h floor, so an 8-day cooldown guarantees a
Dependabot PR always clears the Action Pinning Check on arrival
instead of failing it for a few hours at the day boundary.
instead of failing it for a few hours at the day boundary. Dependabot
only reads this file in-repo, so it cannot come from the check's fallback.
2. **`.pinact.yml`** (optional, copy the repo-root
[`.pinact.yml`](https://github.com/geolonia/.github/blob/main/.pinact.yml)):
sets the minimum release age (org default: 7 days, `min_age.value: 7`,
`always: true`). This check fetches the same canonical file as its fallback
when your repo has none, so commit a local copy only to pin an override.
It is the GitHub Actions analog of pnpm's `minimumReleaseAge`: a new
tag is not adopted until it has survived a week, the window when a
hijacked-tag attack is most likely to still be live. The canonical
file exempts `geolonia/*` from the cooldown (we author our own
releases; the window guards against third-party tag hijacks) and is
still SHA-pinned.

## Check inputs

Expand All @@ -68,7 +72,8 @@ from `geolonia/.github` to `.pre-commit-config.yaml`, install pinact

## Enabling the check

1. Copy `.pinact.yml` and the Dependabot config (see "Required files" above).
1. Add `.github/dependabot.yml` (required); optionally add `.pinact.yml` (see
"Configuration files" above).
2. Open the repo on GitHub and go to **Actions -> New workflow**. Under
**By Geolonia**, pick **Action Pinning Check** and **Configure**.
3. Run `pinact run` once locally (or let the pre-commit hook do it) to
Expand Down
45 changes: 0 additions & 45 deletions pinact/.pinact.yml

This file was deleted.

0