mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix(secrets): forward only planned variables into the sandbox and cache repo env resolution
The sandbox shim forwards only the plan's pinned names, so turning sandbox Git credentials off withholds tokens. Sandboxed shells resolve repo env once, terminals on linked servers get no local env, mapping keys cannot override git credentials, masks are kept per directory, and directory resolution is cached. A legacy gh-env alias keeps adopted OpenCode processes working for one release.
This commit is contained in:
1 parent
a0d1d91f18
commit
3e51280894
36 files changed
+1010
-259
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { ENV_NAME_PATTERN } from '../schemas/secrets'
|
||||
|
||||
export type EnvExpressionContext = 'secrets' | 'vars'
|
||||
|
||||
export interface EnvExpressionReference {
|
||||
@@ -11,7 +13,7 @@ export type ParseEnvExpressionReferencesResult =
|
||||
|
||||
const ENV_EXPRESSION_PATTERN = /\$\{\{([\s\S]*?)\}\}/g
|
||||
|
||||
const ENV_EXPRESSION_REFERENCE_PATTERN = /^\s*(secrets|vars)\.([A-Za-z_][A-Za-z0-9_]*)\s*$/i
|
||||
const ENV_EXPRESSION_REFERENCE_PATTERN = /^\s*(secrets|vars)\.(\S+)\s*$/i
|
||||
|
||||
function toReference(match: RegExpExecArray): EnvExpressionReference {
|
||||
return {
|
||||
@@ -20,6 +22,12 @@ function toReference(match: RegExpExecArray): EnvExpressionReference {
|
||||
}
|
||||
}
|
||||
|
||||
function matchReference(inner: string): EnvExpressionReference | null {
|
||||
const match = ENV_EXPRESSION_REFERENCE_PATTERN.exec(inner)
|
||||
if (!match || !ENV_NAME_PATTERN.test(match[2] ?? '')) return null
|
||||
return toReference(match)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses every `${{ ... }}` occurrence in a value, accepting only
|
||||
* `secrets.<NAME>` and `vars.<NAME>` references. The context is
|
||||
@@ -29,14 +37,14 @@ export function parseEnvExpressionReferences(value: string): ParseEnvExpressionR
|
||||
const references: EnvExpressionReference[] = []
|
||||
|
||||
for (const expression of value.matchAll(ENV_EXPRESSION_PATTERN)) {
|
||||
const reference = ENV_EXPRESSION_REFERENCE_PATTERN.exec(expression[1] ?? '')
|
||||
const reference = matchReference(expression[1] ?? '')
|
||||
if (!reference) {
|
||||
return {
|
||||
ok: false,
|
||||
error: `Unsupported expression "${expression[0]}": only secrets.<NAME> and vars.<NAME> are supported`,
|
||||
}
|
||||
}
|
||||
references.push(toReference(reference))
|
||||
references.push(reference)
|
||||
}
|
||||
|
||||
return { ok: true, references }
|
||||
@@ -45,28 +53,21 @@ export function parseEnvExpressionReferences(value: string): ParseEnvExpressionR
|
||||
/**
|
||||
* 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.
|
||||
* becomes an empty string, matching GitHub Actions. Unsupported expressions and
|
||||
* expressions with an invalid name are left untouched.
|
||||
*/
|
||||
export function interpolateEnvExpressions(
|
||||
value: string,
|
||||
lookup: (reference: EnvExpressionReference) => string | undefined,
|
||||
): { value: string; missing: EnvExpressionReference[] } {
|
||||
const missing: EnvExpressionReference[] = []
|
||||
|
||||
): { value: string } {
|
||||
const interpolated = value.replace(ENV_EXPRESSION_PATTERN, (expression, inner: string) => {
|
||||
const match = ENV_EXPRESSION_REFERENCE_PATTERN.exec(inner)
|
||||
if (!match) {
|
||||
const reference = matchReference(inner)
|
||||
if (!reference) {
|
||||
return expression
|
||||
}
|
||||
const reference = toReference(match)
|
||||
const resolved = lookup(reference)
|
||||
if (resolved === undefined) {
|
||||
missing.push(reference)
|
||||
return ''
|
||||
}
|
||||
return resolved
|
||||
return resolved === undefined ? '' : resolved
|
||||
})
|
||||
|
||||
return { value: interpolated, missing }
|
||||
return { value: interpolated }
|
||||
}
|
||||
Reference in new issue
Block a user