-
Notifications
You must be signed in to change notification settings - Fork 29
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
fix(auth): sync claim/token times in SA creds #789
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #789 +/- ##
==========================================
- Coverage 95.63% 95.62% -0.02%
==========================================
Files 37 37
Lines 1375 1371 -4
==========================================
- Hits 1315 1311 -4
Misses 60 60 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove any unnecessary dependencies and then ship it!
@@ -14,7 +14,6 @@ | |||
|
|||
use crate::credentials::CredentialError; | |||
use crate::credentials::Result; | |||
use derive_builder::Builder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I think there is an unused dependency in src/auth/Cargo.toml
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still used elsewhere:
#[builder(setter(into))] |
let now = OffsetDateTime::now_utc() - CLOCK_SKEW_FUDGE; | ||
let exp = now + DEFAULT_TOKEN_TIMEOUT; | ||
let claims = JwsClaims { | ||
iss: self.service_account_info.client_email.clone(), | ||
scope: Some(DEFAULT_SCOPES.map(|s| s.to_string()).to_vec()), | ||
aud: None, | ||
exp, | ||
iat: now, | ||
typ: None, | ||
sub: None, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, you could create a JwsClaims::new(now: OffsetDateTime) -> Self
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are going to support options to override the scope, so that function will make less sense in the future.
(Also, we should not bother to have typ
or sub
if they are always None
. I assume there will be some code path where they have concrete values in the future)
pub iss: &'a str, | ||
#[derive(Serialize)] | ||
pub struct JwsClaims { | ||
pub iss: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the simplicity of using String
. It is more expensive, but this function will be called like once per hour so we should not complicate things too much in search of small performance improvements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
@@ -116,44 +112,30 @@ mod tests { | |||
) | |||
.unwrap(); | |||
|
|||
// 5 seconds is like 640KiB, good enough for everybody |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Fixes #733
Make sure the token's
expires_at
time matches theexp
field in the claim.We drop the
JwsClaimsBuilder
and do any defaulting inservice_account_credential.rs
. Note that theexp
andiat
fields are required, so they are probably better represented asOffsetDateTime
thanOption<OffsetDateTime>
.