Skip to content

Commit d6b47e3

Browse files
Add permissions to GitHub Actions
1 parent d5467b5 commit d6b47e3

File tree

8 files changed

+60
-6
lines changed

8 files changed

+60
-6
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ updates:
1717
applies-to: version-updates
1818
patterns:
1919
- "mstest*"
20-
EntityFrameworkCore:
20+
- "Microsoft.NET.Test.Sdk"
21+
- "coverlet*"
22+
- "Testcontainers*"
23+
Framework:
2124
applies-to: version-updates
2225
patterns:
2326
- "Microsoft.EntityFrameworkCore*"
27+
- "Microsoft.Extensions*"
28+
- "Microsoft.AspNetCore*"
2429

2530
- package-ecosystem: "github-actions"
2631
directory: "/"

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ defaults:
1212
shell: pwsh
1313
jobs:
1414
build:
15+
permissions:
16+
contents: read
1517
services:
1618
mssql:
1719
image: mcr.microsoft.com/mssql/server:2022-latest

.github/workflows/create_env.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ defaults:
4040
shell: pwsh
4141
jobs:
4242
determine_resourcegroup:
43+
permissions:
44+
contents: read
4345
runs-on: ubuntu-latest
4446
outputs:
4547
resourcegroup: ${{ steps.setupResourcegroup.outputs.resourcegroup }}
@@ -53,6 +55,7 @@ jobs:
5355
permissions:
5456
id-token: write
5557
contents: read
58+
deployments: write
5659
runs-on: ubuntu-latest
5760
needs: determine_resourcegroup
5861
outputs:

.github/workflows/delete_env.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
permissions:
1414
id-token: write
1515
contents: read
16+
deployments: write
1617
runs-on: ubuntu-latest
1718
environment: AzureRemove
1819
steps:

.github/workflows/deploy_db.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
id-token: write
2626
contents: read
27+
deployments: write
2728
runs-on: ubuntu-latest
2829
environment: AzureDeploy
2930
steps:

.github/workflows/main.docker.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ defaults:
2424
shell: pwsh
2525
jobs:
2626
determine_variables:
27+
permissions:
28+
contents: read
2729
runs-on: ubuntu-latest
2830
outputs:
2931
buildConfiguration: ${{ steps.setupVars.outputs.buildConfiguration }}
@@ -40,14 +42,19 @@ jobs:
4042
echo "buildConfiguration=Release" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
4143
}
4244
43-
build:
45+
build:
46+
permissions:
47+
contents: read
4448
needs: [determine_variables]
4549
uses: ./.github/workflows/build.yml
4650
with:
4751
buildConfiguration: ${{needs.determine_variables.outputs.buildConfiguration}}
4852
secrets: inherit
4953

5054
validate_env:
55+
permissions:
56+
contents: read
57+
id-token: write
5158
needs: [build]
5259
uses: ./.github/workflows/create_env.yml
5360
with:
@@ -58,6 +65,8 @@ jobs:
5865
secrets: inherit
5966

6067
dockerfile_artifact:
68+
permissions:
69+
contents: read
6170
runs-on: ubuntu-latest
6271
steps:
6372
- uses: actions/checkout@v5
@@ -71,16 +80,16 @@ jobs:
7180

7281
push_docker_image:
7382
if: inputs.buildConfiguration != ''
83+
permissions:
84+
contents: read
85+
packages: write
7486
runs-on: ubuntu-latest
7587
outputs:
7688
dockerTag: ${{ steps.createTag.outputs.dockerTag }}
7789
env:
7890
REGISTRY: ghcr.io
7991
DOCKER_BUILD_SUMMARY: false
8092
DOCKER_BUILD_RECORD_UPLOAD: false
81-
permissions:
82-
contents: read
83-
packages: write
8493
needs: [validate_env, dockerfile_artifact, determine_variables]
8594
steps:
8695
- uses: actions/download-artifact@v6
@@ -121,6 +130,9 @@ jobs:
121130
tags: ${{ steps.createTag.outputs.dockerTag }}
122131

123132
create_env:
133+
permissions:
134+
contents: read
135+
id-token: write
124136
needs: [build, push_docker_image]
125137
uses: ./.github/workflows/create_env.yml
126138
with:
@@ -131,6 +143,9 @@ jobs:
131143
secrets: inherit
132144

133145
deploy_db:
146+
permissions:
147+
contents: read
148+
id-token: write
134149
needs: [build, create_env]
135150
uses: ./.github/workflows/deploy_db.yml
136151
with:
@@ -139,12 +154,17 @@ jobs:
139154
secrets: inherit
140155

141156
smoketests:
157+
permissions:
158+
contents: read
142159
needs: [deploy_db, create_env]
143160
uses: ./.github/workflows/smoketests.yml
144161
with:
145162
webAppUrl: ${{needs.create_env.outputs.webAppUrl}}
146163

147164
delete_env:
165+
permissions:
166+
contents: read
167+
id-token: write
148168
needs: [create_env, smoketests]
149169
uses: ./.github/workflows/delete_env.yml
150170
with:

.github/workflows/main.nodocker.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ defaults:
2424
shell: pwsh
2525
jobs:
2626
determine_variables_build:
27+
permissions:
28+
contents: read
2729
runs-on: ubuntu-latest
2830
outputs:
2931
buildConfiguration: ${{ steps.setupVars.outputs.buildConfiguration }}
@@ -38,14 +40,19 @@ jobs:
3840
echo "buildConfiguration=Release" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
3941
}
4042
41-
build:
43+
build:
44+
permissions:
45+
contents: read
4246
needs: [determine_variables_build]
4347
uses: ./.github/workflows/build.yml
4448
with:
4549
buildConfiguration: ${{needs.determine_variables_build.outputs.buildConfiguration}}
4650
secrets: inherit
4751

4852
validate:
53+
permissions:
54+
contents: read
55+
id-token: write
4956
needs: [build]
5057
uses: ./.github/workflows/create_env.yml
5158
with:
@@ -56,6 +63,9 @@ jobs:
5663
secrets: inherit
5764

5865
create_env:
66+
permissions:
67+
contents: read
68+
id-token: write
5969
if: inputs.buildConfiguration != ''
6070
needs: [validate]
6171
uses: ./.github/workflows/create_env.yml
@@ -73,6 +83,7 @@ jobs:
7383
permissions:
7484
id-token: write
7585
contents: read
86+
deployments: write
7687
steps:
7788
- name: Download a Build Artifact
7889
uses: actions/download-artifact@v6
@@ -94,6 +105,9 @@ jobs:
94105
az webapp config set --startup-file="dotnet TodoItems.Api.dll" --name ${{ needs.create_env.outputs.webAppName }} --resource-group ${{ needs.create_env.outputs.resourcegroup }}
95106
96107
deploy_db:
108+
permissions:
109+
contents: read
110+
id-token: write
97111
needs: [build, create_env]
98112
uses: ./.github/workflows/deploy_db.yml
99113
with:
@@ -102,12 +116,17 @@ jobs:
102116
secrets: inherit
103117

104118
smoketests:
119+
permissions:
120+
contents: read
105121
needs: [deploy_app, create_env, deploy_db]
106122
uses: ./.github/workflows/smoketests.yml
107123
with:
108124
webAppUrl: ${{needs.create_env.outputs.webAppUrl}}
109125

110126
delete_env:
127+
permissions:
128+
contents: read
129+
id-token: write
111130
needs: [create_env, smoketests]
112131
uses: ./.github/workflows/delete_env.yml
113132
with:

.github/workflows/smoketests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ defaults:
1010
shell: pwsh
1111
jobs:
1212
smoke_tests:
13+
permissions:
14+
contents: read
15+
deployments: write
1316
runs-on: ubuntu-latest
1417
environment: AzureProvision
1518
steps:

0 commit comments

Comments
 (0)