fix(authz): register build agents as resources#283
Merged
Conversation
danielmillerp
approved these changes
Jun 8, 2026
danielmillerp
left a comment
Collaborator
There was a problem hiding this comment.
do we need this for deploys?
Contributor
This was referenced Jun 8, 2026
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.
Summary
/agents/register-buildto callauthorization_service.register_resource(...)for the returned agent resource instead of grant-only authz.grant.Why
grantmaps to Sparkgrant_resource_role, whileregister_resourcemaps to Spark resource lifecycle registration. Build-created agents need the lifecycle registration so downstream resources such as agent builds can use the agent as their parent resource.Validation
uv run python scripts/run_tests.py tests/unit/api/test_agents_register_build_authz.pyuv run ruff check src/api/routes/agents.py tests/unit/api/test_agents_register_build_authz.pyuv run ruff format --check src/api/routes/agents.py tests/unit/api/test_agents_register_build_authz.pyGreptile Summary
This PR fixes the authorization path for the
/agents/register-buildendpoint by replacingauthorization_service.grant(...)withauthorization_service.register_resource(...), which maps to Spark's resource lifecycle registration instead of a role-assignment operation. A new test file is added to explicitly verify the correct call is made and thatgrantis never invoked.agents.py: Single-line swap fromgranttoregister_resourceat the end ofregister_build, plus an updated docstring.test_agents_register_build_authz.py: New test file with a happy-path test and a re-entrant idempotency test that assertregister_resourceis called (andgrantis not) on every invocation, including repeated calls for an already-existing agent.Confidence Score: 5/5
Safe to merge — the change is a targeted one-line correction to the authz call, backed by a new test file that covers both the new-agent and re-entrant paths.
The route change is minimal and intentional: replacing grant with register_resource aligns the build-registration flow with Spark's resource lifecycle model. The new test file explicitly asserts the correct method is called and that grant is never invoked, including on repeated calls for the same agent. No logic outside the authz call was modified.
No files require special attention.
Important Files Changed
grantforregister_resourceon theregister_buildendpoint, with a matching docstring update. Logic is minimal and correct.register_build), assertingregister_resourceis called andgrantis never called.Sequence Diagram
sequenceDiagram participant Client participant register_build route participant authorization_service participant agents_use_case Client->>register_build route: POST /agents/register-build register_build route->>authorization_service: check(agent("*"), create, principal_context) authorization_service-->>register_build route: OK register_build route->>agents_use_case: register_build(name, description, ...) agents_use_case-->>register_build route: agent_entity register_build route->>authorization_service: register_resource(agent(agent_entity.id), principal_context) note over authorization_service: Spark resource lifecycle registration<br/>(was: grant_resource_role) authorization_service-->>register_build route: OK register_build route-->>Client: Agent responseReviews (2): Last reviewed commit: "test(authz): cover reentrant build regis..." | Re-trigger Greptile