Skip to content
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
- name: Validate pinned Rust toolchain alignment
run: pnpm ci:rust-toolchain:test && pnpm ci:rust-toolchain:check

- name: Validate the secret protection settings check
run: pnpm secrets:test

- name: Mainnet readiness matches the committed manifest (recorded fixture, no RPC, no secrets)
run: |
pnpm --filter @sub-rosa/sdk exec tsx scripts/mainnet-ready.ts --strict --fixture
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/secret-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Secret scan

on:
push:
branches: [main]
pull_request:

permissions:
# Lee el repo para escanear el historial y el arbol de trabajo. Escribe
# unicamente en code scanning (SARIF) para que los hallazgos se puedan
# revisar en la pestana Security. No hace push, ni comenta, ni publica.
contents: read
security-events: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
gitleaks:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
# Historial completo: el escaneo tiene que cubrir los commits que
# llegan a main, no solo el ultimo.
fetch-depth: 0

- name: Install gitleaks (version fijada + checksum verificado)
run: |
set -euo pipefail
version="v8.30.1"
archive="gitleaks_8.30.1_linux_x64.tar.gz"
curl -sSfL -o "$archive" "https://github.com/gitleaks/gitleaks/releases/download/${version}/${archive}"
curl -sSfL -o checksums.txt "https://github.com/gitleaks/gitleaks/releases/download/${version}/gitleaks_8.30.1_checksums.txt"
grep " ${archive}\$" checksums.txt | sha256sum --check --strict
tar -xzf "$archive" gitleaks
sudo install gitleaks /usr/local/bin/gitleaks
gitleaks version

- name: Scan history and working tree for secrets
run: |
set -euo pipefail
# --redact nunca imprime el valor detectado: ni en el log del job ni
# en el informe SARIF que se sube a code scanning.
gitleaks detect \
--source . \
--config .gitleaks.toml \
--redact \
--exit-code 1 \
--report-format sarif \
--report-path gitleaks.sarif

# En pull requests desde un fork GitHub degrada security-events: write a
# solo lectura, asi que la subida fallaria y marcaria en rojo un PR
# limpio. El escaneo sigue corriendo en todos los PR; el SARIF solo se
# publica cuando el token puede escribir (push a main o PR del mismo
# repositorio).
- name: Publish results to code scanning
if: >-
always() &&
(github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name == github.repository)
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: gitleaks.sarif
category: secret-scan
35 changes: 35 additions & 0 deletions .gitleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2026 Sub Rosa contributors
#
# Configuracion de gitleaks para el gate de escaneo de secretos.
#
# Se mantienen las reglas por defecto de gitleaks (proveedores + patrones
# genericos) y solo se permite una lista blanca minima para los valores que
# NO son credenciales:
#
# - IDs de contrato Stellar (C...), IDs de cuenta (G...) y hashes SHA-256
# que aparecen en fixtures, artefactos de mainnet y trazas de demo.
#
# La lista blanca combina `paths` (los ficheros concretos) con `regexes` (las
# formas de valor). Un credencial real en esos mismos ficheros no encaja en
# ninguna de esas formas, asi que sigue saltando la alerta.

title = "Sub Rosa secret scanning configuration"

[extend]
useDefault = true

[[allowlists]]
description = "Public Stellar identifiers and hashes used by fixtures, artifacts and demo traces (not credentials)"
paths = [
'''^apps/web/\.env\.example$''',
'''^apps/web/src/demo/demo-trace\.generated\.ts$''',
'''^apps/web/src/lib/config\.test\.ts$''',
'''^packages/sdk/fixtures/mainnet-readiness\.json$''',
'''^packages/sdk/mainnet-artifacts\.json$''',
'''^packages/sdk/src/mainnet-readiness\.test\.ts$''',
]
regexes = [
'''\bC[A-Z2-7]{55}\b''',
'''\bG[A-Z2-7]{55}\b''',
'''\b[0-9a-f]{64}\b''',
]
144 changes: 144 additions & 0 deletions docs/SECRET_PROTECTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Secret protection

This repository treats leaked credentials as a first-class incident. Two
independent layers keep them out:

1. **Repository settings on GitHub** — secret scanning, push protection,
non-provider pattern detection and validity checks. These live in GitHub's
configuration for the repository, not in the tree, so they cannot be
committed; they are verified with a script (see below).
2. **An in-repo CI gate** — `.github/workflows/secret-scan.yml` scans the
history and the working tree with gitleaks on every push to `main` and on
every incoming pull request.

The two layers fail differently on purpose: the settings stop a credential
before it lands in the history, and the CI gate stops it from landing in a
merge.

## Settings that must be enabled

| Setting | `security_and_analysis` field | Required |
| --- | --- | --- |
| Secret scanning | `secret_scanning` | yes |
| Push protection | `secret_scanning_push_protection` | yes |
| Non-provider pattern detection | `secret_scanning_non_provider_patterns` | where available |
| Validity checks | `secret_scanning_validity_checks` | where available |

The last two depend on what the repository's plan exposes. The API omits the
fields it does not offer, and this repository treats "not offered" as
"nothing to enable" — but it never treats "offered and off" as acceptable.

## Enabling them (repository admin)

In the web UI: **Settings → Code security and analysis → Secret scanning →
Enable**, and the same for **Push protection**.

From the command line, with a token that has **Administration: write** on the
repository:

```bash
export GITHUB_TOKEN=<token with Administration: write>
pnpm secrets:enable
```

`pnpm secrets:enable` runs `node scripts/check-secret-protection.mjs --enable`,
which enables one protection per request, ignores the ones the API reports as
unavailable (HTTP 422) and then re-reads the settings so the result is shown
from the API rather than from the request that was sent.

## Verifying them

```bash
export GITHUB_TOKEN=<token with Administration: read>
pnpm secrets:check
```

Expected output (one line per protection, then a summary):

```
[PASS] Secret scanning (secret_scanning) — enabled
[PASS] Push protection (secret_scanning_push_protection) — enabled
[PASS] Non-provider pattern detection (secret_scanning_non_provider_patterns) — enabled
[PASS] Validity checks (secret_scanning_validity_checks) — enabled
PASS: secret protection is enabled for Sub-Rosa-Issue/sub-rosa-issue
```

The command exits non-zero when a protection is disabled, when a required
protection is not reported by the API (usually a token without
**Administration: read**), or when the API call fails. `--json` prints the
same result as a single machine-readable line.

## What each protection covers

| Protection | Scope |
| --- | --- |
| Secret scanning | Scans the history of the default branch and every new push, and opens one alert per detected credential. |
| Push protection | Blocks a push that would introduce a credential — on any branch, including the branch behind an incoming pull request — and lets an admin review or override the block. |
| Non-provider pattern detection | Adds patterns for credentials that have no provider partner (generic API keys, private keys, and similar). |
| Validity checks | Marks each alert as active, inactive or unknown, so a live credential can be told apart from a revoked one. |

Because push protection blocks the push itself, it protects `main` and every
incoming pull request before the code is merged. Secret scanning then covers
what is already in the history.

## The CI gate

`.github/workflows/secret-scan.yml` runs on pushes to `main` and on pull
requests, and:

- downloads a pinned gitleaks release and verifies it against the published
checksum before running it;
- scans the full history and the working tree with the default gitleaks rule
set, so provider patterns and generic patterns are both covered;
- runs with `--redact`, so no secret value is ever written to the job log or
to the SARIF report that gets uploaded to code scanning — reviewers see the
rule, the file and the line, never the value;
- uploads the SARIF results to code scanning, so the findings show up in
the repository's **Security** tab like native secret scanning alerts. For a
pull request from a fork the token is read-only, so the upload is skipped
there (the scan itself still runs and still fails on a finding); this keeps
a clean fork PR from failing on a permission error.

`.gitleaks.toml` keeps the default rules and allowlists only the values in
this repository that look like credentials but are not: Stellar contract IDs
(`C…`), Stellar account IDs (`G…`) and SHA-256 hashes in fixtures, mainnet
artifacts and demo traces. The allowlist pairs those file paths with those
value shapes, so a real credential dropped into one of those files does not
match it and still fails the job.

## Reviewing alerts without exposing values

- Review alerts in **Security → Secret scanning**. Do not copy the value into
an issue, a pull request, a comment or a log.
- To list alerts from the API without the literal secret in the response:
`gh api "repos/OWNER/REPO/secret-scanning/alerts?hide_secret=true"`.
- When an alert turns out to be a real credential: revoke or rotate it first,
then resolve the alert as `revoked`. Resolve non-credentials as
`false_positive` (or `used_in_tests` when they are test values).
- Record the alert number, the secret type and the location — never the value.

## Result of the initial scan

The initial scan of the complete history reachable from `main` at the time of
writing (403 commits) with the rules used by the CI gate found no credential.
The only matches were `generic-api-key` hits on public, non-secret values — Stellar contract IDs,
Stellar account IDs and SHA-256 hashes — in fixtures, mainnet artifacts and
demo traces. Those are exactly the values allowlisted in `.gitleaks.toml`, so
no rotation and no history rewrite are needed.

Native GitHub secret scanning will raise its own alerts for the same values,
because they look like high-entropy strings to a generic pattern. They can be
resolved as false positives; their values are public on-chain identifiers, but
they still do not belong in an issue or a comment.

## Commands

| Command | What it does |
| --- | --- |
| `pnpm secrets:check` | Read the repository settings and report every protection |
| `pnpm secrets:enable` | Enable the settings (needs **Administration: write**) |
| `pnpm secrets:test` | Unit tests for the check/enable script |

See also [CI and quality gates](./CI.md) for the rest of the automated checks
and [DEPLOY.md](./DEPLOY.md) for how runtime secrets are handled in the
deployed app.
1 change: 1 addition & 0 deletions scripts/check-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const FILES = [
'docs/THREAT_MODEL.md',
'docs/DEPLOY.md',
'docs/DEMO_SCRIPT.md',
'docs/SECRET_PROTECTION.md',
'docs/INTEGRATION.md',
'docs/RECEIPTS.md',
'docs/SCF_TRANCHE_PLAN.md',
Expand Down
Loading