feat: implementation of Identity provider client credential flow - #464
Conversation
msardara
left a comment
There was a problem hiding this comment.
LGTM with nits, great work @hackeramitkumar!
|
@msardara @muscariello Let's keep this PR on hold until the OpenID Connect fix is merged: |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
|
||
| impl OidcTokenProvider { | ||
| /// Create a new OIDC Token Provider | ||
| pub async fn new(config: OidcProviderConfig) -> Result<Self, AuthError> { |
There was a problem hiding this comment.
Let's make the new sync and let's perform async ops in a separate function
There was a problem hiding this comment.
done. added one initialize function which is responsible for starting the background task and fetching the initialize token.
There was a problem hiding this comment.
done. added initialize for the async ops
| if let Some(handle) = self.refresh_task.lock().take() { | ||
| tokio::spawn(async move { | ||
| if (handle.await).is_err() { | ||
| eprintln!("Background refresh task panicked"); | ||
| } | ||
| }); | ||
| } |
There was a problem hiding this comment.
Probably we don't need / care to wait for the task to complete. But we need to make sure that self.shutdown_tx.send effectively terminates the task
There was a problem hiding this comment.
removed the waiting logic. We will only send the shutdown signal to the task.
| match self.try_initial_token_fetch() { | ||
| Ok(token) => Ok(token), | ||
| Err(_) => Err(AuthError::GetTokenError( | ||
| "No cached token available and initial fetch failed. Background refresh should handle this.".to_string() | ||
| )) | ||
| } |
There was a problem hiding this comment.
As I commented in the other PR, we could add an async initialize for the trait so that we can perform the initial async operations, launch the background task and finally only rely on fast sync calls for verifying and getting a new token.
There was a problem hiding this comment.
For now I this pr will add initialize for the OidcTokenprovider. In the SPIFFE token provider also I have added initilize.
Adding the initialize in the trait i will do in a separate pr.
There was a problem hiding this comment.
Added initialize function which will take care of the initial token fetch and background task start. So removing this logic. I am completly relying on the background task now.
| fn drop(&mut self) { | ||
| // Signal shutdown when the provider is dropped | ||
| if self.shutdown_tx.send(true).is_err() { | ||
| // Ignore errors during drop |
There was a problem hiding this comment.
done. now will print the error log
| async fn verify(&self, token: impl Into<String> + Send) -> Result<(), AuthError> { | ||
| // Verify the token structure is valid | ||
| let _: serde_json::Value = self.verify_token(&token.into()).await?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn try_verify(&self, token: impl Into<String>) -> Result<(), AuthError> { | ||
| // For synchronous verification, we need a runtime | ||
| let _: serde_json::Value = block_on(self.verify_token(&token.into()))?; | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
I think we should separate the 2 behaviors: in the try_verify, we try to verify the token using the available JWKs, and if no one is available, we download -> cache a new one using verify.
| if !self.can_provide() { | ||
| return Err(AuthError::ConfigError( | ||
| "Configuration missing client credentials for provider functionality".to_string(), | ||
| )); | ||
| } | ||
|
|
||
| // Since OidcTokenProvider::new is async, we can't call it directly here | ||
| Err(AuthError::ConfigError( | ||
| "OIDC provider requires async initialization. Use create_provider() instead." | ||
| .to_string(), | ||
| )) |
There was a problem hiding this comment.
Same comment as before: the new should be sync and an async initialize() method should be added to the trait and called in the jwt_middleware objects.
We can leave this for a second PR.
There was a problem hiding this comment.
will add initialize in trait in the second PR. for now added the initialize for the OidcTokenProvider
|
@msardara thanks for the review comments. I have resolved all of them. Please check it once. |
Signed-off-by: hackeramitkumar <amit9116260192@gmail.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com> thiserror package version Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
Signed-off-by: amitami2 <amitami2@cisco.com>
|
This would be useful addition to https://github.com/agntcy/dir as well |
|
@msardara @ramizpolic |
## [0.6.1](slim-bindings-v0.6.0...slim-bindings-v0.6.1) (2025-10-17) ### Features * implementation of Identity provider client credential flow ([#464](#464)) ([504b1dd](504b1dd)) * move session code in a new crate ([#828](#828)) ([6d0cf90](6d0cf90)) ### Bug Fixes * **python/bindings:** add missing PyMessageContext type export ([#841](#841)) ([6301ced](6301ced)) * **session:** correctly handle multiple subscriptions ([#838](#838)) ([52b49aa](52b49aa)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Signed-off-by: Agntcy Build Bot <build@agntcy.io>
## 🤖 New release
* `agntcy-slim-auth`: 0.3.1 -> 0.4.0 (⚠ API breaking changes)
* `agntcy-slim-config`: 0.4.0 -> 0.4.1 (✓ API compatible changes)
* `agntcy-slim-datapath`: 0.10.0 -> 0.10.1 (✓ API compatible changes)
* `agntcy-slim-service`: 0.7.0 -> 0.8.0 (⚠ API breaking changes)
* `agntcy-slim`: 0.6.0 -> 0.6.1 (✓ API compatible changes)
* `agntcy-protoc-slimrpc-plugin`: 0.1.0 -> 0.1.1
* `agntcy-slim-tracing`: 0.2.4 -> 0.2.5
* `agntcy-slim-controller`: 0.4.0 -> 0.4.1
* `agntcy-slim-mls`: 0.1.2 -> 0.1.3
### ⚠ `agntcy-slim-auth` breaking changes
```text
--- failure auto_trait_impl_removed: auto trait no longer implemented ---
Description:
A public type has stopped implementing one or more auto traits. This can break downstream code that depends on the traits being implemented.
ref: https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.43.0/src/lints/auto_trait_impl_removed.ron
Failed in:
type AuthError is no longer UnwindSafe, in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:7
type AuthError is no longer RefUnwindSafe, in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:7
--- failure enum_variant_added: enum variant added on exhaustive enum ---
Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.43.0/src/lints/enum_variant_added.ron
Failed in:
variant AuthError:JwtAwsLcError in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:30
variant AuthError:UnsupportedOperation in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:33
variant AuthError:HttpError in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:36
variant AuthError:JsonError in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:39
variant AuthError:OAuth2Error in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:42
variant AuthError:TokenEndpointError in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:45
variant AuthError:InvalidClientCredentials in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:48
variant AuthError:TokenRefreshFailed in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:51
variant AuthError:InvalidIssuerEndpoint in /tmp/.tmpi3lLuH/slim/data-plane/core/auth/src/errors.rs:54
```
### ⚠ `agntcy-slim-service` breaking changes
```text
--- failure enum_missing: pub enum removed or renamed ---
Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.43.0/src/lints/enum_missing.ron
Failed in:
enum slim_service::session::timer::TimerType, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/timer.rs:21
enum slim_service::TimerType, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/timer.rs:21
enum slim_service::session::SessionType, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/handle.rs:32
enum slim_service::SessionType, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/handle.rs:32
enum slim_service::session::SessionError, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/errors.rs:11
enum slim_service::SessionError, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/errors.rs:11
enum slim_service::session::notification::Notification, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/notification.rs:16
enum slim_service::session::Notification, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/notification.rs:16
enum slim_service::session::SessionConfig, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/config.rs:12
enum slim_service::SessionConfig, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/config.rs:12
--- failure function_missing: pub fn removed or renamed ---
Description:
A publicly-visible function cannot be imported by its prior path. A `pub use` may have been removed, or the function itself may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.43.0/src/lints/function_missing.ron
Failed in:
function slim_service::session::channel_endpoint::handle_channel_discovery_message, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/channel_endpoint.rs:709
--- failure module_missing: pub module removed or renamed ---
Description:
A publicly-visible module cannot be imported by its prior path. A `pub use` may have been removed, or the module may have been renamed, removed, or made non-public.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.43.0/src/lints/module_missing.ron
Failed in:
mod slim_service::session::context, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/context.rs:5
mod slim_service::session::interceptor, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/interceptor.rs:5
mod slim_service::session::notification, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/notification.rs:7
mod slim_service::session::producer_buffer, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/producer_buffer.rs:5
mod slim_service::session::channel_endpoint, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/channel_endpoint.rs:5
mod slim_service::session::point_to_point, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/point_to_point.rs:5
mod slim_service::session::timer, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/timer.rs:5
mod slim_service::session::receiver_buffer, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/receiver_buffer.rs:5
mod slim_service::session::interceptor_mls, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/interceptor_mls.rs:5
mod slim_service::session::multicast, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/multicast.rs:5
mod slim_service::session::transmitter, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/transmitter.rs:5
mod slim_service::session, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session.rs:4
--- failure pub_module_level_const_missing: pub module-level const is missing ---
Description:
A public const is missing or renamed
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.43.0/src/lints/pub_module_level_const_missing.ron
Failed in:
METADATA_MLS_INIT_COMMIT_ID in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/interceptor_mls.rs:20
METADATA_MLS_ENABLED in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/interceptor_mls.rs:19
SESSION_UNSPECIFIED in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/common.rs:16
SESSION_UNSPECIFIED in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/common.rs:16
--- failure struct_missing: pub struct removed or renamed ---
Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.43.0/src/lints/struct_missing.ron
Failed in:
struct slim_service::session::context::SessionContext, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/context.rs:20
struct slim_service::session::channel_endpoint::MlsProposalMessagePayload, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/channel_endpoint.rs:517
struct slim_service::session::point_to_point::PointToPointConfiguration, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/point_to_point.rs:40
struct slim_service::session::PointToPointConfiguration, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/point_to_point.rs:40
struct slim_service::PointToPointConfiguration, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/point_to_point.rs:40
struct slim_service::session::multicast::MulticastConfiguration, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/multicast.rs:46
struct slim_service::session::MulticastConfiguration, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/multicast.rs:46
struct slim_service::MulticastConfiguration, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/multicast.rs:46
struct slim_service::session::timer::Timer, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/timer.rs:27
struct slim_service::Timer, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/timer.rs:27
struct slim_service::session::interceptor_mls::MlsInterceptor, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/interceptor_mls.rs:23
struct slim_service::session::producer_buffer::ProducerBuffer, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/producer_buffer.rs:10
struct slim_service::session::channel_endpoint::JoinMessagePayload, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/channel_endpoint.rs:502
struct slim_service::session::Session, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/handle.rs:96
struct slim_service::session::channel_endpoint::ChannelParticipant, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/channel_endpoint.rs:749
struct slim_service::session::transmitter::SessionTransmitter, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/transmitter.rs:57
struct slim_service::session::channel_endpoint::ChannelModerator, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/channel_endpoint.rs:1153
struct slim_service::session::channel_endpoint::MlsState, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/channel_endpoint.rs:158
--- failure trait_missing: pub trait removed or renamed ---
Description:
A publicly-visible trait cannot be imported by its prior path. A `pub use` may have been removed, or the trait itself may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.43.0/src/lints/trait_missing.ron
Failed in:
trait slim_service::session::interceptor::SessionInterceptor, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/interceptor.rs:16
trait slim_service::session::timer::TimerObserver, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/timer.rs:14
trait slim_service::TimerObserver, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/timer.rs:14
trait slim_service::session::Transmitter, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/traits.rs:25
trait slim_service::session::interceptor::SessionInterceptorProvider, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/interceptor.rs:24
trait slim_service::session::SessionInterceptorProvider, previously in file /tmp/.tmpzKgv7T/agntcy-slim-service/src/session/interceptor.rs:24
```
<details><summary><i><b>Changelog</b></i></summary><p>
## `agntcy-slim-auth`
<blockquote>
##
[0.4.0](slim-auth-v0.3.1...slim-auth-v0.4.0)
- 2025-10-17
### Added
- implementation of Identity provider client credential flow
([#464](#464))
</blockquote>
## `agntcy-slim-config`
<blockquote>
##
[0.4.1](slim-config-v0.4.0...slim-config-v0.4.1)
- 2025-10-17
### Added
- implementation of Identity provider client credential flow
([#464](#464))
</blockquote>
## `agntcy-slim-datapath`
<blockquote>
##
[0.10.1](slim-datapath-v0.10.0...slim-datapath-v0.10.1)
- 2025-10-17
### Fixed
- *(session)* correctly handle multiple subscriptions
([#838](#838))
</blockquote>
## `agntcy-slim-service`
<blockquote>
##
[0.8.0](slim-service-v0.7.0...slim-service-v0.8.0)
- 2025-10-17
### Added
- move session code in a new crate
([#828](#828))
### Fixed
- *(session)* correctly handle multiple subscriptions
([#838](#838))
</blockquote>
## `agntcy-slim`
<blockquote>
##
[0.6.1](slim-v0.6.0...slim-v0.6.1)
- 2025-10-17
### Other
- update Cargo.lock dependencies
</blockquote>
## `agntcy-protoc-slimrpc-plugin`
<blockquote>
##
[0.1.1](protoc-slimrpc-plugin-v0.1.0...protoc-slimrpc-plugin-v0.1.1)
- 2025-10-17
### Other
- update Cargo.lock dependencies
</blockquote>
## `agntcy-slim-tracing`
<blockquote>
##
[0.2.5](slim-tracing-v0.2.4...slim-tracing-v0.2.5)
- 2025-10-17
### Other
- updated the following local packages: agntcy-slim-config
</blockquote>
## `agntcy-slim-controller`
<blockquote>
##
[0.4.1](slim-controller-v0.4.0...slim-controller-v0.4.1)
- 2025-10-17
### Other
- updated the following local packages: agntcy-slim-auth,
agntcy-slim-config, agntcy-slim-datapath, agntcy-slim-tracing
</blockquote>
## `agntcy-slim-mls`
<blockquote>
##
[0.1.3](slim-mls-v0.1.2...slim-mls-v0.1.3)
- 2025-10-17
### Other
- updated the following local packages: agntcy-slim-auth,
agntcy-slim-datapath
</blockquote>
</p></details>
---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
---------
Co-authored-by: Mauro Sardara <msardara@cisco.com>
Description
Issue: #400
Implemetation of provider and verifier using openid connect,
in particular using the client credentials flow.
Type of Change
Checklist