Skip to content

Commit 496b1b0

Browse files
committed
Login for kibana and token passthrough
1 parent ba75653 commit 496b1b0

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed

docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: '2'
33
volumes:
44
elasticsearch_data: {}
55
postgres_data: {}
6+
nginx_tls: {}
67

78
services:
89
postgres:
@@ -35,3 +36,14 @@ services:
3536
dockerfile: Dockerfile
3637
depends_on:
3738
- elasticsearch
39+
40+
nginx:
41+
build:
42+
context: nginx
43+
dockerfile: Dockerfile
44+
depends_on:
45+
- kibana
46+
volumes:
47+
- nginx_tls:/etc/nginx/external/
48+
ports:
49+
- "127.0.0.1:443:443"

kibana/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM kibana:5.5.2
2+
3+
RUN sh -c 'echo elasticsearch.username: "gatekeeper" >> /etc/kibana/kibana.yml'
4+
RUN sh -c 'echo elasticsearch.password: "keymaster" >> /etc/kibana/kibana.yml'
5+
RUN sh -c 'echo elasticsearch.requestHeadersWhitelist: [cookie] >> /etc/kibana/kibana.yml'

nginx/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM openresty/openresty:alpine AS builder
2+
RUN apk --no-cache add curl perl
3+
RUN /usr/local/openresty/bin/opm get tinyauth/lua-resty-tinyauth
4+
5+
FROM openresty/openresty:alpine
6+
7+
RUN apk --no-cache add openssl
8+
9+
COPY --from=builder /usr/local/openresty/site /usr/local/openresty/site
10+
11+
COPY nginx.conf /etc/nginx/nginx.conf
12+
COPY entrypoint.sh /docker-entrypoint
13+
COPY *.js /srv/static/
14+
15+
ENTRYPOINT ["/docker-entrypoint"]
16+
CMD ["nginx", "-c", "/etc/nginx/nginx.conf"]

nginx/entrypoint.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
if [ -z ${DH_SIZE+x} ]
4+
then
5+
>&2 echo ">> no \$DH_SIZE specified using default"
6+
DH_SIZE="2048"
7+
fi
8+
9+
DH="/etc/nginx/external/dh.pem"
10+
11+
if [ ! -e "$DH" ]
12+
then
13+
echo ">> generating $DH with size: $DH_SIZE"
14+
openssl dhparam -out "$DH" $DH_SIZE
15+
fi
16+
17+
if [ ! -e "/etc/nginx/external/cert.pem" ] || [ ! -e "/etc/nginx/external/key.pem" ]
18+
then
19+
echo ">> generating self signed cert"
20+
openssl req -x509 -newkey rsa:4096 \
21+
-subj "/C=XX/ST=XXXX/L=XXXX/O=XXXX/CN=localhost" \
22+
-keyout "/etc/nginx/external/key.pem" \
23+
-out "/etc/nginx/external/cert.pem" \
24+
-days 3650 -nodes -sha256
25+
fi
26+
27+
echo "$@"
28+
exec "$@"

nginx/main.b9228724.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nginx/nginx.conf

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
worker_processes 1;
2+
error_log /dev/stdout warn;
3+
daemon off;
4+
pid /var/run/nginx.pid;
5+
6+
events {
7+
worker_connections 1024;
8+
}
9+
10+
http {
11+
include /usr/local/openresty/nginx/conf/mime.types;
12+
default_type application/octet-stream;
13+
14+
# Let nginx be able to resolve Docker containers
15+
resolver 127.0.0.11;
16+
17+
access_log /dev/stdout;
18+
19+
upstream kibana {
20+
server kibana:5601;
21+
}
22+
23+
server {
24+
listen 443 default_server;
25+
26+
ssl on;
27+
ssl_certificate external/cert.pem;
28+
ssl_certificate_key external/key.pem;
29+
30+
charset utf-8;
31+
32+
location /login/static/ {
33+
alias /srv/static/;
34+
expires 365;
35+
}
36+
37+
location = /login {
38+
content_by_lua_block {
39+
local tinyauth = require('resty/tinyauth');
40+
local client = tinyauth.new("http://tinyauth:5000/api/v1/", "gatekeeper", "keymaster")
41+
client:handle_login('b9228724')
42+
}
43+
}
44+
45+
location / {
46+
access_by_lua_block {
47+
local tinyauth = require('resty/tinyauth');
48+
local client = tinyauth.new("http://tinyauth:5000/api/v1/", "gatekeeper", "keymaster")
49+
50+
local auth = client:authorize_token_for_action("AccessKibana")
51+
52+
if not auth['Authorized'] then
53+
ngx.redirect('/login')
54+
return
55+
end
56+
57+
if auth['Identity'] then
58+
ngx.req.set_header('X-User', auth['Identity'])
59+
end
60+
}
61+
62+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
63+
proxy_set_header Host $http_host;
64+
proxy_redirect off;
65+
proxy_pass http://kibana;
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)