-
Notifications
You must be signed in to change notification settings - Fork 716
UN-3853 [FIX] Attribute platform-key-created resources to the API key's creator #2274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kirtimanmishrazipstack
wants to merge
14
commits into
main
Choose a base branch
from
UN-3853-co-ownership-resources-with-platform-key
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
91a9e45
UN-3853 [FIX] Attribute platform-key-created resources to the key's c…
kirtimanmishrazipstack b818d85
UN-3853 [FIX] Name the real owner on the deployment and pipeline card…
kirtimanmishrazipstack f3aa84a
UN-3853 Merge branch 'main' into UN-3853-co-ownership-resources-with-…
kirtimanmishrazipstack 136879d
UN-3853 [FIX] Cover platform-key resource ownership with tests
kirtimanmishrazipstack 9194f53
UN-3853 [FIX] Do not grant ownership to a departed organization member
kirtimanmishrazipstack d3421ea
UN-3853 [FIX] Show the owner on a freshly created deployment, and cov…
kirtimanmishrazipstack 8bb2f01
UN-3853 [FIX] Backfill existing platform-key resources and document t…
kirtimanmishrazipstack 98d503c
UN-3853 [FIX] Move the owner grant onto HasMembersMixin
kirtimanmishrazipstack b73e1f8
UN-3853 [FIX] Apply the membership rule on the key-deletion and backf…
kirtimanmishrazipstack 45183a3
UN-3853 [FIX] Name the backfill's model bindings like the rest of the…
kirtimanmishrazipstack b2d830e
UN-3853 [FIX] Cut the comment prose down to what stays true
kirtimanmishrazipstack a57f99b
UN-3853 [FIX] Keep the service account authorized and the audit trail…
kirtimanmishrazipstack 8a18875
UN-3853 [FIX] Drop the now-unused list refresh handler
kirtimanmishrazipstack 1615c57
UN-3853 [FIX] Share the platform-key ownership repair for cloud-only …
kirtimanmishrazipstack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[critical]
grant_ownermoves the OWNER row off the service account, but two authorization paths still authorize by OWNER membership and have nois_service_accountbypass — so every workflow provisioned through a platform key starts failing at execution withPermissionDenied, and migration 0006 applies the same change to already-deployed installs.Provision entirely through a platform API key — the flow this PR exists for: POST an AdapterInstance, then a Workflow, then a tool instance on it.
grant_ownernow writes the OWNERResourceMembershiprow to the key's human creator instead of the service account S.created_byis untouched, soWorkflow.created_byis still S (AuditSerializer.create,backend/backend/serializers.py:12).At run time
WorkflowHelper.run_workflow->validate_tool_instances_metasetsuser = tool.workflow.created_by(= S,workflow_helper.py:289, reached from:321) and callsvalidate_adapter_access(tool_instance_v2/tool_instance_helper.py:520-551). That gate evaluates:is_admin-> False (OrganizationMemberService.is_user_organization_adminearly-returns False for service accounts,organization_member_service.py:40-41;create_api_user_for_keygives the accountUserRole.USER)adapter_instance.shared_to_org-> False (default,adapter_processor_v2/models.py:112-115)_is_resource_owner(S, adapter)-> False after this PR (it consults onlymemberships,permissions/permission.py:79-84; pre-PR the row named S and this returned True)_is_resource_viewer/has_group_access-> False=>
raise PermissionDeniedon every execution. Both transports hit it: the in-backend Celery path and the workers path viatool_instance_v2/internal_views.py:352-366.The same gap hits
IsWorkflowOwnerOrShared(workflow_manager/workflow_v2/permissions.py:40-45) — no service-account short-circuit — so the key gets 403 on the file-history endpoints for workflows it created.Reproduced live against Postgres. With the post-PR grant,
validate_adapter_access(user=service_account)raisesPermissionDenied; the control writing main's service-account OWNER row passes the identical gate. Over real HTTP with platform-key bearer auth:GET .../workflow/<id>/file-histories/returns 403 permission_denied post-PR and 200 with main's row.Note
PromptStudioRegistry.objects.list_toolsdoes have theis_service_accountbypass (prompt_studio_registry_v2/models.py:32-35) — which is likely why this gap went unnoticed. And migration 0006 filtersrole=OWNER, user_id__in=<service accounts>with no content-type restriction, so already-deployed, currently-working platform-key pipelines start failing the moment this deploys.This is not covered by the object-permission short-circuit in
permission.py— neither call site is a DRFhas_object_permissionon a service-account request.Suggested fix: Either add the same
if getattr(user, "is_service_account", False): returnshort-circuit that every other surface has toToolInstanceHelper.validate_adapter_accessandIsWorkflowOwnerOrShared.has_permission; or havegrant_ownerwrite both rows (service account + resolved creator). The owner surfaces already filter service accounts out, so the extra row stays invisible in the UI while nothing that resolves ownership through the membership table regresses.Worth a test that executes a key-provisioned workflow end to end — the new test files assert the create-time row but never an execution.
🤖 Unstract PR review kit (Claude Code) · review-pr-bot:60d76e591c9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Deepak-Kesavan Confirmed and fixed in a57f99b.
Verified the whole chain rather than taking it on trust:
validate_tool_instances_metasetsuser = tool.workflow.created_by(the service account, sincecreated_byis deliberately untouched),validate_adapter_accesshas no service-account bypass,is_user_organization_adminearly-returns False for one, and_is_resource_ownerreads onlymemberships— which after this PR names the human. So every gate term evaluates False. Same gap inIsWorkflowOwnerOrShared.has_permission.Took your first option — the short-circuit — rather than writing both rows, because a second OWNER row would have to be kept in sync by every future create site and the migration, whereas the bypass is the pattern every other surface already uses (
IsOwner,for_user,list_tools).Added two regression tests. Worth noting the first one I wrote was vacuous:
AdapterInstance.objectsis org-scoped andUserContextwas unset, so the gate looped over an empty queryset and passed with the fix reverted. Setting the org identifier makes it fail correctly without the bypass.