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

Backport 1.6: Make cubbyhole revocation/tidying compatible with cubbys in namespace… #11411

Merged
merged 1 commit into from
Apr 19, 2021
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/11408.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
core: Fix cleanup of storage entries from cubbyholes within namespaces.
```
4 changes: 2 additions & 2 deletions vault/logical_cubbyhole.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func (b *CubbyholeBackend) paths() []*framework.Path {
}
}

func (b *CubbyholeBackend) revoke(ctx context.Context, saltedToken string) error {
func (b *CubbyholeBackend) revoke(ctx context.Context, view *BarrierView, saltedToken string) error {
if saltedToken == "" {
return fmt.Errorf("client token empty during revocation")
}

if err := logical.ClearView(ctx, b.storageView.(*BarrierView).SubView(saltedToken+"/")); err != nil {
if err := logical.ClearView(ctx, view.SubView(saltedToken+"/")); err != nil {
return err
}

Expand Down
20 changes: 16 additions & 4 deletions vault/token_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,25 @@ var (
return errors.New("nil token entry")
}

storage := ts.core.router.MatchingStorageByAPIPath(ctx, cubbyholeMountPath)
if storage == nil {
return fmt.Errorf("no cubby mount entry")
}
view := storage.(*BarrierView)

switch {
case te.NamespaceID == namespace.RootNamespaceID && !strings.HasPrefix(te.ID, "s."):
saltedID, err := ts.SaltID(ctx, te.ID)
if err != nil {
return err
}
return ts.cubbyholeBackend.revoke(ctx, salt.SaltID(ts.cubbyholeBackend.saltUUID, saltedID, salt.SHA1Hash))
return ts.cubbyholeBackend.revoke(ctx, view, salt.SaltID(ts.cubbyholeBackend.saltUUID, saltedID, salt.SHA1Hash))

default:
if te.CubbyholeID == "" {
return fmt.Errorf("missing cubbyhole ID while destroying")
}
return ts.cubbyholeBackend.revoke(ctx, te.CubbyholeID)
return ts.cubbyholeBackend.revoke(ctx, view, te.CubbyholeID)
}
}
)
Expand Down Expand Up @@ -1816,7 +1822,13 @@ func (ts *TokenStore) handleTidy(ctx context.Context, req *logical.Request, data
}

// List all the cubbyhole storage keys
cubbyholeKeys, err := ts.cubbyholeBackend.storageView.List(quitCtx, "")
view := ts.core.router.MatchingStorageByAPIPath(ctx, cubbyholeMountPath)
if view == nil {
return fmt.Errorf("no cubby mount entry")
}
bview := view.(*BarrierView)

cubbyholeKeys, err := bview.List(quitCtx, "")
if err != nil {
return errwrap.Wrapf("failed to fetch cubbyhole storage keys: {{err}}", err)
}
Expand Down Expand Up @@ -2013,7 +2025,7 @@ func (ts *TokenStore) handleTidy(ctx context.Context, req *logical.Request, data
key := strings.TrimSuffix(key, "/")
if !validCubbyholeKeys[key] {
ts.logger.Info("deleting invalid cubbyhole", "key", key)
err = ts.cubbyholeBackend.revoke(quitCtx, key)
err = ts.cubbyholeBackend.revoke(quitCtx, bview, key)
if err != nil {
tidyErrors = multierror.Append(tidyErrors, errwrap.Wrapf(fmt.Sprintf("failed to revoke cubbyhole key %q: {{err}}", key), err))
}
Expand Down