Improve grant validation (#3081)
This adds several relationships into the resource package that are then made use of to improve the grant validation that runs during Parse. By understanding mappings between ID and resource type the validation checks can far better align with actual allowed grant formats so we can find several common misunderstandings before they simply result in an authorization failure. In the future some of these functions could be used in the logic in the actual ACL checks but it's not currently necessary and I don't want to lump that change in with this. Note that the tests have not meaningfully changed, but they _have_ had to be updated because the stricter validation is actually catching issues.
This commit is contained in:
1 parent
ef37369c2b
commit
fc664eb35f
12 files changed
+380
-222
No files matched your search
@@ -1671,25 +1671,25 @@ func TestAddGrants(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Add grant on role with grant",
|
||||
existing: []string{"id=1;actions=read"},
|
||||
existing: []string{"id=u_foo;actions=read"},
|
||||
add: []string{"id=*;type=*;actions=delete"},
|
||||
result: []string{"id=1;actions=read", "id=*;type=*;actions=delete"},
|
||||
result: []string{"id=u_foo;actions=read", "id=*;type=*;actions=delete"},
|
||||
},
|
||||
{
|
||||
name: "Add duplicate grant on role with grant",
|
||||
existing: []string{"id=aA1;actions=read"},
|
||||
existing: []string{"id=u_fooaA1;actions=read"},
|
||||
add: []string{"id=*;type=*;actions=delete", "id=*;type=*;actions=delete"},
|
||||
result: []string{"id=aA1;actions=read", "id=*;type=*;actions=delete"},
|
||||
result: []string{"id=u_fooaA1;actions=read", "id=*;type=*;actions=delete"},
|
||||
},
|
||||
{
|
||||
name: "Add grant matching existing grant",
|
||||
existing: []string{"id=1;actions=read", "id=*;type=*;actions=delete"},
|
||||
existing: []string{"id=u_foo;actions=read", "id=*;type=*;actions=delete"},
|
||||
add: []string{"id=*;type=*;actions=delete"},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "Check deprecation",
|
||||
existing: []string{"id=1;actions=read", "id=*;type=*;actions=delete"},
|
||||
existing: []string{"id=u_foo;actions=read", "id=*;type=*;actions=delete"},
|
||||
add: []string{"id=*;type=target;actions=add-host-sets"},
|
||||
wantErr: true,
|
||||
wantErrContains: "Use \\\"add-host-sources\\\" instead",
|
||||
@@ -1810,31 +1810,31 @@ func TestSetGrants(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Set grant on role with grant",
|
||||
existing: []string{"id=1;actions=read"},
|
||||
existing: []string{"id=u_foo;actions=read"},
|
||||
set: []string{"id=*;type=*;actions=delete"},
|
||||
result: []string{"id=*;type=*;actions=delete"},
|
||||
},
|
||||
{
|
||||
name: "Set grant matching existing grant",
|
||||
existing: []string{"id=1;actions=read", "id=*;type=*;actions=delete"},
|
||||
existing: []string{"id=u_foo;actions=read", "id=*;type=*;actions=delete"},
|
||||
set: []string{"id=*;type=*;actions=delete"},
|
||||
result: []string{"id=*;type=*;actions=delete"},
|
||||
},
|
||||
{
|
||||
name: "Set duplicate grant matching existing grant",
|
||||
existing: []string{"id=1;actions=read", "id=*;type=*;actions=delete"},
|
||||
existing: []string{"id=u_foo;actions=read", "id=*;type=*;actions=delete"},
|
||||
set: []string{"id=*;type=*;actions=delete", "id=*;type=*;actions=delete"},
|
||||
result: []string{"id=*;type=*;actions=delete"},
|
||||
},
|
||||
{
|
||||
name: "Set empty on role",
|
||||
existing: []string{"id=1;type=*;actions=read", "id=*;type=*;actions=delete"},
|
||||
existing: []string{"id=hcst_foo;type=*;actions=read", "id=*;type=*;actions=delete"},
|
||||
set: nil,
|
||||
result: nil,
|
||||
},
|
||||
{
|
||||
name: "Check deprecation",
|
||||
existing: []string{"id=1;actions=read", "id=*;type=*;actions=delete"},
|
||||
existing: []string{"id=u_foo;actions=read", "id=*;type=*;actions=delete"},
|
||||
set: []string{"id=*;type=target;actions=add-host-sets"},
|
||||
wantErr: true,
|
||||
wantErrContains: "Use \\\"add-host-sources\\\" instead",
|
||||
@@ -1940,31 +1940,31 @@ func TestRemoveGrants(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Remove all",
|
||||
existing: []string{"id=1;type=*;actions=read"},
|
||||
remove: []string{"id=1;type=*;actions=read"},
|
||||
existing: []string{"id=hcst_1;type=*;actions=read"},
|
||||
remove: []string{"id=hcst_1;type=*;actions=read"},
|
||||
},
|
||||
{
|
||||
name: "Remove partial",
|
||||
existing: []string{"id=1;type=*;actions=read", "id=2;type=*;actions=delete"},
|
||||
remove: []string{"id=1;type=*;actions=read"},
|
||||
result: []string{"id=2;type=*;actions=delete"},
|
||||
existing: []string{"id=hcst_1;type=*;actions=read", "id=hcst_2;type=*;actions=delete"},
|
||||
remove: []string{"id=hcst_1;type=*;actions=read"},
|
||||
result: []string{"id=hcst_2;type=*;actions=delete"},
|
||||
},
|
||||
{
|
||||
name: "Remove duplicate",
|
||||
existing: []string{"id=1;type=*;actions=read", "id=2;type=*;actions=delete"},
|
||||
remove: []string{"id=1;type=*;actions=read", "id=1;type=*;actions=read"},
|
||||
result: []string{"id=2;type=*;actions=delete"},
|
||||
existing: []string{"id=hcst_1;type=*;actions=read", "id=hcst_2;type=*;actions=delete"},
|
||||
remove: []string{"id=hcst_1;type=*;actions=read", "id=hcst_1;type=*;actions=read"},
|
||||
result: []string{"id=hcst_2;type=*;actions=delete"},
|
||||
},
|
||||
{
|
||||
name: "Remove non existant",
|
||||
existing: []string{"id=2;type=*;actions=delete"},
|
||||
remove: []string{"id=1;type=*;actions=read"},
|
||||
result: []string{"id=2;type=*;actions=delete"},
|
||||
existing: []string{"id=hcst_2;type=*;actions=delete"},
|
||||
remove: []string{"id=hcst_1;type=*;actions=read"},
|
||||
result: []string{"id=hcst_2;type=*;actions=delete"},
|
||||
},
|
||||
{
|
||||
name: "Remove from empty role",
|
||||
existing: []string{},
|
||||
remove: []string{"id=1;type=*;actions=read"},
|
||||
remove: []string{"id=hcst_1;type=*;actions=read"},
|
||||
result: nil,
|
||||
},
|
||||
}
|
||||
@@ -2012,7 +2012,7 @@ func TestRemoveGrants(t *testing.T) {
|
||||
name: "Bad Version",
|
||||
req: &pbs.RemoveRoleGrantsRequest{
|
||||
Id: role.GetPublicId(),
|
||||
GrantStrings: []string{"id=2;type=*;actions=create"},
|
||||
GrantStrings: []string{"id=hcst_2;type=*;actions=create"},
|
||||
Version: role.GetVersion() + 2,
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.Internal),
|
||||
|
||||
Reference in new issue
Block a user