Skip to content

Commit 80f2aee

Browse files
authored
Merge pull request #496 from jayfranco999/updatecli-cert-exp-warning
chore(updatecli): add `OpenVPN` certificate expiration tracking manifest
2 parents d40e04e + 8263088 commit 80f2aee

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
# Check if certificate expires within 30 days
3+
set -eu -o pipefail
4+
5+
currentexpirydate="${1}"
6+
7+
DATE_BIN='date'
8+
## non GNU operating system
9+
if command -v gdate >/dev/null 2>&1; then
10+
DATE_BIN='gdate'
11+
fi
12+
13+
command -v "${DATE_BIN}" >/dev/null 2>&1 || { echo "ERROR: ${DATE_BIN} command not found. Exiting."; exit 1; }
14+
15+
currentdateepoch=$("${DATE_BIN}" --utc "+%s" 2>/dev/null)
16+
expirydateepoch=$("${DATE_BIN}" "+%s" -d "${currentexpirydate}")
17+
datediff=$(((expirydateepoch-currentdateepoch)/(60*60*24))) # diff per days
18+
19+
echo "Certificate expires in ${datediff} days"
20+
21+
if [ "${datediff}" -lt 30 ]; then # Alert 30 days before expiration
22+
echo "Certificate expiring soon - action required"
23+
exit 0
24+
else
25+
echo "Certificate not expiring soon"
26+
exit 1
27+
fi
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# Extract expiration date from an OpenVPN certificate
3+
set -eu -o pipefail
4+
5+
cert_file="${1}"
6+
7+
if [ ! -f "${cert_file}" ]; then
8+
echo "ERROR: Certificate file ${cert_file} not found"
9+
exit 1
10+
fi
11+
12+
# Extract the notAfter date from the certificate
13+
# Output format: notAfter=Jan 15 12:34:56 2026 GMT
14+
expiry_raw=$(openssl x509 -enddate -noout -in "${cert_file}" 2>/dev/null | cut -d= -f2)
15+
16+
if [ -z "${expiry_raw}" ]; then
17+
echo "ERROR: Could not extract expiration date from ${cert_file}"
18+
exit 1
19+
fi
20+
21+
# Convert to ISO 8601 format for easier parsing
22+
DATE_BIN='date'
23+
if command -v gdate >/dev/null 2>&1; then
24+
DATE_BIN='gdate'
25+
fi
26+
27+
command -v "${DATE_BIN}" >/dev/null 2>&1 || { echo "ERROR: ${DATE_BIN} command not found. Exiting."; exit 1; }
28+
29+
# Convert to ISO format: YYYY-MM-DDTHH:MM:SSZ
30+
expiry_iso=$("${DATE_BIN}" --utc -d "${expiry_raw}" "+%Y-%m-%dT%H:%M:%SZ" 2>/dev/null)
31+
32+
echo "${expiry_iso}"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{{- range $username := splitList "," .certificates }}
2+
---
3+
# yamllint disable rule:line-length
4+
name: "Check VPN certificate expiration for {{ $username }}"
5+
6+
scms:
7+
default:
8+
kind: github
9+
spec:
10+
user: "{{ $.github.user }}"
11+
email: "{{ $.github.email }}"
12+
owner: "{{ $.github.owner }}"
13+
repository: "{{ $.github.repository }}"
14+
token: "{{ requiredEnv $.github.token }}"
15+
branch: "{{ $.github.branch }}"
16+
17+
sources:
18+
certExpiryDate:
19+
name: "Extract expiration date from {{ $username }}'s certificate"
20+
kind: shell
21+
spec:
22+
command: bash ./updatecli/scripts/cert-expiry-extract.sh cert/pki/issued/{{ $username }}.crt
23+
environments:
24+
- name: PATH
25+
26+
conditions:
27+
checkIfExpiringSoon:
28+
name: "Check if certificate expires within 30 days"
29+
kind: shell
30+
sourceid: certExpiryDate
31+
spec:
32+
command: bash ./updatecli/scripts/cert-expiry-check.sh
33+
environments:
34+
- name: PATH
35+
36+
targets:
37+
markCertExpiring:
38+
name: "Mark {{ $username }}'s certificate as expiring"
39+
kind: file
40+
spec:
41+
file: cert/pki/issued/{{ $username }}.crt.expiring
42+
content: |
43+
Certificate for {{ $username }} expires on {{ source "certExpiryDate" }}.
44+
Please renew your VPN certificate as soon as possible.
45+
scmid: default
46+
47+
actions:
48+
default:
49+
kind: github/pullrequest
50+
scmid: default
51+
spec:
52+
draft: true
53+
title: "[DO NOT MERGE] VPN Certificate Expiring Soon: {{ $username }}"
54+
description: |
55+
@{{ $username }} your VPN certificate will expire on **{{ source "certExpiryDate" }}**.
56+
57+
## Action Required
58+
59+
Your VPN certificate expires in less than **30 days**.
60+
Please renew it to avoid losing VPN access.
61+
62+
---
63+
**Note:** This is an automated notification PR.
64+
It is not meant to be merged and can be closed once acknowledged.
65+
labels:
66+
- vpn
67+
- certificate-expiration
68+
- action-required
69+
{{- end }}

updatecli/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ networks:
3535
resolve_dns: true
3636
dockerhubmirror.azurecr.io:
3737
resolve_dns: true
38+
39+
certificates: abayer,danielbeck,dduportal,hlemeur,jay_jenkins,kevingrdj,kohsuke,krisstern,markewaite,notmyfault,smerle,timja,wfollonier

0 commit comments

Comments
 (0)