mirror of
https://github.com/hashicorp/vault.git
synced 2025-12-08 11:01:47 +01:00
vault: Simpify token checking logic
This commit is contained in:
parent
5180daed1c
commit
ceeebcb5b7
@ -230,8 +230,7 @@ func (c *Core) HandleRequest(req *logical.Request) (*logical.Response, error) {
|
|||||||
|
|
||||||
func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) {
|
func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) {
|
||||||
// Validate the token
|
// Validate the token
|
||||||
err := c.checkToken(
|
err := c.checkToken(req.Operation, req.Path, req.ClientToken)
|
||||||
req.Operation, req.Path, req.ClientToken, c.router.RootPath(req.Path))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If it is an internal error we return that, otherwise we
|
// If it is an internal error we return that, otherwise we
|
||||||
// return invalid request so that the status codes can be correct
|
// return invalid request so that the status codes can be correct
|
||||||
@ -306,7 +305,7 @@ func (c *Core) handleLoginRequest(req *logical.Request) (*logical.Response, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) checkToken(
|
func (c *Core) checkToken(
|
||||||
op logical.Operation, path string, token string, root bool) error {
|
op logical.Operation, path string, token string) error {
|
||||||
// Ensure there is a client token
|
// Ensure there is a client token
|
||||||
if token == "" {
|
if token == "" {
|
||||||
return fmt.Errorf("missing client token")
|
return fmt.Errorf("missing client token")
|
||||||
@ -332,7 +331,7 @@ func (c *Core) checkToken(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is a root protected path
|
// Check if this is a root protected path
|
||||||
if root && !acl.RootPrivilege(path) {
|
if c.router.RootPath(path) && !acl.RootPrivilege(path) {
|
||||||
return logical.ErrPermissionDenied
|
return logical.ErrPermissionDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,11 +616,7 @@ func (c *Core) Seal(token string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate the token is a root token
|
// Validate the token is a root token
|
||||||
err := c.checkToken(
|
err := c.checkToken(logical.WriteOperation, "sys/seal", token)
|
||||||
logical.WriteOperation,
|
|
||||||
"sys/seal",
|
|
||||||
token,
|
|
||||||
true)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ func NewSystemBackend(core *Core) logical.Backend {
|
|||||||
"policy/*",
|
"policy/*",
|
||||||
"audit",
|
"audit",
|
||||||
"audit/*",
|
"audit/*",
|
||||||
|
"seal", // Must be set for Core.Seal() logic
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@ func TestSystemBackend_RootPaths(t *testing.T) {
|
|||||||
"policy/*",
|
"policy/*",
|
||||||
"audit",
|
"audit",
|
||||||
"audit/*",
|
"audit/*",
|
||||||
|
"seal",
|
||||||
}
|
}
|
||||||
|
|
||||||
b := testSystemBackend(t)
|
b := testSystemBackend(t)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user