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
rust-commons gets its first module,
jorisjonkers_commons::identity: the Rust adapter for identity's Principal contract (JorisJonkers-dev/identity#111, 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 arustrelease with the version in the release PR title. It is one crate,jorisjonkers-commons, which consumers take by git URL and tag.PrincipalReader::read(&HeaderMap)is the one entry point. It returns aPrincipal, orReadError::Refused(Refusal)with 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 (NotAnAccessTokenotherwise).Unknown key ids refetch the JWKS at most once a minute.
ReadError::Unavailablemeans identity could not be asked, which is not a refusal.The middleware and the policy helpers are tower layers, so they wrap an axum router or one of its routes:
PrincipalLayerputs the Principal in the request's extensions. It answers 401 to a refused request and 503 when identity is down.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.HTTP goes through a
Fetchtrait. The defaultReqwestFetchuses reqwest with rustls and sits behind the defaultreqwestfeature. Signatures are verified withring, with no JWT crate. ThePrincipaltype is generated from the pinned schema by a golden test,tests/principal_type.rs(PRINCIPAL_UPDATE=truerewrites it).Checks
wrong-typ.activechecks, the refetch limit and the answer lifetime. One mutation survived: accepting an empty-stringclient_id. No vector has one, and a missingclient_idis still refused.inactiveat t₀+30s. Five reads ask identity once.task checkrunscargo fmt --checkandclippy -D warnings(pedantic, with and without default features), plus rustdoc with warnings denied, actionlint,cargo llvm-covwith a 95% line gate (99% now) and gitleaks. The vendored vectors and the tests' signing key are allowlisted in.gitleaks.toml.Contract
contract/is pinned atcontract/principal/v1.1.0, released by JorisJonkers-dev/identity#132.Closes JorisJonkers-dev/identity#111