Skip to content

Commit 99a347b

Browse files
dervoetiTechassi
authored andcommitted
feat: add support for specifying a clientAuthenticationMethod for OIDC (#1158)
* feat: add support for specifying a clientAuthenticationMethod for OIDC * Update crates/stackable-operator/src/crd/authentication/oidc/mod.rs Co-authored-by: Techassi <git@techassi.dev> * Update crates/stackable-operator/src/crd/authentication/oidc/mod.rs Co-authored-by: Techassi <git@techassi.dev> * chore: remove unnecessary serde attributes --------- Co-authored-by: Techassi <git@techassi.dev>
1 parent 7e713a4 commit 99a347b

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

crates/stackable-operator/crds/DummyCluster.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ spec:
3030
description: This field contains OIDC-specific configuration. It is only required in case OIDC is used.
3131
nullable: true
3232
properties:
33+
clientAuthenticationMethod:
34+
default: client_secret_basic
35+
description: 'The client authentication method used when communicating with the token endpoint. Defaults to `client_secret_basic`. The required contents of `clientCredentialsSecret` depend on the chosen method: secret-based methods (`client_secret_basic`, `client_secret_post`, `client_secret_jwt`) expect a client secret, while `private_key_jwt` expects a private key.'
36+
enum:
37+
- client_secret_basic
38+
- client_secret_post
39+
- client_secret_jwt
40+
- private_key_jwt
41+
- none
42+
type: string
3343
clientCredentialsSecret:
3444
description: |-
3545
A reference to the OIDC client credentials secret. The secret contains

crates/stackable-operator/src/crd/authentication/oidc/mod.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,46 @@ pub mod versioned {
9090
Keycloak,
9191
}
9292

93+
/// OAuth2 client authentication methods as defined in the OpenID Connect Core spec.
94+
///
95+
/// These methods are used by clients to authenticate to the authorization server
96+
/// when using the token endpoint.
97+
///
98+
/// See <https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication> for details.
99+
#[derive(
100+
Clone,
101+
Copy,
102+
Debug,
103+
Default,
104+
Deserialize,
105+
Eq,
106+
Hash,
107+
JsonSchema,
108+
Ord,
109+
PartialEq,
110+
PartialOrd,
111+
Serialize,
112+
)]
113+
#[serde(rename_all = "snake_case")]
114+
pub enum ClientAuthenticationMethod {
115+
/// Authenticate using HTTP Basic authentication with client_id and client_secret.
116+
/// This is the default method according to the OIDC spec.
117+
#[default]
118+
ClientSecretBasic,
119+
120+
/// Send client_id and client_secret in the request body.
121+
ClientSecretPost,
122+
123+
/// Authenticate using a JWT signed with an HMAC SHA algorithm using the client_secret.
124+
ClientSecretJwt,
125+
126+
/// Authenticate using a JWT signed with the client's private key.
127+
PrivateKeyJwt,
128+
129+
/// No client authentication (for public clients or implicit flow).
130+
None,
131+
}
132+
93133
/// OIDC specific config options. These are set on the product config level.
94134
#[derive(
95135
Clone, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize,
@@ -111,6 +151,25 @@ pub mod versioned {
111151
#[serde(default)]
112152
pub extra_scopes: Vec<String>,
113153

154+
/// The OAuth2 client authentication method to use for token endpoint requests.
155+
/// Defaults to [`ClientAuthenticationMethod::ClientSecretBasic`].
156+
///
157+
/// The contents and format of the `clientCredentialsSecret` depend on the selected
158+
/// method. For example, [`ClientAuthenticationMethod::ClientSecretBasic`] and
159+
/// [`ClientAuthenticationMethod::ClientSecretPost`] require a client secret string, whereas
160+
/// [`ClientAuthenticationMethod::PrivateKeyJwt`] requires a private key.
161+
///
162+
/// See [`ClientAuthenticationMethod`] for available options.
163+
#[schemars(
164+
description = "The client authentication method used when communicating with the token \
165+
endpoint. Defaults to `client_secret_basic`. The required contents of \
166+
`clientCredentialsSecret` depend on the chosen method: secret-based methods \
167+
(`client_secret_basic`, `client_secret_post`, `client_secret_jwt`) expect a client \
168+
secret, while `private_key_jwt` expects a private key."
169+
)]
170+
#[serde(default)]
171+
pub client_authentication_method: ClientAuthenticationMethod,
172+
114173
// If desired, operators can add custom fields that are only needed for this specific product.
115174
// They need to create a struct holding them and pass that as `T`.
116175
#[serde(flatten)]

0 commit comments

Comments
 (0)