feat(shared-kernel): add application-level authorization hook#340
feat(shared-kernel): add application-level authorization hook#340florishafkenscheid wants to merge 40 commits into
Conversation
…blic_query_handler`
…ption<Actor>>>` to custom `RequestActor` extractor
nanderstabel
left a comment
There was a problem hiding this comment.
Some more places in the code need to utilize a public command handler, see: 20734ae
There was a problem hiding this comment.
Pull request overview
This PR introduces an application-layer authorization hook that wraps command/query execution across bounded contexts, allowing authorization to be enforced below inbound adapters (HTTP, queues, etc.) while preserving current default allow-all behavior.
Changes:
- Added shared authorization primitives (
Actor,AuthorizationRequest,AuthorizationOperation,AuthorizationChecker) and wired them intoApplicationService+ServiceHandledispatch. - Introduced HTTP actor extraction middleware +
RequestActorextractor, and applied actor-required middleware to the configuration endpoint. - Updated shared handler utilities, state wiring, and documentation/configuration to support authorization and dev-only settings.
Reviewed changes
Copilot reviewed 70 out of 71 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| shared-kernel/src/service_registry.rs | Adds actor-aware dispatch APIs and maps authorization errors through service handle. |
| shared-kernel/src/lib.rs | Exposes the new authorization module from shared-kernel. |
| shared-kernel/src/authorization.rs | Introduces core authorization/actor traits and error types. |
| shared-kernel/src/application_service.rs | Adds authorization checks before executing commands/queries; introduces shared error wrapper. |
| docs/problem-details/authorization.md | Documents 401/403 problem details for authorization failures. |
| docs/configuration/profiles.md | Documents dev-only configuration settings (e.g., UNICORE__DEV__API_KEY). |
| Cargo.lock | Locks new/updated workspace dependencies (e.g., async-trait, shared-kernel references). |
| agent_verification/src/state.rs | Adds authorization_checker to verification state. |
| agent_verification/Cargo.toml | Adds shared-kernel dependency. |
| agent_store/src/lib.rs | Wires AllowAllAuthorizationChecker into each bounded-context state. |
| agent_store/Cargo.toml | Adds shared-kernel dependency. |
| agent_shared/src/profile.rs | Makes ApplicationProfile Clone + Copy to support profile application. |
| agent_shared/src/handlers.rs | Adds authorized command/query handlers plus public (no-auth) variants; introduces handler error wrappers. |
| agent_shared/src/config/mod.rs | Adds dev configuration section and profile-based clearing in production. |
| agent_shared/Cargo.toml | Adds shared-kernel dependency. |
| agent_macros/src/lib.rs | Calls apply_profile() after loading derived config structs. |
| agent_library/src/state.rs | Adds authorization_checker to library state. |
| agent_library/Cargo.toml | Adds shared-kernel dependency. |
| agent_issuance/src/status_list/application/token_status_list_service.rs | Switches to public query helper for protocol-level access. |
| agent_issuance/src/state.rs | Adds authorization_checker and threads it into internal command invocations. |
| agent_issuance/src/application/nonce_validation_service.rs | Switches nonce operations to public command/query helpers. |
| agent_issuance/Cargo.toml | Adds shared-kernel dependency. |
| agent_identity/src/state.rs | Adds authorization_checker and updates initialization flows to use public queries + authorized commands. |
| agent_identity/Cargo.toml | Adds shared-kernel dependency. |
| agent_holder/src/state.rs | Adds authorization_checker to holder state. |
| agent_holder/Cargo.toml | Adds shared-kernel dependency. |
| agent_authorization/src/state.rs | Adds authorization_checker and updates initialization to use authorized commands/public queries. |
| agent_authorization/src/application/token_issuance_service.rs | Switches protocol operations to public command/query helpers. |
| agent_authorization/src/application/pushed_authorization_service.rs | Switches protocol operations to public command/query helpers. |
| agent_authorization/src/application/oauth2_authorization_service.rs | Switches protocol operations to public command/query helpers. |
| agent_authorization/src/application/consent_service.rs | Switches protocol operations to public command/query helpers. |
| agent_authorization/src/application/consent_query_service.rs | Switches protocol operations to public query helper. |
| agent_authorization/Cargo.toml | Adds shared-kernel dependency. |
| agent_application/src/lib.rs | Allows injecting a custom ActorExtractor; requires actor for configuration route. |
| agent_application/Cargo.toml | Adds shared-kernel dependency. |
| agent_api_http/src/v0/verification/relying_party/request.rs | Switches to public query helper for relying party request retrieval. |
| agent_api_http/src/v0/verification/relying_party/redirect.rs | Switches to public command helper for relying party redirect handling. |
| agent_api_http/src/v0/verification/authorization_requests.rs | Threads RequestActor into handlers and uses authorized command/query wrappers. |
| agent_api_http/src/v0/templates/mod.rs | Threads RequestActor into template handlers and uses authorized command/query wrappers. |
| agent_api_http/src/v0/issuance/offers/send.rs | Threads RequestActor into offer send endpoints and uses authorized command wrapper. |
| agent_api_http/src/v0/issuance/offers/mod.rs | Threads RequestActor into offer endpoints and uses authorized command/query wrappers. |
| agent_api_http/src/v0/issuance/nonce/mod.rs | Switches nonce creation endpoint to public command helper. |
| agent_api_http/src/v0/issuance/ietf_oauth_sd_jwt_vc.rs | Switches type metadata endpoint to public query helper. |
| agent_api_http/src/v0/issuance/credentials.rs | Threads RequestActor into credential endpoints and uses authorized command/query wrappers. |
| agent_api_http/src/v0/issuance/credential_issuer/well_known/openid_credential_issuer.rs | Switches well-known endpoint to public query helper. |
| agent_api_http/src/v0/issuance/credential_issuer/well_known/oauth_authorization_server.rs | Switches well-known endpoint to public query helper. |
| agent_api_http/src/v0/issuance/credential_issuer/token_status_list.rs | Updates tests to call authorized command handler signature. |
| agent_api_http/src/v0/issuance/credential_issuer/notification.rs | Switches notification endpoint to public command/query helpers. |
| agent_api_http/src/v0/issuance/credential_issuer/credential.rs | Switches credential issuance flow to public command/query helpers; updates tests accordingly. |
| agent_api_http/src/v0/issuance/credential_issuer/credential_offer.rs | Switches credential-offer endpoint to public query helper. |
| agent_api_http/src/v0/issuance/credential_configurations.rs | Threads RequestActor into endpoint and uses authorized command wrapper. |
| agent_api_http/src/v0/identity/well_known/did.rs | Switches DID well-known endpoint to public query helper. |
| agent_api_http/src/v0/identity/well_known/did_configuration.rs | Switches DID configuration endpoint to public query helper. |
| agent_api_http/src/v0/identity/services/mod.rs | Threads RequestActor into services endpoints and uses authorized query wrapper. |
| agent_api_http/src/v0/identity/services/linked_vp.rs | Threads RequestActor and uses authorized command/query wrappers for linked VP. |
| agent_api_http/src/v0/identity/profiles/mod.rs | Threads RequestActor into profile endpoints and uses authorized command/query wrappers. |
| agent_api_http/src/v0/identity/documents/mod.rs | Threads RequestActor into document endpoints and uses authorized query wrapper. |
| agent_api_http/src/v0/identity/connections/mod.rs | Threads RequestActor into connection endpoints and uses authorized command/query wrappers. |
| agent_api_http/src/v0/holder/openid4vci/mod.rs | Threads RequestActor into holder offers ingestion endpoint and uses authorized command wrapper. |
| agent_api_http/src/v0/holder/holder/presentations/presentation_signed.rs | Switches presentation-signed endpoint to public query helper. |
| agent_api_http/src/v0/holder/holder/presentations/mod.rs | Threads RequestActor and uses authorized command/query wrappers for presentations. |
| agent_api_http/src/v0/holder/holder/offers/reject.rs | Threads RequestActor and uses authorized command wrapper for offer rejection. |
| agent_api_http/src/v0/holder/holder/offers/mod.rs | Threads RequestActor and uses authorized query wrappers for offers listing/get. |
| agent_api_http/src/v0/holder/holder/offers/accept.rs | Threads RequestActor and uses authorized command/query wrappers for offer acceptance flow. |
| agent_api_http/src/v0/holder/holder/credentials/mod.rs | Threads RequestActor and uses authorized command/query wrappers for holder credentials. |
| agent_api_http/src/lib.rs | Adds actor extraction middleware (extract_actor / require_actor) and HTTP adapter for ToActor. |
| agent_api_http/src/handlers.rs | Updates API-layer handler wrappers to pass authorization + adds public helpers. |
| agent_api_http/src/extractors.rs | Adds RequestActor extractor reading Actor from request extensions. |
| agent_api_http/src/error.rs | Adds mapping for authorization/handler errors to problem details/public errors. |
| agent_api_http/Cargo.toml | Adds shared-kernel and async-trait dependencies. |
| .env.example | Documents UNICORE__DEV__API_KEY env var for development. |
| pub trait ActorExtractor: Send + Sync + 'static { | ||
| /// Returns the actor that should be attached to the application operation. | ||
| fn extract_actor(&self, input: &dyn ToActor) -> Option<Actor>; | ||
| async fn extract_actor(&self, input: &(dyn ToActor + Sync)) -> Option<Actor>; |
There was a problem hiding this comment.
nit: You've already added Sync as a supertrait of ToActor so you do not need to add it again in these method signatures. So you can simply change all occurrences of &(dyn ToActor + Sync) back to dyn ToActor
Description of change
Added a shared-kernel authorization hook around application command and query execution.
This introduces neutral authorization primitives (
Actor,AuthorizationRequest,AuthorizationOperation, andAuthorizationChecker) plus a default allow-all checker for existing open-source behavior.ServiceHandlecan now dispatch commands and queries with optional actor context, andApplicationServiceauthorizes each command/query before calling the bounded context.The goal is to make authorization enforceable below inbound adapters such as HTTP, GraphQL, gRPC, or queues, rather than tying access checks to a specific API transport.
Links to any relevant issues
N/A
How the change has been tested
Verified locally with:
cargo fmt --check cargo test -p shared-kernel cargo clippy -p shared-kernel -- -D warnings cargo check --workspace git diff --checkThe shared-kernel tests cover default allow-all behavior, actor context propagation, authorization request construction, denied command/query execution, error mapping, dropped reply channels, and service shutdown.
Definition of Done checklist