Skip to content

hashicorp/vault-plugin-auth-gcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Vault Plugin: Google Cloud Platform Auth Backend

This is a standalone backend plugin for use with HashiCorp Vault. This plugin allows for various GCP entities to authenticate with Vault. This is currently included in Vault distributions.

Currently, this plugin supports login for:

  • IAM service accounts
  • GCE Instances

Please note: We take Vault's security and our users' trust very seriously. If you believe you have found a security issue in Vault, please responsibly disclose by contacting us at [email protected].

Quick Links

Getting Started

This is a Vault plugin and is meant to work with Vault. This guide assumes you have already installed Vault and have a basic understanding of how Vault works.

Otherwise, first read this guide on how to get started with Vault.

To learn specifically about how plugins work, see documentation on Vault plugins.

Usage

Please see documentation for the plugin on the Vault website.

This plugin is currently built into Vault and by default is accessed at auth/gcp. To enable this in a running Vault server:

$ vault auth enable gcp
Success! Enabled gcp auth method at: gcp/

To see all the supported paths, see the GCP auth API docs.

Developing

Please note that local development is only required if you plan to contribute or compile this plugin yourself. This plugin is automatically bundled in Vault installations and is available by default. You do not need to compile it yourself unless you intend to modify it.

If you wish to work on this plugin, you'll first need Go installed on your machine (version 1.10+ is required).

For local dev first make sure Go is properly installed, including setting up a GOPATH. Next, clone this repository into your GOPATH:

Build Plugin

  1. Clone this repository:

    $ mkdir -p $GOPATH/src/github.com/hashicorp
    $ git clone https://github.com/hashicorp/vault-plugin-auth-gcp $GOPATH/src/github.com/hashicorp/
    $ cd vault-plugin-auth-gcp
  2. You can then download any required build tools by bootstrapping your environment:

    $ make bootstrap
  3. To compile a development version of this plugin, run make or make dev. This will put the plugin binary in the bin and $GOPATH/bin folders. dev mode will only generate the binary for your platform and is faster:

    $ make
    $ make dev

Start Vault

  1. For local development, use Vault's "dev" mode for fast setup:

    $ vault server -dev -dev-root-token-id=root -dev-plugin-dir="$GOPATH/vault-plugins"

Set Up Plugin in Vault

Next you want Vault to use the newly built binary instead of the version bundled with Vault. You can use the scripted or manual methods depending on your preference.

Scripted method.

  1. A Terraform project sets up the necessary gcp service account & credentials. You can configure the project id via this environment variable: TF_VAR_GOOGLE_CLOUD_PROJECT_ID or paste it in the terminal when prompted.

    $ make setup-env
  2. Source the environment variables generated by the setup project:

    $ source ./bootstrap/terraform/local_environment_setup.sh
  3. Enable the dev version of the plugin on your local Vault instance. You can specify the plugin name, development plugin directory and mount path or leave empty to use the default values.

    $ make configure PLUGIN_NAME=vault-plugin-auth-gcp PLUGIN_DIR=$GOPATH/vault-plugins PLUGIN_PATH=gcp

Manual method.

  1. Save the name of your project as an environment variable for reference:

    $ export GOOGLE_CLOUD_PROJECT=my-project # replace with your project ID

The remaining steps may also be executed by running . scripts/cred_setup.sh.

  1. Enable the IAM service on the project:

    $ gcloud services enable --project "${GOOGLE_CLOUD_PROJECT}" \
        cloudresourcemanager.googleapis.com \
        iam.googleapis.com
  2. Create the service account:

    $ gcloud iam service-accounts create vault-tester \
        --display-name vault-tester \
        --project "${GOOGLE_CLOUD_PROJECT}"
  3. Grant project.viewer and serviceaccount.admin permissions:

    $ gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
        --member "serviceAccount:vault-tester@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com" \
        --role "roles/viewer"
    
    $ gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
        --member "serviceAccount:vault-tester@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com" \
        --role "roles/iam.serviceAccountKeyAdmin"
    
    $ gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
        --member "serviceAccount:vault-tester@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com" \
        --role "roles/iam.serviceAccountTokenCreator"
  4. Download the service account key file to local disk:

    $ gcloud iam service-accounts keys create vault-tester.json \
        --iam-account "vault-tester@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com"
  5. Export the credentials to an environment variable:

    $ export GOOGLE_TEST_CREDENTIALS="$(cat vault-tester.json)"

Tests

This plugin has comprehensive acceptance tests covering most of the features of this auth backend.

If you are developing this plugin and want to verify it is still functioning (and you haven't broken anything else), we recommend running the acceptance tests.

Acceptance tests typically require other environment variables to be set for things such as access keys. The test itself should error early and tell you what to set, so it is not documented here.

Warning: The acceptance tests create/destroy/modify real resources, which may incur real costs in some cases. In the presence of a bug, it is technically possible that broken backends could leave dangling data behind. Therefore, please run the acceptance tests at your own risk. At the very least, we recommend running them in their own private account for whatever backend you're testing.

To run the acceptance tests, you will need a GCP IAM service account with the appropriate permissions. You can use the steps explained in the setup section to configure one for you.

  1. Save the name of your test project as an environment variable for reference:

    $ export GOOGLE_CLOUD_PROJECT_ID=my-project # replace with your project ID
  2. Run the acceptance tests:

    $ make testacc

Note that it may take some time (e.g. over a minute) for the new credentials to work.