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

INFOPLAT-1559 Adds auth header token expiry functionality #963

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

hendoxc
Copy link

@hendoxc hendoxc commented Dec 4, 2024

What

  • Adds BuildAuthHeadersV2 for signing publickey + timestamp.

Why

  • First step towards token expiration using CSA Auth.

Notes

Further implementation for implementing token refresh will in follow up tickets

- Adds function for signing publickey + timestamp.
- Adjusts `BuildAuthHeaders` to take variadic args allowing backwards compatibiilty
pkg/beholder/auth.go Outdated Show resolved Hide resolved
- go recommended way to add extend a function
- added Config as 2nd arg as opposed to optional args
pkg/beholder/auth.go Outdated Show resolved Hide resolved
jmank88
jmank88 previously approved these changes Dec 4, 2024
pkg/beholder/auth.go Outdated Show resolved Hide resolved
// If timestamp is negative, set it to 0. negative values cause overflow on convertsion to uint64
// 0 timestamps will be rejected by the server as being too old
if config.timestamp < 0 {
config.timestamp = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

this sorta conflicts in spirit to the previous block where we set the timestamp to now if it's 0

should this be moved up?

Copy link
Author

@hendoxc hendoxc Dec 6, 2024

Choose a reason for hiding this comment

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

So you're saying if a negative value is passed in, we should auto correct to current time?

There are two things here:

  • need to handle a default value, e.g when config arg is nil
  • need to handle when config.timestamp is a negative value. should this be valid or not. as it is now, this would send a 0 timestamp to the auth server which would fail

If I auto-correct to current timestamp when passing in negative value, which then passes authentication, that to me is somewhat unexpected behaviour from user perspective. I would expect if pass an invalid negative timestamp, I would fail authentication one-way or another

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha, thanks for elaborating

there's definitely tradeoffs with either approach, though I don't feel strongly either way. happy to keep things as-is

Copy link
Author

Choose a reason for hiding this comment

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

I think let's keep as is then

pkg/beholder/auth_test.go Outdated Show resolved Hide resolved

// Verify the timestamp is within the last 50ms
// This verifies that default configuration is to use the current time
assert.InDelta(t, now, timestampParsed, 50, "timestamp should be within the last 50ms")
Copy link
Contributor

@pkcll pkcll Dec 10, 2024

Choose a reason for hiding this comment

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

nit: Should it be just after or equal tonow ? or you can use mock clock github.com/jonboulle/clockwork

pkcll
pkcll previously approved these changes Dec 10, 2024
Comment on lines +47 to +49
if config.version == "" {
config.version = authHeaderVersion2
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how important it is, but with the current code we theoretically allow a caller to build v2 headers while passing in a different version, which will get set in the header key.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, by design, it means this function can support upgrading to a new version

func defaultAuthHeaderConfig() *AuthHeaderConfig {
return &AuthHeaderConfig{
version: authHeaderVersion2,
timestamp: time.Now().UnixMilli(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intended that we don't use config.timestamp here? Seems counter-intuitive

Copy link
Author

Choose a reason for hiding this comment

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

not sure I understand

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I think I mixed things up, nvm!

@hendoxc hendoxc requested a review from pkcll December 13, 2024 19:28
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.

5 participants