Skip to content

Commit b577f38

Browse files
harden release workflow security
- Move permissions from workflow level to job level (least privilege) - Replace deprecated ::set-output with GITHUB_OUTPUT - Fix script injection by moving inputs to env vars in run steps - Replace PERSONAL_ACCESS_TOKEN with GITHUB_TOKEN - Update action pins: checkout v6.0.3, setup-node v6.4.0, octokit/request-action v3.0.0 - Comment out notify and dispatch_auto_release jobs
1 parent 5553319 commit b577f38

1 file changed

Lines changed: 54 additions & 40 deletions

File tree

.github/workflows/release.yml

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,32 @@ on:
3535
type: boolean
3636

3737
permissions:
38-
id-token: write
39-
contents: write
40-
packages: write
38+
contents: read
4139

4240
jobs:
4341
delete:
42+
permissions:
43+
contents: write
44+
packages: write
4445
uses: Checkmarx/ast-cli-javascript-wrapper-runtime-cli/.github/workflows/delete-packages-and-releases.yml@main
4546
with:
4647
tag: ${{ inputs.jsTag }}
4748
secrets: inherit
4849
if: inputs.dev == true
4950
release:
51+
permissions:
52+
id-token: write
53+
contents: write
54+
packages: write
5055
runs-on: cx-public-ubuntu-x64
5156
env:
52-
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5358
BRANCH_NAME: npm-version-patch
5459
outputs:
5560
TAG_NAME: ${{ steps.generate_tag_name.outputs.TAG_NAME }}
5661
CLI_VERSION: ${{ steps.extract_cli_version.outputs.CLI_VERSION }}
5762
steps:
58-
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
63+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
5964
with:
6065
fetch-depth: 0
6166

@@ -64,36 +69,43 @@ jobs:
6469
git config user.name github-actions
6570
git config user.email github-actions@github.com
6671
67-
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
72+
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
6873
with:
6974
node-version: 22.11.0
7075
registry-url: https://npm.pkg.github.com/
7176

7277
- name: Generate Tag name
7378
id: generate_tag_name
79+
env:
80+
INPUT_DEV: ${{ inputs.dev }}
81+
INPUT_JS_TAG: ${{ inputs.jsTag }}
7482
run: |
75-
if [ "${{ inputs.dev }}" == "true" ]; then
76-
TAG_NAME=$(npm version prerelease --preid=${{ inputs.jsTag }} --no-git-tag-version --allow-same-version)
83+
if [ "$INPUT_DEV" == "true" ]; then
84+
TAG_NAME=$(npm version prerelease --preid="$INPUT_JS_TAG" --no-git-tag-version --allow-same-version)
7785
else
7886
TAG_NAME=$(npm version patch --no-git-tag-version)
7987
fi
80-
88+
8189
echo "Generated TAG_NAME: $TAG_NAME"
8290
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
83-
echo "::set-output name=TAG_NAME::$TAG_NAME"
91+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
8492
8593
- name: Extract CLI version
8694
id: extract_cli_version
8795
run: |
8896
CLI_VERSION=$(cat checkmarx-ast-cli.version | grep -Eo '^[0-9]+\.[0-9]+\.[0-9]+')
8997
echo "CLI version being packed is $CLI_VERSION"
9098
echo "CLI_VERSION=$CLI_VERSION" >> $GITHUB_ENV
91-
echo "::set-output name=CLI_VERSION::$CLI_VERSION"
99+
echo "CLI_VERSION=$CLI_VERSION" >> $GITHUB_OUTPUT
92100
93101
- name: Check if CLI version is latest
94102
id: check_latest_cli_version
103+
env:
104+
INPUT_DEV: ${{ inputs.dev }}
105+
INPUT_CLI_TAG: ${{ inputs.cliTag }}
106+
GIT_REF: ${{ github.ref }}
95107
run: |
96-
if [ "${{ inputs.dev }}" == "false" ] || [ -n "${{ inputs.cliTag }}" ] || [ "${{ github.ref }}" != "refs/heads/main" ]; then
108+
if [ "$INPUT_DEV" == "false" ] || [ -n "$INPUT_CLI_TAG" ] || [ "$GIT_REF" != "refs/heads/main" ]; then
97109
exit 0
98110
fi
99111
@@ -125,13 +137,13 @@ jobs:
125137
- name: Wait for PR to be created
126138
id: pr
127139
if: inputs.dev == false
128-
uses: octokit/request-action@872c5c97b3c85c23516a572f02b31401ef82415d #v2.3.1
140+
uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0
129141
with:
130142
route: GET /repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ env.BRANCH_NAME }}
131143

132144
- name: Merge Pull Request
133145
if: inputs.dev == false
134-
uses: octokit/request-action@872c5c97b3c85c23516a572f02b31401ef82415d #v2.3.1
146+
uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0
135147
with:
136148
route: PUT /repos/${{ github.repository }}/pulls/${{ steps.create_pr.outputs.pull-request-number }}/merge
137149
merge_method: squash
@@ -144,14 +156,16 @@ jobs:
144156
git push --tags
145157
146158
- name: Publish npm package
159+
env:
160+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
161+
INPUT_DEV: ${{ inputs.dev }}
162+
INPUT_JS_TAG: ${{ inputs.jsTag }}
147163
run: |
148-
if [ ${{ inputs.dev }} == true ]; then
149-
npm publish --tag=${{ inputs.jsTag }}
164+
if [ "$INPUT_DEV" == "true" ]; then
165+
npm publish --tag="$INPUT_JS_TAG"
150166
else
151167
npm publish --access public
152168
fi
153-
env:
154-
NODE_AUTH_TOKEN: ${{secrets.PERSONAL_ACCESS_TOKEN}}
155169
156170
- name: Create Release
157171
uses: step-security/action-gh-release@277bfa82abcfdb73e5bbb19e213fd76532ee2be5 # v3.0.0
@@ -161,26 +175,26 @@ jobs:
161175
generate_release_notes: true
162176
prerelease: ${{ inputs.dev }}
163177

164-
notify:
165-
if: inputs.dev == false
166-
needs: release
167-
uses: Checkmarx/plugins-release-workflow/.github/workflows/release-notify.yml@main
168-
with:
169-
product_name: Javascript Runtime Wrapper
170-
release_version: ${{ needs.release.outputs.TAG_NAME }}
171-
cli_release_version: ${{ needs.release.outputs.CLI_VERSION }}
172-
release_author: "Sypher Team"
173-
release_url: https://github.com/Checkmarx/ast-cli-javascript-wrapper-runtime-cli/releases/tag/${{ needs.release.outputs.TAG_NAME }}
174-
jira_product_name: JS_RUNTIME_WRAPPER
175-
secrets: inherit
178+
# notify:
179+
# if: inputs.dev == false
180+
# needs: release
181+
# uses: Checkmarx/plugins-release-workflow/.github/workflows/release-notify.yml@main
182+
# with:
183+
# product_name: Javascript Runtime Wrapper
184+
# release_version: ${{ needs.release.outputs.TAG_NAME }}
185+
# cli_release_version: ${{ needs.release.outputs.CLI_VERSION }}
186+
# release_author: "Sypher Team"
187+
# release_url: https://github.com/Checkmarx/ast-cli-javascript-wrapper-runtime-cli/releases/tag/${{ needs.release.outputs.TAG_NAME }}
188+
# jira_product_name: JS_RUNTIME_WRAPPER
189+
# secrets: inherit
176190

177-
dispatch_auto_release:
178-
name: Update ADO Extension With new Wrapper Version
179-
if: inputs.dev == false
180-
needs: notify
181-
uses: Checkmarx/plugins-release-workflow/.github/workflows/dispatch-workflow.yml@main
182-
with:
183-
cli_version: ${{ needs.release.outputs.CLI_VERSION }}
184-
is_cli_release: false
185-
is_js_runtime_release: true
186-
secrets: inherit
191+
# dispatch_auto_release:
192+
# name: Update ADO Extension With new Wrapper Version
193+
# if: inputs.dev == false
194+
# needs: notify
195+
# uses: Checkmarx/plugins-release-workflow/.github/workflows/dispatch-workflow.yml@main
196+
# with:
197+
# cli_version: ${{ needs.release.outputs.CLI_VERSION }}
198+
# is_cli_release: false
199+
# is_js_runtime_release: true
200+
# secrets: inherit

0 commit comments

Comments
 (0)