feat(douanier): adopt the platform's path-derived scope convention (#43)
The audio API now speaks the platform scope convention (nechapi scopes.py):
access is hierarchical realm:domain:path and the required scope is DERIVED FROM
THE ROUTE, so it's maintenance-free — add an endpoint and its scope exists.
- scopes.py — vendored byte-for-byte from nechapi/_platform/scopes.py; a
drift-guard test (test_scopes.py) fails if the two ever diverge, so the
gateway and this service can never disagree on who's allowed in.
- app.py — replaced the per-route require_scope("emotion"|"features"|…) strings
with ONE path-derived dependency: `require` computes api:audio:<path> from the
request and checks it; `require_auth` covers /me (any identity). Also closed a
footgun: a gateway-injected request with a MISSING X-Scopes header now defaults
to NO scopes (was "*").
- auth.py — Principal.has_scope is now the hierarchical matcher (api:audio:*
authorizes api:audio:analyze:emotion, etc.).
- tests — gateway-header tests grant api:audio:*; the scope-enforcement tests now
prove real path-derivation (a sibling grant like api:audio:features → 403 on
/grade and /onsets). +test_scopes.py for the matcher + drift guard. 67 passing.
- clients/README — scope table rewritten to the convention (api:audio:<path>,
grant api:audio:* or api:* for breadth).
Validated end-to-end through https://api.nech.pl/audio/v1 with a freshly minted
api:* token: /me → scopes [api:*]; /features 200 (cache miss→hit); a sibling
scope 403s; no-identity 401s. Built + redeployed douanier:latest to erable
(seccomp=unconfined per DEPLOY.md).
Showing
armada/api/scopes.py
0 → 100644
armada/api/tests/test_scopes.py
0 → 100644
Please
register
or
sign in
to comment