Repository navigation
feat(app-server): enforce an agent profile's secret_refs scope - #364
simonrosenberg wants to merge 6 commits into
Conversation
Cloud resolves the agent profile itself and sends a resolved agent to the agent-server, never agent_profile_id, so the SDK's filter — which lives in the agent-server's profile branch — never ran here. A profile saved with a scope launched with every secret, silently. Resolution now carries the profile's secret_refs out alongside the provenance it already returns (the resolved dump is an AgentSettings, which has no field for it), and both conversation builders narrow their secrets to it after the API merge, so a caller sending extra secrets cannot widen the scope either. Strict, matching the SDK: nothing is added back for either agent kind, so a profile that omits its own ACP provider credential or a git provider token does not receive it. A ref matching no supplied secret is a no-op — this is an allow-list over what a launch assembles, so unlike mcp_server_refs it cannot dangle. Requires an openhands-sdk release containing software-agent-sdk#4931; until the pin in pyproject.toml and the mypy hook's additional_dependencies both move, secret_refs is not a field on AgentProfile and mypy reports it missing. Closes #344 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The gate reads as a permanent exclusion; cloud enforcement is implemented in OpenHands/enterprise#364, so note that it comes out once that ships. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…t scope Two halves were covered but not their join. _user_info_from_settings rebuilds UserInfo from settings.model_dump(); if that ever became a field-by-field copy the refs would be dropped, the filter would read None, and every scoped profile would launch unrestricted without failing anything. Also pins the pass-through for deployments with no agent-profile concept: the file-backed store discards the resolve flags, so the refs stay None there and the filter must not read that as an empty allow-list. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
main added an `llm_profiles` parameter to `_resolve_active_agent_profile` while this branch extended its return tuple with the profile's secret_refs; the signature carries both. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…cret-refs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mypy hook ran in an environment pinned to openhands-sdk 1.39.1, which predates AgentProfile.secret_refs, while pyproject pins 1.50.1. Align the hook with the project pin so mypy sees the field this PR reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||
|
Refreshed onto main without rewriting history. Agent-profile and settings-store suites passed 122 tests against real PostgreSQL; touched-file pre-commit including mypy passed. Keeping this draft: #759 records a reproduced scope bypass when profile resolution fails. A typed stored profile with |
|
CI follow-up: the refreshed branch had 7502 passing tests and 2 failures, both in the unrelated migration-186 OAuth provider tests. The same two tests fail on current main run 38402203103 (7493 passed), and all 5 tests in that migration file pass in isolation locally against real PostgreSQL. This points to an existing suite/process encryption-state interaction, not an agent-profile regression. I am not changing the released migration in this PR. #759 remains the independent reason to keep this secret-scope change draft. |
|
Superseded by #763, which consolidates strict profile secret allow-lists for both OpenHands and ACP launches with the other Enterprise Agent Profile fixes. The replacement uses released SDK 1.54.0, adds strict launch resolution and revision 187 after the current migration head, and includes an upgrade/audit guide. #763 has passing CI, 7,577 passing local backend tests, real HTTP/model QA, and an independent automated QA PASS. Closing this duplicate PR so review and follow-up happen in one place; the linked issues remain tracked until #763 merges. |
HUMAN:
AGENT:
Why
OpenHands/software-agent-sdk#5030 + software-agent-sdk#4931 add
secret_refstoAgentProfileBase: a per-profile allow-list over the user's saved secrets, so a "Code Exploration" agent can be denied the deploy tokens and the production database URL.The SDK's enforcement point is one this app-server never reaches. The filter lives in
conversation_service.start_conversation, insideif request.agent_profile_id is not None:. Cloud resolves the profile itself —settings_store.load(resolve_agent_profile=True, override_agent_profile_id=...)— and builds the outgoing request from the resolved agent:Every
agent_profile_idin that file is an internaloverride_agent_profile_idfor local settings resolution; none becomes a field on the outgoingStartConversationRequest. So a profile saved with a scope resolved and launched with every secret, silently — a control that persists and displays but restricts nothing, which is worse than not offering one. Canvas currently hides it on cloud for that reason (OpenHands/OpenHands#17237); this PR is what lets it be turned back on.Summary
Settings.active_agent_profile_secret_refscarries the resolved profile's allow-list, alongside theactive_agent_profile_id/_revisionprovenance already carried for the same reason: resolution replacesagent_settingswith anAgentSettingsdump, which has no field for it.SaasSettingsStore._resolve_active_agent_profilereturns it (3-tuple → 4-tuple);load()puts it on the settings._apply_profile_secret_scopenarrows the conversation's secrets, applied in both builders (standard and ACP) after the API-secrets merge, so a caller sending extra secrets cannot widen its own scope.Semantics match
openhands.sdk.profiles.resolver.filter_profile_secretsexactly:mcp_server_refsit cannot dangle.None(the default, and every non-profile launch) leaves the secret set byte-identical.store()needs no new guard — it already refuses any settings carryingactive_agent_profile_id, which is always set alongside the new field.Issue Number
Closes OpenHands/OpenHands#344
How to Test
Because the pinned SDK predates the field, the suite above needs the SDK branch:
uv pip install -e /path/to/software-agent-sdk/openhands-sdk # branch: feat-profile-secret-refs uv run --no-sync pytest tests/unit/test_agent_profiles.py -qManually: save several secrets, create an agent profile with
secret_refsnaming a subset, start a conversation with it, and confirm the conversation receives only those.Video/Screenshots
Filter behavior against the real
UserInfo/ resolver on this branch, all four cases:with
agent_profile_secret_scope:filteredlogged (dropped names only, never values).test_resolution_carries_secret_refs_out_of_the_storecovers the half that would otherwise fail silently — if resolution stopped carrying the refs, the filter would simply never fire.Full unit suite: 5724 passed. One unrelated pre-existing failure on macOS (
test_process_sandbox_service.py::test_default_values,/tmpvs/var/foldersTMPDIR) — verified identical onmain.Deployment coverage
Traced each install shape rather than assuming they share a path:
SaasSettingsStoreFileSettingsStoreload()discards the resolve flags — no agent-profile concept, refs stayNone, filter is a pass-through (unchanged behavior)agent_profile_idbranch (software-agent-sdk#4931)Checks behind that table:
AuthUserContext._user_info_from_settingsrebuildsUserInfovia**settings.model_dump(...), so the new field survives the projection — verified live, and now pinned bytest_secret_refs_survive_the_settings_to_user_info_projection. This is the seam that would have disabled the scope silently.SpecifyUserContext.get_user_inforaisesNotImplementedError, so it is not a live conversation-start path.live_status_app_conversation_serviceis the only place that builds aStartConversationRequest; both of its builders loaduserwithresolve_agent_profile=Trueand neither reassignsuserbefore the filter.secretsbetween the filter andcreate_kwargsin either builder, so the filtered map is what ships.store()needed no new guard: it already refuses any settings carryingactive_agent_profile_id, which is always set alongside the new field.Type
Notes
Merge order. This needs three things, in order:
pyproject.toml:openhands-sdk==bumped to that release.dev_config/python/.pre-commit-config.yaml: the mypy hook'sadditional_dependenciespinsopenhands-sdk==1.39.1in its own isolated env — bump it too, or mypy reports"OpenHandsAgentProfile" has no attribute "secret_refs"regardless of the project venv.Until (2) and (3), mypy fails on
storage/saas_settings_store.py. I deliberately did not usegetattr(profile, 'secret_refs', None)to paper over it: the attribute is real once the SDK lands, and a defensive read would silently no-op if the field were ever renamed.Git provider tokens are in scope, by design.
_setup_conversation_secretsinjectsGITHUB_TOKEN/GITLAB_TOKEN/ … on the same channel, so a scoped profile that omits them loses repo auth. That is the honest outcome of the saved configuration, and it matches the SDK — but it is the sharpest edge here, and worth a deliberate look during review. These names are already listed inOVERRIDABLE_SYSTEM_SECRETS.Follow-up: once this ships, re-enable the control for cloud backends in canvas (drop the
kind === "cloud"short-circuit inagentProfileSupportsSecretRefs, OpenHands/OpenHands#17237).🤖 Generated with Claude Code
Enterprise server image for this PR: