Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Gate desktop signing secrets behind a main-only environment (#5711)
Nick Gomezc7078b6a6819
diff --git a/.github/scripts/cache-mode-shape.test.mjs b/.github/scripts/cache-mode-shape.test.mjsindex 1c8964eb3..29df7ab56 100644--- a/.github/scripts/cache-mode-shape.test.mjs+++ b/.github/scripts/cache-mode-shape.test.mjs@@ -338,6 +338,10 @@ describe('cache-mode sweep self-tests', () => {{ permissions: {}, steps: [{ run: '${{ toJSON(secrets) }}' }] },],'an indexed secret': [{}, { permissions: {}, steps: [{ run: "${{ secrets['PAT'] }}" }] }],+ 'the secrets context in another casing': [+ {},+ { permissions: {}, steps: [{ run: '${{ SECRETS.pat }}' }] },+ ],'a secret in a bare if': [{},{ permissions: {}, steps: [{ if: "secrets.PAT != ''", run: 'true' }] },@@ -372,6 +376,13 @@ describe('cache-mode sweep self-tests', () => {steps: [{ env: { GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}' } }],},],+ 'GITHUB_TOKEN in another casing': [+ {},+ {+ permissions: { contents: 'read' },+ steps: [{ env: { GH_TOKEN: '${{ Secrets.github_token }}' } }],+ },+ ],'github.token': [{},{diff --git a/.github/scripts/release-signing-environment-shape.test.mjs b/.github/scripts/release-signing-environment-shape.test.mjsnew file mode 100644index 000000000..0aa989afb--- /dev/null+++ b/.github/scripts/release-signing-environment-shape.test.mjs@@ -0,0 +1,194 @@+// biome-ignore-all lint/suspicious/noTemplateCurlyInString: GitHub expression fixtures must remain literal.+import { readdirSync, readFileSync } from 'node:fs';+import { dirname, join } from 'node:path';+import { fileURLToPath } from 'node:url';+import { describe, expect, test } from 'vitest';+import { parse } from 'yaml';+import { credentialReasons } from './workflow-credentials.test-helper.mjs';++const WORKFLOWS = join(dirname(fileURLToPath(import.meta.url)), '..', 'workflows');+const RELEASE_SIGNING_SECRETS = [+ 'APPLE_API_ISSUER',+ 'APPLE_API_KEY',+ 'APPLE_API_KEY_ID',+ 'APPLE_APP_SPECIFIC_PASSWORD',+ 'APPLE_ID',+ 'APPLE_TEAM_ID',+ 'AZURE_CLIENT_ID',+ 'AZURE_CLIENT_SECRET',+ 'AZURE_TENANT_ID',+ 'CSC_KEY_PASSWORD',+ 'CSC_LINK',+];+const OTHER_SECRETS = [+ 'DISCORD_NOTIFY_TOKEN',+ 'DISCORD_NOTIFY_URL',+ 'DISCORD_WEBHOOK_URL',+ 'INTERNAL_CI_APP_PRIVATE_KEY',+ 'LINEAR_ACCESS_KEY',+ 'LINEAR_API_KEY',+ 'LINUX_REPO_GPG_PRIVATE_KEY',+ 'LINUX_REPO_R2_ACCESS_KEY_ID',+ 'LINUX_REPO_R2_ENDPOINT',+ 'LINUX_REPO_R2_SECRET_ACCESS_KEY',+ 'OK_RELEASE_BRIDGE_APP_ID',+ 'OK_RELEASE_BRIDGE_APP_PRIVATE_KEY',+ 'OSS_SYNC_APP_ID',+ 'OSS_SYNC_APP_PRIVATE_KEY',+ 'SLACK_RELEASES_WEBHOOK_URL',+ 'SLACK_WEBHOOK_URL',+];+const SIGNING_ENVIRONMENT = 'release-signing';+const OTHER_ENVIRONMENTS = ['inkeep-oss-sync'];+const MAIN_ONLY = "${{ github.ref == 'refs/heads/main' && 'release-signing' || '' }}";+const EXPECTED = {+ 'desktop-build-win-linux.yml#build-windows': MAIN_ONLY,+ 'desktop-build.yml#build-macos-dmg': MAIN_ONLY,+ 'desktop-release.yml#build-macos': SIGNING_ENVIRONMENT,+ 'desktop-release.yml#build-windows': SIGNING_ENVIRONMENT,+};+const WHOLE_CONTEXT = '*';+const SECRET_READ = /(?<![\w.-])secrets\b(?:\s*\.\s*([A-Za-z_][\w-]*)|\s*\[\s*'([^']*)'\s*\])?/gi;++const JOBS = readdirSync(WORKFLOWS)+ .filter((name) => /\.ya?ml$/.test(name))+ .sort()+ .flatMap((name) => {+ const workflow = parse(readFileSync(join(WORKFLOWS, name), 'utf8'));+ return Object.entries(workflow?.jobs ?? {}).map(([id, job]) => ({+ key: `${name}#${id}`,+ workflow,+ job,+ }));+ });++function secretReads(workflow, job) {+ const reads = [];+ for (const reason of credentialReasons(workflow, job)) {+ if (reason === 'secrets: inherit') reads.push(WHOLE_CONTEXT);+ if (!reason.startsWith('secret: ')) continue;+ for (const [, dotted, indexed] of reason.slice('secret: '.length).matchAll(SECRET_READ)) {+ const name = (dotted ?? indexed)?.toUpperCase() ?? WHOLE_CONTEXT;+ if (name !== 'GITHUB_TOKEN') reads.push(name);+ }+ }+ return reads;+}++const isSigningRead = (name) => name === WHOLE_CONTEXT || RELEASE_SIGNING_SECRETS.includes(name);++function environmentProblem(key, environment) {+ if (Object.hasOwn(EXPECTED, key)) {+ return environment === EXPECTED[key]+ ? null+ : `${key} must request environment ${EXPECTED[key]}, found ${JSON.stringify(environment)}`;+ }+ if (environment === undefined) return null;+ const name = typeof environment === 'string' ? environment : environment?.name;+ if (typeof name !== 'string' || name.includes('${{')) {+ return `${key} computes its environment name; only the two QA signing jobs may`;+ }+ return OTHER_ENVIRONMENTS.includes(name.toLowerCase())+ ? null+ : `${key} requests environment ${name}, which is not in OTHER_ENVIRONMENTS`;+}++function contractProblems(entries) {+ const problems = [];+ const signingReaders = [];+ for (const { key, workflow, job } of entries) {+ const reads = secretReads(workflow, job);+ for (const name of reads) {+ if (!isSigningRead(name) && !OTHER_SECRETS.includes(name)) {+ problems.push(+ `${key} reads secret ${name}, which is in neither RELEASE_SIGNING_SECRETS nor OTHER_SECRETS; classify it`,+ );+ }+ }+ if (reads.some(isSigningRead)) signingReaders.push(key);+ const environment = environmentProblem(key, job.environment);+ if (environment) problems.push(environment);+ }+ const expected = Object.keys(EXPECTED).sort();+ const readers = signingReaders.sort();+ if (readers.join('\n') !== expected.join('\n')) {+ problems.push(+ `jobs reading a release-signing secret are [${readers.join(', ')}]; expected exactly [${expected.join(', ')}]`,+ );+ }+ return problems;+}++const withJob = (job, workflow = {}) => [...JOBS, { key: 'fixture.yml#probe', workflow, job }];+const step = (run) => ({ steps: [{ run }] });++describe('release-signing environment', () => {+ test('every OK workflow job meets the release-signing contract', () => {+ expect(contractProblems(JOBS)).toEqual([]);+ });++ test('reordered jobs keep the contract and a membership change still breaks it', () => {+ const reordered = [...JOBS].reverse();+ expect(contractProblems(reordered)).toEqual([]);+ expect(+ contractProblems(reordered.filter(({ key }) => key !== 'desktop-release.yml#build-macos')),+ ).toContainEqual(expect.stringContaining('jobs reading'));+ });++ test('the secret lists are disjoint and no other environment is release-signing', () => {+ expect(RELEASE_SIGNING_SECRETS.filter((name) => OTHER_SECRETS.includes(name))).toEqual([]);+ expect(OTHER_ENVIRONMENTS.map((name) => name.toLowerCase())).not.toContain(SIGNING_ENVIRONMENT);+ });++ test.each([+ ['an indexed signing secret', withJob(step("${{ secrets['CSC_LINK'] }}")), 'jobs reading'],+ [+ 'a signing secret in another casing',+ withJob(step('${{ SECRETS.csc_link }}')),+ 'jobs reading',+ ],+ ['the whole secrets context', withJob(step('${{ toJSON(secrets) }}')), 'jobs reading'],+ [+ 'a computed secret index',+ withJob(step("${{ secrets[format('{0}_LINK', 'CSC')] }}")),+ 'jobs reading',+ ],+ [+ 'inherited secrets',+ withJob({ uses: './.github/workflows/x.yml', secrets: 'inherit' }),+ 'jobs reading',+ ],+ [+ 'a workflow-level signing read',+ withJob({ steps: [] }, { env: { K: '${{ secrets.CSC_LINK }}' } }),+ 'jobs reading',+ ],+ ['an unclassified secret', withJob(step('${{ secrets.NEW_SIGNING_KEY }}')), 'classify it'],+ [+ 'a computed environment name',+ withJob({ environment: '${{ vars.SIGNING_ENV }}', steps: [] }),+ 'computes its environment name',+ ],+ [+ 'a computed environment object name',+ withJob({ environment: { name: '${{ vars.SIGNING_ENV }}' }, steps: [] }),+ 'computes its environment name',+ ],+ [+ 'release-signing in another casing',+ withJob({ environment: 'Release-Signing', steps: [] }),+ 'not in OTHER_ENVIRONMENTS',+ ],+ ])('a fabricated job using %s breaks the contract', (_form, entries, problem) => {+ expect(contractProblems(entries)).toContainEqual(expect.stringContaining(problem));+ });++ test.each([+ ['GITHUB_TOKEN in another casing', withJob(step('${{ Secrets.github_token }}'))],+ ['a classified non-signing secret', withJob(step("${{ secrets['SLACK_WEBHOOK_URL'] }}"))],+ ['a property named secrets on another context', withJob(step('${{ inputs.secrets }}'))],+ ['an allowlisted environment', withJob({ environment: 'inkeep-oss-sync', steps: [] })],+ ])('a fabricated job using %s keeps the contract', (_form, entries) => {+ expect(contractProblems(entries)).toEqual([]);+ });+});diff --git a/.github/scripts/workflow-credentials.test-helper.mjs b/.github/scripts/workflow-credentials.test-helper.mjsindex 430e3c743..8549ec15e 100644--- a/.github/scripts/workflow-credentials.test-helper.mjs+++ b/.github/scripts/workflow-credentials.test-helper.mjs@@ -23,7 +23,7 @@ export function credentialReasons(workflow, job) {}}for (const expr of [...expressionsIn(job), ...expressionsIn(workflow.env ?? {})]) {- if (/\bsecrets\b/.test(expr.replace(/\bsecrets\.GITHUB_TOKEN\b/g, ''))) {+ if (/\bsecrets\b/i.test(expr.replace(/\bsecrets\.GITHUB_TOKEN\b/gi, ''))) {reasons.push(`secret: ${expr}`);}}diff --git a/.github/workflows/desktop-build-win-linux.yml b/.github/workflows/desktop-build-win-linux.ymlindex 7bfad008b..15412667e 100644--- a/.github/workflows/desktop-build-win-linux.yml+++ b/.github/workflows/desktop-build-win-linux.yml@@ -24,8 +24,9 @@ name: Desktop build (manual, Windows/Linux)# way.## Windows signing (D3, Azure Artifact Signing): OPTIONAL here. When the-# three AZURE_* secrets + four AZURE_SIGNING_* repo variables are-# configured, the Windows job passes win.azureSignOptions to+# run is on main, the release-signing environment holds the three AZURE_*+# secrets, and the four AZURE_SIGNING_* repo variables are configured, the+# Windows job passes win.azureSignOptions to# electron-builder; when absent it builds unsigned (acceptable for# internal QA only — unsigned Windows builds are never published, and# this workflow cannot publish by construction).@@ -182,6 +183,7 @@ jobs:needs: prepareruns-on: windows-latestcache-mode: none+ environment: ${{ github.ref == 'refs/heads/main' && 'release-signing' || '' }}timeout-minutes: 45steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.ymlindex 1c673672f..a98038046 100644--- a/.github/workflows/desktop-build.yml+++ b/.github/workflows/desktop-build.yml@@ -1,8 +1,9 @@name: Desktop build# M2 per specs/2026-04-11-electron-desktop-app/SPEC.md §14:-# Produces a Universal DMG (arm64 + x64 merged). When Apple Developer cert-# + notary credentials are configured as repo secrets, the DMG is signed with+# Produces a Universal DMG (arm64 + x64 merged). When the run is on main and+# the release-signing environment holds the Apple Developer cert + notary+# credentials, the DMG is signed with# Developer ID, notarized via xcrun notarytool, stapled, and fuse-verified# (D17 paranoid post-sign check). When secrets are absent, the workflow runs# `build:mac:unsigned` explicitly and uploads the artifact under a name that@@ -15,7 +16,7 @@ name: Desktop build# ~10× more expensive than ubuntu — PR-triggering only makes sense after# M2 is closing the DOD loop.#-# Required secrets (when ready to sign — wire via Settings → Secrets):+# Required secrets, held in the release-signing environment (main only):# CSC_LINK Base64-encoded .p12 containing the Developer# ID Application cert + private key. Generate:# base64 -i developer-id.p12 | pbcopy@@ -81,6 +82,7 @@ jobs:# ships with Xcode 26+.runs-on: macos-26cache-mode: none+ environment: ${{ github.ref == 'refs/heads/main' && 'release-signing' || '' }}# 45 min budget. Local `pnpm run build:mac:unsigned` baseline on M3 Max# is ~3-4 min wall-clock; CI runners are ~2× slower; signing +# notarization adds 2-5 min of Apple round-trip on top. 45 min leavesdiff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.ymlindex dbe5a74bb..210fcfd8d 100644--- a/.github/workflows/desktop-release.yml+++ b/.github/workflows/desktop-release.yml@@ -43,7 +43,7 @@ name: Desktop release# GITHUB_TOKEN-authored release events. repository_dispatch is the# documented exemption.# See https://docs.github.com/en/actions/concepts/security/github_token.-# Required secrets:+# Required secrets, held in the release-signing environment (main only):# macOS (identical shape to desktop-build.yml):# CSC_LINK / CSC_KEY_PASSWORD# APPLE_ID + APPLE_APP_SPECIFIC_PASSWORD + APPLE_TEAM_ID@@ -488,6 +488,7 @@ jobs:# `actool`, which only ships with Xcode 26+.runs-on: macos-26cache-mode: none+ environment: release-signingtimeout-minutes: 75permissions:# Explicit so a future step needing more fails at review, not with a@@ -1024,6 +1025,7 @@ jobs:variant: ${{ fromJSON(contains(github.event.client_payload.release_tag || inputs.release_tag, '-beta.') && '["legacy-beta","beta"]' || '["stable"]') }}runs-on: windows-latestcache-mode: none+ environment: release-signingtimeout-minutes: 45env:OK_DESKTOP_VARIANT: ${{ matrix.variant }}@@ -1153,7 +1155,7 @@ jobs:[[ -n "${AZURE_SIGNING_PROFILE:-}" ]] || missing+=(AZURE_SIGNING_PROFILE)[[ -n "${AZURE_SIGNING_PUBLISHER:-}" ]] || missing+=(AZURE_SIGNING_PUBLISHER)if [[ ${#missing[@]} -gt 0 ]]; then- echo "::error::Cannot publish unsigned Windows installers — missing Azure Trusted Signing config: ${missing[*]}. Set the AZURE_* secrets + AZURE_SIGNING_* repo variables (see the workflow header), or use desktop-build-win-linux.yml for unsigned internal-QA builds."+ echo "::error::Cannot publish unsigned Windows installers — missing Azure Trusted Signing config: ${missing[*]}. Set the AZURE_* secrets in the release-signing environment and the AZURE_SIGNING_* repo variables (see the workflow header), or use desktop-build-win-linux.yml for unsigned internal-QA builds."exit 1fiecho "::notice::Azure Trusted Signing credentials present — building SIGNED installers."