-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[grafana][auth] add nginx sidecar in front of grafana for tls and auth (
#10139) * [grafana][auth] add nginx sidecar in front of grafana for tls and auth * use jinja templating instead of bash conditional
- Loading branch information
1 parent
8ecfa26
commit 97ef835
Showing
11 changed files
with
215 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM {{ hail_ubuntu_image.image }} | ||
|
||
RUN hail-apt-get-install nginx | ||
|
||
RUN rm -f /etc/nginx/sites-enabled/default && \ | ||
rm -f /etc/nginx/nginx.conf | ||
ADD nginx.conf.out /etc/nginx/nginx.conf | ||
|
||
RUN ln -sf /dev/stdout /var/log/nginx/access.log | ||
RUN ln -sf /dev/stderr /var/log/nginx/error.log | ||
|
||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
include ../config.mk | ||
|
||
.PHONY: deploy | ||
deploy: | ||
.PHONY: build push deploy | ||
|
||
GRAFANA_NGINX_LATEST = gcr.io/$(PROJECT)/grafana_nginx:latest | ||
GRAFANA_NGINX_IMAGE = gcr.io/$(PROJECT)/grafana_nginx:$(shell docker images -q --no-trunc grafana_nginx | sed -e 's,[^:]*:,,') | ||
|
||
build: | ||
$(MAKE) -C ../docker hail-ubuntu | ||
-docker pull $(GRAFANA_NGINX_LATEST) | ||
python3 ../ci/jinja2_render.py '{"hail_ubuntu_image":{"image":"hail-ubuntu"}}' Dockerfile.nginx Dockerfile.nginx.out | ||
python3 ../ci/jinja2_render.py '{"deploy": $(DEPLOY), "default_ns": {"name": "$(NAMESPACE)"}}' nginx.conf nginx.conf.out | ||
docker build -t grafana_nginx -f Dockerfile.nginx.out --cache-from grafana_nginx,$(GRAFANA_NGINX_LATEST),hail-ubuntu . | ||
|
||
push: build | ||
docker tag grafana_nginx $(GRAFANA_NGINX_LATEST) | ||
docker push $(GRAFANA_NGINX_LATEST) | ||
docker tag grafana_nginx $(GRAFANA_NGINX_IMAGE) | ||
docker push $(GRAFANA_NGINX_IMAGE) | ||
|
||
deploy: push | ||
! [ -z $(NAMESPACE) ] # call this like: make deploy NAMESPACE=default | ||
python3 ../ci/jinja2_render.py '{"deploy":$(DEPLOY),"default_ns":{"name":"$(NAMESPACE)"}}' deployment.yaml deployment.yaml.out | ||
python3 ../ci/jinja2_render.py '{"deploy":$(DEPLOY),"default_ns":{"name":"$(NAMESPACE)"}, "grafana_nginx_image": {"image": "$(GRAFANA_NGINX_IMAGE)"}}' deployment.yaml deployment.yaml.out | ||
kubectl -n $(NAMESPACE) apply -f deployment.yaml.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
worker_processes auto; | ||
pid /run/nginx.pid; | ||
include /etc/nginx/modules-enabled/*.conf; | ||
|
||
events { | ||
worker_connections 768; | ||
} | ||
|
||
http { | ||
|
||
sendfile on; | ||
tcp_nopush on; | ||
tcp_nodelay on; | ||
keepalive_timeout 65; | ||
types_hash_max_size 2048; | ||
server_names_hash_bucket_size 128; | ||
|
||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE | ||
ssl_prefer_server_ciphers on; | ||
|
||
log_format json-log escape=json '{' | ||
'"message":"$scheme $request done in ${request_time}s: $status",' | ||
'"response_status":$status,' | ||
'"request_duration":$request_time,' | ||
'"remote_address":"$remote_addr",' | ||
'"x_real_ip":"$http_x_real_ip",' | ||
'"request_start_time":"$time_local",' | ||
'"body_bytes_sent":"$body_bytes_sent",' | ||
'"http_referer":"$http_referer",' | ||
'"http_user_agent":"$http_user_agent"' | ||
'}'; | ||
|
||
access_log /var/log/nginx/access.log json-log; | ||
error_log /var/log/nginx/error.log; | ||
|
||
gzip on; | ||
|
||
include /ssl-config/ssl-config-http.conf; | ||
map $http_x_forwarded_proto $updated_scheme { | ||
default $http_x_forwarded_proto; | ||
'' $scheme; | ||
} | ||
map $http_x_forwarded_host $updated_host { | ||
default $http_x_forwarded_host; | ||
'' $http_host; | ||
} | ||
map $http_upgrade $connection_upgrade { | ||
default upgrade; | ||
'' close; | ||
} | ||
|
||
server { | ||
server_name grafana.*; | ||
|
||
location = /auth { | ||
internal; | ||
{% if deploy %} | ||
proxy_pass https://auth/api/v1alpha/verify_dev_credentials; | ||
{% else %} | ||
proxy_pass https://auth/{{ default_ns.name }}/auth/api/v1alpha/verify_dev_credentials; | ||
{% endif %} | ||
include /ssl-config/ssl-config-proxy.conf; | ||
} | ||
|
||
location = /healthcheck { | ||
return 204; | ||
} | ||
|
||
location / { | ||
auth_request /auth; | ||
|
||
proxy_pass http://127.0.0.1:3000/; | ||
|
||
proxy_set_header Host $http_host; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Host $updated_host; | ||
proxy_set_header X-Forwarded-Proto $updated_scheme; | ||
proxy_set_header X-Real-IP $http_x_real_ip; | ||
|
||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection $connection_upgrade; | ||
} | ||
|
||
error_page 401 = @error401; | ||
|
||
location @error401 { | ||
{% if deploy %} | ||
return 302 https://auth.hail.is/login?next=https://$http_host$request_uri; | ||
{% else %} | ||
return 302 https://internal.hail.is/{{ default_ns.name }}/auth/login?next=https://internal.hail.is/{{ default_ns.name }}/grafana; | ||
{% endif %} | ||
} | ||
|
||
|
||
listen 443 ssl; | ||
listen [::]:443 ssl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,4 +97,4 @@ principals: | |
kind: json | ||
- name: grafana | ||
domain: grafana | ||
kind: json | ||
kind: nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters