feat(secrets): repository secrets and variables injected into agent shells and terminals

Add a GitHub Actions-style store for secrets and variables so tests can read
credentials from the environment without .env files in the repo.

- secrets table keyed by kind, repo (NULL for global) and environment;
  secrets are encrypted with encryptSecret and write-only, variables are plain
  text. Names follow GitHub's rules and reject Manager-reserved names.
- Global (/api/secrets, /api/variables) and repo
  (/api/repos/:id/secrets|variables) routes.
- The trusted .ocm/project.json gains environment and env fields that map
  names to ${{ secrets.X }} / ${{ vars.X }} expressions. Both are part of the
  trust hash; files without them hash as before, so existing trust survives.
- RepoEnvService.resolveForDirectory resolves the repo and approved mapping
  for any directory, including worktrees outside the repo folder, with
  environment > repo > global precedence. It never throws.
- /api/internal/shell-env replaces /git-credentials/gh-env and feeds the
  ocm-gh-env plugin, the sandbox shell plan and TerminalService.create.
- The plugin masks injected secret values as *** in completed tool results.
- The sandbox shell plan is now the only source of the guest environment: the
  plugin pins OCM_SANDBOX_FORWARD_ENV and the shim forwards only those names.
This commit is contained in:
Chris Scott authored and Chris Scott committed 2026-10-23 22:59:57 -04:00
1 parent b431c121a2
commit e0331b43bf
47 files changed
+2073 -156

No files matched your search

@@ -0,0 +1,26 @@
import type { Migration } from '../migration-runner'
const migration: Migration = {
id: '202610181400-secrets',
up(db) {
db.run(`
CREATE TABLE IF NOT EXISTS secrets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
kind TEXT NOT NULL CHECK (kind IN ('secret','variable')),
repo_id INTEGER REFERENCES repos(id) ON DELETE CASCADE,
environment TEXT NOT NULL DEFAULT '',
name TEXT NOT NULL,
value TEXT NOT NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
)
`)
db.run('CREATE UNIQUE INDEX IF NOT EXISTS idx_secrets_scope ON secrets(kind, COALESCE(repo_id, 0), environment, name)')
},
down(db) {
db.run('DROP TABLE IF EXISTS secrets')
},
}
export default migration
+2
View File
@@ -37,6 +37,7 @@ import migration202610181200 from './202610181200-opencode-servers'
import migration202610181300 from './202610181300-session-server-scope'
import migration202610181310 from './202610181310-multi-run-targets'
import migration202610181320 from './202610181320-remote-schedule-targets'
import migration202610181400 from './202610181400-secrets'
export const allMigrations: Migration[] = [
migration001,
@@ -77,4 +78,5 @@ export const allMigrations: Migration[] = [
migration202610181300,
migration202610181310,
migration202610181320,
migration202610181400,
]
+1
View File
@@ -351,6 +351,7 @@ export function deleteRepo(db: Database, id: number): void {
db.prepare('DELETE FROM multi_run_fusions WHERE multi_run_id IN (SELECT id FROM multi_runs WHERE repo_id = ?)').run(id)
db.prepare('DELETE FROM multi_run_entries WHERE multi_run_id IN (SELECT id FROM multi_runs WHERE repo_id = ?)').run(id)
db.prepare('DELETE FROM multi_runs WHERE repo_id = ?').run(id)
db.prepare('DELETE FROM secrets WHERE repo_id = ?').run(id)
for (const table of TABLES_WITH_REPO_ID) {
db.prepare(`DELETE FROM ${table} WHERE repo_id = ?`).run(id)
}