mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-30 02:51:07 +02:00
initial commit for minor update to token-store
This commit is contained in:
parent
1957de6d12
commit
d29e3d79d2
@ -1076,6 +1076,11 @@ func (ts *TokenStore) handleCreateCommon(
|
||||
logical.ErrInvalidRequest
|
||||
}
|
||||
|
||||
// Prevent attempts to create a root token without an actual root token as parent
|
||||
if strutil.StrListContains(data.Policies, "root") && !strutil.StrListContains(parent.Policies, "root") {
|
||||
return logical.ErrorResponse("root tokens may not be created without parent token being root"), logical.ErrInvalidRequest
|
||||
}
|
||||
|
||||
// Setup the token entry
|
||||
te := TokenEntry{
|
||||
Parent: req.ClientToken,
|
||||
|
@ -832,6 +832,23 @@ func TestTokenStore_HandleRequest_CreateToken_NonRoot_InvalidSubset(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestTokenStore_HandleRequest_CreateToken_NonRoot_RootChild(t *testing.T) {
|
||||
_, ts, _, root := TestCoreWithTokenStore(t)
|
||||
testMakeToken(t, ts, root, "client", "", []string{"foo", "bar"})
|
||||
|
||||
req := logical.TestRequest(t, logical.UpdateOperation, "create")
|
||||
req.ClientToken = "client"
|
||||
req.Data["policies"] = []string{"root", "foo", "bar"}
|
||||
|
||||
resp, err := ts.HandleRequest(req)
|
||||
if err != logical.ErrInvalidRequest {
|
||||
t.Fatalf("err: %v %v", err, resp)
|
||||
}
|
||||
if resp.Data["error"] != "root tokens may not be created without parent token being root" {
|
||||
t.Fatalf("bad: %#v", resp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTokenStore_HandleRequest_CreateToken_NonRoot_NoParent(t *testing.T) {
|
||||
_, ts, _, root := TestCoreWithTokenStore(t)
|
||||
testMakeToken(t, ts, root, "client", "", []string{"foo"})
|
||||
|
Loading…
x
Reference in New Issue
Block a user