githubgithub-actions1password

Dynamically fetching the vaults secrets from 1Pass


How can I dynamically fetch the secrets from 1Password into Github action env variable?

Tried the following to dynamically fetch the item name which is not replacing the $col2 value

if the input param is "prod", then the col2 should be replaced accordingly to fetch the password from prod. How to dynamically replace the item/section ?


 - name: Load secret
        uses: 1password/load-secrets-action@v2
        with:
          # Export loaded secrets as environment variables
          export-env: true
        env:
          OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
          DATABASE_PWD: "op://personal/$col2/password"
          DATABASE_USER: "op://personal/$col2/username" 

Solution

  • Provided that col2 is a workflow input, you can inject it into the values that define location of your secrets like this:

    - name: Load secret
      uses: 1password/load-secrets-action@v2
      with:
        export-env: true
      env:
        OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
        DATABASE_PWD: "op://personal/${{ inputs.col2 }}/password"
        DATABASE_USER: "op://personal/${{ inputs.col2 }}/username"