-
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
Enable support for read-only mode on APIs #1219
Enable support for read-only mode on APIs #1219
Conversation
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.
LGTM!
"""Process request ReadOnlyApiMiddleware.""" | ||
if settings.READ_ONLY_API_MODE and request.method in ["POST", "PUT", "PATCH", "DELETE"]: | ||
return HttpResponse( | ||
json.dumps({"error": "This API is currently in read-only mode. Please try again later."}), |
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.
Wondering what message would pop up in customer's console, they might be confused with API.
Maybe something like the system is currently under maintenance and in read-only mode......
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.
👍 I was going to ping platex to see how a 405 might be handled right now to see if they'd render their own message or need to use the API message.
/retest |
This adds an optional `READ_ONLY_API_MODE` environment variable consumed in settings, which defaults to `False`. It can be configured via params in the deploy template to enable/disable with config per environment. This is used in a new `ReadOnlyApiMiddleware` middleware for all RBAC requests, which checks the request method and the configuration setting to determine whether or not to process the request. In the event of a write method + read-only mode being enabled, we'll return a 405 with a message explaining we're in read-only mode, to be used during migration/maintenance windows for the service. Another option would be to use 503, though since we're still accepting GET requests a 405 with explicit message may be the best approach.
475f2f3
to
623c101
Compare
Link(s) to Jira
Description of Intent of Change(s)
This adds an optional
READ_ONLY_API_MODE
environment variable consumed in settings, which defaults toFalse
. It can be configured via params in the deploy template to enable/disable with config per environment.This is used in a new
ReadOnlyApiMiddleware
middleware for all RBAC requests, which checks the request method and the configuration setting to determine whether or not to process the request.In the event of a write method + read-only mode being enabled, we'll return a 405 with a message explaining we're in read-only mode, to be used during migration/maintenance windows for the service.
Another option would be to use 503, though since we're still accepting GET requests a 405 with explicit message may be the best approach.
Local Testing
By default, you should not be prevented from any write API requests.
Update your
.env
to setREAD_ONLY_API_MODE=True
and note that you receive a 405 on anything butGET
requests.TODO:
Checklist
Secure Coding Practices Checklist Link
Secure Coding Practices Checklist