Repository navigation
fix(kv): enforce automation permissions on user-auth KV access (OHE-4172) - #762
Merged
hieptl merged 1 commit intoNov 18, 2026
Merged
Conversation
…172) The user-authenticated path of the KV API checked only that the automation belonged to the caller's org. Any caller resolved to that org could read, change and delete the KV data of every automation in it, including a caller holding no permissions at all, which every other router refuses. The path now applies the rules the rest of the service uses: - Every request needs view_automations (403 otherwise), checked before the automation is looked up. - A write (any method but GET) must also pass _assert_can_manage, the rule for editing the automation: manage_automations, or being the user it runs as. A service account's key gets no write, as for edits; its runs keep writing through the per-run KV token. Reads stay open to every holder of view_automations, and the KV token path is unchanged. Tests cover a member reading a teammate's automation and being refused on every write route, an admin writing it, a caller without view_automations, and a service account on the automation it runs. The KV feature map and the design doc's error table state the new rule.
Contributor
|
Warning Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it. |
all-hands-bot
approved these changes
Nov 14, 2026
all-hands-bot
left a comment
Contributor
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Reviewed at head 1ba13a0fe8a358cfc39e03d0d391655dc7a0bdee. The change belongs here: it closes an authorization gap in the Automation Service's own KV API, matching the repo rule that org and automation ownership be authorized independently at every mutation boundary.
What I verified against the workspace code:
- Gating order is right.
_verify_automation_accessrejects a caller withoutview_automationswith 403 before any automation lookup (no id-existence leak), keeps the cross-org 404, and only then applies_assert_can_managefor writes. This mirrorsrequire_permissionusage in every other router and closes the empty-permissions hole from #445. - Write classification is complete. All 13 KV routes depend on
get_kv_auth_context; exactly the three read routes (list, get,len) are GET, and the ten mutating routes (PUT/PATCH/DELETE, incr/decr, lpush/rpush/lpop/rpop, batch) are classified as writes viarequest.method != "GET". The heuristic fails closed for future routes. _assert_can_managereuse is consistent with edit/delete/dispatch/cancel semantics:manage_automations, or the run-as user, and no creator escape for service accounts. Its documented precondition (a priorview_automationscheck) is satisfied by the ordering above. The run's KV-token path short-circuits before user auth and is unchanged.- Tests prove the behavior.
uv run pytest tests/test_kv_user_auth.py→ 38 passed locally, including the new member-403 cases asserting stored values stayed unchanged across all ten write routes, admin write allowed, missing-permission 403, and service-account write refusal. - Docs and CI. The F12 feature map and the
docs/kv-store-design.mderror table describe the new 403s; all GitHub Actions checks pass on this head.
No material correctness, security, compatibility, or acceptance issues found.
✅ APPROVED
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.
Why
The KV API takes two kinds of credential: the per-run KV token, and a normal user credential (API key,
X-Session-API-Keyor session cookie) plus?automation_id=. The user path, added in #445, only checked that the automation belongs to the caller's organization. Any caller resolved to that organization could therefore read, change and delete the KV data of every automation in it, including automations that run as another user or as a service account, and so could any conversation running with a member's key. A caller that arrives with anorg_idbut an empty permission list (the OpenHands server can return that when the caller has no active role in the organization) also got through, although every other router answers 403.Ticket: https://linear.app/all-hands-ai/issue/OHE-4172/security-any-org-member-can-read-change-and-delete-any-automations-kv
Summary
view_automations. Without it the answer is 403Requires view_automations permission, decided before the automation is looked up, so it does not reveal which ids exist._assert_can_manage, the rule that already guards editing, deleting, dispatching and cancelling an automation:manage_automations, or being the user the automation runs as. Otherwise the answer is 403 and nothing is stored.get_kv_auth_contexttreats every method except GET as a write. The three read routes (list, get,len) are the only GET routes; the other ten all change data,lpopandrpopincluded. No route signature changes.AUTOMATION_KV_TOKEN; that path is unchanged.view_automations, so a member can still inspect any automation's state.docs/kv-store-design.mddescribe the new rule.Testing
uv run pytest tests/test_kv_user_auth.py: 38 passed. The newTestUserAuthPermissionscovers a member reading a teammate's automation, a member refused with 403 on each of the ten write routes with the stored values unchanged, an admin writing a teammate's automation, a caller withoutview_automations, and a service account refused a write to the automation it runs. Withkv_router.pyfrommain, 12 of these fail: the ten write routes, the missing permission and the service account.tests/test_session_commit_scope.pyandtests/test_verify_automation_skill.py: 337 passed, includingtests/test_kv_postgres_concurrency.pyagainst PostgreSQL.tests/test_router.py, three intests/test_draft_router.py) need a MinIO endpoint atlocalhost:9000and fail the same way onmainlocally; unrelated to this change.ruff check,ruff format --check,pycodestyleandpyrightare clean on the changed Python files.Notes
?automation_id=: a write now needs an admin's or owner's key, or the key of the user the automation runs as. The run scripts in OpenHands/extensions use the KV token and are not affected. The opt-instructured_publicationmode ofgithub-pr-reviewerwrites its lease keys withREVIEW_COORDINATION_API_KEY; that key must now belong to an admin or owner, or to the user the namespace automation runs as.Jev-Fast-Audit
⚡ Jev fast audit · estimates · 0.37s · commit 1ba13a0
Strongest signal: No primary concern selected.
Evidence: No primary concern to locate.
Coverage: complete supplied coverage; 14/14 hunks, 4/4 files.
All estimates and evidence