21316: Merge commit '1416f698b72de4b09350d9c2fb25c1405c3247bc' into 21316-left-panel...
[arvados.git] / tools / salt-install / config_examples / multi_host / aws / pillars / nginx_balancer_configuration.sls
1 ---
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 {%- import_yaml "ssl_key_encrypted.sls" as ssl_key_encrypted_pillar %}
7 {%- set domain = "__DOMAIN__" %}
8 {%- set balancer_backends = "__CONTROLLER_NODES__".split(",") %}
9 {%- set controller_nr = balancer_backends|length %}
10 {%- set disabled_controller = "__DISABLED_CONTROLLER__" %}
11 {%- set max_reqs = ("__CONTROLLER_MAX_QUEUED_REQUESTS__" or 128)|int %}
12
13 ### NGINX
14 nginx:
15   ### SERVER
16   server:
17     config:
18       {%- if max_reqs != "" %}
19       worker_rlimit_nofile: {{ (max_reqs|int * 3 * controller_nr)|round|int }}
20       events:
21         worker_connections: {{ (max_reqs|int * 3 * controller_nr)|round|int }}
22       {%- else %}
23       worker_rlimit_nofile: 4096
24       events:
25         worker_connections: 1024
26       {%- endif %}
27       ### STREAMS
28       http:
29         'geo $external_client':
30           default: 1
31           '127.0.0.0/8': 0
32           '__CLUSTER_INT_CIDR__': 0
33         upstream controller_upstream:
34         {%- for backend in balancer_backends %}
35           {%- if disabled_controller == "" or not backend.startswith(disabled_controller) %}
36           'server {{ backend }}:80': ''
37           {%- else %}
38           'server {{ backend }}:80 down': ''
39           {% endif %}
40         {%- endfor %}
41
42   ### SNIPPETS
43   snippets:
44     # Based on https://ssl-config.mozilla.org/#server=nginx&version=1.14.2&config=intermediate&openssl=1.1.1d&guideline=5.4
45     ssl_hardening_default.conf:
46       - ssl_session_timeout: 1d
47       - ssl_session_cache: 'shared:arvadosSSL:10m'
48       - ssl_session_tickets: 'off'
49
50       # intermediate configuration
51       - ssl_protocols: TLSv1.2 TLSv1.3
52       - ssl_ciphers: ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
53       - ssl_prefer_server_ciphers: 'off'
54
55       # HSTS (ngx_http_headers_module is required) (63072000 seconds)
56       - add_header: 'Strict-Transport-Security "max-age=63072000" always'
57
58       # OCSP stapling
59       - ssl_stapling: 'on'
60       - ssl_stapling_verify: 'on'
61
62       # verify chain of trust of OCSP response using Root CA and Intermediate certs
63       # - ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates
64
65       # curl https://ssl-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
66       # - ssl_dhparam: /path/to/dhparam
67
68       # replace with the IP address of your resolver
69       # - resolver: 127.0.0.1
70
71   ### SITES
72   servers:
73     managed:
74       # Remove default webserver
75       default:
76         enabled: false
77       ### DEFAULT
78       arvados_balancer_default.conf:
79         enabled: true
80         overwrite: true
81         config:
82           - server:
83             - server_name: {{ domain }}
84             - listen:
85               - 80 default
86             - location /.well-known:
87               - root: /var/www
88             - location /:
89               - return: '301 https://$host$request_uri'
90
91       arvados_balancer_ssl.conf:
92         enabled: true
93         overwrite: true
94         requires:
95           __CERT_REQUIRES__
96         config:
97           - server:
98             - server_name: {{ domain }}
99             - listen:
100               - __CONTROLLER_EXT_SSL_PORT__ http2 ssl
101             - index: index.html index.htm
102             - location /:
103               - proxy_pass: 'http://controller_upstream'
104               - proxy_read_timeout: 300
105               - proxy_connect_timeout: 90
106               - proxy_redirect: 'off'
107               - proxy_set_header: X-Forwarded-Proto https
108               - proxy_set_header: 'Host $http_host'
109               - proxy_set_header: 'X-Real-IP $remote_addr'
110               - proxy_set_header: 'X-Forwarded-For $proxy_add_x_forwarded_for'
111               - proxy_set_header: 'X-External-Client $external_client'
112               - proxy_set_header: 'Upgrade $http_upgrade'
113               - proxy_set_header: 'Connection "upgrade"'
114               - proxy_max_temp_file_size: 0
115               - proxy_request_buffering: 'off'
116               - proxy_buffering: 'off'
117               - proxy_http_version: '1.1'
118             - include: snippets/ssl_hardening_default.conf
119             - ssl_certificate: __CERT_PEM__
120             - ssl_certificate_key: __CERT_KEY__
121             {%- if ssl_key_encrypted_pillar.ssl_key_encrypted.enabled %}
122             - ssl_password_file: {{ '/run/arvados/' | path_join(ssl_key_encrypted_pillar.ssl_key_encrypted.privkey_password_filename) }}
123             {%- endif %}
124             - access_log: /var/log/nginx/{{ domain }}.access.log combined
125             - error_log: /var/log/nginx/{{ domain }}.error.log
126             - client_max_body_size: 128m