mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
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:
1 parent
b431c121a2
commit
e0331b43bf
47 files changed
+2073
-156
No files matched your search
@@ -13,7 +13,7 @@ import {
|
||||
} from '../../src/services/opencode-sandbox-plugin'
|
||||
import { installManagedPlugins, getOpenCodePluginDir } from '../../src/services/opencode/plugin-registry'
|
||||
import {
|
||||
SANDBOX_FORWARDED_ENV_NAMES,
|
||||
SANDBOX_SHELL_ENV_FORWARD,
|
||||
SANDBOX_SHELL_ENV_NAME,
|
||||
SANDBOX_SHELL_ENV_WORKDIR,
|
||||
sandboxShellShimPath,
|
||||
@@ -284,6 +284,8 @@ describe('ocm-sandbox plugin', () => {
|
||||
expect(statSync(shimPath).mode & 0o100).not.toBe(0)
|
||||
expect(shim.startsWith('#!/bin/sh')).toBe(true)
|
||||
expect(shim).toContain(`$${SANDBOX_SHELL_ENV_WORKDIR}`)
|
||||
expect(shim).toContain(`\${${SANDBOX_SHELL_ENV_FORWARD}}`)
|
||||
expect(pluginSource).toContain(`var ENV_FORWARD = ${JSON.stringify(SANDBOX_SHELL_ENV_FORWARD)}`)
|
||||
expect(pluginSource).toContain(`var SHELL_SHIM_PATH = ${JSON.stringify(shimPath)}`)
|
||||
})
|
||||
|
||||
@@ -374,6 +376,7 @@ describe('ocm-sandbox plugin', () => {
|
||||
expect(createEvent.shell).toBe(sandboxShellShimPath(configHome))
|
||||
expect(createEvent.env[SANDBOX_SHELL_ENV_WORKDIR]).toBe(WORKDIR)
|
||||
expect(createEvent.env[SANDBOX_SHELL_ENV_NAME]).toBe(PLAN_NAME)
|
||||
expect(createEvent.env[SANDBOX_SHELL_ENV_FORWARD]).toBe('')
|
||||
const planCall = fetchMock.mock.calls.find(([url]) => String(url).endsWith('/sandbox/shell'))
|
||||
expect(planCall).toBeDefined()
|
||||
const [url, init] = planCall as [string, { body: string; headers: Record<string, string> }]
|
||||
@@ -403,6 +406,9 @@ describe('ocm-sandbox plugin', () => {
|
||||
expect(() => {
|
||||
createEvent.env[SANDBOX_SHELL_ENV_NAME] = 'other'
|
||||
}).toThrow(message)
|
||||
expect(() => {
|
||||
createEvent.env[SANDBOX_SHELL_ENV_FORWARD] = 'EVIL'
|
||||
}).toThrow(message)
|
||||
|
||||
expect(createEvent.shell).toBe(sandboxShellShimPath(configHome))
|
||||
expect(createEvent.env[SANDBOX_SHELL_ENV_WORKDIR]).toBe(WORKDIR)
|
||||
@@ -410,9 +416,10 @@ describe('ocm-sandbox plugin', () => {
|
||||
expect(Object.getOwnPropertyDescriptor(createEvent, 'shell')?.configurable).toBe(false)
|
||||
expect(Object.getOwnPropertyDescriptor(createEvent.env, SANDBOX_SHELL_ENV_WORKDIR)?.configurable).toBe(false)
|
||||
expect(Object.getOwnPropertyDescriptor(createEvent.env, SANDBOX_SHELL_ENV_NAME)?.configurable).toBe(false)
|
||||
expect(Object.getOwnPropertyDescriptor(createEvent.env, SANDBOX_SHELL_ENV_FORWARD)?.configurable).toBe(false)
|
||||
})
|
||||
|
||||
it('forwards only the allow-listed plan env values into the spawn environment', async () => {
|
||||
it('forwards the plan env names it can represent and pins the forward list', async () => {
|
||||
const plugin = await loadPlugin(configHome)
|
||||
const fetchMock = managerFetch({
|
||||
session: { sandboxed: true },
|
||||
@@ -421,7 +428,16 @@ describe('ocm-sandbox plugin', () => {
|
||||
mode: 'sandbox',
|
||||
workdir: WORKDIR,
|
||||
name: PLAN_NAME,
|
||||
env: { GH_TOKEN: 'gh-secret', OCM_INTERNAL_TOKEN: 'must-not-be-forwarded', GIT_CONFIG_COUNT: '1' },
|
||||
env: {
|
||||
GH_TOKEN: 'gh-secret',
|
||||
GIT_CONFIG_COUNT: '1',
|
||||
OPENAI_API_KEY: 'sk-secret',
|
||||
OCM_INTERNAL_TOKEN: 'must-not-be-forwarded',
|
||||
MSB_SECRET: 'must-not-be-forwarded',
|
||||
'1BAD': 'invalid',
|
||||
'A-B': 'invalid',
|
||||
NUMERIC: 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -431,12 +447,14 @@ describe('ocm-sandbox plugin', () => {
|
||||
|
||||
expect(createEvent.env.GH_TOKEN).toBe('gh-secret')
|
||||
expect(createEvent.env.GIT_CONFIG_COUNT).toBe('1')
|
||||
expect(createEvent.env.OPENAI_API_KEY).toBe('sk-secret')
|
||||
expect(createEvent.env.OCM_INTERNAL_TOKEN).toBeUndefined()
|
||||
for (const name of Object.keys(createEvent.env)) {
|
||||
if (createEvent.env[name] === undefined) continue
|
||||
if (name === SANDBOX_SHELL_ENV_WORKDIR || name === SANDBOX_SHELL_ENV_NAME || name === 'TERM' || name === 'OPENCODE_TERMINAL') continue
|
||||
expect(SANDBOX_FORWARDED_ENV_NAMES).toContain(name)
|
||||
}
|
||||
expect(createEvent.env.MSB_SECRET).toBeUndefined()
|
||||
expect(createEvent.env['1BAD']).toBeUndefined()
|
||||
expect(createEvent.env['A-B']).toBeUndefined()
|
||||
expect(createEvent.env.NUMERIC).toBeUndefined()
|
||||
expect(createEvent.env[SANDBOX_SHELL_ENV_FORWARD]).toBe('GH_TOKEN GIT_CONFIG_COUNT OPENAI_API_KEY')
|
||||
expect(Object.getOwnPropertyDescriptor(createEvent.env, SANDBOX_SHELL_ENV_FORWARD)?.configurable).toBe(false)
|
||||
})
|
||||
|
||||
it('leaves an unmarked spawn on the host without planning', async () => {
|
||||
|
||||
Reference in new issue
Block a user