Skip to content

Commit d22245c

Browse files
r-krcekkeuko
andcommitted
Change copy-cacerts behaviour
So far, the certificates were not part of config.json files for containers. With future patches that will remove container restarts based on triggers from config and service-copy-cert, it is important that all files that change during config are specified in config.json so that kolla-set-configs --check can detect those changes and based on that restart the container. This patch provides prerequisite for future patch in kolla-ansible. Comments from kevko: The script also takes into account whether review [1] is merged or not, ensuring that it will function correctly in both cases thanks to review [2], because using the state file, we can effectively verify whether the config.json that copies CA certs to /var/lib/kolla/share is being used or not. If we didn’t handle it this way, we would have to rely on checking whether the directory /var/lib/kolla/share exists or some another magic, which is insufficient because various states and combinations of Kolla image and Kolla-Ansible versions could result in certificates always being copied. This method provides a clear and definitive distinction. [1] https://review.opendev.org/c/openstack/kolla-ansible/+/924651 [2] https://review.opendev.org/c/openstack/kolla/+/915440 Change-Id: I5120f1874f25a9ca8326e6db8b12dee4c81feb56 Signed-off-by: Roman Krček <[email protected]> Co-Authored-By: Michal Arbet <[email protected]> Needed-By: https://review.opendev.org/c/openstack/kolla-ansible/+/924651
1 parent 23519e6 commit d22245c

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

docker/base/copy_cacerts.sh

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,46 @@
33
# Copy custom CA certificates to system trusted CA certificates folder
44
# and run CA update utility
55

6+
if [[ -e "/etc/debian_version" ]]; then
7+
ca_dst_path="/usr/local/share/ca-certificates"
8+
update_command="update-ca-certificates"
9+
elif [[ -e "/etc/redhat-release" ]]; then
10+
ca_dst_path="/etc/pki/ca-trust/source/anchors"
11+
update_command="update-ca-trust"
12+
else
13+
echo "Unsupported OS"
14+
exit 1
15+
fi
16+
17+
# Initialize update_needed variable
18+
update_needed="false"
19+
620
# Remove old certificates
7-
rm -f /usr/local/share/ca-certificates/kolla-customca-* \
8-
/etc/pki/ca-trust/source/anchors/kolla-customca-*
21+
if find /etc/ssl/certs/ \
22+
/usr/local/share/ca-certificates/ \
23+
/etc/pki/ca-trust/source/anchors/ \
24+
-name 'kolla*' -exec rm -f {} + 2>/dev/null; then
25+
update_needed="true"
26+
fi
27+
28+
# Determine source path for CA certificates
29+
if grep -q '"source": "/var/lib/kolla/share/ca-certificates"' /etc/kolla/defaults/state; then
30+
ca_src_path="/var/lib/kolla/share/ca-certificates"
31+
else
32+
ca_src_path="/var/lib/kolla/config_files/ca-certificates"
33+
fi
34+
35+
# Check if the source path exists and is not empty
36+
if [[ -d ${ca_src_path} && $(ls -A "${ca_src_path}" 2>/dev/null) ]]; then
37+
# Copy certificates and update CA
38+
for cert in "${ca_src_path}"/*; do
39+
file=$(basename "${cert}")
40+
cp ${cert} ${ca_dst_path}/kolla-customca-${file}
41+
update_needed="true"
42+
done
43+
fi
944

10-
if [[ -d /var/lib/kolla/config_files/ca-certificates ]] && \
11-
[[ ! -z "$(ls -A /var/lib/kolla/config_files/ca-certificates/)" ]]; then
12-
if [[ -e /etc/debian_version ]]; then
13-
# Debian, Ubuntu
14-
for cert in /var/lib/kolla/config_files/ca-certificates/*; do
15-
file=$(basename "$cert")
16-
cp $cert "/usr/local/share/ca-certificates/kolla-customca-$file"
17-
done
18-
update-ca-certificates
19-
elif [[ -e /etc/redhat-release ]]; then
20-
# CentOS
21-
for cert in /var/lib/kolla/config_files/ca-certificates/*; do
22-
file=$(basename "$cert")
23-
cp $cert "/etc/pki/ca-trust/source/anchors/kolla-customca-$file"
24-
done
25-
update-ca-trust
26-
fi
45+
# Run the update command if needed
46+
if [[ "${update_needed}" == "true" ]]; then
47+
${update_command}
2748
fi

0 commit comments

Comments
 (0)