Skip to content
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

Auth updates for formplayer to allow automated app execution #34441

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

snopoke
Copy link
Contributor

@snopoke snopoke commented Apr 16, 2024

See also: dimagi/formplayer#1575

Product Description

Allow Formplayer to submit forms using HMAC auth to allow automatic submissions of forms from FP (when a user isn't making the request).

Technical Summary

The primary change is to allow 'formplayer auth' for form submissions. When requests to FP are made from CommCare use use HMAC auth instead of logging in as a user and using session auth. When this was implemented we did not enable it for form submissions since they required a POST request and there wasn't a need to add that functionality to Formplayer (computing HMAC auth for POST requests).

Some upcoming changes to HQ will require the ability to submit forms from FP to HQ using HMAC auth.

As part of this change the form submission view is refactored (bff809f) to remove the per auth fake views whose only function was to support the different auth decorators. The new approach is similar to what's done in get_auth_decorator_map. I decided not to use that function since there are other decorators that need to be added as well.

Safety Assurance

Safety story

Form submission refactor

This is probably the most risky part of the change however it can be inspected manually to confirm that the changes are equivalent to the previous fake views. The approach to dynamically applying decorators is also not new as mentioned above.

Form submission auth change

This permits and existing auth mechanism to be used for the form submission API. We already use this auth on the 'ota' views. Permitting it for form submissions does increase the scope that this auth has, specifically that this is the first WRITE api to be permitted. I think this is safe.

Changing the order in which auth type is determined

(fe3f2db) This is a small change which should not have any impact. The comment in the code indicates the reason for the change (if it runs before HMAC auth then HMAC auth fails).

Automated test coverage

No additional tests were added. These changes are relying on the existing test suite.

QA Plan

This can be run on staging along with corresponding FP changes (still to come).

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@snopoke snopoke added awaiting QA QA in progress. Do not merge Risk: Medium Change affects files that have been flagged as medium risk. labels Apr 16, 2024
@snopoke snopoke requested a review from biyeun as a code owner April 16, 2024 14:44
@dimagimon dimagimon removed the Risk: Medium Change affects files that have been flagged as medium risk. label Apr 16, 2024
)


@handle_401_response
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't necessary on this view since the decorator only support basic auth

Copy link
Contributor

@esoergel esoergel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually looks safer and more straightforward than I was expecting from the initial description

@@ -405,23 +346,56 @@ def _secure_post_api_key(request, domain, app_id=None):
@set_request_duration_reporting_threshold(60)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice this decorator is on both the parent and the child views. Is it perhaps that one of the decorators doesn't call functools.wraps and so the wrapped fn doesn't have the proper attribute set?

Comment on lines +79 to +80
# do this after header checks since it may read the request body which interferes with
# other auth methods e.g. HMAC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's tricky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting QA QA in progress. Do not merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants