-
Notifications
You must be signed in to change notification settings - Fork 32
Added GPG pvt key as a github secret and updated workflow accordingly #333
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,8 @@ on: | |||||||||||||||||||||
| required: true | ||||||||||||||||||||||
| GPG_SECRET: | ||||||||||||||||||||||
| required: true | ||||||||||||||||||||||
| GPG_PRIVATE_KEY: | ||||||||||||||||||||||
| required: true | ||||||||||||||||||||||
| SLACK_WEBHOOK_URL: | ||||||||||||||||||||||
| required: true | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -46,16 +48,12 @@ jobs: | |||||||||||||||||||||
| run: | | ||||||||||||||||||||||
| # Strip git ref prefix from version | ||||||||||||||||||||||
| echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV | ||||||||||||||||||||||
| echo "GPG_TTY=$(tty)" >> $GITHUB_ENV | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Setup branch and GPG public key | ||||||||||||||||||||||
| run: | | ||||||||||||||||||||||
| # Strip git ref prefix from version | ||||||||||||||||||||||
| echo ${{ env.BRANCH_NAME }} | ||||||||||||||||||||||
| echo ${{ env.GPG_TTY }} | ||||||||||||||||||||||
| sudo apt-get --yes install gnupg2 | ||||||||||||||||||||||
| gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg | ||||||||||||||||||||||
| gpg2 --quiet --batch --passphrase=${{secrets.GPG_SECRET}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg | ||||||||||||||||||||||
| - name: Import GPG key | ||||||||||||||||||||||
| uses: crazy-max/ghaction-import-gpg@v6 | ||||||||||||||||||||||
| with: | ||||||||||||||||||||||
| gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | ||||||||||||||||||||||
| passphrase: ${{ secrets.GPG_SECRET }} | ||||||||||||||||||||||
|
Comment on lines
+52
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Dereference the v6 tag to a commit SHA
gh api repos/crazy-max/ghaction-import-gpg/git/refs/tags/v6 \
--jq '.object.type + " " + .object.sha'
# If type is "tag" (annotated), dereference once more:
# gh api repos/crazy-max/ghaction-import-gpg/git/tags/<sha-from-above> --jq '.object.sha'Repository: mosip/kattu Length of output: 103 🏁 Script executed: #!/bin/bash
set -euo pipefail
file=".github/workflows/maven-build.yml"
# show lines 45-70 with numbers
nl -ba "$file" | sed -n '45,70p'Repository: mosip/kattu Length of output: 98 🌐 Web query:
💡 Result: To ensure security when using the ghaction-import-gpg action, you should implement the following best practices: 1. Use Immutable Commit SHAs: Never pin your workflow actions to mutable tags or branch names (e.g., Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
file=".github/workflows/maven-build.yml"
nl -ba "$file" | sed -n '45,70p'Repository: mosip/kattu Length of output: 98 🌐 Web query:
💡 Result: The crazy-max/ghaction-import-gpg GitHub Action facilitates GPG key usage in GitHub Actions by importing a private key into the runner's environment [1][2]. To use it securely: 1. Store your ASCII-armored private GPG key as a GitHub Secret (e.g., GPG_PRIVATE_KEY) [1][2]. 2. If your key is passphrase-protected, store the passphrase as a separate GitHub Secret (e.g., PASSPHRASE) [1][2]. 3. Pass these secrets into the action's with: block [1][2]. The action automatically seeds the gpg-agent with the provided passphrase, allowing subsequent Git operations to use the key without manual interaction [1][2]. Regarding security and best practices: - Commit SHA Pinning: To protect your CI/CD pipeline against supply chain attacks (such as tag-based mutable ref poisoning), you should pin the action to a specific commit SHA rather than a branch or tag version (e.g., uses: crazy-max/ghaction-import-gpg@<40-char-sha>) [3][4]. - Secret Masking: GitHub automatically masks secrets defined in your workflow [5][6]. When using this action, the passphrase and private key are handled as secrets and will be redacted in logs [5][6]. However, avoid logging these values manually [6]. - No PIN requirement: The action does not require a "PIN" in the traditional hardware-security-module (HSM) sense; it manages GPG-agent caching for you, which eliminates the need for interactive passphrase prompts [1][2]. - Scope: The action configures the runner's local environment. If your workflow involves building and running code in separate Docker containers (e.g., via other custom actions), ensure those environments are also configured to access the imported GPG key, as the configuration does not persist automatically across container boundaries [7]. Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
file=".github/workflows/maven-build.yml"
# Print the relevant section with line numbers without relying on `nl`
awk 'NR>=45 && NR<=70 {printf "%d\t%s\n", NR, $0}' "$file"Repository: mosip/kattu Length of output: 2491 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Find all occurrences of the action to ensure only the expected one exists
rg -n "crazy-max/ghaction-import-gpg@v6|crazy-max/ghaction-import-gpg@" .github/workflows || trueRepository: mosip/kattu Length of output: 324 🏁 Script executed: #!/bin/bash
# Dereference the v6 tag to a commit SHA
gh api repos/crazy-max/ghaction-import-gpg/git/refs/tags/v6 \
--jq '.object.type + " " + .object.sha'
# If type is "tag" (annotated), dereference once more:
# gh api repos/crazy-max/ghaction-import-gpg/git/tags/<sha-from-above> --jq '.object.sha'Repository: mosip/kattu Length of output: 103 Pin
🔒 Pin to a SHA - name: Import GPG key
- uses: crazy-max/ghaction-import-gpg@v6
+ uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_SECRET }}(Also used as 📝 Committable suggestion
Suggested change
🧰 Tools🪛 zizmor (1.25.2)[error] 53-53: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy) (unpinned-uses) 🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Install xmlstartlet and xmllint | ||||||||||||||||||||||
| run: | | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: mosip/kattu
Length of output: 37
🏁 Script executed:
Repository: mosip/kattu
Length of output: 169
🏁 Script executed:
Repository: mosip/kattu
Length of output: 11781
🏁 Script executed:
Repository: mosip/kattu
Length of output: 2286
🏁 Script executed:
Repository: mosip/kattu
Length of output: 216
🏁 Script executed:
Repository: mosip/kattu
Length of output: 37
🏁 Script executed:
Repository: mosip/kattu
Length of output: 731
🏁 Script executed:
Repository: mosip/kattu
Length of output: 12563
Require
GPG_PRIVATE_KEYin all callers (and fix README example) —maven-build.ymlconsumes it.github/workflows/maven-build.ymldeclaresworkflow_call.secrets.GPG_PRIVATE_KEY: required: true(lines 21-22) and passes it tocrazy-max/ghaction-import-gpg@v6asgpg_private_key(lines 52-56). Callers must supplysecrets.GPG_PRIVATE_KEY. In this repo’sdocs/maven-build-readme.mdexample,secrets:includesGPG_SECRETbut omitsGPG_PRIVATE_KEY, so the example would fail as written.Also consider pinning
crazy-max/ghaction-import-gpgto a commit SHA instead of a floatingv6tag.🤖 Prompt for AI Agents