-
Notifications
You must be signed in to change notification settings - 8000 Fork 3.5k
Creating a Schedule with invalid credentials
key raises 500 Error
#4147
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
Comments
The example here is an incorrect usage of the API (you're supposed to attach credentials using |
@AlanCoding what do you think is the cleanest way to resolve this? Here's my Friday afternoon stab at it: diff --git a/awx/api/serializers.py b/awx/api/serializers.py
index 2eb252a5c..f9913ab00 100644
--- a/awx/api/serializers.py
+++ b/awx/api/serializers.py
@@ -3415,6 +3415,12 @@ class LaunchConfigurationBaseSerializer(BaseSerializer):
summary_fields.pop('credential', None)
return summary_fields
+ def to_internal_value(self, data):
+ # promptable credentials are associated at `/credentials/` endpoints,
+ # not in the actual launch config
+ data.pop('credentials', None)
+ return super(LaunchConfigurationBaseSerializer, self).to_internal_value(data)
+ |
credentials
key raises 500 Error
credentials
key raises 500 Errorcredentials
key raises 500 Error
For whatever reason, I can't reproduce this, although the traceback makes perfect sense to me. When I attempt it, it just creates the schedule and doesn't associate any credentials. Anyway, if I could reproduce it, I would test out this fix: diff --git a/awx/api/generics.py b/awx/api/generics.py
index 7c17799d11..4058f7f358 100644
--- a/awx/api/generics.py
+++ b/awx/api/generics.py
@@ -567,7 +567,7 @@ class SubListCreateAPIView(SubListAPIView, ListCreateAPIView):
status=status.HTTP_400_BAD_REQUEST)
# Verify we have permission to add the object as given.
- if not request.user.can_access(self.model, 'add', serializer.initial_data):
+ if not request.user.can_access(self.model, 'add', serializer.validated_data):
raise PermissionDenied()
# save the object through the serializer, reload and returned the saved The key should really only be used for internal purposes, and it's concerning that data the user supplied gets into that logic at all (although in practice it should get by using a reference object instead). This diff should avoid that, but it's been the current way for a long time. |
I was able to reproduce the 500 error. I can also confirm that @AlanCoding's suggestion does prevent a 500 error and the request goes through cleanly with a 201 response. If we like this solution I'd be happy to open a PR with the change, or I can look for another solution to address Alan's concern. |
- 500 error occurs when a non-admin user attempts to add an invalid credential during schedule creation - This change checks that the user can add the object to serializer.validated_data, instead of serializer.initial_data - The invalid credential field is purged in .validated_data, so the request passes through cleanly - Fix for awx issue ansible#4147
fixed and merged into awx devel #5084 |
- 500 error occurs when a non-admin user attempts to add an invalid credential during schedule creation - This change checks that the user can add the object to serializer.validated_data, instead of serializer.initial_data - The invalid credential field is purged in .validated_data, so the request passes through cleanly - Fix for awx issue ansible#4147
Tested this out by adding |
SUMMARY
peon
, with "admin" access to a Job Template.credentials
:AWX raises an uncaught exception:
The text was updated successfully, but these errors were encountered: