Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaste authored Oct 22, 2024
2 parents 0810b11 + 3ad2628 commit a524c2a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/vault/api"
"path"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -181,7 +182,27 @@ func (c *Client) RevokeToken() error {
// MustRevokeToken same as RevokeToken but the program is terminated with an error if this fails.
// Should be used in defer statements only.
func (c *Client) MustRevokeToken() {
if err := c.RevokeToken(); err != nil {
lookupPath := "auth/token/lookup-self"
const serviceTokenPrefix = "hvs."

secret, err := c.GetSecret(lookupPath)
if err != nil {
log.Entry().Warnf("Could not lookup token at %s, not continuing to revoke: %v", lookupPath, err)
return
}

tokenID, ok := secret.Data["id"].(string)
if !ok {
log.Entry().Warnf("Could not lookup token.Data.id at %s, not continuing to revoke", lookupPath)
return
}

if !strings.HasPrefix(tokenID, serviceTokenPrefix) {
log.Entry().Warnf("Service token not identified at %s, not continuing to revoke", lookupPath)
return
}

if err = c.RevokeToken(); err != nil {
log.Entry().WithError(err).Fatal("Could not revoke token")
}
}
Expand Down

0 comments on commit a524c2a

Please sign in to comment.