Skip to content

Commit

Permalink
Make cubbyhole revocation/tidying compatible with cubbys in namespace…
Browse files Browse the repository at this point in the history
…s. (#11408) (#11412)
  • Loading branch information
ncabatoff authored Apr 19, 2021
1 parent be6b0e6 commit 2df19e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
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 @@ -1790,7 +1796,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 @@ -1987,7 +1999,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

0 comments on commit 2df19e5

Please sign in to comment.