Skip to content

Commit

Permalink
make sure pki IDs are unique
Browse files Browse the repository at this point in the history
This was a classic cut-n-paste error. The PKI code was based on the
existing vault_read.go 'secret' code and missed the fact that the ID of
the pkiCert will be identical for all certs pulled form the same PKI
role path.

The fix will be to adjust the ID to be composed of the pki role path
+ the destination path. That should be unique per use case as the
destination path must be unique per Cert.
  • Loading branch information
eikenb committed Aug 1, 2022
1 parent b0fc762 commit bbfd5fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dependency/vault_pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (d *VaultPKIQuery) Stop() {

// String returns the human-friendly version of this dependency.
func (d *VaultPKIQuery) String() string {
return fmt.Sprintf("vault.pki(%s)", d.pkiPath)
return fmt.Sprintf("vault.pki(%s->%s)", d.pkiPath, d.filePath)
}

// Type returns the type of this dependency.
Expand Down
10 changes: 10 additions & 0 deletions dependency/vault_pki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ import (
"github.com/hashicorp/vault/api"
)

func Test_VaultPKI_uniqueID(t *testing.T) {
d1, _ := NewVaultPKIQuery("pki/issue/example-dot-com", "/unique_1", nil)
id1 := d1.String()
d2, _ := NewVaultPKIQuery("pki/issue/example-dot-com", "/unique_2", nil)
id2 := d2.String()
if id1 == id2 {
t.Errorf("IDs should be unique.\n%s\n%s", id1, id2)
}
}

func Test_VaultPKI_notGoodFor(t *testing.T) {
// only test the negation, postive is tested below with pemsificates
// fetched in Vault integration tests (creating pemss is non-trivial)
Expand Down
6 changes: 4 additions & 2 deletions template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,8 @@ func TestTemplate_Execute(t *testing.T) {
{
"func_pkiCert",
&NewTemplateInput{
Contents: `{{ with pkiCert "pki/issue/egs-dot-com" }}{{.Cert}}{{end}}`,
Contents: `{{ with pkiCert "pki/issue/egs-dot-com" }}{{.Cert}}{{end}}`,
Destination: "/dev/null",
},
&ExecuteInput{
Brain: func() *Brain {
Expand All @@ -1983,7 +1984,8 @@ func TestTemplate_Execute(t *testing.T) {
{
"func_pkiCert_Data_compat",
&NewTemplateInput{
Contents: `{{ with pkiCert "pki/issue/egs-dot-com" }}{{.Data.Cert}}{{end}}`,
Contents: `{{ with pkiCert "pki/issue/egs-dot-com" }}{{.Data.Cert}}{{end}}`,
Destination: "/dev/null",
},
&ExecuteInput{
Brain: func() *Brain {
Expand Down

0 comments on commit bbfd5fe

Please sign in to comment.