feat(claude-code): add managed_settings input for policy delivery via /etc/claude-code#863
Open
morganl-ant wants to merge 3 commits intocoder:mainfrom
Open
feat(claude-code): add managed_settings input for policy delivery via /etc/claude-code#863morganl-ant wants to merge 3 commits intocoder:mainfrom
morganl-ant wants to merge 3 commits intocoder:mainfrom
Conversation
…licy delivery The module currently configures permission posture by writing bypassPermissionsModeAccepted, autoModeAccepted, and primaryApiKey directly into the user-writable ~/.claude.json, and forces --dangerously-skip-permissions on every task launch regardless of the configured permission_mode. Both bypass Claude Code's permission system rather than configuring it. This adds a managed_settings input that renders to /etc/claude-code/managed-settings.d/10-coder.json, the sanctioned drop-in directory Claude Code reads at highest precedence. The file is root-owned so users cannot override it from inside the workspace, and the mechanism is purely client-side so it works with any inference backend (Anthropic API, Bedrock, Vertex, AI Gateway). permission_mode, allowed_tools, and disallowed_tools are deprecated in favor of managed_settings.permissions and are shimmed into the policy file for one release when managed_settings is not set. start.sh now only adds --dangerously-skip-permissions for tasks when no explicit permission_mode is configured (same approach as coder#846), and install.sh no longer writes permission-acceptance flags or the API key into ~/.claude.json.
- The legacy-shim test set disallowed_tools, which triggered a pre-existing 'coder --disallowedTools' call in setup_claude_configurations. coder is not present in the test container so set -e aborted before the policy file was written. Those calls are redundant now that the legacy shim writes allow/deny via managed-settings.d, so remove them. - claude-no-policy-keys-in-claudejson: configure_standalone_mode guards on CLAUDE_API_KEY in the environment, which coder_env provides in production but not in the test container. Pass coderEnvVars to execModuleScript so the file is created.
Member
|
This would need rebasing after #861 is merged. Thanks for your contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The module configures Claude Code's permission posture by reaching around the permission system rather than through it:
scripts/install.shwritesbypassPermissionsModeAccepted,autoModeAccepted, andprimaryApiKeydirectly into the user-writable~/.claude.json. Any process in the workspace can read the API key or flip the acceptance flags back.scripts/start.shadds--dangerously-skip-permissionsto every task launch, even when the template author set an explicitpermission_mode. The README has to carry a security warning telling people the module bypasses permission checks.permission_mode,allowed_tools, anddisallowed_toolseach plumb through a different ad-hoc path (CLI flag,codersubcommand) instead of a single policy surface.Change
Add a
managed_settingsinput that renders to/etc/claude-code/managed-settings.d/10-coder.json. Claude Code reads that drop-in directory at startup with the highest configuration precedence (above~/.claude/settings.jsonand project settings), so template authors get an admin-controlled policy file that users inside the workspace cannot override. The mechanism is a local file read with no API call, so it works identically for the Anthropic API, AWS Bedrock, Google Vertex AI, and AI Bridge / AI Gateway.Supporting changes:
install.shwrites the policy file (root-owned, 0644) and stops writingbypassPermissionsModeAccepted,autoModeAccepted, andprimaryApiKeyinto~/.claude.json. The API key is already exported viacoder_envasCLAUDE_API_KEY; duplicating it on disk is unnecessary.hasCompletedOnboardingstays because there is no env-var alternative for it.start.shonly adds--dangerously-skip-permissionsfor tasks when no explicitpermission_modeis set (same fix as fix(claude-code): don't pass --dangerously-skip-permissions in auto mode #846; included here so this PR is self-contained, happy to drop if fix(claude-code): don't pass --dangerously-skip-permissions in auto mode #846 lands first).permission_mode,allowed_tools, anddisallowed_toolsare marked deprecated and shimmed intomanaged_settings.permissionsfor one release whenmanaged_settingsis not provided.Relationship to #861
#861 strips this module to install-and-configure and removes
permission_mode/allowed_tools/disallowed_toolsoutright.managed_settingsis the natural replacement for those: it is install-time (survives thestart.shremoval), it covers everything the dropped variables did plushooks,env,model,apiKeyHelper, and the rest of the settings schema, and it does not require the module to know anything about how Claude is launched. If #861 lands first I will rebase this on top and drop the deprecation shim and thestart.shhunk.Validation
terraform fmt/terraform validatecleanclaude-managed-settings-written,claude-managed-settings-legacy-shim,claude-no-policy-keys-in-claudejson, plus an assertion inclaude-auto-permission-modethat--dangerously-skip-permissionsis absent when a mode is set/etc/claude-code/managed-settings.d/*.jsonprecedence in the Claude Code CLI sourceCloses #818. Relates to #284, #846, #861.
Disclosure: I work at Anthropic on the Claude Code team. Happy to adjust scope or split this further if that is easier to review.