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

feat(vault): not allowing batch token revoke #4918

Closed
wants to merge 2 commits into from

Conversation

anilkeshav27
Copy link
Member

Changes

this is alternative to #4880 and is a clean way to do it

  • Tests
  • Documentation

@anilkeshav27 anilkeshav27 requested a review from a team as a code owner May 2, 2024 13:02
Copy link
Member

@tiloKo tiloKo left a comment

Choose a reason for hiding this comment

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

I do not know vault so just some general feedback

if err := v.RevokeToken(); err != nil {
log.Entry().WithError(err).Fatal("Could not revoke token")

// only service tokens should be revoked and not batch tokens, the below will lookup the token and depends on the token prefix hvs. for service token
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// only service tokens should be revoked and not batch tokens, the below will lookup the token and depends on the token prefix hvs. for service token
const serviceTokenPrefix string = "hvs."


// only service tokens should be revoked and not batch tokens, the below will lookup the token and depends on the token prefix hvs. for service token
lookupPath := "auth/token/lookup-self"
secret, err := v.GetSecret("auth/token/lookup-self")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
secret, err := v.GetSecret("auth/token/lookup-self")
secret, err := v.GetSecret(lookupPath)

log.Entry().Warnf("Could not lookup token at %s, not continuing to revoke", lookupPath)
} else {
if id, ok := secret.Data["id"]; ok {
if strings.HasPrefix(id.(string), "hvs.") {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if strings.HasPrefix(id.(string), "hvs.") {
if strings.HasPrefix(id.(string), serviceTokenPrefix) {

Copy link
Member

Choose a reason for hiding this comment

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

Also id.(string) will cause a panic if id is not of type string. Maybe use instead the 2 parameter version of type assertion which provides a boolean instead of panicing? (e.g. s, ok := i.(string) )

log.Entry().WithError(err).Fatal("Could not revoke token")
}
}
log.Entry().Warnf("Could not lookup token.Data at %s, not continuing to revoke", lookupPath)
Copy link
Member

@tiloKo tiloKo May 2, 2024

Choose a reason for hiding this comment

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

doesn't this Warning has to go into an else branch, otherwise it gets executed every time the RevokeToken was successful or secret could be looked up but has not the prefix?

@@ -281,9 +281,26 @@ func (v Client) RevokeToken() error {
// MustRevokeToken same as RevokeToken but the programm is terminated with an error if this fails.
// Should be used in defer statements only.
func (v Client) MustRevokeToken() {
Copy link
Member

Choose a reason for hiding this comment

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

Must is a quite strong word so it is a bit surprising that according to the comment it only "should" do some thing under certain conditions. Maybe call the function RevokeServiceToken instead?

Copy link

sonarcloud bot commented May 13, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@CCFenner CCFenner changed the title feat (vault) not allowing batch token revoke feat(vault): not allowing batch token revoke May 20, 2024
Copy link
Contributor

Thank you for your contribution! This pull request is stale because it has been open 60 days with no activity. In order to keep it open, please remove stale label or add a comment within the next 10 days. If you need a Piper team member to remove the stale label make sure to add @SAP/jenkins-library-team to your comment.

@github-actions github-actions bot added the stale marks stale issues and pull requests label Jul 20, 2024
Copy link
Contributor

Pull request got stale and no further activity happened. It has automatically been closed. Please re-open in case you still consider it relevant.

@github-actions github-actions bot closed this Jul 30, 2024
@anilkeshav27
Copy link
Member Author

re-working on this pr to allow batch tokens

@anilkeshav27 anilkeshav27 removed the stale marks stale issues and pull requests label Aug 13, 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.

None yet

2 participants