Skip to content

Conversation

@pmeredit
Copy link
Contributor

@pmeredit pmeredit commented Mar 5, 2024

No description provided.


- name: oidc
display_name: OIDC
patchable: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be removed before merge, again :)

refresh_token: Option<String>,
access_token: Option<String>,
token_gen_id: i32,
token_gen_id: u32,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

u32 is the more correct type here, as this should never be negative

pub struct CallbackContext {
pub timeout_seconds: Option<Instant>,
pub version: i32,
pub version: u32,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto

conn: &Connection,
credential: &Credential,
response: &IdpServerResponse,
token_gen_id: i32,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

spec requires caching the IdP info to avoid asking the server for it when it is known (cached).

.write()
.await;
if cache.access_token == Some(access_token) {
cache.access_token = None;
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 like to use let _ to be very explicit that it's being thrown away

};
// Update the credential and connection caches with the access token and the credential
// cache with the refresh token and token_gen_id
update_caches(conn, credential, &idp_response, None).await;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The server info should have been set at some time in the past, but also we don't have it here except for whatever was already in the cache, so we just don't update it here. Updating something with itself is just a waste of time.

pub refresh_token: Option<String>,
}

/// Constructs the first client message in the OIDC handshake for speculative authentication
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it ok for this to return an empty speculative command when there is no access token, or should we actually make this return an Option?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine to return an empty command as long as the calling code doesn't have to special case that.

patchable: true
run_on:
- rhel87-small
- ubuntu2204-small
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just so the oidc tests would start immediately

src/cmap/conn.rs Outdated
compression::Compressor,
error::{load_balanced_mode_mismatch, Error, ErrorKind, Result},
event::cmap::{
CmapEventEmitter, ConnectionCheckedInEvent, ConnectionCheckedOutEvent,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like somehow the rustfmt I run on nvim buffer save is not the correct version of rustfmt.

#[derive(Clone)]
pub struct State {
callback: Callback,
cache: Arc<RwLock<Cache>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be held across await points? If not, this could become a std::sync::RwLock and avoid the async that has to propagate in various places here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me check

Copy link
Contributor Author

@pmeredit pmeredit Mar 6, 2024

Choose a reason for hiding this comment

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

Looks like it will work. I didn't realize that it was safe to use std::sync::RwLock as long as it doesn't cross await, but that makes sense. I assume the only difference of the tokio version is it handles unlocking when the await is rescheduled.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, exactly.

Copy link
Contributor

@abr-egn abr-egn left a comment

Choose a reason for hiding this comment

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

LGTM!

#[derive(Clone)]
pub struct State {
callback: Callback,
cache: Arc<RwLock<Cache>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, exactly.

pub refresh_token: Option<String>,
}

/// Constructs the first client message in the OIDC handshake for speculative authentication
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine to return an empty command as long as the calling code doesn't have to special case that.

@pmeredit
Copy link
Contributor Author

pmeredit commented Mar 6, 2024

@abr-egn unfortunately, the calling code would have to special case it if returned the Option. I think this approach is fine because the worst that happens is we send nonsense (e.g., an empty or missing jwt) in the speculative auth which just gets returned as nothing and then we do normal auth. Seems like there's no downside to that, and then we avoid the special casing.

Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

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

just two very small suggestions, no need for a re-review!


/// Updates the handshake command document with the speculative authenitication info.
fn set_speculative_auth_info(
async fn set_speculative_auth_info(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is async code going to be added to this method? If not recommend reverting this change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope! I just missed this one, thanks!


if credential.oidc_callback.is_none() {
auth_command_doc.insert("jwt", "");
} else if let Some(access_token) = credential
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} else if let Some(access_token) = credential
} else if let Some(access_token) = credential.get_access_token()

(looks like this chain of method calls is the same as the contents of get_access_token)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! Great call!

@pmeredit pmeredit merged commit a2faea4 into mongodb:main Mar 6, 2024
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.

3 participants