Skip to content

Commit a2992ae

Browse files
committed
Use OpenResty instead of plain nginx to support OpenID Connect authorization.
1 parent 102571f commit a2992ae

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{% if openidc_enabled -%}
2+
access_by_lua_block {
3+
local openidc = require("resty.openidc")
4+
local opts = {
5+
redirect_uri = "{{- openidc_redirect_uri -}}",
6+
discovery = "{{- openidc_discovery -}}",
7+
token_endpoint_auth_method = "{{- openidc_auth_method -}}",
8+
client_id = "{{- openidc_client_id -}}",
9+
client_secret = "{{- openidc_client_secret -}}",
10+
scope = "openid email profile"
11+
}
12+
13+
local res, err = openidc.authenticate(opts)
14+
15+
if err then
16+
ngx.status = 500
17+
ngx.say(err)
18+
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
19+
end
20+
21+
22+
ngx.req.set_header("X-OIDC-SUB", res.id_token.sub)
23+
ngx.req.set_header("X-OIDC-EMAIL", res.id_token.email)
24+
ngx.req.set_header("X-OIDC-NAME", res.id_token.name)
25+
}
26+
{% endif %}

backend/templates/proxy_host.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ server {
3939

4040
{% endif %}
4141

42+
{% include "_openid_connect.conf" %}
43+
4244
{% include "_forced_ssl.conf" %}
4345
{% include "_hsts.conf" %}
4446

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ WORKDIR /app
3838
RUN yarn install
3939

4040
# Remove frontend service not required for prod, dev nginx config as well
41-
RUN rm -rf /etc/services.d/frontend RUN rm -f /etc/nginx/conf.d/dev.conf
41+
RUN rm -rf /etc/services.d/frontend && rm -f /etc/nginx/conf.d/dev.conf
4242

4343
VOLUME [ "/data", "/etc/letsencrypt" ]
4444
CMD [ "/init" ]

docker/rootfs/etc/nginx/nginx.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ http {
4343
proxy_cache_path /var/lib/nginx/cache/public levels=1:2 keys_zone=public-cache:30m max_size=192m;
4444
proxy_cache_path /var/lib/nginx/cache/private levels=1:2 keys_zone=private-cache:5m max_size=1024m;
4545

46+
lua_package_path '~/lua/?.lua;;';
47+
48+
lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
49+
lua_ssl_verify_depth 5;
50+
51+
# cache for discovery metadata documents
52+
lua_shared_dict discovery 1m;
53+
# cache for JWKs
54+
lua_shared_dict jwks 1m;
55+
4656
log_format proxy '[$time_local] $upstream_cache_status $upstream_status $status - $request_method $scheme $host "$request_uri" [Client $remote_addr] [Length $body_bytes_sent] [Gzip $gzip_ratio] [Sent-to $server] "$http_user_agent" "$http_referer"';
4757
log_format standard '[$time_local] $status - $request_method $scheme $host "$request_uri" [Client $remote_addr] [Length $body_bytes_sent] [Gzip $gzip_ratio] "$http_user_agent" "$http_referer"';
4858

0 commit comments

Comments
 (0)