Skip to content

Commit 85490fa

Browse files
authored
fix: Construction of OIDC endpoint when rootPath has a trailing slash (#673)
* fix: Calculation of OIDC endpoint when rootPath has a trailing slash * Update test * Use op-rs 0.82.0 * nixfiles * Update tests and docs * changelog * Rename oidc -> client_auth_options
1 parent 0609a15 commit 85490fa

File tree

11 files changed

+48
-33
lines changed

11 files changed

+48
-33
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
2424
- Don't ignore envOverrides ([#633]).
2525
- Don't print credentials to STDOUT during startup. Ideally we should use [config-utils](https://github.com/stackabletech/config-utils), but that's not easy (see [here](https://github.com/stackabletech/trino-operator/tree/fix/secret-printing)) ([#634]).
2626
- Invalid `TrinoCluster`, `TrinoCatalog` or `AuthenticationClass` objects don't stop the operator from reconciliation ([#657])
27+
- Fix OIDC endpoint construction in case the `rootPath` does have a trailing slash ([#673]).
2728

2829
### Removed
2930

@@ -36,6 +37,7 @@ All notable changes to this project will be documented in this file.
3637
[#646]: https://github.com/stackabletech/trino-operator/pull/646
3738
[#655]: https://github.com/stackabletech/trino-operator/pull/655
3839
[#657]: https://github.com/stackabletech/trino-operator/pull/657
40+
[#673]: https://github.com/stackabletech/trino-operator/pull/673
3941

4042
## [24.7.0] - 2024-07-24
4143

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ serde = { version = "1.0", features = ["derive"] }
2424
serde_json = "1.0"
2525
serde_yaml = "0.9"
2626
snafu = "0.8"
27-
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.80.0" }
27+
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.82.0" }
2828
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }
2929
strum = { version = "0.26", features = ["derive"] }
3030
tokio = { version = "1.40", features = ["full"] }

crate-hashes.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/modules/trino/examples/usage-guide/trino-oidc-auth-snippet.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
oidc:
2222
hostname: keycloak.default.svc.cluster.local
2323
port: 8080
24-
rootPath: /realms/stackable
24+
rootPath: /realms/stackable/
2525
scopes:
2626
- openid
2727
principalClaim: preferred_username

examples/simple-trino-oauth2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ spec:
5353
oidc:
5454
hostname: keycloak
5555
port: 8080
56-
rootPath: /realms/stackable
56+
rootPath: /realms/stackable/
5757
scopes: ["openid"]
5858
principalClaim: preferred_username
5959
---

rust/crd/src/authentication.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;
2525
pub struct ResolvedAuthenticationClassRef {
2626
/// An [AuthenticationClass](DOCS_BASE_URL_PLACEHOLDER/concepts/authentication) to use.
2727
pub authentication_class: AuthenticationClass,
28-
pub oidc: Option<oidc::ClientAuthenticationOptions>,
28+
pub client_auth_options: Option<oidc::ClientAuthenticationOptions>,
2929
}
3030

3131
/// Retrieve all provided AuthenticationClass references.
@@ -43,7 +43,7 @@ pub async fn resolve_authentication_classes(
4343
let auth_class_name = resolved_auth_class.name_any();
4444

4545
resolved_auth_classes.push(ResolvedAuthenticationClassRef {
46-
oidc: match &resolved_auth_class.spec.provider {
46+
client_auth_options: match &resolved_auth_class.spec.provider {
4747
AuthenticationClassProvider::Oidc(_) => Some(
4848
client_authentication_detail
4949
.oidc_or_error(&auth_class_name)

rust/operator-binary/src/authentication/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl TryFrom<Vec<ResolvedAuthenticationClassRef>> for TrinoAuthenticationTypes {
508508
);
509509
}
510510
AuthenticationClassProvider::Oidc(provider) => {
511-
let oidc = resolved_auth_class.oidc.context(
511+
let oidc = resolved_auth_class.client_auth_options.context(
512512
OidcAuthenticationDetailsNotSpecifiedSnafu {
513513
auth_class_name: auth_class_name.clone(),
514514
},
@@ -591,7 +591,7 @@ mod tests {
591591

592592
ResolvedAuthenticationClassRef {
593593
authentication_class: input,
594-
oidc: None,
594+
client_auth_options: None,
595595
}
596596
}
597597

@@ -610,7 +610,7 @@ mod tests {
610610

611611
ResolvedAuthenticationClassRef {
612612
authentication_class: input,
613-
oidc: None,
613+
client_auth_options: None,
614614
}
615615
}
616616

@@ -636,7 +636,7 @@ mod tests {
636636

637637
ResolvedAuthenticationClassRef {
638638
authentication_class: input,
639-
oidc: None,
639+
client_auth_options: None,
640640
}
641641
}
642642

@@ -651,7 +651,7 @@ mod tests {
651651
provider:
652652
oidc:
653653
hostname: {HOST_NAME}
654-
rootPath: /realms/master
654+
rootPath: /realms/master/
655655
scopes: ["openid"]
656656
principalClaim: preferred_username
657657
"#,
@@ -663,7 +663,7 @@ mod tests {
663663
deserializer,
664664
)
665665
.unwrap(),
666-
oidc: Some(ClientAuthenticationOptions {
666+
client_auth_options: Some(ClientAuthenticationOptions {
667667
client_credentials_secret_ref: "my-oidc-secret".to_string(),
668668
extra_scopes: Vec::new(),
669669
product_specific_fields: (),

rust/operator-binary/src/authentication/oidc/mod.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ mod tests {
210210
use std::mem;
211211

212212
use super::*;
213+
use rstest::rstest;
213214
use stackable_trino_crd::Container;
214215

215216
const IDP_PORT: u16 = 8080;
216-
const IDP_ROOT_PATH: &str = "/realms/master";
217217
const IDP_SCOPE_1: &str = "openid";
218218
const IDP_SCOPE_2: &str = "test";
219219
const AUTH_CLASS_NAME_1: &str = "trino-oidc-auth-1";
@@ -223,12 +223,13 @@ mod tests {
223223
fn setup_test_authenticator(
224224
auth_class_name: &str,
225225
credential_secret: String,
226+
root_path: &str,
226227
) -> OidcAuthenticator {
227228
let input = format!(
228229
r#"
229230
hostname: keycloak
230231
port: {IDP_PORT}
231-
rootPath: {IDP_ROOT_PATH}
232+
rootPath: {root_path}
232233
scopes:
233234
- {IDP_SCOPE_1}
234235
principalClaim: preferred_username
@@ -249,8 +250,16 @@ mod tests {
249250
#[test]
250251
fn test_oidc_authentication_limit_one_error() {
251252
let oidc_authentication = TrinoOidcAuthentication::new(vec![
252-
setup_test_authenticator(AUTH_CLASS_NAME_1, AUTH_CLASS_CREDENTIAL_SECRET.to_string()),
253-
setup_test_authenticator(AUTH_CLASS_NAME_2, AUTH_CLASS_CREDENTIAL_SECRET.to_string()),
253+
setup_test_authenticator(
254+
AUTH_CLASS_NAME_1,
255+
AUTH_CLASS_CREDENTIAL_SECRET.to_string(),
256+
"/",
257+
),
258+
setup_test_authenticator(
259+
AUTH_CLASS_NAME_2,
260+
AUTH_CLASS_CREDENTIAL_SECRET.to_string(),
261+
"/",
262+
),
254263
]);
255264

256265
let error = oidc_authentication
@@ -264,17 +273,21 @@ mod tests {
264273
);
265274
}
266275

267-
#[test]
268-
fn test_oidc_authentication_settings() {
276+
#[rstest]
277+
#[case("/realms/sdp")]
278+
#[case("/realms/sdp/")]
279+
#[case("/realms/sdp/////")]
280+
fn test_oidc_authentication_settings(#[case] root_path: &str) {
269281
let oidc_authentication = TrinoOidcAuthentication::new(vec![setup_test_authenticator(
270282
AUTH_CLASS_NAME_1,
271283
AUTH_CLASS_CREDENTIAL_SECRET.to_string(),
284+
root_path,
272285
)]);
273286

274287
let trino_oidc_auth = oidc_authentication.oauth2_authentication_config().unwrap();
275288

276289
assert_eq!(
277-
Some(&format!("http://keycloak:{IDP_PORT}{IDP_ROOT_PATH}")),
290+
Some(&format!("http://keycloak:{IDP_PORT}/realms/sdp")),
278291
trino_oidc_auth
279292
.config_properties
280293
.get(&TrinoRole::Coordinator)

0 commit comments

Comments
 (0)