Skip to content

Commit 64db290

Browse files
authored
Merge pull request #91 from arduino/per1234/certificates-check-workflow
Add workflow to check for problems with certificates
2 parents 484fee6 + 2be6bc1 commit 64db290

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

Diff for: .github/workflows/check-certificates.yml

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Check for issues with signing certificates
2+
3+
on:
4+
push:
5+
schedule:
6+
# run every 10 hours
7+
- cron: "0 */10 * * *"
8+
# workflow_dispatch event allows the workflow to be triggered manually.
9+
# This could be used to run an immediate check after updating certificate secrets.
10+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch
11+
workflow_dispatch:
12+
13+
env:
14+
# Begin notifications when there are less than this many days remaining before expiration
15+
EXPIRATION_WARNING_PERIOD: 30
16+
17+
jobs:
18+
check-certificates:
19+
# This workflow would always fail in forks
20+
if: github.repository == 'arduino/arduino-lint'
21+
runs-on: ubuntu-latest
22+
23+
strategy:
24+
fail-fast: false
25+
26+
matrix:
27+
certificate:
28+
- identifier: macOS signing certificate # Text used to identify the certificate in notifications
29+
certificate-secret: INSTALLER_CERT_MAC_P12 # The name of the secret that contains the certificate
30+
password-secret: INSTALLER_CERT_MAC_PASSWORD # The name of the secret that contains the certificate password
31+
32+
steps:
33+
- name: Set certificate path environment variable
34+
run: |
35+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
36+
echo "CERTIFICATE_PATH=${{ runner.temp }}/certificate.p12" >> "$GITHUB_ENV"
37+
38+
- name: Decode certificate
39+
env:
40+
CERTIFICATE: ${{ secrets[matrix.certificate.certificate-secret] }}
41+
run: |
42+
echo "${{ env.CERTIFICATE }}" | base64 --decode > "${{ env.CERTIFICATE_PATH }}"
43+
44+
- name: Verify certificate
45+
env:
46+
CERTIFICATE_PASSWORD: ${{ secrets[matrix.certificate.password-secret] }}
47+
run: |
48+
(
49+
openssl pkcs12 \
50+
-in "${{ env.CERTIFICATE_PATH }}" \
51+
-noout -passin env:CERTIFICATE_PASSWORD
52+
) || (
53+
echo "::error::Verification of ${{ matrix.certificate.identifier }} failed!!!"
54+
exit 1
55+
)
56+
57+
# See: https://github.com/rtCamp/action-slack-notify
58+
- name: Slack notification of certificate verification failure
59+
if: failure()
60+
uses: rtCamp/[email protected]
61+
env:
62+
SLACK_WEBHOOK: ${{ secrets.TEAM_TOOLING_CHANNEL_SLACK_WEBHOOK }}
63+
SLACK_MESSAGE: |
64+
:warning::warning::warning::warning:
65+
WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} verification failed!!!
66+
:warning::warning::warning::warning:
67+
SLACK_COLOR: danger
68+
MSG_MINIMAL: true
69+
70+
- name: Get days remaining before certificate expiration date
71+
env:
72+
CERTIFICATE_PASSWORD: ${{ secrets[matrix.certificate.password-secret] }}
73+
id: get-days-before-expiration
74+
run: |
75+
EXPIRATION_DATE="$(
76+
(
77+
openssl pkcs12 \
78+
-in "${{ env.CERTIFICATE_PATH }}" \
79+
-clcerts \
80+
-nodes \
81+
-passin env:CERTIFICATE_PASSWORD
82+
) | (
83+
openssl x509 \
84+
-noout \
85+
-enddate
86+
) | (
87+
grep \
88+
--max-count=1 \
89+
--only-matching \
90+
--perl-regexp \
91+
'notAfter=(\K.*)'
92+
)
93+
)"
94+
95+
DAYS_BEFORE_EXPIRATION="$((($(date --utc --date="$EXPIRATION_DATE" +%s) - $(date --utc +%s)) / 60 / 60 / 24))"
96+
97+
# Display the expiration information in the log
98+
echo "Certificate expiration date: $EXPIRATION_DATE"
99+
echo "Days remaining before expiration: $DAYS_BEFORE_EXPIRATION"
100+
101+
echo "::set-output name=days::$DAYS_BEFORE_EXPIRATION"
102+
103+
- name: Check if expiration notification period has been reached
104+
id: check-expiration
105+
run: |
106+
if [[ ${{ steps.get-days-before-expiration.outputs.days }} -lt ${{ env.EXPIRATION_WARNING_PERIOD }} ]]; then
107+
echo "::error::${{ matrix.certificate.identifier }} will expire in ${{ steps.get-days-before-expiration.outputs.days }} days!!!"
108+
exit 1
109+
fi
110+
111+
- name: Slack notification of pending certificate expiration
112+
# Don't send spurious expiration notification if verification fails
113+
if: failure() && steps.check-expiration.outcome == 'failure'
114+
uses: rtCamp/[email protected]
115+
env:
116+
SLACK_WEBHOOK: ${{ secrets.TEAM_TOOLING_CHANNEL_SLACK_WEBHOOK }}
117+
SLACK_MESSAGE: |
118+
:warning::warning::warning::warning:
119+
WARNING: ${{ github.repository }} ${{ matrix.certificate.identifier }} will expire in ${{ steps.get-days-before-expiration.outputs.days }} days!!!
120+
:warning::warning::warning::warning:
121+
SLACK_COLOR: danger
122+
MSG_MINIMAL: true

0 commit comments

Comments
 (0)