Disallow deletion of r_default (#398)
If it's a useful named resource and people accidentally delete it e.g. with TF, they can't get it back. This doesn't affect TF's ability to manage it, just delete.
This commit is contained in:
1 parent
f25186f78a
commit
7e3c174b70
5 files changed
+67
-5
No files matched your search
@@ -620,7 +620,14 @@ func validateUpdateRequest(req *pbs.UpdateRoleRequest) error {
|
||||
}
|
||||
|
||||
func validateDeleteRequest(req *pbs.DeleteRoleRequest) error {
|
||||
return handlers.ValidateDeleteRequest(iam.RolePrefix, req, handlers.NoopValidatorFn)
|
||||
return handlers.ValidateDeleteRequest(iam.RolePrefix, req, func() map[string]string {
|
||||
if req.GetId() == "r_default" {
|
||||
return map[string]string{
|
||||
"id": `Deleting "r_default" is not allowed`,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func validateListRequest(req *pbs.ListRolesRequest) error {
|
||||
|
||||
@@ -284,6 +284,14 @@ func TestDelete(t *testing.T) {
|
||||
},
|
||||
errCode: codes.NotFound,
|
||||
},
|
||||
{
|
||||
name: "Delete default role",
|
||||
scopeId: "global",
|
||||
req: &pbs.DeleteRoleRequest{
|
||||
Id: "r_default",
|
||||
},
|
||||
errCode: codes.InvalidArgument,
|
||||
},
|
||||
{
|
||||
name: "Bad Role Id formatting",
|
||||
scopeId: or.GetPublicId(),
|
||||
|
||||
Reference in new issue
Block a user