File tree Expand file tree Collapse file tree 3 files changed +125
-0
lines changed
Expand file tree Collapse file tree 3 files changed +125
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Daily Check to see if any secrets will expire soon
2+
3+ on :
4+ workflow_dispatch :
5+ schedule : # At 04:00 every morning
6+ - cron : ' 0 04 * * *'
7+
8+
9+ jobs :
10+ secret-expire-check :
11+ runs-on : ubuntu-latest
12+ permissions :
13+ id-token : write
14+ contents : write
15+
16+ steps :
17+ - name : Checkout
18+ uses : actions/checkout@v4
19+
20+ - name : Run check if any secrets will expire within next month
21+ id : secrete-expire-check-month
22+ run : |
23+ ./bin/check_secret_expire.sh $(date -d "+1 month" +"%Y-%m-%d")
24+
25+ - name : Slack Notification on Failure
26+ if : ${{ failure() }}
27+ uses : rtCamp/action-slack-notify@v2
28+ env :
29+ SLACK_CHANNEL : secret-expire
30+ SLACK_WEBHOOK : ${{ secrets.MERKELY_SLACK_CI_FAILURES_WEBHOOK }}
31+ SLACK_USERNAME : GithubActions
32+ SLACK_COLOR : ${{ job.status }}
33+ SLACKIFY_MARKDOWN : true
34+ SLACK_TITLE : Secret has expired
35+ SLACK_MESSAGE : " Some secrets in `github-release-example` is about to or has expired. Please check the \
36+ [log](${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}) \
37+ for more details."
38+ SLACK_FOOTER :
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -Eeu
3+
4+ SCRIPT_NAME=check_secret_expire.sh
5+ ROOT_DIR=$( dirname $( readlink -f $0 ) ) /..
6+ NOW_DATE=$( date +%Y-%m-%d)
7+
8+ print_help ()
9+ {
10+ cat << EOF
11+ Usage: $SCRIPT_NAME <options> [yyyy-mm-dd]
12+
13+ Will search all txt-files in secrets directory to see if any of them
14+ has a secret that has expired. You can specify a date if you want to
15+ know if something expires in the future
16+
17+ Options are:
18+ -h Print this help menu
19+ EOF
20+ }
21+
22+ check_arguments ()
23+ {
24+ while getopts " h" opt; do
25+ case $opt in
26+ h)
27+ print_help
28+ exit 1
29+ ;;
30+ \? )
31+ echo " Invalid option: -$OPTARG " >&2
32+ exit 1
33+ ;;
34+ esac
35+ done
36+
37+ # Remove options from command line
38+ shift $(( OPTIND- 1 ))
39+
40+ if [ $# -eq 1 ]; then
41+ NOW_DATE=$1 ; shift
42+ fi
43+ }
44+
45+ echo_if_secret_expired ()
46+ {
47+ local file=$1 ; shift
48+ local now_date=$1 ; shift
49+ local expire_date now_sec expire_sec
50+ expire_date=$( grep " secret-expire:" ${file} | sed " s/secret-expire: *//" )
51+
52+ if [[ ! " ${now_date} " < " ${expire_date} " ]]; then
53+ grep " secret-name:" ${file} | sed " s/secret-name: */ /" | tr ' \n' ' '
54+ grep " secret-expire:" ${file}
55+ return 1
56+ fi
57+ return 0
58+ }
59+
60+ main ()
61+ {
62+ check_arguments " $@ "
63+ local file
64+ local result=0
65+ echo " The following is a list of secrets in 'secrets/*txt' which will have expired on ${NOW_DATE} "
66+ for file in ${ROOT_DIR} /secrets/* txt; do
67+ echo_if_secret_expired ${file} ${NOW_DATE} || result=1
68+ done
69+ return $result
70+ }
71+
72+ main " $@ "
Original file line number Diff line number Diff line change 1+ secret-name: KOSLI_PUBLIC_API_TOKEN
2+ secret-expire: 2026-04-06
3+ secret-updated: 2025-04-06
4+ secret-updated-by: tore
5+ secret-type: gh-repo
6+ is-secret: true
7+ secret-usage: Secret used to report github release example builds to
8+ https://app.kosli.com/kosli-public
9+
10+ update-instructions:
11+ Get new API key from https://app.kosli.com/kosli-public/settings/service-accounts#github-release-example
12+ This is the api-key for the github-release-exampl.
13+
14+ Go to https://github.com/kosli-dev/github-release-example/settings/secrets/actions
15+ under <Repository secrets>
You can’t perform that action at this time.
0 commit comments