Git Product home page Git Product logo

gcp-workload-identity-federation-buildkite-plugin's Introduction

Google Cloud Workload Identity Federation Buildkite Plugin Build status

A Buildkite plugin to assume a Google Cloud service account using workload identity federation.

The plugin requests an OIDC token from Buildkite and uses it to a populate Google Cloud credentials file.

The path to the file is populated in GOOGLE_APPLICATION_CREDENTIALS for SDKs that use Application Default Credentials, and in CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE for the gcloud CLI.

Google Cloud configuration

You should already have a Google Cloud project and a Service Account to assume. See Google's documentation for more detailed instructions for these steps.

  1. Create a Workload Identity Pool.

    We recommend creating a different pool for each security boundary.

    In this example we're using buildkite-example-pipeline.

  2. Add a provider to the pool.

    Use OpenID Connect, and give it a name like buildkite.

    Use https://agent.buildkite.com as the Issuer.

    Copy the value of the default audience or provide your own.

  3. Configure provider attributes.

    Because Google limits the length of attributes to 127 characters, we suggest the following mapping:

    Google OIDC
    google.subject "organization:" + assertion.sub.split(":")[1] + ":pipeline:" + assertion.sub.split(":")[3]
    attribute.pipeline_slug assertion.pipeline_slug
    attribute.build_branch assertion.build_branch

    With this mapping you can use a CEL expression to restrict which pipelines can assume the service account:

    google.subject == "organization:acme:pipeline:buildkite-example-pipeline"
    
  4. Grant access to the service account.

  5. Configure this plugin using the workload provider audience without the leading https:, and the service account email address.

Example

Add the following to your pipeline.yml:

steps:
  - command: |
      echo "Credentials are located at \$GOOGLE_APPLICATION_CREDENTIALS"
    plugins:
      - gcp-workload-identity-federation#v1.0.0:
          audience: "//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/buildkite-example-pipeline/providers/buildkite"
          service-account: "[email protected]"

Configuration

audience (Required, string)

  • The default audience as shown on the Workload Identity Federation Provider page, without the https: prefix, or a custom audience that you configure.

service-account (Required, string)

  • The service account for which you want to acquire an access token.

lifetime (number)

  • The time (in seconds) the OIDC token will be valid for before expiry. Must be a non-negative integer. If the flag is omitted or set to 0, the API will choose a default finite lifetime. (default: 0)

Developing

To run testing, shellchecks and plugin linting use use bk run with the Buildkite CLI.

bk run

Or if you want to run just the tests, you can use the docker Plugin Tester:

docker run --rm -ti -v "${PWD}":/plugin buildkite/plugin-tester:latest

Contributing

  1. Fork the repo
  2. Make the changes
  3. Run the tests
  4. Commit and push your changes
  5. Send a pull request

gcp-workload-identity-federation-buildkite-plugin's People

Contributors

caioicy avatar hugeirl avatar pzeballos avatar renovate[bot] avatar steveh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.