Skip to content

fix: authoritative managed-settings.json applied after all user config - #22296

Closed
Daviey wants to merge 2 commits into
anomalyco:devfrom
Daviey:fix/managed-settings-authoritative
Closed

Daviey wants to merge 2 commits into
anomalyco:devfrom
Daviey:fix/managed-settings-authoritative

Conversation

@Daviey

@Daviey Daviey commented Apr 13, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #22292

Type of change

  • Bug fix

What does this PR do?

Two bypass vectors allowed users to override enterprise managed config:

  1. OPENCODE_PERMISSION env var was merged after managed config, so it won. A managed deny rule could be overwritten to allow.
  2. Object fields like mcp, agent, provider etc. were additively merged. Users could inject extra entries alongside managed ones (e.g. adding an evil MCP server or an extra provider).

The fix introduces managed-settings.json (and a managed-settings.d/ drop-in directory) in the system config location. It is loaded last, after all user config, project config, and OPENCODE_PERMISSION, so it cannot be overridden. Object fields in that file replace rather than merge, closing the injection vector.

The existing opencode.json managed config is unchanged and still loads earlier in the chain (for non-authoritative defaults). managed-settings.json is the opt-in high enforcement layer.

How did you verify your code works?

Three commits in this PR, each with a specific purpose:

Commit 1: 5c25db2 (tests only, no fix)

11 tests fail against unpatched code. Run with:

git checkout 5c25db25b
cd packages/opencode
bun test --test-name-pattern "managed"

Output:

(fail) managed settings override user settings
(fail) managed settings override project settings
(fail) managed instructions should replace user instructions, not union
(fail) managed agents should replace user agents, not additively merge
(fail) managed mcp should replace user mcp, not additively merge
(fail) managed commands should replace user commands, not additively merge
(fail) managed providers should replace user providers, not additively merge
(fail) managed formatters should replace user formatters, not additively merge
(fail) managed lsp should replace user lsp, not additively merge
(fail) managed experimental should replace user experimental, not additively merge
(fail) managed skills should replace user skills, not additively merge

3 pass, 9 skip, 11 fail

Commit 2: c5ca9d1 (the fix)

Same tests, now all pass:

git checkout c5ca9d10c
cd packages/opencode
bun test --test-name-pattern "managed"

Output:

14 pass, 9 skip, 0 fail

The 3 tests that already passed at commit 1 (permission deny via OPENCODE_PERMISSION, drop-in fragment ordering, dotfile ignore) continue to pass.

Commit 3: 3a3c2f2 (docs)

Adds documentation for managed-settings.json and managed-settings.d/ drop-in fragments to packages/web/src/content/docs/config.mdx. No code changes.

Screenshots / recordings

N/A, no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@Daviey Daviey changed the title Fix/managed settings authoritative fix: authoritative managed-settings.json applied after all user config Apr 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title Fix/managed settings authoritative doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@chaomao

chaomao commented Apr 17, 2026

Copy link
Copy Markdown

this is really good, I really need it. 👍

@Daviey
Daviey force-pushed the fix/managed-settings-authoritative branch 2 times, most recently from 481122d to 30f6c15 Compare April 17, 2026 09:24
@Daviey
Daviey force-pushed the fix/managed-settings-authoritative branch 3 times, most recently from 78fe4a2 to b634f0d Compare April 28, 2026 00:39
@Daviey
Daviey force-pushed the fix/managed-settings-authoritative branch from b634f0d to 97f740b Compare May 10, 2026 12:32
@rekram1-node

Copy link
Copy Markdown
Collaborator

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@Daviey

Daviey commented May 15, 2026

Copy link
Copy Markdown
Author

@rekram1-node Please can you re-open this PR, the build fails were due to not updating the tests following a clean rebase.

@rekram1-node rekram1-node reopened this May 15, 2026
@Daviey

Daviey commented May 19, 2026

Copy link
Copy Markdown
Author

@rekram1-node Please can this get your attention?

Just to note, the current published documentation states "Managed settings override everything." and "Organizations can enforce configuration that users cannot override. Managed settings are loaded at the highest priority tier."

Which as it currently stands is entirely inaccurate. Please can you consider merging this PR.

Thanks

Daviey added 2 commits May 19, 2026 09:11
Significant refactor to adapt to dev branch structure (top-level exports,
ConfigParse module, ConfigManaged module). The original PR targeted the old
Config namespace structure which has since been refactored away.

Two bypass vectors allowed users to override enterprise managed config:

1. OPENCODE_PERMISSION env var was merged after managed config, so it won.
   A managed deny rule could be overwritten to allow.
2. Object fields like mcp, agent, provider etc. were additively merged.
   Users could inject extra entries alongside managed ones.

Adds managed-settings.json (and managed-settings.d/ drop-in directory)
in the system config location. It is loaded last, after all user config,
project config, and OPENCODE_PERMISSION, so it cannot be overridden. Object
fields in that file replace rather than merge, closing the injection vector.
The upstream Zod-to-Effect-Schema migration renamed ConfigParse.effectSchema
to ConfigParse.schema. The managed-settings parseManagedFile helper still
called the old name, so managed-settings.json was never successfully parsed
and all authoritative override tests failed.
@Daviey
Daviey force-pushed the fix/managed-settings-authoritative branch from 3377938 to 01b8d54 Compare May 19, 2026 08:15
@rekram1-node

Copy link
Copy Markdown
Collaborator

Yes ill take a look

@markoj3s

markoj3s commented May 23, 2026 •

Copy link
Copy Markdown

Glad to see that I am not the only one to notice. Fully agree with below:

Just to note, the current published documentation states "Managed settings override everything." and "Organizations can enforce configuration that users cannot override. Managed settings are loaded at the highest priority tier."

Which as it currently stands is entirely inaccurate. Please can you consider merging this PR.

This fix is highly needed..

@Daviey

Daviey commented Jun 5, 2026

Copy link
Copy Markdown
Author

@rekram1-node Any update please? Thanks

@markoj3s

markoj3s commented Jun 26, 2026 •

Copy link
Copy Markdown

@rekram1-node any update?
@thdxr can we get support on this one?

@josch700

Copy link
Copy Markdown

I would like to add that for agents as an example I think it makes sense to allow them to be made in a project folder. Not every agent needs to be created through that managed json. It's absolutely not ok for them to overwrite the permissions tho. Not quite sure if the replace of settings rather than merge with this PR would allow that scenario.

@Daviey

Daviey commented Jul 26, 2026

Copy link
Copy Markdown
Author

@rekram1-node Any update please? Thanks

@TheDanHealy

Copy link
Copy Markdown

@Daviey - I would love to also see this get into the codebase. Looks like you may need to rebase and fix conflicts to have it ready again since much time has passed.

@markoj3s

Copy link
Copy Markdown

@rekram1-node 🙏🙏🙏🙏🙏

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Managed settings can be bypassed via OPENCODE_PERMISSION env var and additive object merging

7 participants