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

+72
View File
@@ -0,0 +1,72 @@
export type EnvExpressionContext = 'secrets' | 'vars'
export interface EnvExpressionReference {
context: EnvExpressionContext
name: string
}
export type ParseEnvExpressionReferencesResult =
| { ok: true; references: EnvExpressionReference[] }
| { ok: false; error: string }
const ENV_EXPRESSION_PATTERN = /\$\{\{([\s\S]*?)\}\}/g
const ENV_EXPRESSION_REFERENCE_PATTERN = /^\s*(secrets|vars)\.([A-Za-z_][A-Za-z0-9_]*)\s*$/i
function toReference(match: RegExpExecArray): EnvExpressionReference {
return {
context: (match[1] ?? '').toLowerCase() as EnvExpressionContext,
name: (match[2] ?? '').toUpperCase(),
}
}
/**
* Parses every `${{ ... }}` occurrence in a value, accepting only
* `secrets.<NAME>` and `vars.<NAME>` references. The context is
* case-insensitive and the name is normalized to upper case.
*/
export function parseEnvExpressionReferences(value: string): ParseEnvExpressionReferencesResult {
const references: EnvExpressionReference[] = []
for (const expression of value.matchAll(ENV_EXPRESSION_PATTERN)) {
const reference = ENV_EXPRESSION_REFERENCE_PATTERN.exec(expression[1] ?? '')
if (!reference) {
return {
ok: false,
error: `Unsupported expression "${expression[0]}": only secrets.<NAME> and vars.<NAME> are supported`,
}
}
references.push(toReference(reference))
}
return { ok: true, references }
}
/**
* Replaces every `${{ secrets.<NAME> }}` / `${{ vars.<NAME> }}` occurrence with
* the value returned by `lookup`. A reference that resolves to `undefined`
* becomes an empty string and is reported in `missing`, matching GitHub Actions.
* Unsupported expressions are left untouched.
*/
export function interpolateEnvExpressions(
value: string,
lookup: (reference: EnvExpressionReference) => string | undefined,
): { value: string; missing: EnvExpressionReference[] } {
const missing: EnvExpressionReference[] = []
const interpolated = value.replace(ENV_EXPRESSION_PATTERN, (expression, inner: string) => {
const match = ENV_EXPRESSION_REFERENCE_PATTERN.exec(inner)
if (!match) {
return expression
}
const reference = toReference(match)
const resolved = lookup(reference)
if (resolved === undefined) {
missing.push(reference)
return ''
}
return resolved
})
return { value: interpolated, missing }
}
+1
View File
@@ -1,3 +1,4 @@
export * from './env-expressions'
export * from './jsonc'
export * from './record'
export * from './repo'