Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
41 changes: 30 additions & 11 deletions .github/workflows/launchpad-security-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ name: launchpad — security audit
# matching. Off the hour to avoid GitHub's top-of-hour queue.
# workflow_dispatch manual reruns, and the mechanism used to capture the
# self-test evidence this task's PR links to.
# pull_request filtered to the paths the audit can actually be affected
# by — the audit scripts themselves, any workflow, and
# .gitignore, which the (future) ignore-coverage check
# reads. Unfiltered would run on every unrelated PR for no
# benefit; too narrow risks a check landing that no PR
# trigger ever exercises.
# pull_request UNFILTERED by path as of #67. #66 scoped this to
# ".github/**"/"launchpad/**"/".gitignore" because no
# check existed yet that cared about anything else.
# #67's secret scan has to see every file a PR touches —
# a leaked credential is exactly as real in crates/ or
# desktop/ as it is here — so a path filter narrow
# enough to be cheap is also narrow enough to miss the
# one thing this check exists to catch.
on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch: {}
pull_request:
paths:
- ".github/**"
- "launchpad/**"
- "**/.gitignore"
pull_request: {}

# Read-only, and nothing more. No repository secret is referenced anywhere in
# this file — a check that needed one would be a check this workflow cannot run
Expand All @@ -47,6 +45,27 @@ jobs:
persist-credentials: false
fetch-depth: 0

# Pinned to a specific release and verified against gitleaks' own
# published checksum before extraction — this is the one third-party
# binary this workflow trusts, and it never runs with any credential
# in scope, so a supply-chain compromise here still cannot reach a
# secret. No gitleaks-maintained Action is used, to keep this
# workflow's trust surface to "one pinned, checksummed binary" rather
# than a third party's Action code at whatever version they push next.
- name: Install gitleaks (pinned, checksum-verified)
env:
GITLEAKS_VERSION: "8.30.1"
GITLEAKS_SHA256: "551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb"
run: |
set -euo pipefail
curl -fsSL -o gitleaks.tar.gz \
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
echo "${GITLEAKS_SHA256} gitleaks.tar.gz" | sha256sum -c -
tar -xzf gitleaks.tar.gz gitleaks
sudo install -m 0755 gitleaks /usr/local/bin/gitleaks
rm gitleaks.tar.gz gitleaks
gitleaks version

# The harness's own controls, scoped to this task's tests only — the
# unfiltered `unittest discover` other launchpad-*.yml checks use would
# also run every unrelated script's test suite in this directory, which
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ doc/
identity.key
**/identity.key

# Key/cert material — #68 asserts these stay covered, regardless of shape
*.pem
*.key
id_rsa
id_ed25519

# Claude Code worktrees
.claude/worktrees/

Expand Down
125 changes: 125 additions & 0 deletions .gitleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
title = "launchpad-26/buzz secret-scanning config"

# Engine and allowlist location decided in ADR-0006 (launchpad/decisions/).
# Extends gitleaks' built-in ruleset rather than replacing it — SSH private
# keys, GitHub PATs and generic high-entropy .env-shaped assignments are
# already covered by the default rules (verified empirically against the
# fixtures in launchpad/scripts/security_audit_fixtures/secrets/ before this
# file was written). The rules below cover only what the default ruleset
# does not: Nostr key material, glibc crypt hashes, this fork's BUZZ_S3_*
# naming, and a Postgres URL with an embedded password.

[extend]
useDefault = true

[[rules]]
id = "nostr-nsec-private-key"
description = "Nostr nsec1 bech32-encoded private key"
regex = '''nsec1[023456789acdefghjklmnpqrstuvwxyz]{58}'''
tags = ["key", "nostr"]

[[rules]]
id = "buzz-private-key"
description = "BUZZ_PRIVATE_KEY or a similarly-named 64-hex-character private key assignment"
# Every group below is non-capturing (?:...). A capturing group here silently
# drops the finding entirely once [extend] useDefault = true merges in
# gitleaks' default ruleset — reproduced and isolated empirically before this
# file was written (a bare (a|b) group matches standalone but reports zero
# leaks the moment useDefault is active; (?:a|b) is unaffected). No known
# gitleaks issue was found describing this, so treat every future rule here
# the same way: no capturing groups, ever, unless secretGroup is set to use one.
#
# The key/separator segment accepts an optional closing quote before `:` or
# `=` — found missing by #68's own agent-surface fixtures, which are JSON
# (`"BUZZ_PRIVATE_KEY": "..."`), not `.env`-shaped (`BUZZ_PRIVATE_KEY=...`).
# A `.env` file has no key-side quote to close, so the `['"]?` before the
# separator is optional, not required, and both forms still match.
regex = '''(?i)[A-Z0-9_]*(?:PRIVATE_KEY|NSEC|SECKEY)[A-Z0-9_]*['"]?\s*[:=]\s*['"]?[0-9a-fA-F]{64}['"]?'''
tags = ["key", "nostr"]

[[rules]]
id = "glibc-crypt-hash"
# $1/$5/$6 optionally carry a rounds=N$ parameter before the salt; $y$
# (yescrypt) carries its own short encoded parameter block instead. Both
# shapes are one or two extra $-delimited segments before the final hash, so
# the middle is a repeated group rather than a fixed salt-then-hash count.
description = "glibc/Unix crypt hash ($1$, $5$, $6$, or $y$)"
regex = '''\$(?:1|5|6|y)\$(?:[./A-Za-z0-9=]+\$){1,2}[./A-Za-z0-9]{20,}'''
tags = ["password", "crypt"]

[[rules]]
id = "buzz-s3-minio-key"
description = "BUZZ_S3_ACCESS_KEY or BUZZ_S3_SECRET_KEY assignment"
# {6,} on the value, not \S+: launchpad/deploy/archived/runbooks/dev-deployment-SOP.md
# documents these as a markdown table cell, `` `BUZZ_S3_ACCESS_KEY=` ``, where the
# character immediately after = is a bare backtick — \S+ matched that one
# punctuation character as if it were a credential. Requiring a real value
# shape excludes it without an allowlist entry, and still matches every
# fixture and every real assignment this rule exists for.
# `['"]?` before the separator and `[:=]` instead of a bare `=`: same JSON-vs-
# .env gap #68's fixtures found on buzz-private-key, above — applied here too
# for the same reason, even though no fixture has yet forced this one.
regex = '''BUZZ_S3_(?:ACCESS|SECRET)_KEY['"]?\s*[:=]\s*['"]?[A-Za-z0-9_\-]{6,}['"]?'''
tags = ["key", "s3", "minio"]
# .env.example is, by repository-wide convention, entirely placeholder
# values meant to be copied and replaced — verified against .env.example
# and deploy/compose/.env.example, both CHANGE_ME-or-dev-value templates,
# never a deployed .env. Scoped to that one filename shape, not the repo.
[rules.allowlist]
paths = ['''.*\.env\.example$''']

[[rules]]
id = "postgres-url-with-password"
description = "Postgres connection URL with an embedded password"
regex = '''postgres(?:ql)?://[^:@/\s]+:[^@\s]+@[^\s]+'''
tags = ["password", "postgres"]
# The overwhelming majority of matches on this codebase are the standard
# local dev/test credential postgres://buzz:buzz_dev@localhost:5432/buzz
# (verified: scripts/run-tests.sh, crates/buzz-db/src/usage.rs, and ~100
# more files as of the first full-history scan run for #67) — a local-only
# connection string is not a production credential regardless of what the
# password looks like. Scoped to the host being loopback, not to any file
# or the value itself, so a real leaked URL pointed at a real host still
# fires. scripts/run-tests.sh already marks this same string
# `# sadscan:disable np.postgres.1` for a different, Block-internal
# scanner; this is gitleaks' equivalent for the same known-safe value.
[rules.allowlist]
regexes = ['''postgres(?:ql)?://[^:@/\s]+:[^@\s]+@(?:localhost|127\.0\.0\.1)(?::\d+)?/''']

# Fixtures prove every rule above fires (#67's own definition of done) and
# must therefore be readable by the scanner, but must never themselves be
# reported as a finding of the live audit — they are synthetic, not leaked.
#
# #67 as filed named two placeholders in dev-deployment-SOP.md (an
# ssh-ed25519 public-key fragment at a since-renumbered line, and a $6$
# prefix mentioned in prose) as needing an exclusion. Verified against the
# file's current content and location
# (launchpad/deploy/archived/runbooks/dev-deployment-SOP.md — moved out of
# launchpad/deploy/ entirely by the deploy-method archival that landed after
# #67 was filed): neither of those two strings matches any rule in this
# config any more, so neither needs an entry here. What the file's current
# content does trip is `<64 hex characters>` — a literal bracketed
# placeholder idiom this SOP uses for "a value goes here", not a value
# itself — via gitleaks' own default generic-api-key rule.
[allowlist]
description = "Paths this scan reads but never reports on, and one documentation placeholder idiom"
paths = [
'''launchpad/scripts/security_audit_fixtures/secrets/.*''',
# Same class of false positive .intersect/sadscan.yaml already documents
# for this exact file ("Cargo registry checksums are integrity hashes
# generated by Cargo, not payment data") — here it trips gitleaks'
# generic-api-key entropy heuristic instead of sadscan's payment-card
# rule, but the underlying content and reasoning are the same. Verified
# present in both Cargo.lock files in this repo (root and
# desktop/src-tauri/) — one finding each, both checksum data.
'''(^|/)Cargo\.lock$''',
]
regexes = [
'''<[A-Za-z0-9 ]+>''',
# dev-deployment-SOP.md:1079's worked-example "Public key:" value — a
# fixed, literal walkthrough value, explicitly labelled public (not the
# $6$/secret-key output on adjacent lines, which stay placeholder text
# and trip nothing). Matched literally, not by shape, so this entry
# cannot accidentally swallow any other 64-hex string anywhere else.
'''38980a43aba04331ba61b5e7b64b90e250cd411d042050eaf102a408acc6c379''',
]
38 changes: 38 additions & 0 deletions launchpad/scripts/security_audit_agent_surface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""The agent-configuration surface, in one place, for #68 and any future check
that needs the same list.

**Adding a new agent tool means adding one entry here** — a new directory (a
fifth `.<tool>/` convention) or a new config filename shape (a fifth kind of
persona/plugin/MCP file). Nothing else in #68's check needs to change.

Two kinds of surface, because they show up differently in the tree:

AGENT_SURFACE_DIRS top-level dotdirs a specific agent tool owns.
Scanned whole — anything under one of these is
in scope, regardless of filename.
AGENT_CONFIG_FILE_GLOBS filename shapes an agent pack uses wherever it
lives (e.g. `launchpad/agents/the-professor/`,
not under any `.{tool}/` directory at all) —
matched by glob across the whole repository.
"""

from __future__ import annotations

#: Top-level directories a specific agent tool owns. Verified present at repo
#: root as of #68 (each currently holds only a `skills/` subtree, but that is
#: not asserted here — the whole directory is in scope, not just what it
#: happens to contain today).
AGENT_SURFACE_DIRS = [
".claude",
".codex",
".goose",
".agents",
]

#: Filename shapes an agent/persona pack uses, wherever in the repository it
#: lives. Glob patterns, matched with `Path.rglob` from the repo root.
AGENT_CONFIG_FILE_GLOBS = [
"**/.mcp.json",
"**/*.persona.md",
"**/plugin.json",
]
137 changes: 137 additions & 0 deletions launchpad/scripts/security_audit_agent_surface_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
"""Agent-configuration-surface check for #68.

Scans the agent-surface directories and config-file shapes defined in
`security_audit_agent_surface.py` for credential-shaped strings — reusing
#67's gitleaks ruleset (`.gitleaks.toml`) rather than a second pattern set,
per this task's own definition of done. This is a present-tense content
check (what does the surface carry *today*), not a history scan — #67 already
owns history; this check exists because the agent-surface directories are a
distinct, growing part of the tree a contributor or an agent itself might
populate with a real credential (a live API key dropped into an MCP config
for local testing, for instance) that #67's PR-diff scan would only catch if
the addition happened inside a PR gitleaks actually ran on.

Never prints a matched value — same discipline as #67's check, and the same
`--redact` flag on every gitleaks invocation.
"""

from __future__ import annotations

import json
import subprocess
from pathlib import Path
from typing import List, Optional, Tuple

from security_audit_agent_surface import AGENT_CONFIG_FILE_GLOBS, AGENT_SURFACE_DIRS
from security_audit_core import CheckResult, Status

NAME = "agent-surface-secret-scan"
GITLEAKS_CONFIG = ".gitleaks.toml"
_TIMEOUT_SECONDS = 60


def _collect_surface_paths(repo_root: Path) -> List[Path]:
"""Every file under an AGENT_SURFACE_DIRS directory, plus every file
matching an AGENT_CONFIG_FILE_GLOBS shape anywhere in the repo. A set,
not a list, so a file matched both ways (a persona.md inside .claude/,
say) is scanned once.
"""
paths: set[Path] = set()
for dir_name in AGENT_SURFACE_DIRS:
directory = repo_root / dir_name
if directory.is_dir():
paths.update(p for p in directory.rglob("*") if p.is_file())
for glob_pattern in AGENT_CONFIG_FILE_GLOBS:
paths.update(p for p in repo_root.glob(glob_pattern) if p.is_file())
return sorted(paths)


def _summarize(findings: List[dict], repo_root: Path, limit: int = 8) -> str:
"""file:line (rule-id), repo-relative, never the matched value."""
locations = set()
for f in findings:
try:
rel = Path(f.get("File", "?")).relative_to(repo_root)
except ValueError:
rel = f.get("File", "?")
locations.add(f"{rel}:{f.get('StartLine', '?')} ({f.get('RuleID', '?')})")
shown = sorted(locations)
text = ", ".join(shown[:limit])
if len(shown) > limit:
text += f", and {len(shown) - limit} more"
return text


def _run_gitleaks_no_git(
repo_root: Path, source_paths: List[Path]
) -> Tuple[Optional[List[dict]], Optional[str]]:
config_path = repo_root / GITLEAKS_CONFIG
if not config_path.is_file():
return None, f"{GITLEAKS_CONFIG} not found at {config_path}"
if not source_paths:
return [], None

findings: List[dict] = []
for path in source_paths:
cmd = [
"gitleaks",
"detect",
"--no-git",
"--source",
str(path),
"--config",
str(config_path),
"--report-format",
"json",
"--report-path",
"-",
"--redact",
"--no-banner",
]
try:
result = subprocess.run(
cmd,
cwd=repo_root,
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
timeout=_TIMEOUT_SECONDS,
)
except FileNotFoundError:
return None, "gitleaks is not installed or not on PATH"
except subprocess.TimeoutExpired:
return None, f"gitleaks did not finish within {_TIMEOUT_SECONDS}s scanning {path}"
except OSError as exc:
return None, f"could not run gitleaks on {path}: {exc}"

if result.returncode not in (0, 1):
stderr = (result.stderr or "").strip()[-500:]
return None, f"gitleaks exited {result.returncode} on {path}: {stderr}"

try:
file_findings = json.loads(result.stdout) if result.stdout.strip() else []
except json.JSONDecodeError as exc:
return None, f"could not parse gitleaks report for {path}: {exc}"
findings.extend(file_findings)

return findings, None


def run(repo_root: Path) -> CheckResult:
surface_paths = _collect_surface_paths(repo_root)
findings, error = _run_gitleaks_no_git(repo_root, surface_paths)
if error is not None:
return CheckResult(NAME, Status.INDETERMINATE, error)
if findings:
return CheckResult(
NAME,
Status.FAIL,
f"{len(findings)} finding(s) on the agent-config surface: "
+ _summarize(findings, repo_root),
)
return CheckResult(
NAME,
Status.PASS,
f"no credential-shaped strings found across {len(surface_paths)} agent-surface file(s)",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Fixture for #67. Synthetic (not derived from any real password/host) glibc
# crypt hashes, shaped correctly for the $6$ (SHA-512 crypt) and $y$
# (yescrypt) rules. Excluded from the audit's scan path in .gitleaks.toml.
SIX=$6$rounds=656000$Zq7wYkT2fixtureSalt$k4h2mNtQpXz9r1sJd8vLwYbGcHfEeUoAiSm3NkTpQrXyLzAaVbCcDdFfGgHhIiJjKkLlMm
Y=$y$j9T$fixtureSaltForY$K7pQmR9xTvLnZaWbCcDdEeFfGgHhIiJjKkLlMmNn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Fixture for #67. A .env-shaped file with a real-looking (synthetic) secret
# value, to prove an .env-shaped assignment rule fires on file shape, not
# just on specific known variable names. Excluded from the audit's scan path
# in .gitleaks.toml.
SOME_SERVICE_API_TOKEN=fx_9Kj2mNpQr7VbXzYcWdEeFfGgHhIiJjKkLlMmNnOoPp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Fixture for #67. Synthetic Nostr key material — a bech32 nsec shape and a
# 64-hex private-key shape, including the BUZZ_PRIVATE_KEY env-var name this
# fork uses. None of these decode to or were ever a real key. Excluded from
# the audit's scan path in .gitleaks.toml.
RELAY_OWNER_NSEC=nsec180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6
BUZZ_PRIVATE_KEY=4c9f2e8a1b6d3f705e9c8a2b7d4f1e6c3a9b8d5f2e7c4a1b6d9f3e8c5a2b7d4f
BARE_HEX_KEY=9a3f7c2e5b8d1f4a6c9e2b5d8f1a4c7e9b2d5f8a1c4e7b9d2f5a8c1e4b7d9f2a
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Fixture for #67. A synthetic Postgres connection URL with an embedded
# password, matching the shape deploy/compose's POSTGRES_* variables could
# be assembled into. Excluded from the audit's scan path in .gitleaks.toml.
DATABASE_URL=postgres://buzzuser:fx7Kj2mNpQr7VbXzYcWd@db.internal:5432/buzz
Loading
Loading