Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade jwt_authorizer to axum 0.7 #44

Merged
merged 9 commits into from
Jan 21, 2024
Merged

Conversation

dsgallups
Copy link
Contributor

@dsgallups dsgallups commented Dec 1, 2023

This is some work done to update jwt_authorizer to axum 0.7. In the process, the ReqBody generic was removed in several places, as axum::extract::Request now has a default associated type.

jwt-authorizer/src/layer.rs Outdated Show resolved Hide resolved
jwt-authorizer/src/layer.rs Outdated Show resolved Hide resolved
jwt-authorizer/src/layer.rs Outdated Show resolved Hide resolved
jwt-authorizer/tests/integration_tests.rs Show resolved Hide resolved
jwt-authorizer/tests/integration_tests.rs Outdated Show resolved Hide resolved
@dsgallups dsgallups marked this pull request as ready for review December 2, 2023 00:58
@cduvray
Copy link
Owner

cduvray commented Dec 3, 2023

Thx for the PR, tonic (feature) is not compiling, I think the update of tonic to hyper 1.0 is needed.
Waiting for hyperium/tonic#1579

@dsgallups
Copy link
Contributor Author

dsgallups commented Dec 3, 2023

Thanks! The other thing is that you will notice your test minutes have mysteriously vanished... in oidc.rs line 27 calls discovery_url(issuer)?, which actually results in
Ok(Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Ipv4(0.0.0.0)), port: Some(44281), path: "/.well-known/openid-configuration", query: None, fragment: None }). This leads to a hang when calling send() on client, because it appears that this host actually isn't instantiated...

Would this be due to tonic as well?

Edit: As @cduvray pointed out, this was not the problem. The problem was that the standard listener was in blocking mode. This lead to an asynchronous polling issue because the listener would continuously block the thread until all I/O operations completed...which, they never do.

.serve(app.into_make_service())
.await
.unwrap();
let listener: tokio::net::TcpListener = tokio::net::TcpListener::from_std(listener).unwrap();
Copy link
Owner

Choose a reason for hiding this comment

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

Here you should use the listener from the line 69, I think creating a new listener on the same port makes the tests stuck.

Copy link
Contributor Author

@dsgallups dsgallups Dec 5, 2023

Choose a reason for hiding this comment

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

Resolved by making the std listener non-blocking...the integration tests should no longer hang! Much appreciated for figuring this out!

Reference: tokio docs

@@ -145,7 +143,8 @@ async fn make_proteced_request(app: &mut Router, bearer: &str) -> Response {
}

async fn make_public_request(app: &mut Router) -> Response {
app.ready()
app.as_service()
.ready()
.await
.unwrap()
.call(Request::builder().uri("/public").body(Body::empty()).unwrap())
Copy link
Owner

@cduvray cduvray Dec 7, 2023

Choose a reason for hiding this comment

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

Here I think you could call call() directly on as_service() (type RouterAsService).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll squash several of the prior commits and push this change when the tonic upgrade is complete.

@dsgallups
Copy link
Contributor Author

It seems like the upgrade in tonic is slow progress...hyperium/hyper#3461 is blocking hyperium/tonic#1579, which can't occur until the next version of hyper is released. Wondering if you would consider feature gating the axum version based on use of tonic, or is that a horrible idea?

@cduvray
Copy link
Owner

cduvray commented Dec 31, 2023

I am not sure to understand what you mean by feature gating (tonic is already behind a feature switch).
I tried to move the tonic dependent code into a separate crate but I am blocked by the fact that From cannot be implemented for types from another crates. (impl From<AuthError> for Response<tonic::body::BoxBody> {...}).

@dsgallups
Copy link
Contributor Author

dsgallups commented Dec 31, 2023

My mistake! What I meant to say is you could make the version of axum dependent on whether the tonic feature is enabled. You've made more sense of the situation than me. If you choose to make a separate crate for tonic, then that would basically mean you'd have to ctrl+c/ctrl+v large swathes of the implementation, including AuthError. The alternative (and what I meant) is to set axum = 0.6.20, etc. when the tonic feature is enabled. However, that solution basically would result in the same costs, just in the same crate.

Alternatively, could just wait another month or so hahaha...I'll do what I can to get tonic to http 1 in the meantime.

Please let me know what you want to do, and I can create an according PR/work with you in tandem if you find it useful/necessary to separate versions between tonic and axum. Could also tackle #43 with this approach.

@cduvray cduvray merged commit 976d65d into cduvray:main Jan 21, 2024
1 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants