Skip to content

[BREAKING] feat/refactor/docs: multiple providers, large refactor, configurable ticking interval, fix for jwks endpoint has different host#99

Open
antonengelhardt wants to merge 64 commits into
mainfrom
mulitple-open-id-providers
Open

[BREAKING] feat/refactor/docs: multiple providers, large refactor, configurable ticking interval, fix for jwks endpoint has different host#99
antonengelhardt wants to merge 64 commits into
mainfrom
mulitple-open-id-providers

Conversation

@antonengelhardt
Copy link
Copy Markdown
Owner

@antonengelhardt antonengelhardt commented Sep 5, 2024

Please describe your changes and why you made them

Multiple OpenID providers

  • the plugin can now be configured to use multiple providers for token issuing and validation
  • the discovery fetches all information from the configured providers, loads the jwks etc.
  • if there is more than one provider, then the user can select a provider to authenticate with on a dedicated page. this happens with a callback (_wasm-oidc-plugin/provider-selection?authorize_with_provider=wwu&return_to=lw), which then redirect to the authorization_endpoint, because otherwise we would not be able to know which server sent the code in the code callback.
  • if there is only one provider, the redirection will happen right away

Small features

Refactor & fixes

Does this PR introduce a breaking change?

Warning

This PR introduces a breaking change:
Please see envoy.yaml for the updated config structure

TODOs

Other information and Screenshots (if appropriate)

🤫 It has darkmode

Arc 2024-09-05 23 39 19

Screenshot-Arc-008756@2x

Linked

For #93

more to come

@antonengelhardt antonengelhardt added semver:minor Release in the next minor version feature New Feature or enhancement refactor Code refactoring docs Documentation labels Sep 5, 2024
@antonengelhardt antonengelhardt self-assigned this Sep 5, 2024
@antonengelhardt antonengelhardt force-pushed the mulitple-open-id-providers branch 2 times, most recently from e6806c9 to 0d882e9 Compare September 5, 2024 22:02
@antonengelhardt antonengelhardt linked an issue Sep 6, 2024 that may be closed by this pull request
@antonengelhardt antonengelhardt changed the title [BREAKING] feat/refactor/docs: multiple providers, large refactor [BREAKING] feat/refactor/docs: multiple providers, large refactor, configurable ticking interval, fix for jwks endpoint has different host Sep 9, 2024
@antonengelhardt antonengelhardt force-pushed the mulitple-open-id-providers branch 2 times, most recently from 80e497e to d94b6df Compare September 9, 2024 16:00
@antonengelhardt antonengelhardt force-pushed the mulitple-open-id-providers branch from 36c5896 to 818a32c Compare October 2, 2024 08:41
@antonengelhardt antonengelhardt force-pushed the mulitple-open-id-providers branch 3 times, most recently from eb3e9de to 17ac0f4 Compare October 17, 2024 15:37
* plugin can now have more than one oidc provider
* the discovery will load information from all providers
* user selects the provider on an auth page if there is >1 provider
* more logs
* more comments

TODO:
* error handling
* performance and linting
* large refactoring to file structure

This is just a POC!

THIS IS A BREAKING CHANGE!

Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
* add auth.rs for code flow
* rename cookies.rs to session.rs
* add pause.rs

Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Comment on lines +81 to +83
- name: Install cargo audit
run: cargo install cargo-audit

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Version

Simplify discovery.rs a bit by removing some mutexes that are not strictly necessary.
We do however need to work around proxy-wasm/proxy-wasm-rust-sdk#303
by using the hostcalls module (around which the HttpContext trait is just a trivial wrapper) directly
as defined by the OIDC spec: https://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter
This avoids the need to escape quotes in the "stringly typed" JSON object
and allows the map-type of the value to be validated during config parsing
because that makes sense intuitively and fixes a bug which could
lead to duplicate providers being created
While it would be nice to share these with the Root context,
that would require some refactoring, so we don't currently do that
and the Arc is unnecessary
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR introduces significant changes to support multiple OpenID Connect providers, including a new provider selection UI with dark mode and improved error handling.

  • Added new open_id_configs array in configuration files to support multiple OIDC providers with separate endpoints and settings
  • Changed WASM target from wasm32-wasi to wasm32-wasip1 across all build configurations and documentation
  • Added configurable ticking_interval_in_ms and logout_path with optional end_session_endpoint support
  • Introduced request ID tracking in logs and error pages for better debugging
  • Upgraded Envoy from v1.29 to v1.31 in Docker configurations and fixed JWKS endpoint host issues

Note: The PR contains some potential issues with unwrap() calls in provider selection and artifact path mismatches between build target and upload paths that should be addressed.

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

24 file(s) reviewed, 24 comment(s)
Edit PR Review Bot Settings | Greptile

Comment thread .github/workflows/release.yml Outdated
Comment thread .github/workflows/test.yml Outdated
@@ -116,7 +185,7 @@ jobs:
path: target/wasm32-wasi/release/wasm_oidc_plugin.wasm
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Path mismatch: Build uses wasm32-wasip1 target (line 179) but artifact upload looks for wasm32-wasi path. This will cause the artifact upload to fail.

Suggested change
path: target/wasm32-wasi/release/wasm_oidc_plugin.wasm
path: target/wasm32-wasip1/release/wasm_oidc_plugin.wasm

Comment thread .github/workflows/test.yml Outdated
Comment on lines 158 to 159
needs: [verify-project]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Build job only depends on verify-project and not on test/clippy/fmt jobs. This could allow builds with failing tests or linting issues.

Suggested change
needs: [verify-project]
needs: [verify-project, test, clippy, fmt]

Comment thread Cargo.toml Outdated
authors = [
"WWU Cloud Developer <cloud@uni-muenster.de>, Anton Engelhardt <antoncengelhardt@icloud.com>",
]
description = "A Wasm-Pplugin for the Envoy Proxy written in Rust acting as an HTTP-Filter, that implements the OpenID Authorization Code Flow. Requests sent to the filter are checked for the presence of a valid session cookie. If the cookie is not present, the user is redirected to OpenID Provider to authenticate. After successful authentication, the user is redirected back to the original path with the autorization code in the URL query. The plugin then exchanges the code for a token using the token_endpoint and stores the token in the session."
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Typo in description: 'Wasm-Pplugin' should be 'Wasm plugin'

Suggested change
description = "A Wasm-Pplugin for the Envoy Proxy written in Rust acting as an HTTP-Filter, that implements the OpenID Authorization Code Flow. Requests sent to the filter are checked for the presence of a valid session cookie. If the cookie is not present, the user is redirected to OpenID Provider to authenticate. After successful authentication, the user is redirected back to the original path with the autorization code in the URL query. The plugin then exchanges the code for a token using the token_endpoint and stores the token in the session."
description = "A Wasm plugin for the Envoy Proxy written in Rust acting as an HTTP-Filter, that implements the OpenID Authorization Code Flow. Requests sent to the filter are checked for the presence of a valid session cookie. If the cookie is not present, the user is redirected to OpenID Provider to authenticate. After successful authentication, the user is redirected back to the original path with the autorization code in the URL query. The plugin then exchanges the code for a token using the token_endpoint and stores the token in the session."

Comment thread Cargo.toml Outdated
authors = [
"WWU Cloud Developer <cloud@uni-muenster.de>, Anton Engelhardt <antoncengelhardt@icloud.com>",
]
description = "A Wasm-Pplugin for the Envoy Proxy written in Rust acting as an HTTP-Filter, that implements the OpenID Authorization Code Flow. Requests sent to the filter are checked for the presence of a valid session cookie. If the cookie is not present, the user is redirected to OpenID Provider to authenticate. After successful authentication, the user is redirected back to the original path with the autorization code in the URL query. The plugin then exchanges the code for a token using the token_endpoint and stores the token in the session."
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Typo in description: 'autorization' should be 'authorization'

Suggested change
description = "A Wasm-Pplugin for the Envoy Proxy written in Rust acting as an HTTP-Filter, that implements the OpenID Authorization Code Flow. Requests sent to the filter are checked for the presence of a valid session cookie. If the cookie is not present, the user is redirected to OpenID Provider to authenticate. After successful authentication, the user is redirected back to the original path with the autorization code in the URL query. The plugin then exchanges the code for a token using the token_endpoint and stores the token in the session."
description = "A Wasm-Pplugin for the Envoy Proxy written in Rust acting as an HTTP-Filter, that implements the OpenID Authorization Code Flow. Requests sent to the filter are checked for the presence of a valid session cookie. If the cookie is not present, the user is redirected to OpenID Provider to authenticate. After successful authentication, the user is redirected back to the original path with the authorization code in the URL query. The plugin then exchanges the code for a token using the token_endpoint and stores the token in the session."

Comment thread src/html.rs
Comment on lines +243 to +247
logo.style.visibility = 'hidden';
setTimeout(() => {{
logo.style.visibility = 'visible';
}}, 0);
}});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The visibility toggle hack could cause flickering. Consider using CSS transitions or opacity instead

Comment thread src/lib.rs

Ok(values)
}
proxy_wasm::set_log_level(LogLevel::Debug);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Setting log level to Debug in production could impact performance and expose sensitive information

Comment thread src/pause.rs
307,
vec![
// Redirect to the requested path
("location", self.original_path.as_ref().unwrap()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: unwrap on original_path could panic if None - should handle this case gracefully

Suggested change
("location", self.original_path.as_ref().unwrap()),
("location", self.original_path.as_ref().unwrap_or(&"/".to_string())),

Comment thread src/session.rs
Comment on lines +111 to +113
let num_parts = cookie_values.len();
let num_parts_cookie_value = format!("{cookie_name}-parts={num_parts}; Path=/; HttpOnly; Secure; Max-Age={cookie_duration}; ");
cookie_values.push(num_parts_cookie_value);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The trailing space in the cookie value format string could cause issues with some browsers or proxies

Comment thread src/session.rs
Comment on lines 116 to 119
let nonce_cookie_value = format!(
"{}-nonce={}; Path=/; HttpOnly; Secure; Max-Age={}; ",
cookie_name, &encoded_nonce, cookie_duration
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The trailing space in the nonce cookie format string could cause issues with some browsers or proxies

Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
…-open-id-providers

Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
…iders

Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Signed-off-by: Anton Engelhardt <antoncengelhardt@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation feature New Feature or enhancement refactor Code refactoring semver:minor Release in the next minor version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error IDs on Error Page & in Logs Logout Route to clear cookies Multiple OIDC providers

2 participants