apache-custom-slave-list.cfg.in 23.1 KB
Newer Older
1
{% if software_type == slap_software_type %}
2

3
{% set kedifa_updater_mapping = [] %}
4 5
{% set cached_server_dict = {} %}
{% set part_list = [] %}
6 7 8
{% set cache_port = caddy_configuration.get('cache-port') %}
{% set cached_port = caddy_configuration.get('cache-through-port') %}
{% set ssl_cached_port = caddy_configuration.get('ssl-cache-through-port') %}
9 10 11
{% set cache_access = "http://%s:%s" % (local_ipv4, cache_port) %}
{% set ssl_cache_access = "http://%s:%s/HTTPS" % (local_ipv4, cache_port) %}
{% set TRUE_VALUES = ['y', 'yes', '1', 'true'] %}
12
{% set generic_instance_parameter_dict = { 'cache_access': cache_access, 'local_ipv4': local_ipv4, 'http_port': http_port, 'https_port': https_port} %}
13 14 15 16 17
{% set slave_log_dict = {} %}
{% if extra_slave_instance_list %}
{%   set slave_instance_information_list = [] %}
{%   set slave_instance_list = slave_instance_list + json_module.loads(extra_slave_instance_list) %}
{% endif %}
18 19 20 21 22
[jinja2-template-base]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
extra-context =
context =
23
    raw common_profile {{ common_profile }}
24 25 26 27 28 29 30 31 32
    ${:extra-context}

post = {{ frontend_lazy_graceful_reload }} &
frequency = daily
rotatep-num = 30
sharedscripts = true
notifempty = true
create = true

33
{% if master_key_download_url %}
34
{%   do kedifa_updater_mapping.append((master_key_download_url, master_certificate, apache_certificate)) %}
35
{% else %}
36
{%   do kedifa_updater_mapping.append(('notreadyyet', master_certificate, apache_certificate)) %}
37 38 39 40 41 42 43
{% endif %}

{% if slave_kedifa_information %}
{%   set slave_kedifa_information = json_module.loads(slave_kedifa_information) %}
{% else %}
{%   set slave_kedifa_information = {} %}
{% endif %}
44

45 46 47
# empty section if no cached slaves are available
[slave-log-cache-direct-directory-dict]

48
{# Loop thought slave list to set up slaves #}
49
{% for slave_instance in slave_instance_list %}
50 51 52 53 54 55 56 57
{#   Manage ciphers #}
{%   set slave_ciphers = slave_instance.get('ciphers', '').strip().split() %}
{%   if slave_ciphers %}
{%     set slave_cipher_list = ' '.join(slave_ciphers) %}
{%   else %}
{%     set slave_cipher_list = ciphers.strip() %}
{%   endif %}
{%   do slave_instance.__setitem__('cipher_list', slave_cipher_list) %}
58 59
{%   set slave_type = slave_instance.get('type', '') %}
{%   set enable_cache = (('' ~ slave_instance.get('enable_cache', '')).lower() in TRUE_VALUES and slave_type != 'redirect') %}
60
{%   set slave_reference = slave_instance.get('slave_reference') %}
61 62 63 64
{%   set slave_kedifa = slave_kedifa_information.get(slave_reference) %}
{%   if slave_kedifa %}
{%     set key_download_url = slave_kedifa.get('key-download-url') %}
{%   else %}
65
{%     set key_download_url = 'notreadyyet' %}
66
{%   endif %}
67 68 69
{%   set slave_section_title = 'dynamic-template-slave-instance-%s' % slave_reference %}
{%   set slave_parameter_dict = generic_instance_parameter_dict.copy() %}
{%   set slave_publish_dict = {} %}
70
{%   set slave_configuration_section_name = 'slave-instance-%s-configuration' % slave_reference %}
71
{%   set slave_logrotate_section = slave_reference + "-logs" %}
72
{%   set slave_logrotate_cache_direct_section = slave_reference + "-cache-direct-logs" %}
73 74
{%   set slave_password_section = slave_reference + "-password" %}
{%   set slave_ln_section = slave_reference + "-ln" %}
75 76

{#   extend parts #}
77 78
{%   do part_list.extend([slave_ln_section]) %}
{%   do part_list.extend([slave_logrotate_section, slave_section_title]) %}
79

80
{%   set slave_log_folder = '${logrotate-directory:logrotate-backup}/' + slave_reference + "-logs" %}
81
{%   if enable_cache %}
82 83
{%     set slave_log_cache_direct_folder = '${logrotate-directory:logrotate-backup}/' + slave_logrotate_cache_direct_section %}
{%     do part_list.extend([slave_logrotate_cache_direct_section]) %}
84
{%   endif %}
85

86 87
{#   Pass HTTP2 switch #}
{%   do slave_instance.__setitem__('enable_http2_by_default', enable_http2_by_default) %}
88
{%   do slave_instance.__setitem__('global_disable_http2', global_disable_http2) %}
89

90 91 92 93
{#   Pass proxy_try_duration and proxy_try_interval #}
{%   do slave_instance.__setitem__('proxy_try_duration', proxy_try_duration) %}
{%   do slave_instance.__setitem__('proxy_try_interval', proxy_try_interval) %}

94
{#   Set Up log files #}
95 96 97 98
{%   do slave_parameter_dict.__setitem__('access_log', '/'.join([caddy_log_directory, '%s_access_log' % slave_reference])) %}
{%   do slave_parameter_dict.__setitem__('error_log', '/'.join([caddy_log_directory, '%s_error_log' % slave_reference])) %}
{%   do slave_instance.__setitem__('access_log', slave_parameter_dict.get('access_log')) %}
{%   do slave_instance.__setitem__('error_log', slave_parameter_dict.get('error_log')) %}
99 100 101 102 103 104
{%   if enable_cache %}
{%     do slave_parameter_dict.__setitem__('access_log_cache_direct', '/'.join([caddy_log_cache_direct_directory, '%s_access_log' % slave_reference])) %}
{%     do slave_parameter_dict.__setitem__('error_log_cache_direct', '/'.join([caddy_log_cache_direct_directory, '%s_error_log' % slave_reference])) %}
{%     do slave_instance.__setitem__('access_log_cache_direct', slave_parameter_dict.get('access_log_cache_direct')) %}
{%     do slave_instance.__setitem__('error_log_cache_direct', slave_parameter_dict.get('error_log_cache_direct')) %}
{%   endif %}
105 106 107 108

{#   Add slave log directory to the slave log access dict #}
{%   do slave_log_dict.__setitem__(slave_reference, slave_log_folder) %}

109
{%   set slave_log_access_url = 'https://' + slave_reference.lower() + ':${'+ slave_password_section +':passwd}@[' + frontend_configuration.get('caddy-ipv6') + ']:' + frontend_configuration.get('caddy-https-port') + '/' + slave_reference.lower() + '/' %}
110 111 112 113 114
{%   do slave_publish_dict.__setitem__('log-access', slave_log_access_url) %}
{%   do slave_publish_dict.__setitem__('slave-reference', slave_reference) %}
{%   do slave_publish_dict.__setitem__('public-ipv4', public_ipv4) %}

{# Set slave domain if none was defined #}
115 116
{%   if slave_instance.get('custom_domain', None) == None %}
{%     set domain_prefix = slave_instance.get('slave_reference').replace("-", "").replace("_", "").lower() %}
117
{%     do slave_instance.__setitem__('custom_domain', "%s.%s" % (domain_prefix, slapparameter_dict.get('domain'))) %}
118 119 120 121
{%   endif %}

{%   if enable_cache and 'url' in slave_instance %}
{%     if 'domain' in slave_instance %}
122 123 124
{%       if not slave_instance.get('custom_domain') %}
{%         do slave_instance.__setitem__('custom_domain', slave_instance.get('domain')) %}
{%       endif %}
125 126 127 128 129 130 131
{%     endif %}
{%     do slave_instance.__setitem__('backend_url', slave_instance.get('url')) %}
{%     do slave_instance.__setitem__('https_backend_url', slave_instance.get('https-url', slave_instance.get('url'))) %}
{%     do slave_instance.__setitem__('url', cache_access) %}
{%     do slave_instance.__setitem__('https-url', ssl_cache_access) %}
{%     do cached_server_dict.__setitem__(slave_reference, slave_configuration_section_name) %}
{%   endif %}
132

133 134
{# BBB: apache_custom_https and apache_custom_http #}
{%   if not slave_instance.has_key('caddy_custom_http') and not slave_instance.has_key('caddy_custom_https') and not slave_instance.has_key('apache_custom_http') and not slave_instance.has_key('apache_custom_https') %}
135 136 137 138 139
{%     do slave_publish_dict.__setitem__('domain', slave_instance.get('custom_domain')) %}
{%     do slave_publish_dict.__setitem__('url', "http://%s" % slave_instance.get('custom_domain')) %}
{%     do slave_publish_dict.__setitem__('site_url', "http://%s" % slave_instance.get('custom_domain')) %}
{%     do slave_publish_dict.__setitem__('secure_access', 'https://%s' % slave_instance.get('custom_domain')) %}
{%   endif %}
140

141
[slave-log-directory-dict]
142 143
{{slave_reference}} = {{ slave_log_folder }}

144 145 146 147
{%   if enable_cache %}
[slave-log-cache-direct-directory-dict]
{{slave_reference}}_cache_direct = {{ slave_log_cache_direct_folder }}
{%   endif %}
148

149 150 151
[slave-password]
{{ slave_reference }} = {{ '${' + slave_password_section + ':passwd}' }}

152 153
{# Set slave logrotate entry #}
[{{slave_logrotate_section}}]
154
<= logrotate-entry-base
155 156 157
name = ${:_buildout_section_name_}
log = {{slave_parameter_dict.get('access_log')}} {{slave_parameter_dict.get('error_log')}}
backup = {{ slave_log_folder }} 
158
{%    if enable_cache %}
159
[{{slave_logrotate_cache_direct_section}}]
160 161 162 163 164
<= logrotate-entry-base
name = ${:_buildout_section_name_}
log = {{slave_parameter_dict.get('access_log_cache_direct')}} {{slave_parameter_dict.get('error_log_cache_direct')}}
backup = {{ slave_log_cache_direct_folder }}
{%    endif %}
165 166 167 168 169

{# integrate current logs inside #}
[{{slave_ln_section}}]
recipe = plone.recipe.command
stop-on-error = false
170
command = ln -s {{slave_parameter_dict.get('error_log')}} {{ slave_log_folder }}/error.log && ln -s {{slave_parameter_dict.get('access_log')}} {{ slave_log_folder }}/access.log
171 172 173 174

{# Set password for slave #}
[{{slave_password_section}}]
recipe = slapos.cookbook:generate.password
175
storage-path = {{caddy_configuration_directory}}/.{{slave_reference}}.passwd
176 177 178 179
bytes = 8

{# ################################################## #}
{# Set Slave Certificates if needed                   #}
180 181 182
{# Set certificate key for custom configuration       #}
{% set cert_name = slave_reference.replace('-','.') + '.pem' %}
{% set certificate = '%s/%s' % (autocert, cert_name) %}
183
{% do slave_parameter_dict.__setitem__('certificate', certificate )%}
184

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
{# Set ssl certificates for each slave #}
{%   for cert_name in ('ssl_csr', 'ssl_proxy_ca_crt')%}
{%     if cert_name in slave_instance %}
{%       set cert_title = '%s-%s' % (slave_reference, cert_name.replace('ssl_', '')) %}
{%       set cert_file = '/'.join([custom_ssl_directory, cert_title.replace('-','.')]) %}
{%       do part_list.append(cert_title) %}
{%       do slave_parameter_dict.__setitem__(cert_name, cert_file) %}
{%       do slave_instance.__setitem__('path_to_' + cert_name, cert_file) %}
{# Store certificates on fs #}
[{{ cert_title }}]
< = jinja2-template-base
template = {{ empty_template }}
rendered = {{ cert_file }}
extra-context =
    key content {{ cert_title + '-config:value' }}
200
# BBB: SlapOS Master non-zero knowledge BEGIN
201 202 203 204 205 206 207 208 209
# Store certificate in config
[{{ cert_title + '-config' }}]
value = {{ dumps(slave_instance.get(cert_name)) }}
{%     endif %}
{%   endfor %}

{#-   Set Up Certs #}
{%   if 'ssl_key' in slave_instance and 'ssl_crt' in slave_instance %}
{%     set cert_title = '%s-crt' % (slave_reference) %}
210
{%     set cert_file = '/'.join([bbb_ssl_directory, cert_title.replace('-','.')]) %}
211
{%     do kedifa_updater_mapping.append((key_download_url, certificate, cert_file)) %}
212 213 214 215 216 217 218
{%     do part_list.append(cert_title) %}
{%     do slave_parameter_dict.__setitem__("ssl_crt", cert_file) %}

[{{cert_title}}]
< = jinja2-template-base
template = {{ empty_template }}
rendered = {{ cert_file }}
219
cert-content = {{ dumps(slave_instance.get('ssl_crt') + '\n' + slave_instance.get('ssl_ca_crt', '') + '\n' + slave_instance.get('ssl_key')) }}
220 221
extra-context =
    key content :cert-content
222 223 224
{%   else %}
{%     do kedifa_updater_mapping.append((key_download_url, certificate, master_certificate)) %}
{%   endif %}
225 226
# BBB: SlapOS Master non-zero knowledge END

227 228 229
{# ########################################## #}
{# Set Slave Configuration                    #}
[{{ slave_configuration_section_name }}]
230
certificate = {{ certificate }}
231 232 233 234 235
https_port = {{ dumps('' ~ https_port) }}
http_port = {{ dumps('' ~ http_port) }}
local_ipv4 = {{ dumps('' ~ local_ipv4) }}
cached_port = {{ dumps('' ~ cached_port) }}
ssl_cached_port = {{ ('' ~ ssl_cached_port) }}
236
request_timeout = {{ ('' ~ request_timeout) }}
237
{# BBB: apache_custom_https and apache_custom_http #}
238 239 240 241
{%     set caddy_custom_http_template = slave_instance.pop('caddy_custom_http', slave_instance.pop('apache_custom_http', '')) %}
{%     set caddy_custom_https_template = slave_instance.pop('caddy_custom_https', slave_instance.pop('apache_custom_https', '')) %}
{%     if caddy_custom_http_template is not none %}
{%       set caddy_custom_http = ('' ~ caddy_custom_http_template) % slave_parameter_dict %}
242
caddy_custom_http = {{ dumps(caddy_custom_http) }}
243 244 245 246 247
{%     else %}
{%       set caddy_custom_http = None %}
{%     endif %}
{%     if caddy_custom_https_template is not none %}
{%       set caddy_custom_https = ('' ~ caddy_custom_https_template) % slave_parameter_dict %}
248
caddy_custom_https = {{ dumps(caddy_custom_https) }}
249 250 251
{%     else %}
{%       set caddy_custom_https = None %}
{%     endif %}
252
{{ '\n' }}
253
{%     for key, value in slave_instance.iteritems() %}
254 255 256
{%       if value is not none %}
{{ key }} = {{ dumps('' ~ value) }}
{%       endif %}
257 258 259 260
{%     endfor %}

[{{ slave_section_title }}]
< = jinja2-template-base
261
rendered = {{ caddy_configuration_directory }}/${:filename}
262

263
{%   if caddy_custom_http or caddy_custom_https %}
264
template = {{ template_custom_slave_configuration }}
265 266
extra-context =
    section slave_parameter {{ slave_configuration_section_name }}
267 268
{%   else %}
template = {{ template_default_slave_configuration }}
269 270 271
extra-context =
    section slave_parameter {{ slave_configuration_section_name }}
    import urllib_module urllib
272 273 274 275 276 277 278 279 280
{%   endif %}

filename = {{ '%s.conf' % slave_reference }}
{{ '\n' }}


{%   set monitor_ipv6_test = slave_instance.get('monitor-ipv6-test', '') %}
{%   if monitor_ipv6_test %}
{%     set monitor_ipv6_section_title = 'check-%s-ipv6-packet-list-test' % slave_instance.get('slave_reference') %}
281
{%     do part_list.append(monitor_ipv6_section_title) %}
282
[{{ monitor_ipv6_section_title }}]
283
<= monitor-promise-base
284 285 286 287 288
module = check_icmp_packet_lost
name = {{ monitor_ipv6_section_title }}.py
config-address = {{ dumps(monitor_ipv6_test) }}
# promise frequency in minutes (2 times/day)
config-frequency = 720
289 290 291 292 293
{%   endif %}

{%   set monitor_ipv4_test = slave_instance.get('monitor-ipv4-test', '') %}
{%   if monitor_ipv4_test %}
{%     set monitor_ipv4_section_title = 'check-%s-ipv4-packet-list-test' % slave_instance.get('slave_reference') %}
294
{%     do part_list.append(monitor_ipv4_section_title) %}
295
[{{ monitor_ipv4_section_title }}]
296
<= monitor-promise-base
297 298 299 300 301 302
module = check_icmp_packet_lost
name = {{ monitor_ipv4_section_title }}.py
config-address = {{ dumps(monitor_ipv4_test) }}
config-ipv4 = true
# promise frequency in minutes (2 times/day)
config-frequency = 720
303 304
{%   endif %}

305
{%   set re6st_optimal_test = '' ~ slave_instance.get('re6st-optimal-test', '') %}
306 307 308
{%   set re6st_ipv6 = None %}
{%   set re6st_ipv4 = None %}
{%   if ',' in re6st_optimal_test %}
309
{%     set re6st_ipv6, re6st_ipv4 = re6st_optimal_test.split(",") %}
310 311
{%   endif %}
{%   if re6st_ipv6 and re6st_ipv4 %}
312
{%     set re6st_optimal_test_section_title = 'check-%s-re6st-optimal-test' % slave_instance.get('slave_reference') %}
313
{%     do part_list.append(re6st_optimal_test_section_title) %}
314

315
[{{ re6st_optimal_test_section_title }}]
316
<= monitor-promise-base
317 318 319 320 321 322
module = check_re6st_optimal_status
name = {{ re6st_optimal_test_section_title }}.py
config-ipv4 = {{ dumps(re6st_ipv4) }}
config-ipv6 = {{ dumps(re6st_ipv6) }}
# promise frequency in minutes (2 times/day)
config-frequency = 720
323 324 325 326 327
{%   endif %}


{# ###############################  #}
{# Publish Slave Information        #}
328 329 330
{%   if not extra_slave_instance_list %}
{%     set publish_section_title = 'publish-%s-connection-information' % slave_instance.get('slave_reference') %}
{%     do part_list.append(publish_section_title) %}
331 332 333 334 335
[{{ publish_section_title }}]
recipe = slapos.cookbook:publish
{%     for key, value in slave_publish_dict.iteritems() %}
{{ key }} = {{ value }}
{%     endfor %}
336 337 338
{%   else %}
{%     do slave_instance_information_list.append(slave_publish_dict) %}
{%   endif %}
339 340

{# End of the main for loop#}
341
{% endfor %}
342

343 344 345 346 347 348
[slave-log-directories]
<= slave-log-directory-dict
recipe = slapos.cookbook:mkdirectory

{% do part_list.append('slave-log-directories') %}

349 350 351 352 353 354
[slave-log-cache-direct-directories]
<= slave-log-cache-direct-directory-dict
recipe = slapos.cookbook:mkdirectory

{% do part_list.append('slave-log-cache-direct-directories') %}

355 356 357 358 359 360 361 362 363 364 365
[caddy-log-access]
< = jinja2-template-base
template = {{frontend_configuration.get('template-log-access')}}
rendered = {{frontend_configuration.get('log-access-configuration')}}
extra-context =
    section slave_log_directory slave-log-directory-dict
    section slave_password slave-password
    section parameter_dict caddy-log-access-parameters

{% do part_list.append('caddy-log-access') %}

366 367 368 369 370
###############################################
### Prepare virtualhost for slaves using cache

{% for slave_reference, slave_configuration_section_name in cached_server_dict.iteritems() %}
{%   set cached_slave_configuration_section_title = '%s-cached-virtualhost' % slave_reference %}
371
{%   do part_list.append(cached_slave_configuration_section_title) %}
372 373 374 375
[{{ cached_slave_configuration_section_title }}]
< = jinja2-template-base
template = {{ template_cached_slave_configuration }}
filename = {{ '%s.conf' % slave_reference }}
376
rendered = {{ caddy_cached_configuration_directory }}/${:filename}
377 378 379 380 381 382
extensions = jinja2.ext.do
extra-context =
    section slave_parameter {{ slave_configuration_section_name }}
{{ '\n' }}
{% endfor %}

383 384 385 386 387 388 389
{#- Define IPv6 to IPV4 tunneling #}
[tunnel-6to4-base]
recipe = slapos.cookbook:wrapper
ipv4 = ${slap-network-information:local-ipv4}
ipv6 = ${slap-network-information:global-ipv6}
wrapper-path = {{ service_directory}}/6tunnel-${:ipv6-port}
command-line = {{ sixtunnel_executable }} -6 -4 -d -l ${:ipv6} ${:ipv6-port} ${:ipv4} ${:ipv4-port}
390
hash-existing-files = ${buildout:directory}/software_release/buildout.cfg
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411

[tunnel-6to4-base-http_port]
<= tunnel-6to4-base
ipv4-port = {{ http_port }}
ipv6-port = {{ http_port }}

[tunnel-6to4-base-https_port]
<= tunnel-6to4-base
ipv4-port = {{ https_port }}
ipv6-port = {{ https_port }}

[tunnel-6to4-base-cached_port]
<= tunnel-6to4-base
ipv4-port = {{ cached_port }}
ipv6-port = {{ cached_port }}

[tunnel-6to4-base-ssl_cached_port]
<= tunnel-6to4-base
ipv4-port = {{ ssl_cached_port }}
ipv6-port = {{ ssl_cached_port }}

412
{# Define log access #}
413 414 415 416 417 418 419
[caddy-log-access-parameters]
caddy_log_directory = {{ dumps(caddy_log_directory) }}
caddy_configuration_directory = {{ dumps(caddy_configuration_directory) }}
local_ipv4 = {{ dumps(local_ipv4) }}
global_ipv6 = {{ dumps(global_ipv6) }}
https_port = {{ dumps(https_port) }}
http_port = {{ dumps(http_port) }}
420
ip_access_certificate = {{ frontend_configuration.get('ip-access-certificate') }}
421 422 423 424
access_log = {{ dumps(access_log) }}
error_log = {{ dumps(error_log) }}
not_found_file = {{ dumps(not_found_file) }}

425
[caddy-log-access]
426 427 428 429
< = jinja2-template-base
template = {{frontend_configuration.get('template-log-access')}}
rendered = {{frontend_configuration.get('log-access-configuration')}}
extra-context =
430 431
    section slave_log_directory slave-log-directory-dict
    section slave_password slave-password
432
    section parameter_dict caddy-log-access-parameters
433

434

435
{# Publish information for the instance #}
436
[publish-caddy-information]
437
recipe = slapos.cookbook:publish.serialised
438 439
public-ipv4 = {{ public_ipv4 }}
private-ipv4 = {{ local_ipv4 }}
440
{% if extra_slave_instance_list %}
441 442
{# sort_keys are important in order to avoid shuffling parameters on each run #}
slave-instance-information-list = {{ json_module.dumps(slave_instance_information_list, sort_keys=True) }}
443
{% endif %}
444
monitor-base-url = {{ monitor_base_url }}
445 446
csr_id-url = https://[${expose-csr_id-configuration:ip}]:${expose-csr_id-configuration:port}/csr_id.txt
csr_id-certificate = ${get-csr_id-certificate:certificate}
447

448 449 450 451 452 453
[kedifa-updater]
recipe = slapos.cookbook:wrapper
command-line = {{ kedifa_updater }}
  --server-ca-certificate {{ kedifa_caucase_ca_certificate }}
  --identity {{ kedifa_login_certificate }}
  --master-certificate {{ master_certificate }}
454
  --on-update "{{ frontend_graceful_reload }}"
455 456 457 458
  ${kedifa-updater-mapping:file}
  {{ kedifa_updater_state_file }}

wrapper-path = {{ service_directory }}/kedifa-updater
459
hash-existing-files = ${buildout:directory}/software_release/buildout.cfg
460

461 462
[kedifa-updater-run]
recipe = plone.recipe.command
463 464
stop-on-error = True
command = {{ kedifa_updater }} --prepare-only ${kedifa-updater-mapping:file} --on-update "{{ frontend_graceful_reload }}"
465 466
update-command = ${:command}

467 468 469 470 471
[kedifa-updater-mapping]
recipe = slapos.recipe.template:jinja2
file = {{ kedifa_updater_mapping_file }}
template = inline:
{% for mapping in kedifa_updater_mapping %}
472
  {{ mapping[0] }} {{ mapping[1] }} {{ mapping[2] }}
473 474 475 476
{% endfor %}

rendered = ${:file}

477 478 479 480 481 482 483
[caddy-log-access-header]
# Caddy refuse to start if an `import`ed file is empty, so we prepend a header
# so that the file is never empty.
< = jinja2-template-base
template = inline: # This file contain directives to serve directories with log files
rendered = {{frontend_configuration.get('log-access-configuration')}}

484
[buildout]
485 486 487
extends =
  {{ common_profile }}
  {{ logrotate_base_instance }} 
488
  {{ monitor_template }}
489

490
parts +=
491
    kedifa-updater
492
    kedifa-updater-run
493
    caddy-log-access-header
494
{% for part in part_list %}
495 496
{{ '    %s' % part }}
{% endfor %}
497
    publish-caddy-information
498 499 500 501
    tunnel-6to4-base-http_port
    tunnel-6to4-base-https_port
    tunnel-6to4-base-cached_port
    tunnel-6to4-base-ssl_cached_port
502
    expose-csr_id
503
    promise-expose-csr_id-ip-port
504 505 506

cache-access = {{ cache_access }}

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
[store-csr_id]
recipe = plone.recipe.command

csr_id_path = {{ directory_csr_id }}/csr_id.txt
csr_work_path = {{ directory_tmp }}/${:_buildout_section_name_}

stop-on-error = False
update-command = ${:command}
command =
  {{ bin_directory }}/caucase \
    --ca-url {{ caucase_url }} \
    --ca-crt {{ csr_cas_ca_certificate }} \
    --crl {{ csr_crl }} \
    --mode service \
    --send-csr {{ csr_id_csr }} > ${:csr_work_path} && \
  cut -d ' ' -f 1 ${:csr_work_path} > ${:csr_id_path}

[certificate-csr_id]
recipe = plone.recipe.command
certificate = {{ directory_caddy_csr_id }}/certificate.pem
key = {{ directory_caddy_csr_id }}/key.pem

stop-on-error = True
update-command = ${:command}
command =
  if ! [ -f ${:key} ] && ! [ -f ${:certificate} ] ; then
    openssl req -new -newkey rsa:2048 -sha256 -subj \
      "/O={{ certificate_organization }}/OU={{ certificate_organizational_unit }}/CN=${slap-network-information:global-ipv6}" \
      -days 5 -nodes -x509 -keyout ${:key} -out ${:certificate}
  fi

[expose-csr_id-configuration]
ip = ${slap-network-information:global-ipv6}
port = 17001
key = ${certificate-csr_id:key}
certificate = ${certificate-csr_id:certificate}
error-log = {{ directory_caddy_csr_id_log }}/expose-csr_id.log

[expose-csr_id-template]
recipe = slapos.recipe.template:jinja2
template = inline:
  https://:${expose-csr_id-configuration:port}/ {
    bind ${expose-csr_id-configuration:ip}
    tls ${expose-csr_id-configuration:certificate} ${expose-csr_id-configuration:key}
    log ${expose-csr_id-configuration:error-log}
  }

rendered = {{ directory_caddy_csr_id }}/Caddyfile

556
[promise-expose-csr_id-ip-port]
557
<= monitor-promise-base
558 559 560 561 562
module = check_port_listening
name = expose-csr_id-ip-port-listening.py
config-hostname = ${expose-csr_id-configuration:ip}
config-port = ${expose-csr_id-configuration:port}

563 564 565 566 567 568 569 570
[expose-csr_id]
depends = ${store-csr_id:command}
recipe = slapos.cookbook:wrapper
command-line = {{ caddy_executable }}
  -conf ${expose-csr_id-template:rendered}
  -log ${expose-csr_id-configuration:error-log}
  -http2=true
  -disable-http-challenge
571
  -disable-tls-alpn-challenge
572 573 574
  -root {{ directory_csr_id }}

wrapper-path = {{ service_directory }}/expose-csr_id
575
hash-existing-files = ${buildout:directory}/software_release/buildout.cfg
576 577 578 579 580 581

[get-csr_id-certificate]
recipe = collective.recipe.shelloutput
commands =
  certificate = cat ${certificate-csr_id:certificate}

582
{% endif %}