Skip to content

Commit 4cf79d1

Browse files
authored
Merge pull request #61 from opensafely-core/cleanups2
Fix deploy and more logs tweaks
2 parents 4220dd9 + 0f4d0ff commit 4cf79d1

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

changelogs.opensafely.org.conf.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ server {
1111
limit_except GET { deny all; }
1212
proxy_pass https://changelogs.ubuntu.com;
1313
proxy_redirect default;
14+
# ensure Host header and SNI domain match
15+
proxy_ssl_server_name on;
16+
17+
1418
}
1519
}

docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ services:
22
proxy:
33
# use host for access to host RESOLVER
44
network_mode: host
5+
image: opensafely-proxy
6+
container_name: proxy
57
build:
68
target: opensafely-proxy
79
cache_from: # should speed up the build in CI, where we have a cold cache

ghcr.io.conf.template

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Read-only proxy certain organisation to ghcr.io
1+
# Read-only proxy certain organisations to ghcr.io
22
#
33
# RESOLVER:a DNS resolver for dynamically looking up redirect domains. Defaults to 127.0.0.1
44
# PORT: defaults to 8080, but dokku can override
@@ -18,8 +18,7 @@ proxy_http_version 1.1; # keep alives to upstream
1818

1919
server {
2020

21-
# note: embdatalab domain is for when we are being proxied by cloudflare
22-
server_name docker-proxy.opensafely.org docker-proxy.dokku2.embdatalab.net;
21+
server_name docker-proxy.opensafely.org;
2322
root /var/www/html;
2423
listen ${PORT};
2524

@@ -37,11 +36,10 @@ server {
3736
location = /v2/ {
3837
limit_except GET { deny all; }
3938
proxy_pass https://ghcr.io;
40-
# explicitly change host header to expected host
41-
proxy_set_header Host ghcr.io;
4239
proxy_redirect default;
4340
# ensure Host header and SNI domain match
4441
proxy_ssl_server_name on;
42+
4543
# hide upstream header
4644
proxy_hide_header www-authenticate;
4745
# add our modified header
@@ -52,9 +50,9 @@ server {
5250
location /token {
5351
limit_except GET { deny all; }
5452
proxy_pass https://ghcr.io;
53+
proxy_redirect default;
5554
# ensure Host header and SNI domain match
5655
proxy_ssl_server_name on;
57-
proxy_redirect default;
5856
}
5957

6058
# opensafely images only, and handle redirects
@@ -64,6 +62,7 @@ server {
6462
# ensure Host header and SNI domain match
6563
proxy_ssl_server_name on;
6664
proxy_redirect default;
65+
6766
# ghcr.io redirects to an S3 bucket, which is not accessible from
6867
# backends. So handle redirects to S3 here in the proxy rather than
6968
# passing back to the client
@@ -74,9 +73,9 @@ server {
7473
location @handle_redirect {
7574
# set saves the initial response's Location: header
7675
set $redirect '$upstream_http_location';
77-
# strip the ghcr.io auth or else AWS rejects it, also stops it leaking
76+
# strip the ghcr.io auth or else CDN rejects it, also stops it leaking
7877
proxy_set_header Authorization "";
79-
# proxy the AWS location back to the client
78+
# proxy the CDN location back to the client
8079
proxy_pass $redirect;
8180
# ensure Host header and SNI domain match
8281
proxy_ssl_server_name on;

github.com.conf.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,26 @@ server {
4646
limit_except POST { deny all; }
4747
proxy_pass https://github.com;
4848
proxy_redirect default;
49+
# ensure Host header and SNI domain match
50+
proxy_ssl_server_name on;
4951
}
5052

5153
# allow ssh keys to be retreived for a user
5254
location ~ ^/[^/]+\.keys {
5355
limit_except GET { deny all; }
5456
proxy_pass https://github.com;
5557
proxy_redirect default;
58+
# ensure Host header and SNI domain match
59+
proxy_ssl_server_name on;
5660
}
5761

5862
# allow release artifacts to be downloaded from specified repo only
5963
location ~ ^/opensafely-core/backend-server/releases/download {
6064
limit_except GET { deny all; }
6165
proxy_pass https://github.com;
6266
proxy_redirect default;
67+
# ensure Host header and SNI domain match
68+
proxy_ssl_server_name on;
6369
# `releases/download` redirects to an S3 bucket, which is not accessible from
6470
# backends. So handle redirects to S3 here in the proxy rather than
6571
# passing back to the client
@@ -72,6 +78,8 @@ server {
7278
set $redirect '$upstream_http_location';
7379
# proxy the AWS location back to the client
7480
proxy_pass $redirect;
81+
# ensure Host header and SNI domain match
82+
proxy_ssl_server_name on;
7583
}
7684

7785
location / {

nginx.conf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ http {
1515
include /etc/nginx/mime.types;
1616
default_type application/octet-stream;
1717

18-
log_format main 'ts=$time_iso8601 status=$status req="$request" proxy=$proxy_host '
19-
'ms=$request_time bytes=$bytes_sent '
18+
# custom log format
19+
# - more readable format
20+
# - includes proxy host
21+
# - includes virtual host, because we only have one log stream, and multiple hosts
22+
log_format main 'ts=$time_iso8601 status=$status method=$request_method uri=$host$request_uri proxy=$proxy_host '
23+
'ms=$request_time bytes=$bytes_sent/$request_length '
2024
'ua="$http_user_agent" ip=$remote_addr user=$remote_user';
2125

2226
access_log /var/log/nginx/access.log main;

0 commit comments

Comments
 (0)