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

+73 -1
View File
@@ -7,6 +7,9 @@
# archie-ui) with its own config, state dir and ports. The loop's commands --
# release canary start, release canary status, release canary check and
# release canary promote -- are then run against that host, each step printed.
# The loop authenticates with a scoped service-account token carrying only
# the org-canary-grant policy (#1727), and a step proves that token is denied
# everything outside the grant.
# The local host has no systemd, so once the install has switched the binary
# the script restarts archied itself, the way an unmanaged host's operator
# would.
@@ -41,6 +44,7 @@ trap cleanup EXIT INT TERM
die() {
echo "canary-rehearse: $*" >&2
keep=1
exit 1
}
@@ -269,6 +273,60 @@ resp=$(api POST /api/control-plane/resources/update-settings/commands/replace \
"{\"value\":$value,\"expected_version\":$ver}")
printf '%s' "$resp" | grep -q '"resource"' || die "could not set update-settings on the local host: $resp"
# --- the scoped canary grant (#1727): a service account, not instance admin --
# Create a service_account identity, mint a token for it, install the
# org-canary-grant policy, then prove the token can read the signals but
# nothing else.
echo
echo "== creating the canary service account and installing the scoped grant"
canary_id=$(api POST /api/identities '{"display_name":"canary","kind":"service_account"}' | py 'd["id"]') ||
die "could not create the canary service account"
[ -n "$canary_id" ] || die "identity create printed no id"
scoped=$(api POST "/api/identities/$canary_id/tokens" '{"name":"canary","days":7}' | py 'd["token"]') ||
die "could not mint a token for the canary identity"
[ -n "$scoped" ] || die "token create printed no token"
grant_policy() { # id prefix permit|forbid -> policy JSON on stdout
python3 -c 'import json, sys
who, effect, identity = sys.argv[1], sys.argv[2], sys.argv[3]
actions = """(
(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")
)"""
body = """ resource.org == principal.org &&
principal == Archie::Identity::"%s" &&
%s%s""" % (identity, "!" if effect == "forbid" else "", actions)
print(json.dumps({"id": "org-canary-grant" + ("-forbid" if effect == "forbid" else ""),
"level": "org", "org_id": "org-sys",
"text": "%s(principal, action, resource) when {\n%s\n};" % (effect, body)}))' "$1" "$2" "$canary_id"
}
for effect in permit forbid; do
resp=$(api PUT /api/access/policies "$(grant_policy grant "$effect")")
printf '%s' "$resp" | grep -q '"version"' || die "could not install the canary grant $effect policy: $resp"
done
bearer() { # path -> curl with the scoped token, prints the status code
curl -sS --max-time 15 -o /dev/null -w '%{http_code}' \
-H "Authorization: Bearer $scoped" "$base$1"
}
bearer_body() { # path -> curl with the scoped token, prints the body
curl -sS --max-time 15 -H "Authorization: Bearer $scoped" "$base$1"
}
# The policy chain reloads asynchronously; allow a few seconds for the grant.
# The negative probe can run now; the positive one must wait for the canary
# loop to switch the channel to next (a missing stable tag is a 502 from the
# update check, not an authorization answer).
i=0
code=000
while :; do
code=$(bearer /api/access/policies)
[ "$code" != "200" ] && break
i=$((i + 1)); [ "$i" -gt 45 ] && die "the scoped canary token can read the policies API: the grant is not scoped"
sleep 1
done
echo "scoped token reads /api/access/policies: $code (denied, as intended)"
# --- the canary loop, each step printed ---------------------------------------
failed=0
@@ -287,7 +345,9 @@ run_step() { # description command...
fi
}
export ARCHIE_CANARY_TOKEN=$token
# The canary loop runs with the scoped service-account token, not the admin
# one: that is the point of #1727.
export ARCHIE_CANARY_TOKEN=$scoped
echo
echo "== release canary start -- point the host at next and install $release_version"
@@ -326,6 +386,18 @@ else
keep=1
fi
# Now that the canary follows next, the scoped token's positive probe: the
# policy chain reloads asynchronously, so allow a few seconds.
i=0
code=000
while :; do
code=$(bearer /api/chat/update)
[ "$code" = "200" ] && break
i=$((i + 1)); [ "$i" -gt 45 ] && die "the scoped canary token never got read access to /api/chat/update (last status $code: $(bearer_body /api/chat/update))"
sleep 1
done
echo "scoped token reads /api/chat/update: 200"
run_step "release canary status -- what the canary runs and how the window is going" \
timeout 120 "$bin/archied" release canary status -dashboard "$base" \
-source "127.0.0.1:$reg_port/archie" -key "$pub"