-
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
Add ability to disable an entity #4353
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -802,6 +802,10 @@ func (c *Core) checkToken(ctx context.Context, req *logical.Request, unauth bool | |
} | ||
} | ||
|
||
if entity != nil && entity.Disabled { | ||
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. Should we also be disallowing the entity from getting tokens? 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. Fixed |
||
return nil, te, logical.ErrEntityDisabled | ||
} | ||
|
||
// Check if this is a root protected path | ||
rootPath := c.router.RootPath(req.Path) | ||
|
||
|
@@ -1319,20 +1323,21 @@ func (c *Core) sealInitCommon(ctx context.Context, req *logical.Request) (retErr | |
return retErr | ||
} | ||
|
||
// Since there is no token store in standby nodes, sealing cannot be done. | ||
// Ideally, the request has to be forwarded to leader node for validation | ||
// and the operation should be performed. But for now, just returning with | ||
// an error and recommending a vault restart, which essentially does the | ||
// same thing. | ||
if c.standby { | ||
c.logger.Error("vault cannot seal when in standby mode; please restart instead") | ||
retErr = multierror.Append(retErr, errors.New("vault cannot seal when in standby mode; please restart instead")) | ||
c.stateLock.RUnlock() | ||
return retErr | ||
} | ||
|
||
// Validate the token is a root token | ||
acl, te, entity, err := c.fetchACLTokenEntryAndEntity(req.ClientToken) | ||
if err != nil { | ||
// Since there is no token store in standby nodes, sealing cannot | ||
// be done. Ideally, the request has to be forwarded to leader node | ||
// for validation and the operation should be performed. But for now, | ||
// just returning with an error and recommending a vault restart, which | ||
// essentially does the same thing. | ||
if c.standby { | ||
c.logger.Error("vault cannot seal when in standby mode; please restart instead") | ||
retErr = multierror.Append(retErr, errors.New("vault cannot seal when in standby mode; please restart instead")) | ||
c.stateLock.RUnlock() | ||
return retErr | ||
} | ||
retErr = multierror.Append(retErr, err) | ||
c.stateLock.RUnlock() | ||
return retErr | ||
|
@@ -1341,10 +1346,12 @@ func (c *Core) sealInitCommon(ctx context.Context, req *logical.Request) (retErr | |
// Audit-log the request before going any further | ||
auth := &logical.Auth{ | ||
ClientToken: req.ClientToken, | ||
Policies: te.Policies, | ||
Metadata: te.Meta, | ||
DisplayName: te.DisplayName, | ||
EntityID: te.EntityID, | ||
} | ||
if te != nil { | ||
auth.Policies = te.Policies | ||
auth.Metadata = te.Meta | ||
auth.DisplayName = te.DisplayName | ||
auth.EntityID = te.EntityID | ||
} | ||
|
||
logInput := &audit.LogInput{ | ||
|
@@ -1358,6 +1365,12 @@ func (c *Core) sealInitCommon(ctx context.Context, req *logical.Request) (retErr | |
return retErr | ||
} | ||
|
||
if entity != nil && entity.Disabled { | ||
retErr = multierror.Append(retErr, logical.ErrEntityDisabled) | ||
c.stateLock.RUnlock() | ||
return retErr | ||
} | ||
|
||
// Attempt to use the token (decrement num_uses) | ||
// On error bail out; if the token has been revoked, bail out too | ||
if te != nil { | ||
|
@@ -1450,10 +1463,12 @@ func (c *Core) StepDown(req *logical.Request) (retErr error) { | |
// Audit-log the request before going any further | ||
auth := &logical.Auth{ | ||
ClientToken: req.ClientToken, | ||
Policies: te.Policies, | ||
Metadata: te.Meta, | ||
DisplayName: te.DisplayName, | ||
EntityID: te.EntityID, | ||
} | ||
if te != nil { | ||
auth.Policies = te.Policies | ||
auth.Metadata = te.Meta | ||
auth.DisplayName = te.DisplayName | ||
auth.EntityID = te.EntityID | ||
} | ||
|
||
logInput := &audit.LogInput{ | ||
|
@@ -1466,6 +1481,12 @@ func (c *Core) StepDown(req *logical.Request) (retErr error) { | |
return retErr | ||
} | ||
|
||
if entity != nil && entity.Disabled { | ||
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. I wonder if we should do this before audit logging. 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. No -- for the same reason that we attempt to log whatever we get back from the token store before fully checking validity. The fact that a request is invalid doesn't mean it wasn't an attempted request. |
||
retErr = multierror.Append(retErr, logical.ErrEntityDisabled) | ||
c.stateLock.RUnlock() | ||
return retErr | ||
} | ||
|
||
// Attempt to use the token (decrement num_uses) | ||
if te != nil { | ||
te, err = c.tokenStore.UseToken(ctx, te) | ||
|
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.
I’m suspicious having this commented out might break if a user upgrades from oss -> ent
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.
Should be fine so long as the number is distinct.