fix(access): forbid clause scopes the canary grant against its developer role (#1727)
Quality / check (push) Successful in 3m37s
deploy / gate (push) Successful in 4m45s
deploy / archied-image (push) Successful in 2m53s
deploy / agent-image (push) Successful in 10s
deploy / dist-zip (push) Skipped

Service accounts created through the identities API are assigned the
developer role in the request's org, whose shipped policy permits read and
write across the org -- the permit alone did not scope the canary. Install a
matching org-canary-grant-forbid policy (access.CanaryGrantForbidPolicy) that
negates exactly the permit's surface for the canary identity; a forbid wins
within the level, so the role can no longer widen access. Engine tests pin
the surface with the principal carrying the developer role, and the
rehearsal now proves it live: the scoped token gets 403 on /api/access/policies
and 200 on /api/chat/update, and the full canary loop runs on it.

task check passes; task canary:rehearse green (REHEARSE_EXIT=0).
This commit is contained in:
sam committed 2026-11-02 06:23:38 +11:00
1 parent c180a2debb
commit 2f8076d7f8
5 files changed
+180 -29

No files matched your search

+21 -10
View File
@@ -113,17 +113,23 @@ func TestWorkspaceEnvironment(t *testing.T) {
}
}
// TestCanaryGrant pins the scoped canary grant: the one identity it names, with
// no role, may read the signal surface, read and write update-settings, and
// trigger an install -- and nothing else, neither for it nor for anyone else.
// TestCanaryGrant pins the scoped canary grant: the one identity it names may
// read the signal surface, read and write update-settings, and trigger an
// install -- and nothing else, neither for it nor for anyone else. The canary
// principal carries the developer role (API-created service accounts are
// assigned it); the grant's forbid must keep the role from widening access.
func TestCanaryGrant(t *testing.T) {
const canaryID = identity.IdentityID("canary-svc")
grant := access.CanaryGrantPolicy(org.DefaultOrgID, string(canaryID))
engine := New(append(access.ShippedOrgPolicies(org.DefaultOrgID), grant))
forbid := access.CanaryGrantForbidPolicy(org.DefaultOrgID, string(canaryID))
engine := New(append(access.ShippedOrgPolicies(org.DefaultOrgID), grant, forbid))
if len(engine.Problems()) != 0 {
t.Fatalf("problems = %v, want the canary grant to compile", engine.Problems())
}
canary := access.Principal{IdentityID: canaryID, Org: org.DefaultOrgID}
canary := access.Principal{
IdentityID: canaryID, Org: org.DefaultOrgID,
Memberships: []org.Membership{{IdentityID: canaryID, OrgID: org.DefaultOrgID, Role: org.RoleDeveloper}},
}
other := access.Principal{IdentityID: "someone-else", Org: org.DefaultOrgID}
at := func(kind access.ResourceKind, id string) access.Resource {
return access.Resource{Kind: kind, ID: id, Org: org.DefaultOrgID}
@@ -171,12 +177,17 @@ func TestCanaryGrant(t *testing.T) {
// through the policy store.
func TestCanaryGrantValidates(t *testing.T) {
grant := access.CanaryGrantPolicy(org.DefaultOrgID, "canary-svc")
if err := grant.Validate(); err != nil {
t.Fatalf("Validate: %v", err)
forbid := access.CanaryGrantForbidPolicy(org.DefaultOrgID, "canary-svc")
for _, p := range []access.Policy{grant, forbid} {
if err := p.Validate(); err != nil {
t.Fatalf("Validate %s: %v", p.ID, err)
}
}
engine := New([]access.Policy{grant})
if err := engine.Validate(grant); err != nil {
t.Fatalf("engine Validate: %v", err)
engine := New([]access.Policy{grant, forbid})
for _, p := range []access.Policy{grant, forbid} {
if err := engine.Validate(p); err != nil {
t.Fatalf("engine Validate %s: %v", p.ID, err)
}
}
if len(engine.Problems()) != 0 {
t.Fatalf("problems = %v, want none", engine.Problems())