-
Notifications
You must be signed in to change notification settings - Fork 21
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
Switched to use Access API for checking expired token #230
Conversation
Remove mutex from RefreshAccessToken() Switch to RW lock for pathConfigUserTokenRead() and pathUserTokenCreatePerform() Add scripts for testing refreshable tokens creation and concurrent token generation
@elestedt Would you be able to test this out before I merge this into |
I will test it today. But I did notice that the API used requires some form of admin permissions. If you run this as a normal user the endpoint returns
response back. It would be better to use an endpoint that does not generate and "error" in the artifactory logs. Such as the |
When I tried to build, I had to change |
The new method works flawlessly - if the user is a platform Admin. For normal users it always fails with
|
I built a local version that uses |
artifactory.go
Outdated
|
||
logger.Debug("fetching Viewer role") | ||
|
||
resp, err := b.performArtifactoryGet(config, "/access/api/v1/roles/Viewer") |
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.
Just to be clear - this is the endpoint that seems to require some form of admin permissions.
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 for building and testing in your environment. I don't think there's a faster Access API to use for checking.
I just had a Doh! moment as I realized the expiration value is part of the token. I just need to decode it and check if the exp
value is passed/after the current time.
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.
Yeah - that would be a good inital check. But assumes that the system time pf vault server is matched with the artifactory server and tinezones are set correctly. Now adays it should be, but... So if you go that route, add it as a requirement for the plugin and maybe also still have a backup that if it fails to create a token it renews the refreshable.
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.
You also only have the expiry in the JWT, if someone uses a reference token, it's not there. Another requirement if you want to inspect the token.
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.
😠 Never mind. To parse the token I need the public key from the root certificate, which requires a admin token to fetch.
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.
@elestedt I found the API to use. The Get token by ID API will work for both admin and non-admin tokens.
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.
That will work, as long as save the token id of the refreshable token. Assume you will do a rotation immediately when it's set? (As the token id is not supplied by the user)
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.
The API accepts me
as the token ID to get info about the token (in header). It's a reasonable 'hack'.
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.
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.
Yeah, that is a good way to do it. Non admin and time deterministic, maybe even constant.
Go for it.
Remove mutex from RefreshAccessToken()
Switch to RW lock for pathConfigUserTokenRead() and pathUserTokenCreatePerform()
Add scripts for testing refreshable tokens creation and concurrent token generation
Fixes #225