Skip to content

Commit 90c1748

Browse files
committed
add lock to ca,ensure acl isnt rotated if no pillar data
1 parent 706ec31 commit 90c1748

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

salt/_extensions/pillar/ca.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import binascii
44
import datetime
5+
import fcntl
56
import os.path
67

78
import salt.loader
@@ -342,10 +343,18 @@ def ext_pillar(minion_id, pillar, base="/etc/ssl", name="PSFCA", cert_opts=None)
342343
opts["CN"] = certificate
343344
opts["days"] = config.get("days", 1)
344345

345-
create_ca_signed_cert(base, name, **opts)
346+
# Lock per-CN to prevent concurrent pillar compilations from
347+
# racing on the same cert/key files.
348+
lockp = os.path.join(base, name, "certs", "{}.lock".format(certificate))
349+
lock_fd = open(lockp, "w")
350+
try:
351+
fcntl.flock(lock_fd, fcntl.LOCK_EX)
352+
create_ca_signed_cert(base, name, **opts)
353+
cert_data = get_ca_signed_cert(base, name, certificate)
354+
finally:
355+
fcntl.flock(lock_fd, fcntl.LOCK_UN)
356+
lock_fd.close()
346357

347-
# Add the signed certificates to the pillar data
348-
cert_data = get_ca_signed_cert(base, name, certificate)
349358
data["tls"]["certs"][certificate] = cert_data
350359

351360
# Collect ACME certs (acme.cert) for this minion based on its roles

salt/consul/etc/acl.json.jinja

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
{% set acl_token = salt['pillar.get']("consul:acl:tokens:default") %}
2+
{% if not acl_token %}
3+
{# Fail rendering rather than write an empty acl.json, which would break consul #}
4+
{{ MISSING_CONSUL_ACL_TOKEN }}
5+
{% endif %}
16
{
2-
{% if "default" in salt['pillar.get']("consul:acl:tokens", []) %}
3-
"acl_token": "{{ pillar['consul']['acl']['tokens']['default'] }}"
4-
{% endif %}
7+
"acl_token": "{{ acl_token }}"
58
}

0 commit comments

Comments
 (0)