instance-caucase.cfg.jinja2.in 8.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
{% set part_list = [] -%}
{% set ipv6 = (ipv6 | list)[0] -%}
{% set default_subject = '/C=FR/O=Company/CN=SlapOS Certificate Authority/emailAddress=xx@example.com' -%}
{% if slapparameter_dict is not defined -%}
{% set slapparameter_dict = {} -%}
{% endif -%}

[ca-parameters]
server-port = {{ slapparameter_dict.get('server-port', 8009) }}
server-https-port = {{ slapparameter_dict.get('server-https-port', 8010) }}
ipv6 = {{ ipv6 }}
12 13
# Overrite this to set frontend or DNS URL (URL is used as CRL distribution point)
# Please set http not HTTPS scheme
14 15 16 17 18 19 20 21 22 23 24 25 26
crl-external-url = {{ slapparameter_dict.get('external-url', 'http://[${:ipv6}]:${:server-port}') }}
# /CN=XXX is required and should be unique
ca-subject = {{ slapparameter_dict.get('ca-subject', default_subject) }}
# Number of pending csr to accept
max-request-amount = {{ slapparameter_dict.get('max-request-amount', 10) }}
# one year (in seconds)
crt-life-time = {{ slapparameter_dict.get('crt-life-time', 31536000) }}
# crl-life-period correspond to about one week
crl-life-period = {{ slapparameter_dict.get('crl-life-period', 0.02) }}
# ca-life-period = ca-life-period * crt-life-time
ca-life-period = {{ slapparameter_dict.get('ca-life-period', 10) }}
# time before clean certificate on CA: 60*24*60*60
crt-keep-time = {{ slapparameter_dict.get('crt-keep-time', 5184000) }}
27 28 29 30 31 32
# number of csr to sign automaticaly, minimum value is 1
{% if int(slapparameter_dict.get('auto-sign-csr-amount', 1)) < 1 -%}
auto-sign-csr-amount = 1
{% else -%}
auto-sign-csr-amount = {{ slapparameter_dict.get('auto-sign-csr-amount', 1) }}
{% endif -%}
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

[directory]
recipe = slapos.cookbook:mkdirectory
etc = ${buildout:directory}/etc
bin = ${buildout:directory}/bin
srv = ${buildout:directory}/srv
var = ${buildout:directory}/var
run = ${:var}/run
log = ${:var}/log
scripts = ${:etc}/run
services = ${:etc}/service
promises = ${:etc}/promise
ssl=${:etc}/ssl
ca-dir = ${directory:srv}/ca
ca-temp = ${:ca-dir}/tmp
client-body-temp-path = ${:ca-temp}/client_body_temp_path
proxy-temp-path = ${:ca-temp}/proxy_temp_path
fastcgi-temp-path = ${:ca-temp}/fastcgi_temp_path
uwsgi-temp-path = ${:ca-temp}/uwsgi_temp_path
scgi-temp-path = ${:ca-temp}/scgi_temp_path

[nginx-certificate-request-base]
recipe = slapos.cookbook:wrapper
wrapper-path = ${directory:bin}/request-base-certificate
cert-file = ${ca-nginx-ssl-config:cert}
key-file = ${ca-nginx-ssl-config:key}
ca-cert = ${directory:ssl}/cacert.pem
command-line = {{ certificate_request_bin }}
  --crt-file ${:cert-file}
  --key-file ${:key-file}
63
  --ca-url http://[${ca-parameters:ipv6}]:${ca-parameters:server-port}
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  --ca-crt-file ${:ca-cert}

[nginx-certificate-request]
recipe = slapos.cookbook:wrapper
wrapper-path = ${directory:scripts}/request-server-certificate
command-line =
  ${nginx-certificate-request-base:wrapper-path}
  --cn nginx@certificate.authority
  --request

[ca-nginx-ssl-config]
# if ssl certificate is signed write to file so that zero-knowledge can read
recipe = plone.recipe.command
command = 
  if [ -s "${:key}" ] && [ -s "${:cert}" ]; then
79 80 81 82 83
  cat << EOF > ${:output}
  [ca-nginx-ssl]
  key=${:key}
  cert=${:cert}
  EOF
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
  fi
key = ${directory:ssl}/ca-cert.key
cert = ${directory:ssl}/ca-cert.crt
update-command = ${:command}
output = ${directory:etc}/ca-nginx-ssl.cfg
stop-on-error = true

[ca-nginx-ssl]
recipe = slapos.cookbook:zero-knowledge.read
file-path = ${ca-nginx-ssl-config:output}
# initials values are empty, the section https (ssl) in nginx config will be skipped
cert = 
key = 

[ca-nginx-conf-parameter]
99 100 101
ip = ${ca-parameters:ipv6}
port = ${ca-parameters:server-port}
https-port = ${ca-parameters:server-https-port}
102 103 104 105 106
pid-file = ${directory:run}/nginx-ca.pid
access-log = ${directory:log}/nginx-ca-access.log
error-log = ${directory:log}/nginx-ca-error.log
cert-file = ${ca-nginx-ssl:cert}
key-file = ${ca-nginx-ssl:key}
107
ca-conf = ${caucase-conf:output}
108 109 110 111 112 113
workers-processes = 1
client-body-temp-path = ${directory:client-body-temp-path}
proxy-temp-path = ${directory:proxy-temp-path}
fastcgi-temp-path = ${directory:fastcgi-temp-path}
uwsgi-temp-path = ${directory:uwsgi-temp-path}
scgi-temp-path = ${directory:scgi-temp-path}
114
socket = ${caucase-gunicorn:socket}
115 116 117 118 119 120 121 122 123

[ca-nginx-conf]
recipe = slapos.recipe.template:jinja2
template = {{ template_nginx_ca_conf }}
rendered = ${directory:etc}/nginx-ca.conf
mode = 0700
context =
  section parameter_dict ca-nginx-conf-parameter

124
[caucase-conf]
125 126 127 128 129 130 131
recipe = collective.recipe.template
# Values here are intended to be changed in your instance. override this section
input = inline:
  ca-dir ${directory:ca-dir}
  # enable debug
  # debug
  # log-file ${directory:log}/ca-server.log
132 133 134
  subject ${ca-parameters:ca-subject}
  max-request-amount ${ca-parameters:max-request-amount}
  external-url ${ca-parameters:crl-external-url}
135
  # one year (in seconds)
136
  crt-life-time ${ca-parameters:crt-life-time}
137
  # crl-life-period correspond to about one week
138
  crl-life-period ${ca-parameters:crl-life-period}
139
  # ca-life-time = ca-life-period * crt-life-time
140
  ca-life-period ${ca-parameters:ca-life-period}
141
  # time before clean certificate on CA: 60*24*60*60
142
  crt-keep-time ${ca-parameters:crt-keep-time}
143 144
  # number of csr to sign automaticaly
  auto-sign-csr-amount ${ca-parameters:auto-sign-csr-amount}
145 146 147 148 149 150 151

output = ${directory:etc}/ca.conf
mode = 700

[ca-nginx-graceful]
recipe = collective.recipe.template
input = inline:#!{{ dash_executable_location }}
152
  kill -HUP "$(cat '${ca-nginx-conf-parameter:pid-file}')"
153 154 155 156

output = ${directory:scripts}/ca-server-graceful
mode = 700

157
[caucase-gunicorn]
158
recipe = slapos.cookbook:wrapper
159
socket = ${directory:ca-dir}/ng.sock
160
command-line =  {{ gunicorn_bin }} caucase.wsgi:app -b unix:${:socket} -e CA_CONFIGURATION_FILE=${caucase-conf:output} --error-logfile ${:log-file} --pid ${:pid-file} --capture-output --timeout 60 --threads 2 --log-level error --preload
161 162 163 164
log-file = ${directory:log}/ca-gunicorn-error.log
pid-file = ${directory:run}/ca-gunicorn.pid
wrapper-path = ${directory:services}/ca-gunicorn

165
[caucase-server]
166
recipe = slapos.cookbook:wrapper
167 168 169 170
command-line = {{ nginx_location }}/sbin/nginx -p ${directory:ca-dir} -c ${ca-nginx-conf:rendered}
wrapper-path = ${directory:services}/caucase-server
url = https://[${ca-parameters:ipv6}]:${ca-parameters:server-https-port}
http-url = ${ca-parameters:crl-external-url}
171 172
depends = 
  ${nginx-certificate-request:wrapper-path}
173
  ${caucase-https-server-promise:filename}
174 175 176 177
  ${ca-nginx-graceful:output}
  ${ca-certificate-renew-cron-entry:name}
  ${logrotate-ca-nginx:name}

178 179 180
# Disabled to be re-implemented.
#  ${caucase-server-promise:filename}

181 182 183 184 185
[ca-certificate-renew-cron-entry]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = ca-server-certificate-auto-renew
# check renew every-week
186 187 188
time = weekly
# 2592000 = 30*24*60*60  equivalent to one month in seconds
command = ${nginx-certificate-request-base:wrapper-path} --renew --threshold 2592000 --on-renew="${ca-nginx-graceful:output}"
189 190 191

[logrotate-ca-nginx]
< = logrotate-entry-base
192
name = caucase-nginx-server
193 194 195
log = ${ca-nginx-conf-parameter:access-log} ${ca-nginx-conf-parameter:access-log}
post = {{ slapos_kill_bin }} --pidfile ${ca-nginx-conf-parameter:pid-file} -s USR1

196 197 198 199 200 201 202 203 204 205 206
# This promise is disabled as it requires user to take action so the buildout
# will fail for way too long, and overload master. Please reimplement on a 
# better way
#[caucase-server-promise]
#recipe = slapos.cookbook:check_url_available
#path = ${directory:promises}/${:filename}
#filename = caucase-server-listening-on-tcp
#url = http://[${ca-parameters:ipv6}]:${ca-parameters:server-port}
#dash_path = {{ dash_executable_location }}
#curl_path = {{ curl_executable_location }}
#
207
[caucase-https-server-promise]
208 209
recipe = slapos.cookbook:check_url_available
path = ${directory:promises}/${:filename}
210 211
filename = caucase-server-https-on-${ca-parameters:server-https-port}
url = https://[${ca-parameters:ipv6}]:${ca-parameters:server-https-port}
212 213 214 215
check-secure = 1
dash_path = {{ dash_executable_location }}
curl_path = {{ curl_executable_location }}

216 217 218 219 220
{% if publish_parameter is defined and publish_parameter == 'yes' -%}
[publish-connection-parameter]
recipe = slapos.cookbook:publish.serialised
http-url = ${caucase-server:http-url}
https-url = ${caucase-server:url}
221
init-user = admin
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
{% do part_list.append('publish-connection-parameter') -%}
{% endif -%}

[buildout]

extends =
  {{ template_logrotate_base }}

parts = 
  caucase-server
# Complete parts with sections
  {{ part_list | join('\n  ') }}

eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
237
offline = true