Repository navigation
Conversation
…sal is one shared helper server/identity/app/reviewers.py owns the rule: a person who administers the namespace, acts under their own name and wrote none of what they review. A second review of proposed content, with several authors, needs the same rule; one helper keeps the two from drifting. reviewer_subjects() refuses with a typed reason (signed_out, service_account, actor, role) and the calling op words its answer. memory.proposal_decide maps every reason to its one 403 AUTH_INSUFFICIENT body, so no status, code or message changes. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch has not been deployed
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.
Part of: #1143
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
None. No op, field, message or status changes.
Why
memory.proposal_decideaccepts a proposal only from an authenticated person who administers the namespace, acts under their own name and is not the proposer. The rule lived inserver/memory/app/proposals.pyas two private functions. Reviewing a skill revision, which can have several authors, needs the same rule. One helper holds it, so the two reviews cannot drift apart.The design, in
server/identity/app/reviewers.py:person() -> AuthInfo | None: the request's principal when it is authenticated, has a subject and is not a service account.independent(reviewers, authors) -> bool: false whenauthorsis empty or when any author, case-folded, is inreviewers.async reviewer_subjects(org, namespace, actor) -> set[str]: the case-folded subject and aliases of the caller. The aliases are read undersequential_reads(), and a failed read raises. It raisesNotAReviewer(reason), wherereasonis the first test failed, in this order:signed_out(no principal, or no subject),service_account,actor(actoris notwriter_actor()),role(no admin role on the namespace).The helper raises a typed reason and the calling op words its answer, so the rule names no kind of content.
In
server/memory/app/proposals.py:_reviewer_subjectsis deleted._accepting_reviewercallsreviewer_subjectsand maps everyNotAReviewerto the 403AUTH_INSUFFICIENTbodymemory.proposal_decideanswers onmain("A human administrator must review the proposal.").decide()keeps its 48 statements._approval_refusalkeeps its valid-actor test and its content-hash test, and callsindependent(reviewers, {subject_of(proposer)})for the comparison.Choices made while writing it:
reviewer_subjectsstarts fromperson(). A principal that has a subject and is no person is a service account, which gives the second reason. Ifperson()gains a test, a reviewer is held to it too.subject_ofgives''for a pipeline's actor, and{''}is an author set with one member that names no reviewer. This is whatmaindoes;test_a_human_administrator_can_accept_what_a_pipeline_proposedpins it.server.authat module level, asserver/identity/app/caller_home.pyand its neighbours do, and callscontext.current_auth()andaliases.read_aliases()through their modules.proposals.pyimports the helper at module level. No module underserver/importsproposals.pyat module level, so no import cycle forms; the import check under Tests covers twelve entry orders.Scope and risk
Touches:
server/identity/app/reviewers.py(added): the three functions andNotAReviewer.server/memory/app/proposals.py:_reviewer_subjectsis replaced by_accepting_reviewer, and one condition of_approval_refusalcallsindependent.tests/unit/test_reviewer_rule.py(added) and one test added totests/unit/test_proposals.py. No existing test is edited.Left alone:
decide()beyond the one renamed call, the content-hash test, the automatic policy, the wire models, the transports, the SDKs, the CLI and the dashboard. Reviewing a skill revision, and its messages, is a later change. Stopping a person from accepting what their own token proposed is a behaviour change and is not made here.What could break:
test_an_unreadable_alias_directory_cannot_establish_an_independent_reviewer, which is unchanged).actoris still tied to the token throughwriter_actor().server.memory.app.proposalsloadsserver.auth.authz,server.auth.aliasesandserver.auth.contextwhen it is first imported, wheremainloads them on the first accepted decision.Compatibility, rollout and rollback
memory.proposal_decideanswers the same status, code and message for the same request over HTTP, MCP, the SDKs andloom call.Tests
The tests were written before the code.
tests/unit/test_reviewer_rule.pyfailed at import while the module did not exist. With the helper written andproposals.pystill as onmain,test_proposal_refusal_is_unchangedand the test added totest_proposals.pypassed: they pin the answersmaingives.tests/unit/test_reviewer_rule.py, with realAuthInfoprincipals in the request context, the gate answered from the token's role claim, and an alias read that records whether it ran sequentially:test_each_refusal_has_its_reason(8 cases): no principal, a principal with no subject, a service account, an actor other than the token's, and a writer each raiseNotAReviewerwith their reason and make no alias read. Three more cases fail several tests at once and get the first reason in the order above.test_another_actor_is_refused: a human administrator under their own actor gets{subject, alias}case-folded, from one sequential alias read. The same administrator passing another name, theprocess:kind, their own name in another case, a bare subject or''is refused withactor.test_no_author_is_not_independent: an empty author set is not independent, and neither is an author equal to the reviewer's alias in another case, alone or beside an unrelated author.test_a_person_is_signed_in_and_not_a_service_account:person()returns the principal for a signed-in person andNonewith no principal, with no subject, and for a service account.test_proposal_refusal_is_unchanged(the same 8 cases throughproposals.decide): each raises a 403 whose detail is{"code": "AUTH_INSUFFICIENT", "message": "A human administrator must review the proposal."}and runs no statement.tests/unit/test_proposals.py::test_a_human_administrator_can_accept_what_a_pipeline_proposed: a proposal whose actor is a pipeline's is accepted by a human administrator.Each of these thirteen one-line defects, applied alone, fails at least one of the tests above: the role tested before the actor; a service account admitted by
person(); the actor test removed; the role test removed; an empty author set independent; authors not case-folded; reviewer subjects not case-folded; the alias read not sequential;signed_outgiven to a service account; the 403 message, status or code changed; the independence comparison removed from_approval_refusal.What ran at this head, with
pytest -n 2:test_reviewer_rule.py,test_proposals.py,test_definition_draft_access.py,test_proposals_read_scope.py,test_graded_runs.py,test_proposal_triage.py,test_badge_reads.py,test_memory_import.py) under three random seeds: 184 passed, 9 skipped each time. The skipped cases need aclickhousebinary, which this machine does not have.test_package_contracts.py(unchanged),test_op_transport_contract.py,test_tunable_constants.py,test_store_names_refused.py,test_degraded_unnoted.py,test_public_copy.py,test_doc_links.py,test_agent_instructions.py,test_test_inventory.py,test_coverage_floors.py,test_integration_suite_targets.py,test_clickhouse_mutation_inventory.py, and the 54 unit files that scan the tree's Python files: 1853 passed, 10 skipped. The skipped cases are intest_store_names_refused.pyand need theclickhousebinary.python -P -c "import <module>"in a fresh interpreter forserver.auth.authz,server.auth.context,server.auth.aliases,server.memory.app.provenance,server.operations.registry,server.memory.app.proposals_ops,server.tasks.app.run,server.identity.app.reviewers,server.memory.app.proposals,server.memory.api.ops_proposals,server.transport.gatesandserver.workers.registry: each imports.pytest tests/analyzeragainst a ClickHouse started for this task (dev/ci_start_clickhouse.sh,make migrate): 12 passed, andtests/analyzer/shapes.txthas no diff.test_proposal_independent_review.py(unchanged),test_graded_runs_proposals.pyandtest_proposal_triage.py: 4 passed.test_sdk_example_knowledge_factory.py, whose example accepts proposals: 17 passed.ruff checkon the pathsmake lintnames,ruff format --checkonserverandtests,make typecheck, the function-length gate (decide()has 48 statements here and onmain), the secret gate, and the generator checksdocs_referenceandop_reach_censuspass.make formatas a whole and the Rust, Go and shell formatters (rustfmt,gofmtandshfmtare not installed on this machine), and Biome. This change touches no op, field, setting, shell file or frontend file, so no generator has new output.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code wrote the diff and ran the checks listed under Tests.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.Unticked: this change has no migration, no plugin file and no frontend file, so those three checks did not run; the CLA line is the committer's to confirm. No generated file changes: the generator checks listed under Tests report every generated file current. No page under
docs/names the two private functions, so no page changes.🤖 Generated with Claude Code
Note
Medium Risk
Refactors the security boundary for proposal acceptance without intended wire or behavior changes; correctness depends on preserved check order and refusal mapping, which new tests pin.
Overview
Extracts who may accept proposed content into
server/identity/app/reviewers.pyso memory proposal acceptance and future skill-revision review can use the same rule without duplicating checks.The new module exposes
person(), case-foldedindependent(reviewers, authors), andreviewer_subjects(org, namespace, actor), which enforces signed-in human (not service account), actor matcheswriter_actor(), namespace ADMIN, and sequential alias reads. Failures raiseNotAReviewerwith ordered reasons (signed_out→service_account→actor→role).In
proposals.py, private_reviewer_subjectsbecomes_accepting_reviewer, which calls the shared helper and still maps every refusal to the same 403AUTH_INSUFFICIENTmessage._approval_refusalusesindependent()for the proposer-vs-reviewer check (including empty author sets and alias case-folding).Adds
test_reviewer_rule.pyand pins that a human admin can accept proposals whose actor is a pipeline (process:…).Reviewed by Cursor Bugbot for commit e8138bf. Bugbot is set up for automated code reviews on this repo. Configure here.