|
|
|
@ -1415,6 +1415,85 @@ func TestVaultCAProvider_ConsulManaged(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestVaultCAProvider_EnterpriseNamespace(t *testing.T) {
|
|
|
|
|
SkipIfVaultNotPresent(t, vaultRequirements{Enterprise: true})
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
cases := map[string]struct {
|
|
|
|
|
namespaces map[string]string
|
|
|
|
|
}{
|
|
|
|
|
"no configured namespaces": {},
|
|
|
|
|
"only base namespace provided": {namespaces: map[string]string{"Namespace": "base-ns"}},
|
|
|
|
|
"only root namespace provided": {namespaces: map[string]string{"RootPKINamespace": "root-pki-ns"}},
|
|
|
|
|
"only intermediate namespace provided": {namespaces: map[string]string{"IntermediatePKINamespace": "int-pki-ns"}},
|
|
|
|
|
"base and root namespace provided": {
|
|
|
|
|
namespaces: map[string]string{
|
|
|
|
|
"Namespace": "base-ns",
|
|
|
|
|
"RootPKINamespace": "root-pki-ns",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"base and intermediate namespace provided": {
|
|
|
|
|
namespaces: map[string]string{
|
|
|
|
|
"Namespace": "base-ns",
|
|
|
|
|
"IntermediatePKINamespace": "int-pki-ns",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"root and intermediate namespace provided": {
|
|
|
|
|
namespaces: map[string]string{
|
|
|
|
|
"RootPKINamespace": "root-pki-ns",
|
|
|
|
|
"IntermediatePKINamespace": "int-pki-ns",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"all namespaces provided": {
|
|
|
|
|
namespaces: map[string]string{
|
|
|
|
|
"Namespace": "base-ns",
|
|
|
|
|
"RootPKINamespace": "root-pki-ns",
|
|
|
|
|
"IntermediatePKINamespace": "int-pki-ns",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for name, c := range cases {
|
|
|
|
|
c := c
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
testVault := NewTestVaultServer(t)
|
|
|
|
|
token := "root"
|
|
|
|
|
|
|
|
|
|
providerConfig := map[string]any{
|
|
|
|
|
"RootPKIPath": "pki-root/",
|
|
|
|
|
"IntermediatePKIPath": "pki-intermediate/",
|
|
|
|
|
}
|
|
|
|
|
for k, v := range c.namespaces {
|
|
|
|
|
providerConfig[k] = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(c.namespaces) > 0 {
|
|
|
|
|
// If explicit namespaces are provided, try to create the provider before any of the namespaces
|
|
|
|
|
// have been created. Verify that the provider fails to initialize.
|
|
|
|
|
provider, err := createVaultProviderE(t, true, testVault.Addr, token, providerConfig)
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
require.NotNil(t, provider)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the namespaces
|
|
|
|
|
client := testVault.Client()
|
|
|
|
|
client.SetToken(token)
|
|
|
|
|
|
|
|
|
|
for _, ns := range c.namespaces {
|
|
|
|
|
_, err := client.Logical().Write(fmt.Sprintf("/sys/namespaces/%s", ns), map[string]any{})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify that once the namespaces have been created we are able to initialize the provider.
|
|
|
|
|
provider, err := createVaultProviderE(t, true, testVault.Addr, token, providerConfig)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.NotNil(t, provider)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getIntermediateCertTTL(t *testing.T, caConf *structs.CAConfiguration) time.Duration {
|
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
|
@ -1436,6 +1515,15 @@ func getIntermediateCertTTL(t *testing.T, caConf *structs.CAConfiguration) time.
|
|
|
|
|
|
|
|
|
|
func createVaultProvider(t *testing.T, isPrimary bool, addr, token string, rawConf map[string]any) *VaultProvider {
|
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
|
|
provider, err := createVaultProviderE(t, isPrimary, addr, token, rawConf)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
return provider
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func createVaultProviderE(t *testing.T, isPrimary bool, addr, token string, rawConf map[string]any) (*VaultProvider, error) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
cfg := vaultProviderConfig(t, addr, token, rawConf)
|
|
|
|
|
|
|
|
|
|
provider := NewVaultProvider(hclog.New(nil))
|
|
|
|
@ -1446,15 +1534,19 @@ func createVaultProvider(t *testing.T, isPrimary bool, addr, token string, rawCo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.Cleanup(provider.Stop)
|
|
|
|
|
require.NoError(t, provider.Configure(cfg))
|
|
|
|
|
if err := provider.Configure(cfg); err != nil {
|
|
|
|
|
return provider, err
|
|
|
|
|
}
|
|
|
|
|
if isPrimary {
|
|
|
|
|
_, err := provider.GenerateCAChain()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = provider.GenerateLeafSigningCert()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
if _, err := provider.GenerateCAChain(); err != nil {
|
|
|
|
|
return provider, err
|
|
|
|
|
}
|
|
|
|
|
if _, err := provider.GenerateLeafSigningCert(); err != nil {
|
|
|
|
|
return provider, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return provider
|
|
|
|
|
return provider, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func vaultProviderConfig(t *testing.T, addr, token string, rawConf map[string]any) ProviderConfig {
|
|
|
|
|