-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RHCLOUD-27273] Enforce correct value/operation pairings #1418
base: master
Are you sure you want to change the base?
[RHCLOUD-27273] Enforce correct value/operation pairings #1418
Conversation
@mjholder do we need to make changes in the OpenAPI specs? |
That's a good question. We do have the types that are acceptable listed but not the fact that a string expects |
It looks like if we move to OpenAPI 3.1 we can use conditional blocks for schema validation but not in 3.0.0. |
rbac/management/role/serializer.py
Outdated
@@ -49,6 +49,18 @@ def validate_attributeFilter(self, value): | |||
message = f"attributeFilter operation must be one of {ALLOWED_OPERATIONS}" | |||
error = {key: [_(message)]} | |||
raise serializers.ValidationError(error) | |||
else: | |||
values = value.get("value") | |||
if type(values) is str and op == "in": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These checks are insufficient, as these check only for string. If for example int
was supplied, it would fall through. Why not check the expected type for each operator?
Be aware, that previously a documentation mentioned a string of comma separated values. Have you checked current state of the database? If users would have already stored badly formatted data, they could hit these errors.
I suggest to prefer isinstance
over a strong type check. See Duck Typing.
BLOCKED BY: #1448
Link(s) to Jira
Description of Intent of Change(s)
The what, why and how.
In order to keep JSON parsing working we need to make sure the value types and operations provided by resourceDefinitions are compatible.
Specifically, if a String is provided the operation needs to be
equals
. Otherwise, if a List is provided, the operation needs to bein
.In order to achieve this I added some extra checks in the ResourceDefinition Serializer to make sure the pairings are correct.
Local Testing
How can the feature be exercised?
How can the bug be exploited and fix confirmed?
Is any special local setup required?
I added a couple tests to the unit test suite. If you want to test locally you can try to create a role with either of the following access definitions:
OR
Checklist
Secure Coding Practices Checklist Link
Secure Coding Practices Checklist