diff --git a/README.md b/README.md index 8aacc8c9..feed161c 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ job: - id: auth uses: google-github-actions/auth@v0 with: - credentials_json: ${{ secrets.gcp_credentials }} + credentials_json: ${{ secrets.GCP_CREDENTIALS }} - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v0.3.0 diff --git a/example-workflows/cloud-build/.github/workflows/cloud-build.yml b/example-workflows/cloud-build/.github/workflows/cloud-build.yml index e9c7bc93..09f06d79 100644 --- a/example-workflows/cloud-build/.github/workflows/cloud-build.yml +++ b/example-workflows/cloud-build/.github/workflows/cloud-build.yml @@ -28,17 +28,32 @@ jobs: name: Setup, Build, and Deploy runs-on: ubuntu-latest + # Add "id-token" with the intended permissions. + permissions: + contents: 'read' + id-token: 'write' + steps: - name: Checkout uses: actions/checkout@v2 - # Setup gcloud CLI - - uses: google-github-actions/setup-gcloud@master + # Configure Workload Identity Federation and generate an access token. + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v0' with: - version: '286.0.0' - service_account_email: ${{ secrets.RUN_SA_EMAIL }} - service_account_key: ${{ secrets.RUN_SA_KEY }} - project_id: ${{ secrets.RUN_PROJECT }} + workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + # - id: 'auth' + # uses: 'google-github-actions/auth@v0' + # with: + # credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + # Setup gcloud CLI + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v0 # Build and push image to Google Container Registry - name: Build diff --git a/example-workflows/cloud-run/cloud-run.yml b/example-workflows/cloud-run/cloud-run.yml index 550ff569..3f667e30 100644 --- a/example-workflows/cloud-run/cloud-run.yml +++ b/example-workflows/cloud-run/cloud-run.yml @@ -26,15 +26,33 @@ env: jobs: deploy: runs-on: ubuntu-latest + + # Add "id-token" with the intended permissions. + permissions: + contents: 'read' + id-token: 'write' + steps: - name: Checkout uses: actions/checkout@v2 - - name: Setup Cloud SDK - uses: google-github-actions/setup-gcloud@v0.2.0 + # Configure Workload Identity Federation and generate an access token. + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v0' with: - project_id: ${{ env.PROJECT_ID }} - service_account_key: ${{ secrets.GCP_SA_KEY }} + workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + # - id: 'auth' + # uses: 'google-github-actions/auth@v0' + # with: + # credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + # Setup gcloud CLI + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v0 - name: Authorize Docker push run: gcloud auth configure-docker diff --git a/example-workflows/gae/app-engine.yml b/example-workflows/gae/app-engine.yml index 41e941f9..3131738a 100644 --- a/example-workflows/gae/app-engine.yml +++ b/example-workflows/gae/app-engine.yml @@ -23,15 +23,33 @@ jobs: deploy: name: Deploy runs-on: ubuntu-latest + + # Add "id-token" with the intended permissions. + permissions: + contents: 'read' + id-token: 'write' + steps: - name: Checkout uses: actions/checkout@v2 - - name: Setup Cloud SDK - uses: google-github-actions/setup-gcloud@v0.2.0 + # Configure Workload Identity Federation and generate an access token. + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v0' with: - project_id: ${{ env.PROJECT_ID }} - service_account_key: ${{ secrets.GCP_SA_KEY }} + workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + # - id: 'auth' + # uses: 'google-github-actions/auth@v0' + # with: + # credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + # Setup gcloud CLI + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v0 - name: Deploy to App Engine run: gcloud app deploy --quiet diff --git a/example-workflows/gce/.github/workflows/gce.yaml b/example-workflows/gce/.github/workflows/gce.yaml index 75bdfd35..7ada1d87 100644 --- a/example-workflows/gce/.github/workflows/gce.yaml +++ b/example-workflows/gce/.github/workflows/gce.yaml @@ -29,16 +29,32 @@ jobs: name: Setup, Build, Publish, and Deploy runs-on: ubuntu-latest + # Add "id-token" with the intended permissions. + permissions: + contents: 'read' + id-token: 'write' + steps: - name: Checkout uses: actions/checkout@v2 - # Setup gcloud CLI - - uses: google-github-actions/setup-gcloud@master + # Configure Workload Identity Federation and generate an access token. + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v0' with: - version: '290.0.1' - service_account_key: ${{ secrets.GCE_SA_KEY }} - project_id: ${{ secrets.GCE_PROJECT }} + workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + # - id: 'auth' + # uses: 'google-github-actions/auth@v0' + # with: + # credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + # Setup gcloud CLI + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v0 # Configure Docker to use the gcloud command-line tool as a credential # helper for authentication diff --git a/example-workflows/gke-kustomize/.github/workflows/gke-kustomize.yml b/example-workflows/gke-kustomize/.github/workflows/gke-kustomize.yml index cb04b03d..9c01b00c 100644 --- a/example-workflows/gke-kustomize/.github/workflows/gke-kustomize.yml +++ b/example-workflows/gke-kustomize/.github/workflows/gke-kustomize.yml @@ -33,15 +33,32 @@ jobs: name: Setup, Build, Publish, and Deploy runs-on: ubuntu-latest + # Add "id-token" with the intended permissions. + permissions: + contents: 'read' + id-token: 'write' + steps: - name: Checkout uses: actions/checkout@v2 - # Setup gcloud CLI - - uses: google-github-actions/setup-gcloud@master + # Configure Workload Identity Federation and generate an access token. + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v0' with: - service_account_key: ${{ secrets.GKE_SA_KEY }} - project_id: ${{ secrets.GKE_PROJECT }} + workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + # - id: 'auth' + # uses: 'google-github-actions/auth@v0' + # with: + # credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + # Setup gcloud CLI + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v0 # Configure Docker to use the gcloud command-line tool as a credential # helper for authentication (https://cloud.google.com/artifact-registry/docs/docker/authentication) diff --git a/example-workflows/gke/.github/workflows/gke.yml b/example-workflows/gke/.github/workflows/gke.yml index b52b36ff..0390a94b 100644 --- a/example-workflows/gke/.github/workflows/gke.yml +++ b/example-workflows/gke/.github/workflows/gke.yml @@ -30,15 +30,32 @@ jobs: name: Setup and Deploy runs-on: ubuntu-latest + # Add "id-token" with the intended permissions. + permissions: + contents: 'read' + id-token: 'write' + steps: - name: Checkout uses: actions/checkout@v2 - # Setup gcloud CLI - - uses: google-github-actions/setup-gcloud@master + # Configure Workload Identity Federation and generate an access token. + - id: 'auth' + name: 'Authenticate to Google Cloud' + uses: 'google-github-actions/auth@v0' with: - service_account_key: ${{ secrets.GKE_SA_KEY }} - project_id: ${{ secrets.GKE_PROJECT }} + workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' + service_account: 'my-service-account@my-project.iam.gserviceaccount.com' + + # Alternative option - authentication via credentials json + # - id: 'auth' + # uses: 'google-github-actions/auth@v0' + # with: + # credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + # Setup gcloud CLI + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v0 # Get the GKE credentials so we can deploy to the cluster - run: |-