mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-28 19:14:53 +00:00
feat(core): stabilize top-level policies config (#55297)
This commit is contained in:
parent
1c28c2fec5
commit
f576da508d
20 changed files with 285 additions and 135 deletions
|
|
@ -2154,6 +2154,11 @@ export type ConfigEntry =
|
|||
enterprise?: { url?: string }
|
||||
username?: string
|
||||
permissions?: PermissionRuleset
|
||||
policies?: Array<{
|
||||
action: "provider.use" | "tool.use" | "integration.use"
|
||||
resource: string
|
||||
effect: "allow" | "deny"
|
||||
}>
|
||||
agents?: {
|
||||
[x: string]: {
|
||||
model?: string | { providerID: string; model: string; variant?: string }
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import { ConfigNormalize } from "./config/normalize.js"
|
|||
import { ConfigDiscovery } from "./config/discovery.js"
|
||||
import { ConfigWatch } from "./config/watch.js"
|
||||
import { WellKnown } from "./wellknown.js"
|
||||
import { ConfigExperimental } from "@opencode/schema/config/experimental"
|
||||
import { AppProcess } from "@opencode/util/process"
|
||||
import { ChildProcess } from "effect/process"
|
||||
|
||||
|
|
@ -252,28 +251,20 @@ export const layer = (options?: Options) =>
|
|||
]
|
||||
const managedPolicies = managed
|
||||
.flatMap((entry) =>
|
||||
entry.type === "document" && entry.info.experimental?.policies
|
||||
entry.type === "document" && entry.info.policies
|
||||
? [
|
||||
new Document({
|
||||
type: "document",
|
||||
path: entry.path,
|
||||
info: new Info({
|
||||
experimental: new ConfigExperimental.Info({ policies: entry.info.experimental.policies }),
|
||||
}),
|
||||
info: new Info({ policies: entry.info.policies }),
|
||||
}),
|
||||
]
|
||||
: [],
|
||||
)
|
||||
.toReversed()
|
||||
const managedSettings = managed.map((entry) =>
|
||||
entry.type === "document" && entry.info.experimental?.policies
|
||||
? new Document({
|
||||
...entry,
|
||||
info: new Info({
|
||||
...entry.info,
|
||||
experimental: new ConfigExperimental.Info({ ...entry.info.experimental, policies: undefined }),
|
||||
}),
|
||||
})
|
||||
entry.type === "document" && entry.info.policies
|
||||
? new Document({ ...entry, info: new Info({ ...entry.info, policies: undefined }) })
|
||||
: entry,
|
||||
)
|
||||
// Global entries sit below explicit and direct files; project directories rank above them.
|
||||
|
|
@ -428,7 +419,16 @@ export function configured(options?: Options) {
|
|||
return makeLocationNode({
|
||||
service: Service,
|
||||
layer: layer(options),
|
||||
deps: [Watcher.node, Bus.node, FSUtil.node, Global.node, Location.node, Credential.node, WellKnown.node, AppProcess.node],
|
||||
deps: [
|
||||
Watcher.node,
|
||||
Bus.node,
|
||||
FSUtil.node,
|
||||
Global.node,
|
||||
Location.node,
|
||||
Credential.node,
|
||||
WellKnown.node,
|
||||
AppProcess.node,
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -192,6 +192,7 @@ export function normalize(input: unknown): Result {
|
|||
normalizeSkills(input, encoded, diagnostics)
|
||||
normalizeMcp(input, encoded, diagnostics)
|
||||
normalizeCompaction(input, encoded, diagnostics)
|
||||
normalizePolicies(input, encoded, diagnostics)
|
||||
normalizeExperimental(input, encoded, diagnostics)
|
||||
normalizeWatcher(input, encoded, diagnostics)
|
||||
normalizeFormatter(input, encoded, diagnostics)
|
||||
|
|
@ -378,12 +379,13 @@ function normalizeCompaction(
|
|||
if (Object.keys(result).length || !Object.keys(input.compaction).length) encoded.compaction = result
|
||||
}
|
||||
|
||||
function normalizeExperimental(
|
||||
// V1 provider lists and `experimental.policies` stay supported and merge into
|
||||
// top-level `policies`; within a document, later sources win ties.
|
||||
function normalizePolicies(
|
||||
input: Record<string, unknown>,
|
||||
encoded: Record<string, unknown>,
|
||||
diagnostics: Diagnostic[],
|
||||
) {
|
||||
const result: Record<string, unknown> = {}
|
||||
const generated: unknown[] = []
|
||||
const enabled = decodeProviderList(input, "enabled_providers", diagnostics)
|
||||
if (enabled.present && (!enabled.nonEmpty || enabled.values.length)) {
|
||||
|
|
@ -404,7 +406,32 @@ function normalizeExperimental(
|
|||
effect: "deny",
|
||||
})),
|
||||
)
|
||||
const native: unknown[] = []
|
||||
const experimental = isRecord(input.experimental)
|
||||
? decodeList(
|
||||
input.experimental.policies,
|
||||
ConfigPolicy.Info,
|
||||
["experimental", "policies"],
|
||||
diagnostics,
|
||||
decodeEncoded,
|
||||
)
|
||||
: []
|
||||
const native = decodeList(input.policies, ConfigPolicy.Info, ["policies"], diagnostics, decodeEncoded)
|
||||
if (
|
||||
generated.length ||
|
||||
experimental.length ||
|
||||
native.length ||
|
||||
Array.isArray(input.policies) ||
|
||||
(isRecord(input.experimental) && Array.isArray(input.experimental.policies))
|
||||
)
|
||||
encoded.policies = [...generated, ...experimental, ...native]
|
||||
}
|
||||
|
||||
function normalizeExperimental(
|
||||
input: Record<string, unknown>,
|
||||
encoded: Record<string, unknown>,
|
||||
diagnostics: Diagnostic[],
|
||||
) {
|
||||
const result: Record<string, unknown> = {}
|
||||
if (own(input, "experimental")) {
|
||||
if (!isRecord(input.experimental)) invalid(["experimental"], diagnostics)
|
||||
if (isRecord(input.experimental)) {
|
||||
|
|
@ -430,19 +457,8 @@ function normalizeExperimental(
|
|||
)
|
||||
if (value !== undefined) result.subagent_depth = value
|
||||
}
|
||||
native.push(
|
||||
...decodeList(
|
||||
experimental.policies,
|
||||
ConfigPolicy.Info,
|
||||
["experimental", "policies"],
|
||||
diagnostics,
|
||||
decodeEncoded,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
if (generated.length || native.length || (isRecord(input.experimental) && Array.isArray(input.experimental.policies)))
|
||||
result.policies = [...generated, ...native]
|
||||
if (Object.keys(result).length || (isRecord(input.experimental) && !Object.keys(input.experimental).length))
|
||||
encoded.experimental = result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ export function statements(entries: readonly Entry[], organization: State) {
|
|||
...entries
|
||||
.filter((entry): entry is Document => entry.type === "document")
|
||||
.toReversed()
|
||||
.flatMap((entry) => entry.info.experimental?.policies ?? [])
|
||||
.flatMap((entry) => entry.info.policies ?? [])
|
||||
.map((policy) => ({ ...policy, message: "Blocked by configuration policy" })),
|
||||
...organization.statements.map((policy) => ({
|
||||
...policy,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,23 @@ import { Money } from "@opencode/schema/money"
|
|||
const defaultServer = "https://opencode.ai/console"
|
||||
const clientID = "opencode-cli"
|
||||
const methodID = Integration.MethodID.make("device")
|
||||
// Drop statements whose action or effect is a value this version does not know, so a newer Console can
|
||||
// extend either enum. Malformed statements still fail validation.
|
||||
const RemotePolicies = Schema.Array(Schema.Unknown).pipe(
|
||||
Schema.decodeTo(Schema.Unknown, {
|
||||
decode: SchemaGetter.transform((policies) =>
|
||||
policies.filter((policy) => {
|
||||
const action = Schema.decodeUnknownOption(Schema.Struct({ action: Schema.String }))(policy)
|
||||
if (Option.isSome(action) && !Schema.is(ConfigPolicy.Info.fields.action)(action.value.action)) return false
|
||||
const effect = Schema.decodeUnknownOption(Schema.Struct({ effect: Schema.String }))(policy)
|
||||
return Option.isNone(effect) || Schema.is(ConfigPolicy.Effect)(effect.value.effect)
|
||||
}),
|
||||
),
|
||||
encode: SchemaGetter.passthrough({ strict: false }),
|
||||
}),
|
||||
Schema.decodeTo(Schema.Array(ConfigPolicy.Info)),
|
||||
Schema.optional,
|
||||
)
|
||||
const RemoteResponse = Schema.Struct({
|
||||
providers: Schema.Record(Schema.String, ConfigProvider.Info),
|
||||
websearch: Schema.Struct({
|
||||
|
|
@ -35,22 +52,9 @@ const RemoteResponse = Schema.Struct({
|
|||
),
|
||||
}).pipe(Schema.optional),
|
||||
// Organization policy compiled for the authenticated caller; omitted when there is none.
|
||||
experimental: Schema.Struct({
|
||||
policies: Schema.Array(Schema.Unknown).pipe(
|
||||
Schema.decodeTo(Schema.Unknown, {
|
||||
// Filter only unsupported actions. Malformed supported statements still fail validation.
|
||||
decode: SchemaGetter.transform((policies) =>
|
||||
policies.filter((policy) => {
|
||||
const action = Schema.decodeUnknownOption(Schema.Struct({ action: Schema.String }))(policy)
|
||||
return Option.isNone(action) || Schema.is(ConfigPolicy.Info.fields.action)(action.value.action)
|
||||
}),
|
||||
),
|
||||
encode: SchemaGetter.passthrough({ strict: false }),
|
||||
}),
|
||||
Schema.decodeTo(Schema.Array(ConfigPolicy.Info)),
|
||||
Schema.optional,
|
||||
),
|
||||
}).pipe(Schema.optional),
|
||||
// `experimental.policies` remains accepted alongside top-level `policies`.
|
||||
policies: RemotePolicies,
|
||||
experimental: Schema.Struct({ policies: RemotePolicies }).pipe(Schema.optional),
|
||||
})
|
||||
const Device = Schema.Struct({
|
||||
device_code: Schema.String,
|
||||
|
|
@ -243,7 +247,10 @@ export const OpencodePlugin = define<HttpClient.HttpClient | Bus.Service | Manag
|
|||
})
|
||||
// Statements ride on the snapshot, so a credential switch, disconnect, or 404 replaces them too.
|
||||
const publish = (next: typeof snapshot) =>
|
||||
managed.set({ statements: next.config?.experimental?.policies ?? [], organization: next.organization })
|
||||
managed.set({
|
||||
statements: [...(next.config?.experimental?.policies ?? []), ...(next.config?.policies ?? [])],
|
||||
organization: next.organization,
|
||||
})
|
||||
|
||||
yield* ctx.integration.transform((editor) => {
|
||||
editor.update("opencode", (integration) => {
|
||||
|
|
|
|||
|
|
@ -709,7 +709,7 @@ describe("Config", () => {
|
|||
const project = path.join(tmp.path, "project")
|
||||
const remote = (entries: readonly Entry[]) => ({
|
||||
provider: Config.latest(entries, "providers")?.remote?.package,
|
||||
policies: Config.latest(entries, "experimental")?.policies,
|
||||
policies: Config.latest(entries, "policies"),
|
||||
})
|
||||
const loaded = {
|
||||
provider: "aisdk:@ai-sdk/openai-compatible",
|
||||
|
|
@ -966,14 +966,14 @@ describe("Config", () => {
|
|||
migrateV1({
|
||||
enabled_providers: ["anthropic", "openai"],
|
||||
disabled_providers: ["openai"],
|
||||
}).experimental?.policies,
|
||||
}).policies,
|
||||
).toEqual([
|
||||
{ action: "provider.use", resource: "*", effect: "deny" },
|
||||
{ action: "provider.use", resource: "anthropic", effect: "allow" },
|
||||
{ action: "provider.use", resource: "openai", effect: "allow" },
|
||||
{ action: "provider.use", resource: "openai", effect: "deny" },
|
||||
])
|
||||
expect(migrateV1({ enabled_providers: [] }).experimental?.policies).toEqual([
|
||||
expect(migrateV1({ enabled_providers: [] }).policies).toEqual([
|
||||
{ action: "provider.use", resource: "*", effect: "deny" },
|
||||
])
|
||||
})
|
||||
|
|
@ -1031,7 +1031,7 @@ describe("Config", () => {
|
|||
expect(migrated.model).toEqual({ providerID: "azure", model: "deployment" })
|
||||
expect(migrated.agents?.reviewer?.model).toEqual({ providerID: "google-vertex", model: "claude-sonnet" })
|
||||
expect(migrated.commands?.review?.model).toEqual({ providerID: "azure", model: "deployment" })
|
||||
expect(migrated.experimental?.policies).toEqual([
|
||||
expect(migrated.policies).toEqual([
|
||||
{ action: "provider.use", resource: "*", effect: "deny" },
|
||||
{ action: "provider.use", resource: "google-vertex", effect: "allow" },
|
||||
{ action: "provider.use", resource: "azure", effect: "deny" },
|
||||
|
|
|
|||
|
|
@ -44,6 +44,15 @@ function withoutEmptyCompatibilityContainers(input: Record<string, unknown>) {
|
|||
delete compaction.keep
|
||||
if (!originallyEmpty && !Object.keys(compaction).length) delete result.compaction
|
||||
}
|
||||
// Deprecated experimental policies normalize into top-level policies.
|
||||
if (typeof result.experimental === "object" && result.experimental !== null && !Array.isArray(result.experimental)) {
|
||||
const experimental = result.experimental as Record<string, unknown>
|
||||
if (Array.isArray(experimental.policies)) {
|
||||
result.policies = [...experimental.policies, ...(Array.isArray(result.policies) ? result.policies : [])]
|
||||
delete experimental.policies
|
||||
if (!Object.keys(experimental).length) delete result.experimental
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +65,7 @@ describe("ConfigNormalize", () => {
|
|||
] as const
|
||||
const result = normalized({ experimental: { policies } })
|
||||
expect(result.diagnostics).toEqual([])
|
||||
expect(Schema.decodeUnknownSync(Info)(result.encoded).experimental?.policies).toEqual(policies)
|
||||
expect(Schema.decodeUnknownSync(Info)(result.encoded).policies).toEqual(policies)
|
||||
})
|
||||
|
||||
test("drops unsupported policy actions without losing supported policies", () => {
|
||||
|
|
@ -70,7 +79,7 @@ describe("ConfigNormalize", () => {
|
|||
],
|
||||
},
|
||||
})
|
||||
expect(Schema.decodeUnknownSync(Info)(result.encoded).experimental?.policies).toEqual([supported])
|
||||
expect(Schema.decodeUnknownSync(Info)(result.encoded).policies).toEqual([supported])
|
||||
expect(result.diagnostics.map((diagnostic) => diagnostic.path)).toEqual([
|
||||
["experimental", "policies", "0"],
|
||||
["experimental", "policies", "2"],
|
||||
|
|
@ -467,42 +476,47 @@ describe("ConfigNormalize", () => {
|
|||
})
|
||||
|
||||
test("distinguishes empty, mixed, and wholly malformed enabled provider lists", () => {
|
||||
expect(normalized({ enabled_providers: [] }).encoded.experimental).toEqual({
|
||||
policies: [{ action: "provider.use", resource: "*", effect: "deny" }],
|
||||
})
|
||||
expect(normalized({ enabled_providers: [1, "anthropic", false] }).encoded.experimental).toEqual({
|
||||
policies: [
|
||||
{ action: "provider.use", resource: "*", effect: "deny" },
|
||||
{ action: "provider.use", resource: "anthropic", effect: "allow" },
|
||||
],
|
||||
})
|
||||
expect(normalized({ enabled_providers: [1, false] }).encoded.experimental).toBeUndefined()
|
||||
expect(normalized({ enabled_providers: "anthropic" }).encoded.experimental).toBeUndefined()
|
||||
expect(normalized({ enabled_providers: [] }).encoded.policies).toEqual([
|
||||
{ action: "provider.use", resource: "*", effect: "deny" },
|
||||
])
|
||||
expect(normalized({ enabled_providers: [1, "anthropic", false] }).encoded.policies).toEqual([
|
||||
{ action: "provider.use", resource: "*", effect: "deny" },
|
||||
{ action: "provider.use", resource: "anthropic", effect: "allow" },
|
||||
])
|
||||
expect(normalized({ enabled_providers: [1, false] }).encoded.policies).toBeUndefined()
|
||||
expect(normalized({ enabled_providers: "anthropic" }).encoded.policies).toBeUndefined()
|
||||
})
|
||||
|
||||
test("appends native policies after migrated provider policies", () => {
|
||||
test("merges migrated, experimental, and native policies in order", () => {
|
||||
expect(
|
||||
normalized({
|
||||
enabled_providers: ["anthropic"],
|
||||
disabled_providers: ["openai"],
|
||||
policies: [{ action: "provider.use", resource: "native", effect: "deny" }],
|
||||
experimental: {
|
||||
portable_shell_scanner: true,
|
||||
subagent_depth: 0,
|
||||
policies: [{ action: "provider.use", resource: "custom", effect: "allow" }],
|
||||
},
|
||||
}).encoded.experimental,
|
||||
).toEqual({
|
||||
portable_shell_scanner: true,
|
||||
subagent_depth: 0,
|
||||
}).encoded,
|
||||
).toMatchObject({
|
||||
experimental: { portable_shell_scanner: true, subagent_depth: 0 },
|
||||
policies: [
|
||||
{ action: "provider.use", resource: "*", effect: "deny" },
|
||||
{ action: "provider.use", resource: "anthropic", effect: "allow" },
|
||||
{ action: "provider.use", resource: "openai", effect: "deny" },
|
||||
{ action: "provider.use", resource: "custom", effect: "allow" },
|
||||
{ action: "provider.use", resource: "native", effect: "deny" },
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
test("never emits experimental policies", () => {
|
||||
expect(
|
||||
normalized({ experimental: { policies: [{ action: "provider.use", resource: "*", effect: "deny" }] } }).encoded,
|
||||
).toEqual({ policies: [{ action: "provider.use", resource: "*", effect: "deny" }] })
|
||||
})
|
||||
|
||||
test("reports unsupported legacy settings without including their values", () => {
|
||||
const secret = "do-not-log-this-value"
|
||||
const result = normalized({
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ import { PluginTestLayer } from "../plugin/fixture"
|
|||
const it = testEffect(PluginTestLayer)
|
||||
const decode = Schema.decodeUnknownSync(Info)
|
||||
|
||||
const document = (...policies: ConfigPolicy.Info[]) =>
|
||||
new Document({ type: "document", info: decode({ experimental: { policies } }) })
|
||||
const document = (...policies: ConfigPolicy.Info[]) => new Document({ type: "document", info: decode({ policies }) })
|
||||
const provider = (effect: ConfigPolicy.Effect, resource: string): ConfigPolicy.Info => ({
|
||||
action: "provider.use",
|
||||
resource,
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ function resourceMcpLayer(
|
|||
new Document({
|
||||
type: "document",
|
||||
info: new Info({
|
||||
experimental: { policies: overrides?.policies ?? [] },
|
||||
policies: overrides?.policies ?? [],
|
||||
mcp: new ConfigMCP.Info({
|
||||
servers: {
|
||||
resources:
|
||||
|
|
@ -2635,7 +2635,7 @@ for (const source of ["config", "organization"] as const) {
|
|||
mcp: new ConfigMCP.Info({
|
||||
servers: { resources: new ConfigMCP.Remote({ type: "remote", url: server.url, oauth: false }) },
|
||||
}),
|
||||
experimental: { policies: [{ action: "integration.use", resource: "mcp:*", effect }] },
|
||||
policies: [{ action: "integration.use", resource: "mcp:*", effect }],
|
||||
}),
|
||||
})
|
||||
yield* test.setEntries([document("allow")])
|
||||
|
|
|
|||
|
|
@ -766,7 +766,7 @@ describe("OpencodePlugin", () => {
|
|||
),
|
||||
)
|
||||
|
||||
it.effect("ignores unsupported managed actions and keys while enforcing supported policies", () =>
|
||||
it.effect("ignores unsupported managed actions, effects, and keys while enforcing supported policies", () =>
|
||||
Effect.acquireUseRelease(
|
||||
Effect.sync(() =>
|
||||
Bun.serve({
|
||||
|
|
@ -781,6 +781,7 @@ describe("OpencodePlugin", () => {
|
|||
{ action: "provider.use", resource: "opencode", effect: "allow" },
|
||||
{ action: "tool.use", resource: "shell:*", effect: "deny" },
|
||||
{ action: "tool.use", resource: "shell:git *", effect: "allow" },
|
||||
{ action: "tool.use", resource: "shell:git status", effect: "future-effect" },
|
||||
{ action: "permission", resource: "*", effect: "deny" },
|
||||
{ action: "tool.use", resource: "shell:sudo *", effect: "deny", audience: "ignored" },
|
||||
{ action: "integration.use", resource: "mcp:restricted", effect: "deny" },
|
||||
|
|
@ -845,7 +846,7 @@ describe("OpencodePlugin", () => {
|
|||
),
|
||||
)
|
||||
|
||||
it.effect("refreshes past future-only policies while retaining config on malformed supported statements", () =>
|
||||
it.effect("refreshes past future-only policies while retaining config on malformed statements", () =>
|
||||
Effect.acquireUseRelease(
|
||||
Effect.sync(() => {
|
||||
const state: { policies: unknown[] } = {
|
||||
|
|
@ -877,7 +878,6 @@ describe("OpencodePlugin", () => {
|
|||
expect(managed.current()).toEqual({ statements: [sudo], organization: "Acme" })
|
||||
|
||||
for (const malformed of [
|
||||
{ action: "tool.use", resource: "shell:*", effect: "future-effect" },
|
||||
{ action: "tool.use", resource: 42, effect: "deny" },
|
||||
{ action: "tool.use", effect: "deny" },
|
||||
null,
|
||||
|
|
@ -890,6 +890,11 @@ describe("OpencodePlugin", () => {
|
|||
expect(yield* providers.get(Provider.ID.opencode)).toBeDefined()
|
||||
}
|
||||
|
||||
state.policies = [env, { action: "tool.use", resource: "shell:*", effect: "future-effect" }]
|
||||
yield* TestClock.adjust("1 minute")
|
||||
yield* drain
|
||||
expect(managed.current()).toEqual({ statements: [env], organization: "Acme" })
|
||||
|
||||
state.policies = [{ action: "future.use", future: { values: [true] } }]
|
||||
yield* TestClock.adjust("1 minute")
|
||||
yield* drain
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ describe("Skill", () => {
|
|||
new Document({
|
||||
type: "document",
|
||||
info: {
|
||||
experimental: { policies: [{ action: "integration.use", resource: "skill:*", effect: "allow" }] },
|
||||
policies: [{ action: "integration.use", resource: "skill:*", effect: "allow" }],
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
|
@ -82,12 +82,12 @@ describe("Skill", () => {
|
|||
yield* config.setEntries([
|
||||
new Document({
|
||||
type: "document",
|
||||
info: { experimental: { policies: [{ action: "integration.use", resource: "skill:*", effect: "deny" }] } },
|
||||
info: { policies: [{ action: "integration.use", resource: "skill:*", effect: "deny" }] },
|
||||
}),
|
||||
new Document({
|
||||
type: "document",
|
||||
info: {
|
||||
experimental: { policies: [{ action: "integration.use", resource: "skill:review", effect: "allow" }] },
|
||||
policies: [{ action: "integration.use", resource: "skill:review", effect: "allow" }],
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
|
|
|||
|
|
@ -13817,6 +13817,27 @@
|
|||
"permissions": {
|
||||
"$ref": "#/components/schemas/Permission.Ruleset"
|
||||
},
|
||||
"policies": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"enum": ["provider.use", "tool.use", "integration.use"]
|
||||
},
|
||||
"resource": {
|
||||
"type": "string"
|
||||
},
|
||||
"effect": {
|
||||
"type": "string",
|
||||
"enum": ["allow", "deny"]
|
||||
}
|
||||
},
|
||||
"required": ["action", "resource", "effect"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"agents": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
|
|
@ -14190,6 +14211,9 @@
|
|||
"properties": {
|
||||
"compaction": {
|
||||
"$ref": "#/components/schemas/Provider.Compaction"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
@ -14369,6 +14393,9 @@
|
|||
},
|
||||
"transport": {
|
||||
"$ref": "#/components/schemas/Provider.Transport"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
@ -16838,6 +16865,9 @@
|
|||
"properties": {
|
||||
"compaction": {
|
||||
"$ref": "#/components/schemas/Provider.Compaction"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
@ -17755,6 +17785,10 @@
|
|||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"Provider.Encoding": {
|
||||
"type": "string",
|
||||
"enum": ["zstd", "gzip", "none"]
|
||||
},
|
||||
"Provider.ID": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
@ -17859,6 +17893,9 @@
|
|||
},
|
||||
"transport": {
|
||||
"$ref": "#/components/schemas/Provider.Transport"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import { ConfigLSP } from "./config/lsp.js"
|
|||
import { ConfigMCP } from "./config/mcp.js"
|
||||
import { ConfigModel } from "./config/model.js"
|
||||
import { ConfigPlugin } from "./config/plugin.js"
|
||||
import { ConfigPolicy } from "./config/policy.js"
|
||||
import { ConfigProvider } from "./config/provider.js"
|
||||
import { ConfigReference } from "./config/reference.js"
|
||||
import { ConfigWebSearch } from "./config/websearch.js"
|
||||
|
|
@ -54,6 +55,9 @@ export class Info extends Schema.Class<Info>("Config.Info")({
|
|||
permissions: Permission.Ruleset.pipe(optional).annotate({
|
||||
description: "Ordered tool permission rules applied to agent tool use",
|
||||
}),
|
||||
policies: ConfigPolicy.Info.pipe(Schema.Array, optional).annotate({
|
||||
description: "Ordered policies controlling access to providers, tools, and integrations",
|
||||
}),
|
||||
agents: Schema.Record(Schema.String, ConfigAgent.Info).pipe(optional).annotate({
|
||||
description: "Named built-in agent overrides and custom agent definitions",
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -12,6 +12,6 @@ export class Info extends Schema.Class<Info>("ConfigExperimental.Info")({
|
|||
description: "Maximum subagent nesting depth. Defaults to 1.",
|
||||
}),
|
||||
policies: ConfigPolicy.Info.pipe(Schema.Array, optional).annotate({
|
||||
description: "Ordered policies controlling access to configured resources",
|
||||
description: "Deprecated: use top-level policies. Ordered policies controlling access to configured resources",
|
||||
}),
|
||||
}) {}
|
||||
|
|
|
|||
|
|
@ -13817,6 +13817,27 @@
|
|||
"permissions": {
|
||||
"$ref": "#/components/schemas/Permission.Ruleset"
|
||||
},
|
||||
"policies": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"enum": ["provider.use", "tool.use", "integration.use"]
|
||||
},
|
||||
"resource": {
|
||||
"type": "string"
|
||||
},
|
||||
"effect": {
|
||||
"type": "string",
|
||||
"enum": ["allow", "deny"]
|
||||
}
|
||||
},
|
||||
"required": ["action", "resource", "effect"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"agents": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
|
|
@ -14190,6 +14211,9 @@
|
|||
"properties": {
|
||||
"compaction": {
|
||||
"$ref": "#/components/schemas/Provider.Compaction"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
@ -14369,6 +14393,9 @@
|
|||
},
|
||||
"transport": {
|
||||
"$ref": "#/components/schemas/Provider.Transport"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
@ -16838,6 +16865,9 @@
|
|||
"properties": {
|
||||
"compaction": {
|
||||
"$ref": "#/components/schemas/Provider.Compaction"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
@ -17755,6 +17785,10 @@
|
|||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"Provider.Encoding": {
|
||||
"type": "string",
|
||||
"enum": ["zstd", "gzip", "none"]
|
||||
},
|
||||
"Provider.ID": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
@ -17859,6 +17893,9 @@
|
|||
},
|
||||
"transport": {
|
||||
"$ref": "#/components/schemas/Provider.Transport"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
|
|||
|
|
@ -13817,6 +13817,27 @@
|
|||
"permissions": {
|
||||
"$ref": "#/components/schemas/Permission.Ruleset"
|
||||
},
|
||||
"policies": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"enum": ["provider.use", "tool.use", "integration.use"]
|
||||
},
|
||||
"resource": {
|
||||
"type": "string"
|
||||
},
|
||||
"effect": {
|
||||
"type": "string",
|
||||
"enum": ["allow", "deny"]
|
||||
}
|
||||
},
|
||||
"required": ["action", "resource", "effect"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"agents": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
|
|
@ -14190,6 +14211,9 @@
|
|||
"properties": {
|
||||
"compaction": {
|
||||
"$ref": "#/components/schemas/Provider.Compaction"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
@ -14369,6 +14393,9 @@
|
|||
},
|
||||
"transport": {
|
||||
"$ref": "#/components/schemas/Provider.Transport"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
@ -16838,6 +16865,9 @@
|
|||
"properties": {
|
||||
"compaction": {
|
||||
"$ref": "#/components/schemas/Provider.Compaction"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
@ -17755,6 +17785,10 @@
|
|||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"Provider.Encoding": {
|
||||
"type": "string",
|
||||
"enum": ["zstd", "gzip", "none"]
|
||||
},
|
||||
"Provider.ID": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
@ -17859,6 +17893,9 @@
|
|||
},
|
||||
"transport": {
|
||||
"$ref": "#/components/schemas/Provider.Transport"
|
||||
},
|
||||
"encoding": {
|
||||
"$ref": "#/components/schemas/Provider.Encoding"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
|
|
|
|||
|
|
@ -227,13 +227,11 @@ override.
|
|||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [
|
||||
{ "action": "provider.use", "resource": "*", "effect": "deny" },
|
||||
{ "action": "provider.use", "resource": "anthropic", "effect": "allow" },
|
||||
{ "action": "tool.use", "resource": "shell:git push *", "effect": "deny" },
|
||||
],
|
||||
},
|
||||
"policies": [
|
||||
{ "action": "provider.use", "resource": "*", "effect": "deny" },
|
||||
{ "action": "provider.use", "resource": "anthropic", "effect": "allow" },
|
||||
{ "action": "tool.use", "resource": "shell:git push *", "effect": "deny" },
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ V2.
|
|||
As in V1, system configuration and macOS managed preferences have the highest precedence, so their settings override
|
||||
global and project files. Their [policies](/policies#precedence), including migrated `enabled_providers` and
|
||||
`disabled_providers`, also outrank global and project policies. Overriding a setting cannot stop users from adding
|
||||
providers, MCP servers, agents, or plugins, so express admin-enforced restrictions as `experimental.policies` rather
|
||||
providers, MCP servers, agents, or plugins, so express admin-enforced restrictions as `policies` rather
|
||||
than ordinary settings such as `permissions`.
|
||||
|
||||
### Ask OpenCode to migrate
|
||||
|
|
|
|||
|
|
@ -285,9 +285,7 @@ approvals run. It turns `allow` or `ask` into `deny` and never grants access.
|
|||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [{ "action": "tool.use", "resource": "shell:sudo *", "effect": "deny" }],
|
||||
},
|
||||
"policies": [{ "action": "tool.use", "resource": "shell:sudo *", "effect": "deny" }],
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ description: "Allow or deny OpenCode actions on named resources, with organizati
|
|||
---
|
||||
|
||||
Policies decide whether OpenCode may perform an action on a named resource. They are
|
||||
authored under `experimental.policies` and can also be delivered by a connected
|
||||
authored under `policies` and can also be delivered by a connected
|
||||
[OpenCode Console](/console) workspace.
|
||||
|
||||
Policies are separate from [permissions](/permissions). Permissions are per-agent tool
|
||||
|
|
@ -18,15 +18,24 @@ Deny one provider everywhere by adding a statement to `opencode.jsonc`:
|
|||
```jsonc
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"experimental": {
|
||||
"policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }],
|
||||
},
|
||||
"policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }],
|
||||
}
|
||||
```
|
||||
|
||||
A denied provider disappears from the catalog and model selection even when it has
|
||||
valid credentials.
|
||||
|
||||
Earlier releases read policies from `experimental.policies`. That key still works and
|
||||
merges into `policies`:
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }],
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
## Statements
|
||||
|
||||
Each statement has three fields:
|
||||
|
|
@ -47,9 +56,7 @@ more characters and `?` matches one.
|
|||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [{ "action": "provider.use", "resource": "company-*", "effect": "deny" }],
|
||||
},
|
||||
"policies": [{ "action": "provider.use", "resource": "company-*", "effect": "deny" }],
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -64,12 +71,10 @@ action is allowed.
|
|||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [
|
||||
{ "action": "provider.use", "resource": "*", "effect": "deny" },
|
||||
{ "action": "provider.use", "resource": "anthropic", "effect": "allow" },
|
||||
],
|
||||
},
|
||||
"policies": [
|
||||
{ "action": "provider.use", "resource": "*", "effect": "deny" },
|
||||
{ "action": "provider.use", "resource": "anthropic", "effect": "allow" },
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -89,12 +94,10 @@ provider ID: `anthropic`, `openai`, `opencode`, or a custom ID from
|
|||
"settings": { "baseURL": "https://ai.company.example/v1" },
|
||||
},
|
||||
},
|
||||
"experimental": {
|
||||
"policies": [
|
||||
{ "action": "provider.use", "resource": "*", "effect": "deny" },
|
||||
{ "action": "provider.use", "resource": "company-ai", "effect": "allow" },
|
||||
],
|
||||
},
|
||||
"policies": [
|
||||
{ "action": "provider.use", "resource": "*", "effect": "deny" },
|
||||
{ "action": "provider.use", "resource": "company-ai", "effect": "allow" },
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -113,13 +116,11 @@ lists. V1 files still load; see
|
|||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [
|
||||
{ "action": "tool.use", "resource": "shell:git push *", "effect": "deny" },
|
||||
{ "action": "tool.use", "resource": "edit:*.env", "effect": "deny" },
|
||||
{ "action": "tool.use", "resource": "webfetch:*", "effect": "deny" },
|
||||
],
|
||||
},
|
||||
"policies": [
|
||||
{ "action": "tool.use", "resource": "shell:git push *", "effect": "deny" },
|
||||
{ "action": "tool.use", "resource": "edit:*.env", "effect": "deny" },
|
||||
{ "action": "tool.use", "resource": "webfetch:*", "effect": "deny" },
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -141,12 +142,10 @@ broader `deny`, after which the agent's own rules decide.
|
|||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [
|
||||
{ "action": "tool.use", "resource": "shell:*", "effect": "deny" },
|
||||
{ "action": "tool.use", "resource": "shell:git status *", "effect": "allow" },
|
||||
],
|
||||
},
|
||||
"policies": [
|
||||
{ "action": "tool.use", "resource": "shell:*", "effect": "deny" },
|
||||
{ "action": "tool.use", "resource": "shell:git status *", "effect": "allow" },
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -165,13 +164,11 @@ resource is the integration kind and its ID:
|
|||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [
|
||||
{ "action": "integration.use", "resource": "mcp:*", "effect": "deny" },
|
||||
{ "action": "integration.use", "resource": "mcp:github", "effect": "allow" },
|
||||
{ "action": "integration.use", "resource": "plugin:opencode-acme-cli", "effect": "deny" },
|
||||
],
|
||||
},
|
||||
"policies": [
|
||||
{ "action": "integration.use", "resource": "mcp:*", "effect": "deny" },
|
||||
{ "action": "integration.use", "resource": "mcp:github", "effect": "allow" },
|
||||
{ "action": "integration.use", "resource": "plugin:opencode-acme-cli", "effect": "deny" },
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -197,17 +194,13 @@ A repository cannot re-enable a provider you deny globally:
|
|||
|
||||
```jsonc title="~/.config/opencode/opencode.jsonc"
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }],
|
||||
},
|
||||
"policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }],
|
||||
}
|
||||
```
|
||||
|
||||
```jsonc title="project/opencode.jsonc"
|
||||
{
|
||||
"experimental": {
|
||||
"policies": [{ "action": "provider.use", "resource": "openai", "effect": "allow" }],
|
||||
},
|
||||
"policies": [{ "action": "provider.use", "resource": "openai", "effect": "allow" }],
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue