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