Skip to content

Commit 218d688

Browse files
cleaned up artifacts, added role explanation to README, fixed domain check.
1 parent ccd12a4 commit 218d688

File tree

9 files changed

+121
-113
lines changed

9 files changed

+121
-113
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
.vs/*
2-
vaultSecretsEngine-update.zip
2+
*.zip
33
vault/plugins/*
4+
*.sh
45
*.exe
56
keyfactor
6-
hashicorp-vault-secretsengine.zip
7+
Keyfactor Vault Secrets Engine Guide.docx
8+
Makefile
9+
sample_config.json
-29.7 KB
Binary file not shown.

README.md

Lines changed: 96 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ certificate authority. After issuance, the certificate is then returned to Hashi
2828
- [Check the Vault server status](#check-the-vault-server-status)
2929
- [Install and register the plugin](#install-and-register-the-plugin)
3030
- [Configure the plugin](#configure-the-plugin)
31-
- [Using the plugin](#using-the-plugin)
3231
- [Adding Roles](#adding-roles)
32+
- [Using the plugin](#using-the-plugin)
3333
- [Issuing Certificates](#issuing-certificates)
3434
- [Viewing Certificates](#viewing-certificates)
3535
- [Command Reference](#plugin-command-reference)
@@ -79,18 +79,18 @@ document.
7979

8080
### Keyfactor Requirements
8181

82-
- A functional instance of Keyfactor Command
83-
- An administrative user account to be used for configuring the Keyfactor options needed for the implementation
84-
- A functional integrated certificate authority to be used for issuing the certificates
85-
- A certificate template (or templates) defined to use for certificate issuance.
86-
- A user account with permissions to connect to the Keyfactor API and submit certificate requests. This user account will require READ and ENROLL permissions on the certificate template that you will use for the Vault plugin.
82+
- A functional instance of Keyfactor Command
83+
- An administrative user account to be used for configuring the Keyfactor options needed for the implementation
84+
- A functional integrated certificate authority to be used for issuing the certificates
85+
- A certificate template (or templates) defined to use for certificate issuance.
86+
- A user account with permissions to connect to the Keyfactor API and submit certificate requests. This user account will require READ and ENROLL permissions on the certificate template that you will use for the Vault plugin.
8787

8888
### Hashicorp Vault Requirements
8989

90-
- A functional Hashicorp Vault Installation **version 1.10.xx or greater**.
91-
- An administrative account with permission to login to the Hashicorp Vault server in order to make administrative changes.
92-
- An adequate number of unseal keys to meet the minimum criteria to unseal the Hashicorp Vault
93-
- A Hashicorp Vault login token
90+
- A functional Hashicorp Vault Installation **version 1.10.xx or greater**.
91+
- An administrative account with permission to login to the Hashicorp Vault server in order to make administrative changes.
92+
- An adequate number of unseal keys to meet the minimum criteria to unseal the Hashicorp Vault
93+
- A Hashicorp Vault login token
9494

9595
## Installation - Keyfactor
9696

@@ -363,97 +363,103 @@ in order to view the configuration settings (see example below).
363363

364364
!["configread"](images/configread.png)
365365

366-
## Using the plugin
367-
368366
### Adding Roles
369367

370-
Hashicorp Vault supports being able to add roles to control certificate issuance policies such as allowed domains. To create a role, use the vault write command as in the below example.
371-
`vault write keyfactor/roles/hashiwebserver allowed_domains=kftrain.lab allow_subdomains=true`
368+
Hashicorp Vault supports being able to add roles to control certificate issuance policies for allowed domains and allowing sub-domain certificates to be created.
369+
To create a role, use the vault write command as in the below example.
370+
371+
`vault write keyfactor/roles/hashiwebserver allowed_domains=kftrain.lab allow_subdomains=true`
372+
373+
This will create a role called "hashiwebserver" that can be used to generate certificates for domains ending with "kftrain.lab".
374+
375+
These properties can also be set in the certificate template. If they differ, the most restrictive setting is applied.
376+
377+
## Using the plugin
372378

373379
### Issuing Certificates
374380

375-
When requesting a certificate using the Keyfactor plugin, the command is the same as if you were issuing the certificate through the vault integrated PKI. As a part of the write command you will specify the role name you would like to use, as well as the common name on the certificate. A typical certificate issuance command is listed below for the hashiwebserver role, and a CN of foo.kftrain.lab on the certificate.
381+
When requesting a certificate using the Keyfactor plugin, the command is the same as if you were issuing the certificate through the vault integrated PKI. As a part of the write command you will specify the role name you would like to use, as well as the common name on the certificate. A typical certificate issuance command is listed below for the hashiwebserver role, and a CN of foo.kftrain.lab on the certificate.
376382

377-
`vault write keyfactor/issue/hashiwebserver common_name=foo.kftrain.lab dns_sans=foo.kftrain.lab`
383+
`vault write keyfactor/issue/hashiwebserver common_name=foo.kftrain.lab dns_sans=foo.kftrain.lab`
378384

379-
The resulting response will show the certificate data response for the request. This certificate will also be stored in the Vault secrets store.
385+
The resulting response will show the certificate data response for the request. This certificate will also be stored in the Vault secrets store.
380386

381387
!["vault3"](images/vault3.png)
382388

383389
### Viewing Certificates
384390

385-
After certificates are stored in the secrets store, you can then retrieve those certificates at a later time if necessary. To list the certificates that exist within the Vault store, use the LIST option with vault. The only parameter that you need to include is the secrets store name for the store that you would like to read. The system will then return a list of all of the serial numbers for certificates that are present in that secrets store.
386-
387-
`vault list keyfactor/certs`
388-
389-
The results of the command will be a list of serial numbers for the certificates in that store location:
390-
391-
```
392-
Keys
393-
----
394-
750000276546d818cbe70231b6000000002765
395-
750000276623facfaddb6c4ca1000000002766
396-
```
397-
398-
If you would like to retrieve a specific certificate from the store, you can do so by using the "vault read" command, and specifying the serial number of the certificate that you would like returned. The format for the command looks like this:
399-
400-
`vault read keyfactor/cert/<serial>`
401-
402-
example:
403-
404-
`vault read keyfactor/cert/750000276546d818cbe70231b6000000002765`
405-
406-
The response will show the value for that certificate.
407-
408-
```
409-
Key Value
410-
--- -----
411-
certificate -----BEGIN CERTIFICATE-----
412-
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tDQpNSUlGZXpDQ0JHT2dBd0lCQWdJ
413-
VGRRQUFKMlZHMkJqTDV3SXh0Z0FBQUFBblpUQU5CZ2txaGtpRzl3MEJBUXNGDQpB
414-
REJQTVJNd0VRWUtDWkltaVpQeUxHUUJHUllEYkdGaU1Sa3dGd1lLQ1pJbWlaUHlM
415-
R1FCR1JZSmEyVjVabUZqDQpkRzl5TVIwd0d3WURWUVFERXhSclpYbG1ZV04wYjNJ
416-
dFMwWlVVa0ZKVGkxRFFUQWVGdzB5TWpBME1qSXhOVE0xDQpNVGxhRncweU1qQTNN
417-
akV4TlRNMU1UbGFNQm94R0RBV0JnTlZCQU1URDNWMWRTNXJablJ5WVdsdUxteGhZ
418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RM0xocEFtcmZXbzYxU0l3bHl3WEowV1YxU050UEtu
449-
bUFvQUV2ZUIvSEpNSitkeTM1Q084Y2tOMFVidmk2OUhsDQoya1pIdE1LUWJsckk3
450-
ZXV2MHdnVERqWVIvdms3Yjl0UWlxSmE0YURvMnRsZmF2KzF4Tk40WVdxa3R2QUth
451-
c3hsDQpBVW02bjdydVh5OEs4d005bEFVU2Rwb29iNzdQQ1lpTWhZRkF0ODUzQVlD
452-
R1N0bU1nT21Pa0F1YVVEUHNET3pQDQplUXd1S25Hdy82WDJlUXltaU1BWQ0KLS0t
453-
LS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ0K
454-
-----END CERTIFICATE-----
455-
revocation_time 0
456-
```
391+
After certificates are stored in the secrets store, you can then retrieve those certificates at a later time if necessary. To list the certificates that exist within the Vault store, use the LIST option with vault. The only parameter that you need to include is the secrets store name for the store that you would like to read. The system will then return a list of all of the serial numbers for certificates that are present in that secrets store.
392+
393+
`vault list keyfactor/certs`
394+
395+
The results of the command will be a list of serial numbers for the certificates in that store location:
396+
397+
```
398+
Keys
399+
----
400+
750000276546d818cbe70231b6000000002765
401+
750000276623facfaddb6c4ca1000000002766
402+
```
403+
404+
If you would like to retrieve a specific certificate from the store, you can do so by using the "vault read" command, and specifying the serial number of the certificate that you would like returned. The format for the command looks like this:
405+
406+
`vault read keyfactor/cert/<serial>`
407+
408+
example:
409+
410+
`vault read keyfactor/cert/750000276546d818cbe70231b6000000002765`
411+
412+
The response will show the value for that certificate.
413+
414+
```
415+
Key Value
416+
--- -----
417+
certificate -----BEGIN CERTIFICATE-----
418+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tDQpNSUlGZXpDQ0JHT2dBd0lCQWdJ
419+
VGRRQUFKMlZHMkJqTDV3SXh0Z0FBQUFBblpUQU5CZ2txaGtpRzl3MEJBUXNGDQpB
420+
REJQTVJNd0VRWUtDWkltaVpQeUxHUUJHUllEYkdGaU1Sa3dGd1lLQ1pJbWlaUHlM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SUJBUUNBDQpqa1ZBTi9hL0NtVm5DTVV2RW1V
452+
S0FuN1BhMFlpTmxxZVJwU2NIZ1dpYnZjc0NLM1Z1VTlSaENBdldpb1RBMytwDQpr
453+
VXhYL0c4LzFlOXRlcWJnaElMZ2ZtemJuWndvZU1BTHo0aFZqYmtVYy83cGpaSVBr
454+
ejA1cXRaT1ZSUzluaEVMDQpRM0xocEFtcmZXbzYxU0l3bHl3WEowV1YxU050UEtu
455+
bUFvQUV2ZUIvSEpNSitkeTM1Q084Y2tOMFVidmk2OUhsDQoya1pIdE1LUWJsckk3
456+
ZXV2MHdnVERqWVIvdms3Yjl0UWlxSmE0YURvMnRsZmF2KzF4Tk40WVdxa3R2QUth
457+
c3hsDQpBVW02bjdydVh5OEs4d005bEFVU2Rwb29iNzdQQ1lpTWhZRkF0ODUzQVlD
458+
R1N0bU1nT21Pa0F1YVVEUHNET3pQDQplUXd1S25Hdy82WDJlUXltaU1BWQ0KLS0t
459+
LS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ0K
460+
-----END CERTIFICATE-----
461+
revocation_time 0
462+
```
457463

458464
## Plugin command reference
459465

@@ -511,4 +517,4 @@ The following commands are supported by the Keyfactor Hashicorp Vault Secrets En
511517

512518
### Read CA chain
513519

514-
`vault read keyfactor/ca_chain`
520+
`vault read keyfactor/ca_chain`
-1.36 MB
Binary file not shown.

launch-vault.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

path_certs.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,33 @@ func (b *keyfactorBackend) pathIssueSignCert(ctx context.Context, req *logical.R
326326

327327
//check role permissions
328328
var err_resp error
329-
if strings.Contains(cn.(string), role.AllowedBaseDomain) && !role.AllowSubdomains {
330-
err_resp = fmt.Errorf("sub-domains not allowed for role")
329+
var valid bool
330+
var hasSuffix bool
331+
332+
for _, v := range role.AllowedDomains {
333+
b.Logger().Warn(v)
334+
if strings.HasSuffix(cn.(string), v) {
335+
hasSuffix = true
336+
if cn.(string) == v || role.AllowSubdomains {
337+
valid = true
338+
}
339+
}
331340
}
332-
if role.AllowedBaseDomain == cn.(string) {
333-
err_resp = fmt.Errorf("common name not allowed for provided role")
341+
342+
if !valid {
343+
err_resp = fmt.Errorf("common name not allowed for role")
344+
}
345+
if !valid && hasSuffix {
346+
err_resp = fmt.Errorf("sub-domains not allowed for role")
334347
}
335348

336349
if err_resp != nil {
337350
return nil, err_resp
338351
}
339352

353+
b.Logger().Warn("role.AllowedBaseDomain = " + role.AllowedBaseDomain)
354+
b.Logger().Warn("domain for cert = " + cn.(string))
355+
340356
for u := range dns_sans {
341357
if !strings.Contains(dns_sans[u], role.AllowedBaseDomain) || strings.Contains(dns_sans[u], role.AllowedBaseDomain) && !role.AllowSubdomains {
342358
return nil, fmt.Errorf("Subject Alternative Name " + dns_sans[u] + " not allowed for provided role")

sample_config.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

unseal.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

write.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)