Skip to content
This repository was archived by the owner on Jan 14, 2023. It is now read-only.

Commit 16eb69c

Browse files
authored
Merge pull request #1 from salrashid123/ga-api
Upgrade to GA
2 parents 4011daa + bf1afd3 commit 16eb69c

14 files changed

Lines changed: 378 additions & 187 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GOMAXPROCS = 4
22

3-
PROJECT = "github.com/salrashid123/vault-plugin-secrets-gcpca"
3+
PROJECT = "github.com/GoogleCloudPlatform/vault-plugin-secrets-gcppca"
44
NAME = $(shell go run version/cmd/main.go name)
55
VERSION = $(shell go run version/cmd/main.go version)
66
COMMIT = $(shell git rev-parse --short HEAD)

README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ To issue certificates, you need to first define a profile (config) for the mount
5656

5757
1. Define a config profile
5858

59-
A profile dictates the specifications of the CA a specific Vault mount will use. In the example used here, the mount path is `gcppca` with the CA of `prod-root`
59+
A profile dictates the specifications of the CA a specific Vault mount will use. In the example used here, the mount path is `gcppca` with the CAPool of `my-pool`
6060

6161
```bash
6262
vault write gcppca/config \
63-
issuer="prod-root" \
63+
pool="my-pool" \
6464
location="us-central1" \
6565
project="your-project-id"
6666
```
@@ -81,15 +81,24 @@ Under no circumstance does this plugin retain the private key for any certificat
8181

8282
- The sub-path under `<mount>/issue-with-csr/` is intended for user-provided CSR
8383

84-
This plugin will create a certificate within GCP CA Service with a certificate `Name` using the final path parameter in the Vault resource path. For example, `gcppca/issue-with-genkey/my_tls_cert_rsa_1` will create a GCP CA Service Resource path `projects/your-project-id/locations/us-central1/certificateAuthorities/prod-root/certificates/my_tls_cert_rsa_1`. This is the actual CA Service unique name for the certificate and cannot be reused once created.
84+
This plugin will create a certificate within GCP CA Service with a certificate `Name` using the final path parameter in the Vault resource path. For example, `gcppca/issue-with-genkey/my_tls_cert_rsa_1` will create a GCP CA Service Resource path `projects/your-project-id/locations/us-central1/caPools/my-pool/certificates/my_tls_cert_rsa_1`. This is the actual CA Service unique name for the certificate and cannot be reused once created.
8585

8686
Deleting the key in Vault will revoke the certificate in CA Service which also means the same name cannot be reused.
8787

88+
The examples below uses a default certificate authority pool with a CA. That is, you should have a set pre-generated
89+
90+
```
91+
```bash
92+
$ gcloud privateca pools create my-pool-1 --location=us-central1
93+
$ gcloud privateca roots create ca-1 --location=us-central1 --pool my-pool-1 \
94+
--subject "C=US,ST=California,L=Mountain View,O=Google LLC,CN=google.com"
95+
```
96+
8897
### Vault Generated
8998

9099
To generate a certificate keypair on vault, first apply a configuration that allows Vault to reference which CA to sign against
91100

92-
The configuration below will generate a certificate called `my_tls_cert_rsa_1` within CA Service using a GCP CA `prod-root` that was defined earlier by specifying `gcppca/config`.
101+
The configuration below will generate a certificate called `my_tls_cert_rsa_1` within CA Service using a GCP CA `prod-root` that was defined separately.
93102

94103
Apply the config and acquire a `VAULT_TOKEN` based off of those policies.
95104

@@ -102,7 +111,6 @@ path "gcppca/issue-with-genkey/my_tls_cert_rsa_1" {
102111
"validity"= ["P30D"]
103112
"dns_san" = ["client.domain.com,client2.domain.com"]
104113
"subject" = ["C=US,ST=California,L=Mountain View,O=Google LLC,CN=google.com"]
105-
"reusable_config" = ["leaf-server-tls"]
106114
}
107115
}
108116
EOF
@@ -120,8 +128,7 @@ vault write gcppca/issue-with-genkey/my_tls_cert_rsa_1 \
120128
key_type="rsa" \
121129
validity="P30D" \
122130
dns_san="client.domain.com,client2.domain.com" \
123-
subject="C=US,ST=California,L=Mountain View,O=Google LLC,CN=google.com" \
124-
reusable_config="leaf-server-tls"
131+
subject="C=US,ST=California,L=Mountain View,O=Google LLC,CN=google.com"
125132
```
126133

127134
The output will be Public Certificate and PrivateKey
@@ -196,6 +203,7 @@ Plugin configuration supports various options that are common and mode-specific
196203
|:------------|-------------|
197204
| **`validity`** | `string` validity of the issued certificate (default: `P30d`) |
198205
| **`labels`** | `[]string` list of GCP labels to apply to the certificate (format `k1=v1,k2=v2`) |
206+
| **`issuing_certificate_authority`** | `string` Optional. The resource ID of the CertificateAuthority that should issue the certificate. By default, the certificate will be issued from any of the active CAs in the CA Pool. |
199207

200208
#### Generated (/issue-with-genkey/) Options
201209

@@ -204,7 +212,7 @@ Plugin configuration supports various options that are common and mode-specific
204212
| **`key_type`** | `string` what type of key to generate (default: `rsa`; either `rsa` or `ecdsa`; cannot be specified if `csr` is set) |
205213
| **`key_usage`** | `[]string` what are the `key_usage` settings (default: `[]`) |
206214
| **`extended_key_usage`** | `[]string` what are the `extended_key_usage` settings (default: `[]`) |
207-
| **`reusable_config`** | `string` reusable_config to use (cannot be set if `key_usage`,`extended_key_usage` is set; default `[]`) |
215+
| **`certificate_template`** | `string` certificate_template to use (cannot be set if `key_usage`,`extended_key_usage` is set; default `[]`) |
208216
| **`subject`** | `string` subject field value (must be in canonical format `C=,ST=,L=,O=,CN=`)|
209217
| **`dns_san`** | `[]string` list of `dns_san` to use |
210218
| **`email_san`** | `[]string` list of `email_san` to use |
@@ -213,6 +221,8 @@ Plugin configuration supports various options that are common and mode-specific
213221
| **`is_ca_cert`** | `bool` whether this certificate is for a CA or not. |
214222
| **`max_chain_length`** | `int` Maximum depth of subordinate CAs allowed under this CA for a CA certificate.|
215223

224+
Note, if you use `certificate_template`, specify the fully qualified name:
225+
`"certificate_template" = ["projects/your_project_id/locations/your_location/certificateTemplates/your_template"]`
216226
#### CSR (/issue-with-csr/) Options
217227

218228
| Option | Description |
@@ -221,9 +231,9 @@ Plugin configuration supports various options that are common and mode-specific
221231

222232
Sample usage
223233

224-
The following policies describe usage of `reusable_config` and `key_usage` options.
234+
The following policies describe usage of `certificate_template` and `key_usage` options.
225235

226-
`reusable_config` options:
236+
`certificate_template` options:
227237

228238
```bash
229239
vault policy write genkey-reusable-policy -<<EOF
@@ -234,7 +244,6 @@ path "gcppca/issue-with-genkey/my_tls_cert_ecdsa_1" {
234244
"validity"= ["P30D"]
235245
"dns_san" = ["client.domain.com,client2.domain.com"]
236246
"subject" = ["C=US,ST=California,L=Mountain View,O=Google LLC,CN=google.com"]
237-
"reusable_config" = ["leaf-server-tls"]
238247
}
239248
}
240249
EOF
@@ -250,7 +259,7 @@ path "gcppca/issue-with-genkey/my_tls_cert_encipher_1" {
250259
"validity"= ["P30D"]
251260
"dns_san" = ["client.domain.com,client2.domain.com"]
252261
"subject" = ["C=US,ST=California,L=Mountain View,O=Google LLC,CN=google.com"]
253-
"key_usages" = ["encipher_only"]
262+
"key_usages" = ["encipher_only"]
254263
}
255264
}
256265
EOF
@@ -259,12 +268,11 @@ EOF
259268
When a derived VAULT_TOKEN is used with `vault write gcppca/issue-with-genkey/..` operations, you must provide the _exact_ parameters defined in the policy. For example
260269

261270
```bash
262-
vault write gcppca/issue-with-genkey/my_tls_cert_ecdsa_1 \
263-
key_type="ecdsa" \
271+
vault write gcppca/issue-with-genkey/my_tls_cert_encipher_1 \
264272
validity="P30D" \
265273
dns_san="client.domain.com,client2.domain.com" \
266274
subject="C=US,ST=California,L=Mountain View,O=Google LLC,CN=google.com" \
267-
reusable_config="leaf-server-tls"
275+
key_usages="encipher_only"
268276
```
269277

270278
### Revoke Certificates
@@ -280,7 +288,8 @@ To install, download `vault-plugin-secrets-gcpca` from the "Releases" page on gi
280288
- Register the Plugin (remember to update `path/to/vault/plugins/`).
281289

282290
```bash
283-
export SHASUM=`curl -L -s https://github.com/salrashid123/vault-plugin-secrets-gcppca/releases/download/v1.0.1/checksum.sha256`
291+
export VERSION=v1.0.3
292+
export SHASUM=`curl -L -s https://github.com/GoogleCloudPlatform/vault-plugin-secrets-gcppca/releases/download/$VERSION/checksum.sha256`
284293

285294
vault plugin register \
286295
-sha256="${SHASUM}" \

backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"golang.org/x/oauth2/google"
2727
"google.golang.org/api/option"
2828

29-
pcaapi "cloud.google.com/go/security/privateca/apiv1beta1"
29+
pcaapi "cloud.google.com/go/security/privateca/apiv1"
3030
)
3131

3232
var (

backend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"google.golang.org/api/option"
2727
"google.golang.org/grpc/connectivity"
2828

29-
pcaapi "cloud.google.com/go/security/privateca/apiv1beta1"
29+
pcaapi "cloud.google.com/go/security/privateca/apiv1"
3030
hclog "github.com/hashicorp/go-hclog"
3131
)
3232

config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
type Config struct {
3333
Credentials string `json:"credentials"`
3434
Scopes []string `json:"scopes"`
35-
Issuer string `json:"issuer"`
35+
Pool string `json:"pool"`
3636
Location string `json:"location"`
3737
Project string `json:"project"`
3838
}
@@ -68,10 +68,10 @@ func (c *Config) Update(d *framework.FieldData) (bool, error) {
6868
}
6969
}
7070

71-
if v, ok := d.GetOk("issuer"); ok {
71+
if v, ok := d.GetOk("pool"); ok {
7272
nv := strings.TrimSpace(v.(string))
73-
if nv != c.Issuer {
74-
c.Issuer = nv
73+
if nv != c.Pool {
74+
c.Pool = nv
7575
changed = true
7676
}
7777
}
@@ -92,8 +92,8 @@ func (c *Config) Update(d *framework.FieldData) (bool, error) {
9292
}
9393
}
9494

95-
if c.Issuer == "" || c.Location == "" || c.Project == "" {
96-
return true, errors.New("Must specify Issuer, Location and Project in config ")
95+
if c.Pool == "" || c.Location == "" || c.Project == "" {
96+
return true, errors.New("Must specify CAPool, Location and Project in config ")
9797
}
9898

9999
return changed, nil

config_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,26 @@ func TestConfig_Update(t *testing.T) {
4444
"expect_project",
4545
&Config{
4646
Credentials: "creds",
47-
Issuer: "iss",
47+
Pool: "my-pool",
4848
Location: "us-central1",
4949
},
5050
&framework.FieldData{
5151
Raw: map[string]interface{}{
5252
"credentials": "creds",
53-
"issuer": "iss",
53+
"pool": "my-pool",
5454
"location": "us-central1",
5555
},
5656
},
5757
&Config{
5858
Credentials: "creds",
59-
Issuer: "iss",
59+
Pool: "my-pool",
6060
Location: "us-central1",
6161
},
6262
true,
6363
true,
6464
},
6565
{
66-
"expect_issuer",
66+
"expect_pool",
6767
&Config{
6868
Credentials: "creds",
6969
Project: "project",
@@ -89,19 +89,19 @@ func TestConfig_Update(t *testing.T) {
8989
&Config{
9090
Credentials: "creds",
9191
Project: "project",
92-
Issuer: "iss",
92+
Pool: "my-pool",
9393
},
9494
&framework.FieldData{
9595
Raw: map[string]interface{}{
9696
"credentials": "creds",
97-
"issuer": "iss",
97+
"pool": "my-pool",
9898
"project": "project",
9999
},
100100
},
101101
&Config{
102102
Credentials: "creds",
103103
Project: "project",
104-
Issuer: "iss",
104+
Pool: "my-pool",
105105
},
106106
true,
107107
true,
@@ -111,14 +111,14 @@ func TestConfig_Update(t *testing.T) {
111111
&Config{
112112
Credentials: "creds",
113113
Project: "project",
114-
Issuer: "iss",
114+
Pool: "my-pool",
115115
Location: "us-central1",
116116
},
117117
nil,
118118
&Config{
119119
Credentials: "creds",
120120
Project: "project",
121-
Issuer: "iss",
121+
Pool: "my-pool",
122122
Location: "us-central1",
123123
},
124124
false,
@@ -129,21 +129,21 @@ func TestConfig_Update(t *testing.T) {
129129
&Config{
130130
Credentials: "creds",
131131
Project: "project",
132-
Issuer: "iss",
132+
Pool: "my-pool",
133133
Location: "us-central1",
134134
},
135135
&framework.FieldData{
136136
Raw: map[string]interface{}{
137137
"credentials": "foo",
138138
"project": "project",
139-
"issuer": "iss",
139+
"pool": "my-pool",
140140
"location": "us-central1",
141141
},
142142
},
143143
&Config{
144144
Credentials: "foo",
145145
Project: "project",
146-
Issuer: "iss",
146+
Pool: "my-pool",
147147
Location: "us-central1",
148148
},
149149
true,
@@ -154,23 +154,23 @@ func TestConfig_Update(t *testing.T) {
154154
&Config{
155155
Credentials: "creds",
156156
Project: "project",
157-
Issuer: "iss",
157+
Pool: "my-pool",
158158
Location: "us-central1",
159159
},
160160
&framework.FieldData{
161161
Raw: map[string]interface{}{
162162
"credentials": "foo",
163163
"scopes": "bar",
164164
"project": "project",
165-
"issuer": "iss",
165+
"pool": "my-pool",
166166
"location": "us-central1",
167167
},
168168
},
169169
&Config{
170170
Credentials: "foo",
171171
Scopes: []string{"bar"},
172172
Project: "project",
173-
Issuer: "iss",
173+
Pool: "my-pool",
174174
Location: "us-central1",
175175
},
176176
true,
@@ -181,21 +181,21 @@ func TestConfig_Update(t *testing.T) {
181181
&Config{
182182
Scopes: []string{"bar", "foo"},
183183
Project: "project",
184-
Issuer: "iss",
184+
Pool: "my-pool",
185185
Location: "us-central1",
186186
},
187187
&framework.FieldData{
188188
Raw: map[string]interface{}{
189189
"scopes": "foo,bar",
190190
"project": "project",
191-
"issuer": "iss",
191+
"pool": "my-pool",
192192
"location": "us-central1",
193193
},
194194
},
195195
&Config{
196196
Scopes: []string{"bar", "foo"},
197197
Project: "project",
198-
Issuer: "iss",
198+
Pool: "my-pool",
199199
Location: "us-central1",
200200
},
201201
false,
@@ -206,21 +206,21 @@ func TestConfig_Update(t *testing.T) {
206206
&Config{
207207
Scopes: []string{"bar", "foo"},
208208
Project: "project",
209-
Issuer: "iss",
209+
Pool: "my-pool",
210210
Location: "us-central1",
211211
},
212212
&framework.FieldData{
213213
Raw: map[string]interface{}{
214214
"scopes": "FOO,baR",
215215
"project": "project",
216-
"issuer": "iss",
216+
"pool": "my-pool",
217217
"location": "us-central1",
218218
},
219219
},
220220
&Config{
221221
Scopes: []string{"bar", "foo"},
222222
Project: "project",
223-
Issuer: "iss",
223+
Pool: "my-pool",
224224
Location: "us-central1",
225225
},
226226
false,
@@ -231,21 +231,21 @@ func TestConfig_Update(t *testing.T) {
231231
&Config{
232232
Scopes: []string{"bar", "foo"},
233233
Project: "project",
234-
Issuer: "iss",
234+
Pool: "my-pool",
235235
Location: "us-central1",
236236
},
237237
&framework.FieldData{
238238
Raw: map[string]interface{}{
239239
"scopes": "foo, foo, foo, bar",
240240
"project": "project",
241-
"issuer": "iss",
241+
"pool": "my-pool",
242242
"location": "us-central1",
243243
},
244244
},
245245
&Config{
246246
Scopes: []string{"bar", "foo"},
247247
Project: "project",
248-
Issuer: "iss",
248+
Pool: "my-pool",
249249
Location: "us-central1",
250250
},
251251
false,

0 commit comments

Comments
 (0)