-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
core: revoke the proper token on partial failures from token-related requests #7835
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -860,7 +860,11 @@ func (c *Core) handleRequest(ctx context.Context, req *logical.Request) (retResp | |
|
||
_, identityPolicies, err := c.fetchEntityAndDerivedPolicies(ctx, tokenNS, resp.Auth.EntityID) | ||
if err != nil { | ||
c.tokenStore.revokeOrphan(ctx, te.ID) | ||
// Best-effort clean up on error, so we log the cleanup error as a | ||
// warning but still return as internal error. | ||
if err := c.tokenStore.revokeOrphan(ctx, resp.Auth.ClientToken); err != nil { | ||
c.logger.Warn("failed to clean up token lease", "request_path", req.Path, "error", err) | ||
} | ||
return nil, nil, ErrInternalError | ||
} | ||
|
||
|
@@ -874,7 +878,11 @@ func (c *Core) handleRequest(ctx context.Context, req *logical.Request) (retResp | |
Path: resp.Auth.CreationPath, | ||
NamespaceID: ns.ID, | ||
}, resp.Auth); err != nil { | ||
c.tokenStore.revokeOrphan(ctx, te.ID) | ||
// Best-effort clean up on error, so we log the cleanup error as | ||
// a warning but still return as internal error. | ||
if err := c.tokenStore.revokeOrphan(ctx, resp.Auth.ClientToken); err != nil { | ||
c.logger.Warn("failed to clean up token lease", "request_path", req.Path, "error", err) | ||
} | ||
c.logger.Error("failed to register token lease", "request_path", req.Path, "error", err) | ||
retErr = multierror.Append(retErr, ErrInternalError) | ||
return nil, auth, retErr | ||
|
@@ -1209,7 +1217,9 @@ func (c *Core) RegisterAuth(ctx context.Context, tokenTTL time.Duration, path st | |
case logical.TokenTypeService: | ||
// Register with the expiration manager | ||
if err := c.expiration.RegisterAuth(ctx, &te, auth); err != nil { | ||
c.tokenStore.revokeOrphan(ctx, te.ID) | ||
if err := c.tokenStore.revokeOrphan(ctx, te.ID); err != nil { | ||
c.logger.Warn("failed to clean up token lease", "request_path", path, "error", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps failing here should produce a slightly different log message to make orphan revocation by ID distinct from revocation by client token lease. Something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to the difference between using The reason why we're able to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was indeed referring to |
||
} | ||
c.logger.Error("failed to register token lease", "request_path", path, "error", err) | ||
return ErrInternalError | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably should log the error here as well?