Skip to content

Commit ae24ece

Browse files
committed
Check all supported locations for CA file in rotation check script
1 parent b6ad445 commit ae24ece

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

mgradm/shared/podman/clients.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,28 @@ func parseClientTrustResults(saltOutput []byte, unreachable map[string]bool) (
132132
// CA file holds a certificate matching a given SHA-256 fingerprint.
133133
// It prints "OK" on a match and "MISSING" otherwise.
134134
const clientTrustCheckScript = `
135-
caFile="/etc/pki/trust/anchors/RHN-ORG-TRUSTED-SSL-CERT"
135+
found=MISSING
136136
137-
# Without the managed CA file the minion cannot trust the new CA yet.
138-
[ -f "$caFile" ] || { echo MISSING; exit 0; }
137+
for caFile in \
138+
/etc/pki/trust/anchors/RHN-ORG-TRUSTED-SSL-CERT \
139+
/etc/pki/ca-trust/source/anchors/RHN-ORG-TRUSTED-SSL-CERT \
140+
/usr/local/share/ca-certificates/RHN-ORG-TRUSTED-SSL-CERT.crt; do
141+
# Skip the locations that do not apply to this minion's OS.
142+
[ -f "$caFile" ] || continue
139143
140-
# Split the (possibly multi-cert) CA file into one file per certificate.
141-
d=$(mktemp -d)
142-
trap 'rm -rf "$d"' EXIT
143-
csplit -z -s -f "$d/cert-" "$caFile" '/-----BEGIN CERTIFICATE-----/' '{*}' 2>/dev/null
144+
# Split the (possibly multi-cert) CA file into one file per certificate.
145+
d=$(mktemp -d)
146+
csplit -z -s -f "$d/cert-" "$caFile" '/-----BEGIN CERTIFICATE-----/' '{*}' 2>/dev/null
144147
145-
# Report OK as soon as one of the certificates matches the expected fingerprint.
146-
found=MISSING
147-
for cert in "$d"/cert-*; do
148-
fp=$(openssl x509 -in "$cert" -noout -fingerprint -sha256 2>/dev/null | cut -d= -f2)
149-
[ "$fp" = "%[1]s" ] && found=OK
148+
# Report OK as soon as one of the certificates matches the expected fingerprint.
149+
for cert in "$d"/cert-*; do
150+
fp=$(openssl x509 -in "$cert" -noout -fingerprint -sha256 2>/dev/null | cut -d= -f2)
151+
[ "$fp" = "%[1]s" ] && found=OK
152+
done
153+
154+
rm -rf "$d"
150155
done
156+
151157
echo "$found"
152158
`
153159

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Check all supported locations for CA file in rotation check script

0 commit comments

Comments
 (0)