Files
archie/internal/domain/access/canary.go
T
sam 2f8076d7f8
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
fix(access): forbid clause scopes the canary grant against its developer role (#1727)
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).
2026-11-02 06:23:38 +11:00

60 lines
2.9 KiB
Go

package access
import "github.com/samcharles93/archie-core/internal/domain/org"
// CanaryGrantID is the ID the canary's scoped grant is known by in the policy
// store and in denial records. A stored policy must not reuse it: the store's
// seeding and the reset command overwrite shipped IDs, and this one is
// installed by the operator from CanaryGrantPolicy's text.
const CanaryGrantID = "org-canary-grant"
// CanaryGrantForbidID is the matching forbid's ID: the grant only scopes the
// canary if everything else it could reach is forbidden, because the identity
// may also carry a role (API-created service accounts are assigned developer)
// whose shipped policy permits broadly within the org. A forbid wins within
// the level, so the pair scopes the identity regardless of its role.
const CanaryGrantForbidID = "org-canary-grant-forbid"
// canaryGrantActions is the exact action surface the canary needs, as one
// Cedar condition shared by the grant's permit and its forbid.
func canaryGrantActions() string {
return `(
(action == Archie::Action::"read" && ["dashboard", "task"].contains(resource.kind)) ||
(action == Archie::Action::"read" && resource == Archie::Object::"update-settings") ||
(action == Archie::Action::"update" && resource == Archie::Object::"update") ||
(action == Archie::Action::"manage_identities" && resource == Archie::Object::"update-settings")
)`
}
func canaryPrincipal(identityID string) string {
return `principal == Archie::Identity::"` + identityID + `"`
}
// CanaryGrantPolicy is the grant a CI canary carries instead of instance
// admin: exactly one named identity may read the dashboard's signal surface
// (chat update, alerts, logs, tasks), read and write the update-settings
// resource, and trigger an update install or deferral. Install it together
// with CanaryGrantForbidPolicy, which forbids the same identity from
// everything else. Every clause is guarded by the resource belonging to the
// principal's own org, which the engine enforces structurally anyway.
func CanaryGrantPolicy(orgID org.OrgID, identityID string) Policy {
text := `permit(principal, action, resource) when {
resource.org == principal.org &&
` + canaryPrincipal(identityID) + ` &&
` + canaryGrantActions() + `
};`
return Policy{ID: CanaryGrantID, Level: LevelOrg, OrgID: orgID, Text: text}
}
// CanaryGrantForbidPolicy forbids the canary identity from everything outside
// CanaryGrantPolicy's surface, so a role assigned to the identity (service
// accounts created through the API carry developer) cannot widen it.
func CanaryGrantForbidPolicy(orgID org.OrgID, identityID string) Policy {
text := `forbid(principal, action, resource) when {
resource.org == principal.org &&
` + canaryPrincipal(identityID) + ` &&
!` + canaryGrantActions() + `
};`
return Policy{ID: CanaryGrantForbidID, Level: LevelOrg, OrgID: orgID, Text: text}
}