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

Nginx storage authentication #38

Merged
merged 3 commits into from
Jan 12, 2018
Merged

Nginx storage authentication #38

merged 3 commits into from
Jan 12, 2018

Conversation

bartoszbetka
Copy link
Contributor

@bartoszbetka bartoszbetka commented Jan 9, 2018

Resolves #19

@bartoszbetka bartoszbetka requested a review from cameel January 9, 2018 14:47
@cameel cameel force-pushed the nginx-storage-authentication branch from 7cd21e3 to eacadfb Compare January 10, 2018 14:03
@bartoszbetka bartoszbetka force-pushed the nginx-storage-authentication branch from eacadfb to 6c22a7e Compare January 10, 2018 15:34
Copy link
Contributor

@cameel cameel left a 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.

@@ -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 \
Copy link
Contributor

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
Copy link
Contributor

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.

@@ -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
Copy link
Contributor

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 "";
Copy link
Contributor

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"}';
Copy link
Contributor

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 "";
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@cameel cameel Jan 11, 2018

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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/(.*)") {
Copy link
Contributor

@cameel cameel Jan 11, 2018

Choose a reason for hiding this comment

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

  1. Why case-insensitive regex match (~*) and and not a normal one (~)?
  2. What will the match be if request_uri looks like this: /download/a/b/c/download/file.jpg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. 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.
  2. 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

Copy link
Contributor

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.

@cameel cameel force-pushed the nginx-storage-authentication branch from 91c54b8 to 585ea8e Compare January 12, 2018 15:16
@cameel cameel merged commit 585ea8e into master Jan 12, 2018
@cameel cameel deleted the nginx-storage-authentication branch January 12, 2018 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants