fix: do not bypass permission grants for agent-created resources #142
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.
Summary
Fixes the authorization bypass bug that caused 403 Forbidden errors when users tried to view agent-created tasks from the SGP UI.
Root Cause: When agents create tasks via ACP,
authorization_service._bypass()was returningTruebecauseagent_identityis set. This causedgrant()to skip creating permission records, so users couldn't access those tasks later even with proper role-based access.The Fix: Split the bypass logic into two methods:
_bypass_check(): Used forcheck()andlist_resources()- bypasses whenagent_identityis set OR authorization is disabled (preserves existing agent-to-agent trust behavior)_bypass_write(): Used forgrant()andrevoke()- only bypasses when authorization is disabled, NOT whenagent_identityis set (ensures permission records are always created)Evidence
From SGP staging logs, multiple 403 errors for task
f46e8192-2cca-415c-95e3-27f5867ea418:Infrastructure was healthy (RDS CPU 8-9%, replica lag 15-25ms, Redis 1% CPU) - confirming this is an application-level bug, not infrastructure.
Test plan
Related
6939c7450f636b79305ab5ce([Demo] Financial Services)