• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.circleci/H19-Aug-2021-

.github/H19-Aug-2021-

plugin/H19-Aug-2021-

scripts/H19-Aug-2021-

vendor/H03-May-2022-

.gitignoreH A D19-Aug-2021800

CHANGELOG.mdH A D19-Aug-2021196

LICENSEH A D19-Aug-202115.5 KiB

MakefileH A D19-Aug-20211.8 KiB

README.mdH A D19-Aug-20218.6 KiB

go.modH A D19-Aug-2021881

go.sumH A D19-Aug-202133.1 KiB

main.goH A D19-Aug-2021583

README.md

1# Vault Plugin: Google Cloud Platform Secrets Backend [![CircleCI](https://circleci.com/gh/hashicorp/vault-plugin-secrets-gcp.svg?style=svg)](https://circleci.com/gh/hashicorp/vault-plugin-secrets-gcp)
2
3This is a backend plugin to be used with [Hashicorp Vault](https://www.github.com/hashicorp/vault).
4This plugin generates either one-time (non-renewable) OAuth2 access tokens or
5service account keys with a given set of [IAM roles](https://cloud.google.com/iam/docs/understanding-roles)
6bound to GCP resources for various GCP entities to authenticate with Vault.
7
8**Please note**: We take Vault's security and our users' trust very seriously.
9If you believe you have found a security issue in Vault or with this plugin,
10_please responsibly disclose_ by
11contacting us at [security@hashicorp.com](mailto:security@hashicorp.com).
12
13## Quick Links
14- [Vault Website](https://www.vaultproject.io)
15- [GCP Secrets Docs](https://www.vaultproject.io/docs/secrets/gcp/index.html)
16- [Vault Github](https://www.github.com/hashicorp/vault)
17- [General Announcement List](https://groups.google.com/forum/#!forum/hashicorp-announce)
18- [Discussion List](https://groups.google.com/forum/#!forum/vault-tool)
19
20
21## Usage
22
23This is a [Vault plugin](https://www.vaultproject.io/docs/internals/plugins.html)
24and is meant to work with Vault. This guide assumes you have already installed Vault
25and have a basic understanding of how Vault works. Otherwise, first read this guide on
26how to [get started with Vault](https://www.vaultproject.io/intro/getting-started/install.html).
27
28If you are just interested in using this plugin with Vault, it is packaged with Vault and
29by default can be enabled by running:
30
31```sh
32$ vault secrets enable gcp
33Success! Enabled the gcp secrets engine at: gcp/
34```
35
36If you are testing this plugin in an earlier version of Vault or want to
37test or use a custom build of the plugin, see the next section.
38
39## Developing
40
41If you wish to work on this plugin, you'll first need [Go](https://www.golang.org)
42installed on your machine (whichever version is required by Vault).
43
44Make sure Go is properly installed, including setting up a [GOPATH](https://golang.org/doc/code.html#GOPATH).
45
46### Get Plugin
47
48Clone this repository:
49
50```text
51$ mkdir $GOPATH/src/github.com/hashicorp/vault-plugin-secrets-gcp`
52$ cd $GOPATH/src/github.com/hashicorp/
53$ git clone https://github.com/hashicorp/vault-plugin-secrets-gcp.git
54```
55
56or use `go get github.com/hashicorp/vault-plugin-secrets-gcp`
57
58You can then download any required build tools by bootstrapping your
59environment:
60
61```sh
62$ make bootstrap
63```
64
65To compile a development version of this plugin, run `make` or `make dev`.
66This will put the plugin binary in the `bin` and `$GOPATH/bin` folders. `dev`
67mode will only generate the binary for your platform and is faster:
68
69```sh
70$ make
71$ make dev
72```
73
74### Install Plugin in Vault
75
76Put the plugin binary into a location of your choice. This directory
77will be specified as the [`plugin_directory`](https://www.vaultproject.io/docs/configuration/index.html#plugin_directory)
78in the Vault config used to start the server.
79
80```hcl
81plugin_directory = "path/to/plugin/directory"
82```
83
84Start a Vault server with this config file:
85
86```sh
87$ vault server -config=path/to/config.json #...
88```
89
90Once the server is started, register the plugin in the Vault server's [plugin catalog](https://www.vaultproject.io/docs/internals/plugins.html#plugin-catalog):
91
92```sh
93$ vault write sys/plugins/catalog/gcpsecrets \
94    sha_256="$(shasum -a 256 path/to/plugin/directory/vault-plugin-secrets-gcp | cut -d " " -f1)" \
95    command="vault-plugin-secrets-gcp"
96```
97
98Any name can be substituted for the plugin name "gcpsecrets". This
99name will be referenced in the next step, where we enable the secrets
100plugin backend using the GCP secrets plugin:
101
102```sh
103$ vault secrets enable --plugin-name='gcpsecrets' --path="gcp" plugin
104```
105
106### Tests
107
108To run the unit tests:
109
1101. Run the unit tests:
111
112   ```text
113   $ make test
114   ```
115
116This plugin also has comprehensive [acceptance tests](https://en.wikipedia.org/wiki/Acceptance_testing)
117covering most of the features of this auth backend.
118
119If you are developing this plugin and want to verify it is still
120functioning (and you haven't broken anything else), we recommend
121running the acceptance tests.
122
123**Warning:** The acceptance tests create/destroy/modify *real resources*,
124which may incur real costs in some cases. In the presence of a bug,
125it is technically possible that broken backends could leave dangling
126data behind. Therefore, please run the acceptance tests at your own risk.
127At the very least, we recommend running them in their own private
128account for whatever backend you're testing.
129
130To run the acceptance tests, you will need a GCP IAM service account with the
131permissions listed below. The following steps assume you have
132[gcloud][install-gcloud] installed.
133
1341. Save the name of your test project as an environment variable for reference:
135
136    ```text
137    $ export GOOGLE_CLOUD_PROJECT=my-project # replace with your project ID
138    ```
139
140    Do not use a production project. Use a dedicated project for testing.
141
1421. Enable the IAM service on the project:
143
144    ```text
145    $ gcloud services enable --project "${GOOGLE_CLOUD_PROJECT}" \
146        cloudresourcemanager.googleapis.com \
147        iam.googleapis.com
148    ```
149
1501. Create a testing service account:
151
152    ```text
153    $ gcloud iam service-accounts create vault-tester \
154        --display-name vault-tester \
155        --project "${GOOGLE_CLOUD_PROJECT}"
156    ```
157
1581. Grant required test permissions:
159
160    ```text
161    $ gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
162        --member "serviceAccount:vault-tester@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com" \
163        --role "roles/owner"
164    ```
165
166    Note: these are overly broad permissions because the account needs a
167    superset of all permissions it might grant. For this reason, it is
168    **strongly recommended** that you have a dedicated project for running
169    tests.
170
1711. Download the service account key file to local disk:
172
173    ```text
174    $ gcloud iam service-accounts keys create vault-tester.json \
175        --iam-account "vault-tester@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com"
176    ```
177
1781. Export the credentials to an environment variable. You can set the env variable to either
179   the path or the JSON itself, i.e.
180
181    ```text
182    $ export GOOGLE_CREDENTIALS="path/to/vault-tester.json"
183    ```
184
185    ```text
186    $ export GOOGLE_CREDENTIALS="$(cat path/to/vault-tester.json)"
187    ```
188
1891. Run the acceptance tests:
190
191    ```text
192    $ make test-acc
193    ```
194
195## Auto-generated IAM Config
196
197An IAM-enabled resource (under an arbitrary GCP service) supports the following three IAM methods:
198
199* `getIamPolicy`
200* `setIamPolicy`
201* `testIamPermissions`
202
203In the case of this secrets engine, we need to call `getIamPolicy` and `setIamPolicy` on
204an arbitrary resource under an arbitrary service, which would be difficult using
205the [generated Go google APIs](https://github.com/google/google-api-go-client). Instead,
206we autogenerated a library, using the [Google API Discovery Service](https://developers.google.com/discovery/)
207to find IAM-enabled resources and configure HTTP calls on arbitrary services/resources for IAM.
208
209For each binding config resource block (with a resource name), we attempt to find the resource type based on the
210relative resource name and match it to a service config as seen in this
211[autogenerated config file](https://github.com/hashicorp/vault-plugin-secrets-gcp/blob/master/plugin/iamutil/iam_resources_generated.go)
212
213To re-generate this file, run:
214
215```
216go generate github.com/hashicorp/vault-plugin-secrets-gcp/plugin/iamutil
217```
218
219
220In general, we try to make it so you can specify the resource as given in the HTTP API URL
221(between base API URL and get/setIamPolicy suffix). For some possibly non-standard APIs, we have also
222 added exceptions to try to reach something more standard; a notable current example is the Google Cloud Storage API,
223 whose methods look like `https://www.googleapis.com/storage/v1/b/bucket/o/object` where we accept either
224 `b/bucket/o/object` or `buckets/bucket/objects/object` as valid relative resource names.
225
226If you are having trouble during role set creation with errors suggesting the resource format is invalid or API calls
227are failing for a resource you know exists, please [report any issues](https://github.com/hashicorp/vault-plugin-secrets-gcp/issues)
228you run into. It could be that the API is a non-standard form or we need to re-generate our config file.
229
230## Other Docs
231
232See up-to-date [engine docs](https://www.vaultproject.io/docs/secrets/gcp/index.html)
233and general [API docs](https://www.vaultproject.io/api/secret/gcp/index.html).
234
235