From 3b499f0666a2a1147bcbcf1cca25661386a4ccaa Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Sat, 1 Jun 2024 02:47:42 +0000 Subject: [PATCH] chore(ci): use native permissions instead of LAVAMOAT_UPDATE_TOKEN the token is no longer necessary and permissions can be configured on the workflow --- .../workflows/update-lavamoat-policies.yml | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/.github/workflows/update-lavamoat-policies.yml b/.github/workflows/update-lavamoat-policies.yml index 80615df8f1ce..40505fbd447b 100644 --- a/.github/workflows/update-lavamoat-policies.yml +++ b/.github/workflows/update-lavamoat-policies.yml @@ -11,13 +11,17 @@ jobs: runs-on: ubuntu-latest outputs: IS_FORK: ${{ steps.is-fork.outputs.IS_FORK }} + permissions: + actions: read + contents: read + pull-requests: read steps: - uses: actions/checkout@v4 - name: Determine whether this PR is from a fork id: is-fork run: echo "IS_FORK=$(gh pr view --json isCrossRepository --jq '.isCrossRepository' "${PR_NUMBER}" )" >> "$GITHUB_OUTPUT" env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.issue.number }} react-to-comment: @@ -26,6 +30,10 @@ jobs: needs: is-fork-pull-request # Early exit if this is a fork, since later steps are skipped for forks if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }} + permissions: + actions: read + contents: write + pull-requests: write steps: - name: Checkout repository uses: actions/checkout@v4 @@ -39,7 +47,7 @@ jobs: -f content='+1' env: COMMENT_ID: ${{ github.event.comment.id }} - GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} REPO: ${{ github.repository }} prepare: @@ -50,6 +58,10 @@ jobs: if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }} outputs: COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }} + permissions: + actions: read + contents: write + pull-requests: write steps: - name: Setup Node.js uses: actions/setup-node@v4 @@ -61,7 +73,7 @@ jobs: - name: Checkout pull request run: gh pr checkout "${PR_NUMBER}" env: - GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.issue.number }} - name: Use Node.js uses: actions/setup-node@v4 @@ -79,6 +91,10 @@ jobs: runs-on: ubuntu-latest needs: - prepare + permissions: + actions: read + contents: read + pull-requests: read steps: - name: Setup Node.js uses: actions/setup-node@v4 @@ -90,7 +106,7 @@ jobs: - name: Checkout pull request run: gh pr checkout "${PR_NUMBER}" env: - GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.issue.number }} - name: Setup Node.js uses: actions/setup-node@v4 @@ -118,6 +134,10 @@ jobs: needs: - prepare - update-lavamoat-build-policy + permissions: + actions: read + contents: read + pull-requests: read steps: - name: Setup Node.js uses: actions/setup-node@v4 @@ -129,7 +149,7 @@ jobs: - name: Checkout pull request run: gh pr checkout "${PR_NUMBER}" env: - GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.issue.number }} - name: Setup Node.js uses: actions/setup-node@v4 @@ -164,16 +184,20 @@ jobs: - update-lavamoat-webapp-policy # Ensure forks don't get access to the LavaMoat update token if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }} + permissions: + actions: read + contents: write + pull-requests: write steps: - name: Checkout repository uses: actions/checkout@v4 with: # Use PAT to ensure that the commit later can trigger status check workflows - token: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }} + token: ${{ github.token }} - name: Checkout pull request run: gh pr checkout "${PR_NUMBER}" env: - GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.issue.number }} - name: Get commit SHA id: commit-sha @@ -243,7 +267,7 @@ jobs: fi env: HAS_CHANGES: ${{ steps.policy-changes.outputs.HAS_CHANGES }} - GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.issue.number }} check-status: @@ -265,10 +289,14 @@ jobs: needs: - is-fork-pull-request - check-status + permissions: + actions: read + contents: write + pull-requests: write steps: - uses: actions/checkout@v4 with: - token: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }} + token: ${{ github.token }} - name: Post comment if the update failed run: | passed="${{ needs.check-status.outputs.PASSED }}" @@ -276,6 +304,6 @@ jobs: gh pr comment "${PR_NUMBER}" --body "Policy update failed. You can [review the logs or retry the policy update here](${ACTION_RUN_URL})" fi env: - GITHUB_TOKEN: ${{ secrets.LAVAMOAT_UPDATE_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.issue.number }} ACTION_RUN_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"