Repository navigation
feat(identity): the Principal adapter, read from identity's contract - #2
Merged
Merged
Conversation
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.
Summary
python-commons gets its first package,
jorisjonkers_commons.identity: the Python adapter for identity's Principal contract (JorisJonkers-dev/identity#110, spec JorisJonkers-dev/identity#105, Epic JorisJonkers-dev/identity#114). The repository itself was bootstrapped from repo-template. It has theworkspace-libstopic and theMainruleset requiringPipeline Complete, and release-please is set up as apythonrelease with the version in the release PR title.PrincipalReader.readis the one entry point. It takes a request's headers by name and returns aPrincipal, or raisesPrincipalRefusedwith the contract's reason:X-Identity-Principal, typidentity-principal+jwt, is verified against the Issuer's JWKS. The plainX-Auth-Request-*headers are never read.JWTand aclient_idrequired (not-an-access-tokenotherwise).Unknown key ids refetch the JWKS at most once a minute.
IdentityUnavailablemeans identity could not be asked, which is not a refusal.The policy helpers are plain ASGI, so they wrap a Starlette or FastAPI app or one of its routes:
principal_middlewareanswers 401 to a refused request and 503 when identity is down. A refused WebSocket is closed with 1008.require_role,refuse_tools,require_userandrequire_machineeach answer 403 for the case they refuse.require_recent_two_factor(minutes)sends a stale session 303 to/.auth/step-up?minutes=…&rd=…. It answers 403 to a Personal Token, a tool or a machine.The
Principaldataclass is generated from the pinned schema byscripts/generate_principal.py, and a golden test fails when the two disagree. Signatures usecryptographydirectly, with no JWT library.Checks
wrong-typ.client_idandactivechecks.inactiveat t₀+30s. Five reads ask identity once.task checkruns ruff, ruff format,mypy --strict, actionlint, pytest with a 95% branch-coverage gate (100% now),uv buildand gitleaks. The vendored vectors are allowlisted in.gitleaks.toml, because they hold tokens signed by a test key.Contract
contract/is pinned atcontract/principal/v1.1.0, released by JorisJonkers-dev/identity#132.Closes JorisJonkers-dev/identity#110