Skip to content

Commit

Permalink
Merge pull request #1915 from headlamp-k8s/workflow-permissions
Browse files Browse the repository at this point in the history
github: Fix permissions so they are minimal
  • Loading branch information
joaquimrocha committed Apr 18, 2024
2 parents 79300da + b2c5cd5 commit ccf663a
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/app-artifacts-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ on:
required: true
default: 'main'

permissions:
contents: read

jobs:
build-linux:
runs-on: ubuntu-latest
permissions:
actions: write # needed to upload artifacts
contents: write
steps:
- uses: actions/checkout@v4
with:
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/app-artifacts-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ on:
description: Notarize app
default: true
type: boolean

permissions:
contents: read

jobs:
build-mac:
runs-on: macos-latest
permissions:
contents: read
secrets: read
actions: write # needed to upload artifacts
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -61,8 +69,9 @@ jobs:
retention-days: 1
notarize:
permissions:
id-token: write
id-token: write # For fetching an OpenID Connect (OIDC) token
contents: read
secrets: read
runs-on: windows-latest
needs: build-mac
if: ${{ inputs.signBinaries }}
Expand Down Expand Up @@ -135,6 +144,9 @@ jobs:
stapler:
runs-on: macos-latest
needs: notarize
permissions:
actions: write # for downloading and uploading artifacts
contents: read
if: ${{ inputs.signBinaries }}
steps:
- name: Download artifact
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/app-artifacts-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ on:
default: true
type: boolean

permissions:
contents: read

jobs:
build-windows:
permissions:
id-token: write
id-token: write # For fetching an OpenID Connect (OIDC) token
contents: read
actions: write # needed to upload artifacts
runs-on: windows-2022
steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ on:
- 'app/**'
- 'backend/**'

permissions:
contents: read

jobs:
build-linux:
runs-on: ubuntu-22.04
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/backend-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,31 @@ on:

permissions:
contents: read
# We need to write a comment for the coverage change message.
issues: write

env:
HEADLAMP_RUN_INTEGRATION_TESTS: true

jobs:
build:
runs-on: ubuntu-latest

permissions:
issues: write # needed for commenting on PRs for coverage changes
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version: 1.22.0
go-version: '1.22.*'

- name: Install dependencies
run: |
cd backend
go mod download
- name: Start cluster
uses: medyagh/setup-minikube@master
uses: medyagh/setup-minikube@latest

- name: Check cluster status and enable headlamp addon
run: |
Expand Down Expand Up @@ -103,4 +102,4 @@ jobs:
echo "Pull request raised from a fork. Skipping comment."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
3 changes: 3 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
- Makefile
- '.github/**'

permissions:
contents: read

jobs:

build:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ on:
- Dockerfile.plugins
- 'e2e-tests/**'

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
name: build discover and deploy
permissions:
actions: write # needed to upload artifacts
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Start cluster
uses: medyagh/setup-minikube@master
uses: medyagh/setup-minikube@latest
# now you can run kubectl to see the pods in the cluster
- name: Try the cluster!
run: kubectl get pods -A
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/container-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
description: 'Container tags (separated by a comma)'
type: string

permissions:
contents: read

env:
REGISTRY: ghcr.io
IMAGE_NAME: headlamp-k8s/headlamp
Expand All @@ -21,8 +24,7 @@ jobs:
name: Test building container image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
packages: write # needed for publishing the container image
steps:
- name: Check out the repo
uses: actions/checkout@v4
Expand Down Expand Up @@ -71,7 +73,7 @@ jobs:
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
password: ${{ github.token }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/docker-extension-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ on:
- completed
workflow_dispatch:

permissions:
contents: read

env:
REGISTRY: docker.io
IMAGE_NAME: headlamp/headlamp-docker-extension
jobs:
build_and_push_docker_extension:
name: Build docker extension
runs-on: ubuntu-latest
permissions:
secrets: read # needed to fetch docker hub creds
steps:
- name: Login to DockerHub
uses: docker/login-action@v1
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
required: true
default: 'X.Y.Z'

permissions:
contents: read

jobs:
build:
permissions:
Expand All @@ -18,7 +21,7 @@ jobs:
- name: Create Release Draft
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ github.token }}
draft: true
name: ${{ github.event.inputs.releaseName }}
body: |
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ on:
- 'app/**'
- 'plugins/**'

permissions:
contents: read

jobs:
build:

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/helm-chart-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- charts/**
- '!charts/**/README.md'

permissions:
contents: read

jobs:
lint-test:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -39,7 +42,7 @@ jobs:
run: ct lint --config .github/ct.yaml

- name: Setup Minikube
uses: medyagh/setup-minikube@master
uses: medyagh/setup-minikube@latest

- name: Build image & Run chart-testing (install)
run: |
Expand Down
20 changes: 12 additions & 8 deletions .github/workflows/helm-chart-release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Release Charts

# See https://github.com/helm/chart-releaser-action

on:
push:
branches:
Expand All @@ -9,10 +11,14 @@ on:
- '!charts/**/README.md'
# For manual dispatch
workflow_dispatch:

permissions:
contents: read

jobs:
release:
permissions:
contents: write
contents: write # need to write a commit to the repo
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand All @@ -26,14 +32,12 @@ jobs:
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.4.0

uses: azure/setup-helm@v3

- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.2.1
uses: helm/chart-releaser-action@v1.6.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_TOKEN: "${{ github.token }}"
with:
config: .github/cr.yaml

mark_as_latest: false # only headlamp is set to latest
6 changes: 6 additions & 0 deletions .github/workflows/pr-to-update-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ on:
- completed
workflow_dispatch:

permissions:
contents: read

env:
LATEST_HEADLAMP_TAG: latest
jobs:
create_pr_to_upgrade_chart:
name: Create PR to update Headlamp's version in the Helm Chart
runs-on: ubuntu-latest
permissions:
contents: write # needed to push a branch
pull-requests: write # needed to open a pull request
steps:
- name: Checkout headlamp repo
uses: actions/checkout@v4
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pr-to-update-homebrew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ jobs:
create_pr_to_upgrade_homebrew:
name: Create PR to upgrade homebrew
runs-on: ubuntu-latest
permissions:
contents: write # needed to push a branch
pull-requests: write # needed to open a pull request
secrets: read

steps:
- name: Checkout headlamp repo
uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/pr-to-update-minikube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ on:
- completed
workflow_dispatch:

permissions:
contents: read

env:
LATEST_HEADLAMP_TAG: latest
jobs:
create_pr_to_upgrade_minikube:
name: Create PR to upgrade minikube
runs-on: ubuntu-latest
permissions:
contents: write # needed to push a branch
pull-requests: write # needed to open a pull request
steps:
- name: Checkout headlamp repo
uses: actions/checkout@v4
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/trigger-flatpak-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ on:
- 'v*'
workflow_dispatch:

permissions:
contents: read

jobs:
trigger_flatpak_update:
name: Trigger Flatpak Headlamp version update
runs-on: ubuntu-latest

permissions:
secrets: read # needed to fetch gh token

steps:
- name: Trigger via gh
env:
Expand Down

0 comments on commit ccf663a

Please sign in to comment.