-
Notifications
You must be signed in to change notification settings - Fork 109
feat: add GitHub Actions workflow to check pinned CA certificate validity #1112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexKaravaev
wants to merge
2
commits into
main
Choose a base branch
from
codex/linear-mention-orbs-860-automated-checking-validity-of-pin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| name: Check pinned CA validity | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 3 * * *' | ||
| workflow_dispatch: | ||
| pull_request: | ||
| paths: | ||
| - '.github/workflows/security-utils-cert-validity.yaml' | ||
| - 'security-utils/certs/*.pem' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| check-pinned-cas: | ||
| name: Check pinned CA validity | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Check pinned CA certificates | ||
| id: cert_check | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| threshold_seconds=$((60 * 24 * 60 * 60)) | ||
| expiring_certs=() | ||
|
|
||
| for cert in security-utils/certs/*.pem; do | ||
| echo "Checking certificate validity for ${cert}" | ||
|
|
||
| if ! openssl x509 -in "${cert}" -noout >/dev/null; then | ||
| echo "::error file=${cert}::Invalid certificate format" | ||
| exit 1 | ||
| fi | ||
|
|
||
| expiration="$(openssl x509 -in "${cert}" -noout -enddate | sed 's/notAfter=//')" | ||
| echo "${cert} notAfter=${expiration}" | ||
|
|
||
| if ! openssl x509 -in "${cert}" -checkend 0 -noout >/dev/null; then | ||
| echo "::error file=${cert}::Certificate is expired (notAfter=${expiration})" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! openssl x509 -in "${cert}" -checkend "${threshold_seconds}" -noout >/dev/null; then | ||
| echo "::error file=${cert}::Certificate expires in less than 60 days (notAfter=${expiration})" | ||
| expiring_certs+=("${cert} (notAfter=${expiration})") | ||
| fi | ||
| done | ||
|
|
||
| if ((${#expiring_certs[@]} > 0)); then | ||
| { | ||
| echo 'expiring_certs<<EOF' | ||
| printf '%s\n' "${expiring_certs[@]}" | ||
| echo EOF | ||
| } >>"$GITHUB_OUTPUT" | ||
|
|
||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Notify maintainers via GitHub issue | ||
| if: failure() && steps.cert_check.outputs.expiring_certs != '' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const title = 'security-utils pinned CA certificates expire in less than 60 days'; | ||
| const body = [ | ||
| 'The nightly pinned CA validity workflow detected certificates expiring within 60 days.', | ||
| '', | ||
| 'Please rotate affected certificates in `security-utils/certs`.', | ||
| '', | ||
| 'Affected certificates:', | ||
| '```', | ||
| `${{ toJSON(steps.cert_check.outputs.expiring_certs) }}`, | ||
| '```', | ||
| '', | ||
| `Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | ||
| ].join('\n'); | ||
|
|
||
| const { data: issues } = await github.rest.issues.listForRepo({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'open', | ||
| creator: 'github-actions[bot]', | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| const existing = issues.find((issue) => issue.title === title); | ||
|
|
||
| if (existing) { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: existing.number, | ||
| body, | ||
| }); | ||
| core.info(`Updated existing issue #${existing.number}`); | ||
| return; | ||
| } | ||
|
|
||
| const { data: issue } = await github.rest.issues.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title, | ||
| body, | ||
| labels: ['security'], | ||
| }); | ||
|
|
||
| core.info(`Created issue #${issue.number}`); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The notification step only runs when
steps.cert_check.outputs.expiring_certsis non-empty, but the check step exits immediately for invalid or already expired certificates before writing that output. In those cases the workflow fails silently (no issue is created/updated), which defeats the automation for the most urgent certificate problems and leaves maintainers reliant on manually noticing failed runs.Useful? React with 👍 / 👎.