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

Fix cubbyhole and token revocation for legacy service tokens #19416

Merged
merged 3 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/19416.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
auth/token: Fix cubbyhole and revocation for legacy service tokens
```
2 changes: 1 addition & 1 deletion vault/token_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ func (ts *TokenStore) create(ctx context.Context, entry *logical.TokenEntry) err
entry.ID = fmt.Sprintf("%s.%s", entry.ID, tokenNS.ID)
}

if tokenNS.ID != namespace.RootNamespaceID || strings.HasPrefix(entry.ID, consts.ServiceTokenPrefix) {
if tokenNS.ID != namespace.RootNamespaceID || strings.HasPrefix(entry.ID, consts.ServiceTokenPrefix) || strings.HasPrefix(entry.ID, consts.LegacyServiceTokenPrefix) {
if entry.CubbyholeID == "" {
cubbyholeID, err := base62.Random(TokenLength)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions vault/token_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,22 @@ func TestTokenStore_CreateOrphanResponse(t *testing.T) {
}
}

// TestTokenStore_CubbyholeDeletion tests that a token's cubbyhole
// can be used and that the cubbyhole is removed after the token is revoked.
func TestTokenStore_CubbyholeDeletion(t *testing.T) {
c, _, root := TestCoreUnsealed(t)
testTokenStore_CubbyholeDeletion(t, c, root)
}

// TestTokenStore_CubbyholeDeletionSSCTokensDisabled tests that a legacy token's
// cubbyhole can be used, and that the cubbyhole is removed after the token is revoked.
func TestTokenStore_CubbyholeDeletionSSCTokensDisabled(t *testing.T) {
c, _, root := TestCoreUnsealed(t)
c.disableSSCTokens = true
testTokenStore_CubbyholeDeletion(t, c, root)
}

func testTokenStore_CubbyholeDeletion(t *testing.T, c *Core, root string) {
ts := c.tokenStore

for i := 0; i < 10; i++ {
Expand Down