diff --git a/.github/workflows/argocd-promote-helm.yaml b/.github/workflows/argocd-promote-helm.yaml index cd87695..469f9fb 100644 --- a/.github/workflows/argocd-promote-helm.yaml +++ b/.github/workflows/argocd-promote-helm.yaml @@ -303,6 +303,22 @@ jobs: core.info('Resolved configuration:'); core.info(JSON.stringify({ ...outputs, ...envVars }, null, 2)); + - name: Validate GitHub App repository scope + if: inputs.auth_mode == 'app' + id: token-scope + shell: bash + env: + ENVIRONMENT_REPOSITORY: ${{ inputs.environment_repository }} + run: | + set -euo pipefail + shopt -s nocasematch + if [[ ! "$ENVIRONMENT_REPOSITORY" =~ ^([A-Za-z0-9-]+)/([A-Za-z0-9_.-]+)$ || + "${BASH_REMATCH[1]}" != "${GITHUB_REPOSITORY_OWNER}" ]]; then + echo "::error::The environment repository must be owner/repo in the caller's organization" + exit 1 + fi + printf 'repository=%s\n' "${BASH_REMATCH[2]}" >> "$GITHUB_OUTPUT" + - name: Generate GitHub App Token if: inputs.auth_mode == 'app' id: generate-token @@ -311,6 +327,7 @@ jobs: app-id: ${{ secrets.GH_APP_ID }} private-key: ${{ secrets.GH_APP_KEY }} owner: ${{ github.repository_owner }} + repositories: ${{ steps.token-scope.outputs.repository }} - name: Resolve Auth Token id: auth diff --git a/.github/workflows/preview-cleanup.yaml b/.github/workflows/preview-cleanup.yaml index 9671eb3..0a65602 100644 --- a/.github/workflows/preview-cleanup.yaml +++ b/.github/workflows/preview-cleanup.yaml @@ -45,6 +45,22 @@ jobs: contents: write steps: + - name: Validate GitHub App repository scope + if: inputs.auth_mode == 'app' + id: token-scope + shell: bash + env: + ENVIRONMENT_REPOSITORY: ${{ inputs.environment_repository }} + run: | + set -euo pipefail + shopt -s nocasematch + if [[ ! "$ENVIRONMENT_REPOSITORY" =~ ^([A-Za-z0-9-]+)/([A-Za-z0-9_.-]+)$ || + "${BASH_REMATCH[1]}" != "${GITHUB_REPOSITORY_OWNER}" ]]; then + echo "::error::The environment repository must be owner/repo in the caller's organization" + exit 1 + fi + printf 'repository=%s\n' "${BASH_REMATCH[2]}" >> "$GITHUB_OUTPUT" + - name: Generate GitHub App Token if: inputs.auth_mode == 'app' id: generate-token @@ -53,6 +69,7 @@ jobs: app-id: ${{ secrets.GH_APP_ID }} private-key: ${{ secrets.GH_APP_KEY }} owner: ${{ github.repository_owner }} + repositories: ${{ steps.token-scope.outputs.repository }} - name: Resolve Auth Token id: auth