Skip to content

Commit

Permalink
chore(updatecli): create an issue when CRL cert close to expiration (#…
Browse files Browse the repository at this point in the history
…354)

* WIP

* change variable name

* chore(updatecli): manifest to create an Issue on helpdesk to renew CRL certificate

* chore

* revert delay to 30days
  • Loading branch information
smerle33 authored Sep 3, 2024
1 parent b4911da commit e8bc16d
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
33 changes: 33 additions & 0 deletions updatecli/scripts/createIssue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# This script log to github and create an issue if not in dry mode
set -eux -o pipefail

command -v "gh" >/dev/null 2>&1 || { echo "ERROR: gh command not found. Exiting."; exit 1; }

cmd=$(cat <<- EOM
gh issue create --title "[private.vpn.jenkins.io] $1 VPN CRL expires" \
--body "follow https://github.com/jenkins-infra/docker-openvpn?tab=readme-ov-file#howto-renew-certificate-revocation-list \
See https://github.com/jenkins-infra/helpdesk/issues/4266 for details." \
--label crl \
--label updatecli \
--repo jenkins-infra/helpdesk
EOM
)

if test "$DRY_RUN" == "false"
then
export GITHUB_TOKEN="${UPDATECLI_GITHUB_TOKEN}"
alreadyOpened=$(gh issue list --repo jenkins-infra/helpdesk --state open --search "label:crl label:updatecli" | wc -l)
if test "$alreadyOpened" -eq 0
then
"${cmd}"
else
echo "issue already opened"
fi
else
echo "should create an issue on --repo jenkins-infra/helpdesk"
echo "with title: [private.vpn.jenkins.io] $1 VPN CRL expires"
echo "${cmd}"
fi

exit 0
27 changes: 27 additions & 0 deletions updatecli/scripts/datediff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# This script calculate diff between dates for letsencrypt expiration
set -eux -o pipefail

currentexpirydate="${1}"
DATE_BIN='date'

## non GNU operating system
if command -v gdate >/dev/null 2>&1
then
DATE_BIN='gdate'
fi
command -v "${DATE_BIN}" >/dev/null 2>&1 || { echo "ERROR: ${DATE_BIN} command not found. Exiting."; exit 1; }

currentdateepoch=$("${DATE_BIN}" --utc "+%s" 2>/dev/null)
expirydateepoch=$("${DATE_BIN}" "+%s" -d "$currentexpirydate")

datediff=$(((expirydateepoch-currentdateepoch)/(60*60*24))) # diff per days

if [ "$datediff" -lt 30 ] # launch renew 30 days before expiration
then
echo "time for update"
exit 0
else
echo "not yet expired"
exit 1
fi
44 changes: 44 additions & 0 deletions updatecli/updatecli.d/crl.enddate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# yamllint disable rule:line-length
name: "CRL Renew cert for the VPN"

scms:
default:
kind: github
spec:
user: "{{ .github.user }}"
email: "{{ .github.email }}"
owner: "{{ .github.owner }}"
repository: "{{ .github.repository }}"
token: "{{ requiredEnv .github.token }}"
username: "{{ .github.username }}"
branch: "{{ .github.branch }}"

sources:
currentEndDate:
name: Get current `end_date` date
kind: shell
spec:
command: openssl crl -in ./cert/pki/crl.pem -noout -nextupdate | cut -d= -f2
transformers:
- addprefix: "'"
- addsuffix: "'"

conditions:
checkIfEndDateSoonExpired:
kind: shell
sourceid: currentEndDate
spec:
# Current end_date date value passed as argument
command: bash ./updatecli/scripts/datediff.sh
environments:
- name: PATH
targets:
createIssue:
kind: shell
sourceid: currentEndDate
spec:
environments:
- name: PATH
- name: UPDATECLI_GITHUB_TOKEN
command: bash ./updatecli/scripts/createIssue.sh

0 comments on commit e8bc16d

Please sign in to comment.