[SQSERVICES-1913] Move OAuth authentication to nginz#3086
Conversation
eac9bf9 to
befeca0
Compare
libs/libzauth/libzauth-c/Makefile
Outdated
|
|
||
| build-release: | ||
| cargo build --release | ||
| cargo build |
libs/libzauth/libzauth-c/src/lib.rs
Outdated
| pub struct OAuthJwk(String); | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Clone, Copy, Debug)] |
There was a problem hiding this comment.
You probably don't want to derive Copy here. It's basically an "implicit" clone. And since your struct holds pointer, it could silently copy those pointers and somehow result in double free errors
| } | ||
| } | ||
|
|
||
| impl From<io::Error> for OAuthResultStatus { |
There was a problem hiding this comment.
You probably could have handled all these manual From implementations with the thiserror crate.
But it could be tricky to handle with the discriminant so leave it alone if it's too complex
#[repr(C)]
#[derive(Error, Clone, Copy, Debug)]
pub enum OAuthResultStatus {
Ok,
IoError(#[from] io::Error),
}| impl From<str::Utf8Error> for OAuthResultStatus { | ||
| fn from(_: str::Utf8Error) -> OAuthResultStatus { | ||
| OAuthResultStatus::Utf8Error | ||
| } | ||
| } |
There was a problem hiding this comment.
| impl From<str::Utf8Error> for OAuthResultStatus { | |
| fn from(_: str::Utf8Error) -> OAuthResultStatus { | |
| OAuthResultStatus::Utf8Error | |
| } | |
| } | |
| impl From<str::Utf8Error> for OAuthResultStatus { | |
| fn from(_: str::Utf8Error) -> Self { | |
| Self::Utf8Error | |
| } | |
| } |
| status: OAuthResultStatus::NullArg, | ||
| }; | ||
| } | ||
| if scope.is_null() { |
There was a problem hiding this comment.
Missed that, thanks!
pcapriotti
left a comment
There was a problem hiding this comment.
Looks generally good, as far as I can tell. I did find a potential problem though. See below.
| uid: c_str.into_raw(), | ||
| status: OAuthResultStatus::Ok, | ||
| } | ||
| }) { |
There was a problem hiding this comment.
Can't you use catch_unwind_with here too?
|
|
||
| static ngx_int_t zauth_token_var_user (ngx_http_request_t * r, ngx_http_variable_value_t * v, uintptr_t _) { | ||
| ZauthToken const * t = ngx_http_get_module_ctx(r, zauth_module); | ||
| if (t != NULL && zauth_is_authorized_and_allowed(r)) { |
There was a problem hiding this comment.
This doesn't look right. First t is cast to ZauthToken and assumed to be a valid pointer to that struct by zauth_is_authorized_and_allowed. Later, it is fetched again and cast to a string pointer.
You might want to store a tagged union in the context, so that this function can discriminate if it's the zauth or oauth case.
Co-authored-by: Paolo Capriotti <paolo@capriotti.io>
…nz' of github.com:wireapp/wire-server into SQSERVICES-1913-oauth-move-o-auth-authentication-to-nginz
…nz' of github.com:wireapp/wire-server into SQSERVICES-1913-oauth-move-o-auth-authentication-to-nginz
pcapriotti
left a comment
There was a problem hiding this comment.
I looked at the C code only this time. Looks good to me modulo the comments below.
| if (strncmp((char const *) hdr.data, "Bearer ", 7) == 0) { | ||
| OAuthResult res = oauth_verify_token(key, &hdr.data[7], hdr.len - 7, scope.data, scope.len, r->method_name.data, r->method_name.len); | ||
| if (res.status == OAUTH_OK) { | ||
| ZauthContext * ctx = alloc_oauth_context(r, res.uid); |
There was a problem hiding this comment.
For OOM-safety, you can add
if (ctx == NULL) return NGX_ERROR;or similar.
| if (finaliser == NULL) { | ||
| return NGX_ERROR; | ||
| ZauthContext * ctx = alloc_zauth_context(r, tkn); | ||
| ngx_int_t e = setup_zauth_context(r, ctx); |
2af8cf7
into
SQSERVICES-1825-be-oauth-refresh-token-generation
No description provided.