gcp setting up workload identity authentication with github actions

We need to setup our :-

1. Workload identity pool 

2 Create a provider 

3. Create service account called - 

4. And setup the required attributes mapping.

5. Create our yaml pipeline 

I create a pool call github. And next, I create my provider and call it githubprovider. 




You can see my mappings here :-



Run the following command to add service account to the github worker pool :-  

gcloud iam service-accounts add-iam-policy-binding "github-wif@project-f54eacb9-b4e5-40b9-b0c.iam.gserviceaccount.com" \

  --project="project-f54eacb9-b4e5-40b9-b0c" \

  --role="roles/iam.workloadIdentityUser" \

  --member="principalSet://iam.googleapis.com/projects/1092851139093/locations/global/workloadIdentityPools/github/attribute.repository/kepungnzai/testrepo"

And once you run this command, you will get something like this :-



This is the github actions yaml that we can use the run and test our workload identity federation. 



# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:


permissions:
    contents: read
    id-token: write

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v4

      - name: Authenticate to Google Cloud
        uses: google-github-actions/auth@v3 # Use the latest stable major version
        with:
          workload_identity_provider: 'projects/xxxxxxxx/locations
/global/workloadIdentityPools/github/providers/githubprovider'
          service_account: 'github-wif@project-f54eacb9-b4e5-40b9-b0c.iam.
gserviceaccount.com'

      - name: Test Authentication (e.g., check gcloud version/account)
        run: |
          gcloud info
          gcloud auth list



And here you can see that the run is successful :-







Comments

Popular posts from this blog

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

llama cpp running it in google colab