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

Merged
merged 8 commits into from
Oct 22, 2024
21 changes: 19 additions & 2 deletions pkg/vault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Googlom marked this conversation as resolved.
Show resolved Hide resolved
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
Googlom marked this conversation as resolved.
Show resolved Hide resolved
lookupPath := "auth/token/lookup-self"
secret, err := v.GetSecret("auth/token/lookup-self")
anilkeshav27 marked this conversation as resolved.
Show resolved Hide resolved

if err != nil {
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.") {
anilkeshav27 marked this conversation as resolved.
Show resolved Hide resolved
if err := v.RevokeToken(); err != nil {
log.Entry().WithError(err).Fatal("Could not revoke token")
}
}
log.Entry().Warnf("Could not lookup token.Data at %s, not continuing to revoke", lookupPath)
anilkeshav27 marked this conversation as resolved.
Show resolved Hide resolved
} else {
log.Entry().Warnf("Could not lookup token.Data.id at %s, not continuing to revoke", lookupPath)
}
}

}

// GetAppRoleName returns the AppRole role name which was used to authenticate.
Expand Down
Loading