-
Notifications
You must be signed in to change notification settings - Fork 8
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
Nginx storage authentication #38
Conversation
7cd21e3
to
eacadfb
Compare
eacadfb
to
6c22a7e
Compare
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 have fixed the small issues and pushed a few fixups. Please review them.
Please fix the remaining issues. Mostly in nginx-storage/default.conf.j2
.
kubernetes/create-config-maps.sh
Outdated
@@ -14,3 +14,7 @@ kubectl create configmap nginx-config \ | |||
kubectl create configmap concent-api-settings \ | |||
--from-file=local_settings.py=config-maps/concent-api/local_settings.py \ | |||
--from-literal=__init__.py= | |||
|
|||
kubectl create configmap gatekeeper-api-settings \ | |||
--from-file=local_settings.py=config-maps/gatekeeper/local_settings.py \ |
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.
We don't have a container called gatekeeper-api
. This should be called gatekeeper-settings
, not gatekeeper-api-settings
.
run: gatekeeper | ||
spec: | ||
containers: | ||
- name: concent-api |
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.
The container is running the gatekeeper not concent API so it does not make sense to call it concent-api
. This is misleading. It should be called gatekeeper
.
kubernetes/create-services.sh
Outdated
@@ -4,4 +4,5 @@ | |||
|
|||
kubectl create --record --filename services/concent-api.yml | |||
kubectl create --record --filename services/nginx-storage.yml | |||
kubectl create --record --filename services/gatekeeper.yml | |||
kubectl create --record --filename services/nginx-proxy.yml |
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.
Services should be created and destroyed in the right order. nginx instances should be created last and destroyed first because they open access to the cluster.
proxy_method POST; | ||
proxy_pass $gatekeeper_api_backend/gatekeeper/upload-auth/$http_concent_upload_path; | ||
proxy_set_header Concent-Upload-Path ""; | ||
proxy_set_header Content-Length ""; |
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.
Why are you removing Content-Length
? Gatekeeper will need to be able to access it in later releases.
|
||
location @error_401 { | ||
default_type application/json; | ||
return 401 '{"error_message": "Access denied.", "error_code": "Unauthorized"}'; |
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.
Your error responses are inconsistent. Here you have error_message
and error_code
but a few lines above it's message
and code
. We need to stick to a single format of error responses to make it easy for the client to parse them.
internal; | ||
proxy_pass $gatekeeper_api_backend/gatekeeper/download-auth/$download_url; | ||
proxy_pass_request_body off; | ||
proxy_set_header Content-Length ""; |
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.
Why are you removing the body and Content-Length
? Doesn't auth_request
strip the body automatically?
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.
According to nginx site: https://www.nginx.com/resources/admin-guide/restricting-access-auth-request/ request body is discarded for authentication subrequests, so we will need to removing the body and Content-Length
.
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.
But if it's discarded, it should not be necessary, right? What happens in gatekeeper if you remove these lines?
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 not sure what happend, because gatekeeper not work properly now(problem with golem token)
Without this header, I occur additional errors:
- download-auth:
[DEBUG] Ignoring connection reset
- update-auth:
ERROR | Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE
In update-auth looks like subrequest send file in body to the django.
Smaller file occur next problem:
[DEBUG] Ignoring EPIPE
I think it not work porperly without this header.
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.
OK. Looks like auth_request
does not remove the body after all. So we do have to remove it.
proxy_pass $gatekeeper_api_backend/gatekeeper/download-auth/$download_url; | ||
proxy_pass_request_body off; | ||
proxy_set_header Content-Length ""; | ||
proxy_set_header X-Original_URI $request_uri; |
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.
Why do you need this header? And shouldn't it be called X-Original-URI
?
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.
According to nginx site: https://www.nginx.com/resources/admin-guide/restricting-access-auth-request/ this header pass the full original request URI with arguments but It's look like without it, also work. I find also this topic: bitly/oauth2_proxy#247
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 know, but do you use it? If not then it's not necessary here.
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.
Ok. I delete it.
proxy_pass $gatekeeper_api_backend/gatekeeper/upload-auth/$http_concent_upload_path; | ||
proxy_set_header Concent-Upload-Path ""; | ||
proxy_set_header Content-Length ""; | ||
proxy_set_header X-Original_URI $request_uri; |
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.
Why do you need this header? And shouldn't it be called X-Original-URI
?
limit_except GET { deny all; } | ||
limit_except GET { deny all; } | ||
auth_request /download-auth/; | ||
auth_request_set $auth_status $upstream_status; |
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.
What is this for? I don't see this variable used anywhere else in this file. Is it needed here?
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.
Ok. So, I forgot to remove these variables, their goal was to check the http status during debugging.
limit_except GET { deny all; } | ||
auth_request /download-auth/; | ||
auth_request_set $auth_status $upstream_status; | ||
if ($request_uri ~* "/download/(.*)") { |
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.
- Why case-insensitive regex match (
~*
) and and not a normal one (~
)? - What will the match be if
request_uri
looks like this:/download/a/b/c/download/file.jpg
?
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.
- According to this post https://serverfault.com/questions/801356/what-is-the-difference-between-nginx-and-regexes, version with
~*
is matching as a case-insensitive regular expression. - So if request look like this
download/a/b/c/download/file.jpg
, it change properly and go to gatekeeper in this form of request/gatekeeper/download-auth/a/b/c/download/file.jpg
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.
According to this post https://serverfault.com/questions/801356/what-is-the-difference-between-nginx-and-regexes, version with ~* is matching as a case-insensitive regular expression.
I'm asking why do you need a case-insensitive match here.
91c54b8
to
585ea8e
Compare
Resolves #19