[CIAM-2473] Update validation to check all namespaces#1531
[CIAM-2473] Update validation to check all namespaces#1531Lucy Fan (lucy-fan) merged 7 commits intomainfrom
Conversation
| if err != nil { | ||
| notFoundErr = err | ||
| } | ||
| if role.Name != "" { // Check if resource type is supported in this particular role |
There was a problem hiding this comment.
I remember that the role api will return the internal name of this role (like ClusterOperator) instead cli only works with display name (Operator) so this validation might fail as well..? We're migrating to new role endpoints in Q1, will that resolve this issue?
There was a problem hiding this comment.
The role API should be able to get a role by either name or display name (since this PR) so I think it should be okay. I've tested it with creating a DeveloperRead with SR scope + Subject resource and the validation passed.
There was a problem hiding this comment.
Do you mind explaining why this check is being made? I don't think I'm following the logic here.
There was a problem hiding this comment.
If there is a role with the specified rolename in a particular namespace, then we want to check if the resource is valid or not for this role. Since there are now roles with the same name but different resource types in the access policies, we need to check all the possible roles.
Ie. There is a DeveloperRead in dataplane, public and datagovernance namespace. The DeveloperRead in dataplane namespace has access policies with Topic, etc. whereas the DeveloperRead in datagovernance has access policies with Subject, etc. Since this function only takes in a role name (DeveloperRead) and the resourceType(something like Subject or Topic), then there is no way of knowing exactly which DeveloperRead we are trying to check. Hence we need to check all of them. Otherwise we can run into issues where we are trying to make a DeveloperRead with the datagovernance namespace and it fails because it looks at the DeveloperRead in dataplane and sees there are no Subject resourcetypes, and does not look at the DeveloperRead in datagovernance at all.
There was a problem hiding this comment.
This validation is being removed in v3 and will be added back when v2 role api becomes available
Akshay Ben (aben) (dragonmushu)
left a comment
There was a problem hiding this comment.
Could we add a test for this. Also were you able to build and test locally
Co-authored-by: Brian Strauch <bstrauch@confluent.io> Co-authored-by: MuweiHe <83249359+MuweiHe@users.noreply.github.com>
Co-authored-by: Brian Strauch <bstrauch@confluent.io>
| var uniqueResourceTypes []string | ||
| for rt := range allResourceTypes { | ||
| uniqueResourceTypes = append(uniqueResourceTypes, rt) | ||
| for resourceType := range allResourceTypes { | ||
| uniqueResourceTypes = append(uniqueResourceTypes, resourceType) | ||
| } |
There was a problem hiding this comment.
Oops, forgot to mention, we have a set package with a Slice() function!
There was a problem hiding this comment.
This is also currently done in validateResourceTypeV2, so we would probably need to update both of those to use the set package. I can do this in another PR later so that the content of this one isn't too confusing.
There was a problem hiding this comment.
It would probably just be a 4-5 line diff, so feel free to add it to this PR!
There was a problem hiding this comment.
If it's not urgent, then if it's alright with you, I would rather do it in a separate PR next week, as I am currently on PTO for this week 😅
Co-authored-by: Brian Strauch <bstrauch@confluent.io>
Checklist
What
SR role binding creation was failing when including a resource type:
It turns out that one of the validation steps involved seeing if a resource type was in the access policy of the role it was trying to create, but it would only check the dataplane and public namespace, whereas the SR roles are in datagovernance. In addition, the validation used an API that got a role only based off of a role name (and optional namespace), so in the instance where we tried to create a DeveloperRead, it would see the DeveloperRead in the dataplane namespace (ie. The one for Kafka) and fail the validation since Subject is not a valid resource type for this particular DeveloperRead. So this PR updates the validation by getting all the roles that have the role name in all the namespaces and checking each one to see if the resource type is valid.
References
https://confluentinc.atlassian.net/browse/CIAM-2473
Test & Review
Successfully created SR DeveloperRead and Kafka DeveloperRead