Skip to content

Commit 956a062

Browse files
authored
🧹 Set default workflow permissions (#6369)
This addresses the CodeQL alerts: https://github.com/mondoohq/cnquery/security/code-scanning This sets default permissions on the workflow level. The various jobs have extended permissions when needed. Signed-off-by: Christian Zunker <christian@mondoo.com>
1 parent 017861f commit 956a062

14 files changed

+128
-84
lines changed

.github/workflows/cla.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ on:
66
pull_request_target:
77
types: [opened, closed, synchronize]
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
CLAssistant:
1114
runs-on: ubuntu-latest
15+
permissions:
16+
actions: write
17+
contents: write
18+
pull-requests: write
19+
statuses: write
1220
steps:
1321
- name: "CLA Assistant"
1422
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the Mondoo CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'

.github/workflows/codeql.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ on:
1919
schedule:
2020
- cron: "30 17 * * *"
2121

22+
permissions:
23+
contents: read
24+
2225
jobs:
2326
analyze:
2427
name: Analyze (${{ matrix.language }})

.github/workflows/goreleaser-edge.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ name: goreleaser edge containers
33
on:
44
push:
55
branches:
6-
- 'main'
6+
- "main"
77
workflow_dispatch:
88

99
env:
1010
REGISTRY: docker.io
1111

12+
permissions:
13+
contents: read
14+
1215
jobs:
1316
goreleaser:
1417
permissions:
1518
# Add "contents" to write release
16-
contents: 'write'
19+
contents: "write"
1720
# Add "id-token" for google-github-actions/auth
18-
id-token: 'write'
21+
id-token: "write"
1922

2023
runs-on:
2124
group: Default
@@ -40,7 +43,7 @@ jobs:
4043
with:
4144
repo-token: ${{ secrets.GITHUB_TOKEN }}
4245
version: ${{ env.protoc-version }}
43-
46+
4447
- name: Log in to the Container registry
4548
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
4649
with:
@@ -52,7 +55,7 @@ jobs:
5255
run: |
5356
VERSION=$(make version)
5457
git tag ${VERSION/\+/-}
55-
58+
5659
- name: Run GoReleaser
5760
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
5861
with:

.github/workflows/goreleaser.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: goreleaser
33
on:
44
push:
55
tags:
6-
- '*'
6+
- "*"
77
workflow_dispatch:
88
inputs:
99
skip-publish:
10-
description: 'Skip publishing to releases.mondoo.com?'
10+
description: "Skip publishing to releases.mondoo.com?"
1111
type: boolean
1212
required: false
1313
default: false
@@ -17,7 +17,7 @@ on:
1717
default: false
1818
type: boolean
1919
goreleaser-snapshot:
20-
description: 'Run goreleaser in snapshot mode, which will not publish and bypass tag checks.'
20+
description: "Run goreleaser in snapshot mode, which will not publish and bypass tag checks."
2121
required: false
2222
default: false
2323
type: boolean
@@ -30,13 +30,16 @@ on:
3030
env:
3131
REGISTRY: docker.io
3232

33+
permissions:
34+
contents: read
35+
3336
jobs:
3437
goreleaser:
3538
permissions:
3639
# Add "contents" to write release
37-
contents: 'write'
40+
contents: "write"
3841
# Add "id-token" for google-github-actions/auth
39-
id-token: 'write'
42+
id-token: "write"
4043

4144
runs-on:
4245
group: Default
@@ -61,7 +64,7 @@ jobs:
6164
6265
- name: Import environment variables from file
6366
run: cat ".github/env" >> $GITHUB_ENV
64-
67+
6568
- name: Set up Go
6669
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
6770
with:
@@ -74,8 +77,8 @@ jobs:
7477
repo-token: ${{ secrets.GITHUB_TOKEN }}
7578
version: ${{ env.protoc-version }}
7679

77-
- name: 'Authenticate to Google Cloud'
78-
uses: 'google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093' # v3.0.0
80+
- name: "Authenticate to Google Cloud"
81+
uses: "google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093" # v3.0.0
7982
with:
8083
workload_identity_provider: ${{ secrets.GCP_WIP }}
8184
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
@@ -86,10 +89,10 @@ jobs:
8689
base64 -d <<<"$GPG_KEY" > "$gpgkey"
8790
echo "GPG_KEY_PATH=$gpgkey" >> $GITHUB_ENV
8891
env:
89-
GPG_KEY: '${{ secrets.GPG_KEY}}'
92+
GPG_KEY: "${{ secrets.GPG_KEY}}"
9093

91-
# jsign and azure-cli are both requirements for Azure Trusted Signing and these actions to authenticate
92-
# These packages have been installed on the self-hosted runner using ansible from the private repo
94+
# jsign and azure-cli are both requirements for Azure Trusted Signing and these actions to authenticate
95+
# These packages have been installed on the self-hosted runner using ansible from the private repo
9396

9497
- name: Azure login
9598
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
@@ -112,11 +115,10 @@ jobs:
112115
echo "Access token prefix: ${PREFIX}..."
113116
echo "TSIGN_ACCESS_TOKEN=$TSIGN_ACCESS_TOKEN" >> $GITHUB_OUTPUT
114117
115-
116118
- name: Install Quill for Mac Signing and Notarization
117119
run: |
118-
curl -sSfL https://raw.githubusercontent.com/anchore/quill/main/install.sh | sh -s -- -b /tmp
119-
/tmp/quill help
120+
curl -sSfL https://raw.githubusercontent.com/anchore/quill/main/install.sh | sh -s -- -b /tmp
121+
/tmp/quill help
120122
121123
- name: Log in to the Container registry
122124
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
@@ -149,7 +151,7 @@ jobs:
149151
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
150152
CERT_PASSWORD: ${{ steps.gcp_secrets.outputs.code_sign_cert_challenge }}
151153
NFPM_DEFAULT_RPM_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
152-
QUILL_SIGN_PASSWORD: ''
154+
QUILL_SIGN_PASSWORD: ""
153155
QUILL_SIGN_P12: ${{ secrets.APPLE_SIGN_P12 }}
154156
QUILL_NOTARY_KEY: ${{ secrets.APPLE_NOTARY_KEY }}
155157
QUILL_NOTARY_KEY_ID: ${{ secrets.APPLE_NOTARY_KEY_ID }}
@@ -175,7 +177,7 @@ jobs:
175177
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176178
CERT_PASSWORD: ${{ steps.gcp_secrets.outputs.code_sign_cert_challenge }}
177179
NFPM_DEFAULT_RPM_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
178-
QUILL_SIGN_PASSWORD: ''
180+
QUILL_SIGN_PASSWORD: ""
179181
QUILL_SIGN_P12: ${{ secrets.APPLE_SIGN_P12 }}
180182
QUILL_NOTARY_KEY: ${{ secrets.APPLE_NOTARY_KEY }}
181183
QUILL_NOTARY_KEY_ID: ${{ secrets.APPLE_NOTARY_KEY_ID }}
@@ -217,5 +219,5 @@ jobs:
217219
repository: "mondoohq/cnspec"
218220
event-type: update-cnquery
219221
client-payload: '{
220-
"version": "${{ github.ref_name }}"
222+
"version": "${{ github.ref_name }}"
221223
}'

.github/workflows/license.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: License Test
33
on:
44
push:
55

6+
permissions:
7+
contents: read
8+
69
jobs:
710
license-check:
811
runs-on: ubuntu-latest

.github/workflows/link-check.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ name: Link Checking
66
push:
77
branches: [main]
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
md-links:
1114
name: Run markdown link check

.github/workflows/pr-extended-linting.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ name: Extended Linting
44
on:
55
pull_request:
66
paths:
7-
- '**.go'
8-
- '**.mod'
9-
- 'go.sum'
7+
- "**.go"
8+
- "**.mod"
9+
- "go.sum"
10+
11+
permissions:
12+
contents: read
1013

1114
jobs:
1215
golangci-lint:
@@ -27,7 +30,7 @@ jobs:
2730
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
2831
with:
2932
go-version: ">=${{ env.golang-version }}"
30-
cache: false
33+
cache: false
3134
- name: Generate test files
3235
run: make test/generate
3336
- name: Run golangci-lint

.github/workflows/pr-test-generated-files.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ name: Generated Code Test
44
on:
55
push:
66
paths:
7-
- '**.proto'
8-
- '**.lr'
9-
- '**.go'
7+
- "**.proto"
8+
- "**.lr"
9+
- "**.go"
1010

1111
env:
1212
PROTO_VERSION: "21.7"
1313

14+
permissions:
15+
contents: read
16+
1417
jobs:
1518
# Check if there is any dirty change for generated files
1619
generated-files:
@@ -32,10 +35,10 @@ jobs:
3235
# We do not permit sudo on self-hosted runners
3336
- name: "Ensure GCC is installed"
3437
run: |
35-
if gcc --version; then
36-
echo "Good to go";
37-
else
38-
echo "Install GCC on the runner.";
38+
if gcc --version; then
39+
echo "Good to go";
40+
else
41+
echo "Install GCC on the runner.";
3942
fi
4043
4144
# Note we do not use apt install -y protobuf-compiler` since it is too old

.github/workflows/pr-test-lint.yml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ name: Code Test
44
on:
55
push:
66
paths:
7-
- '**.go'
8-
- '**.mod'
9-
- 'go.sum'
10-
- 'Makefile'
11-
- '.github/workflows/pr-test-lint.yml'
12-
- '**.toml' # run tests when any recording changed
7+
- "**.go"
8+
- "**.mod"
9+
- "go.sum"
10+
- "Makefile"
11+
- ".github/workflows/pr-test-lint.yml"
12+
- "**.toml" # run tests when any recording changed
13+
14+
permissions:
15+
contents: read
1316

1417
jobs:
1518
# Check if there is any dirty change for go mod tidy
@@ -77,8 +80,8 @@ jobs:
7780
go-version: ">=${{ env.golang-version }}"
7881
cache: false
7982

80-
- name: 'Set up gcloud CLI'
81-
uses: 'google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db' # v3.0.1
83+
- name: "Set up gcloud CLI"
84+
uses: "google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db" # v3.0.1
8285

8386
- name: Set provider env
8487
run: echo "PROVIDERS_PATH=${PWD}/.providers" >> $GITHUB_ENV
@@ -92,10 +95,10 @@ jobs:
9295
run: make providers/test
9396

9497
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
95-
if: success() || failure() # run this step even if previous step failed
98+
if: success() || failure() # run this step even if previous step failed
9699
with:
97100
name: test-results
98-
path: '*.xml'
101+
path: "*.xml"
99102

100103
go-test-integration:
101104
runs-on:
@@ -114,8 +117,8 @@ jobs:
114117
go-version: ">=${{ env.golang-version }}"
115118
cache: false
116119

117-
- name: 'Set up gcloud CLI'
118-
uses: 'google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db' # v3.0.1
120+
- name: "Set up gcloud CLI"
121+
uses: "google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db" # v3.0.1
119122

120123
- name: Set provider env
121124
run: echo "PROVIDERS_PATH=${PWD}/.providers" >> $GITHUB_ENV
@@ -126,7 +129,7 @@ jobs:
126129
run: make test/integration
127130

128131
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
129-
if: success() || failure() # run this step even if previous step failed
132+
if: success() || failure() # run this step even if previous step failed
130133
with:
131134
name: test-results-cli
132135
path: report.xml
@@ -182,7 +185,7 @@ jobs:
182185
uses: benchmark-action/github-action-benchmark@4bdcce38c94cec68da58d012ac24b7b1155efe8b # v1.20.7
183186
with:
184187
# What benchmark tool the output.txt came from
185-
tool: 'go'
188+
tool: "go"
186189
# Where the output from the benchmark tool is stored
187190
output-file-path: benchmark.txt
188191
# Where the previous data file is stored
@@ -192,7 +195,7 @@ jobs:
192195
summary-always: true
193196
fail-on-alert: true
194197
save-data-file: false
195-
alert-threshold: '150%'
198+
alert-threshold: "150%"
196199

197200
go-auto-approve:
198201
runs-on: ubuntu-latest
@@ -228,13 +231,13 @@ jobs:
228231
gh pr merge ${{ steps.pr.outputs.number }} --squash
229232
env:
230233
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
231-
234+
232235
event_file:
233236
name: "Store event file"
234237
runs-on: ubuntu-latest
235238
steps:
236-
- name: Upload
237-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
238-
with:
239-
name: Event File
240-
path: ${{ github.event_path }}
239+
- name: Upload
240+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
241+
with:
242+
name: Event File
243+
path: ${{ github.event_path }}

.github/workflows/providers.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ on:
2222
default: false
2323
type: boolean
2424

25+
permissions:
26+
contents: read
27+
2528
env:
2629
BUCKET: releases-us.mondoo.io
2730
SKIP_PROVIDERS: "core"

0 commit comments

Comments
 (0)