|
@@ -39,10 +39,13 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
var (
|
|
|
- svcURL = "https://example.com"
|
|
|
|
|
- svcUser = "user"
|
|
|
|
|
- svcApikey = "apikey"
|
|
|
|
|
- svcAccount = "account1"
|
|
|
|
|
|
|
+ svcURL = "https://example.com"
|
|
|
|
|
+ svcUser = "user"
|
|
|
|
|
+ svcApikey = "apikey"
|
|
|
|
|
+ svcAccount = "account1"
|
|
|
|
|
+ jwtAuthenticator = "jwt-authenticator"
|
|
|
|
|
+ jwtAuthnService = "jwt-auth-service"
|
|
|
|
|
+ jwtSecretName = "jwt-secret"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func makeValidRef(k string) *esv1beta1.ExternalSecretDataRemoteRef {
|
|
func makeValidRef(k string) *esv1beta1.ExternalSecretDataRemoteRef {
|
|
@@ -81,27 +84,27 @@ func TestValidateStore(t *testing.T) {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
- store: makeJWTSecretStore(svcURL, "conjur", "", "jwt-auth-service", "myconjuraccount"),
|
|
|
|
|
|
|
+ store: makeJWTSecretStore(svcURL, "conjur", "", jwtAuthnService, "", "myconjuraccount"),
|
|
|
err: nil,
|
|
err: nil,
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- store: makeJWTSecretStore(svcURL, "", "jwt-secret", "jwt-auth-service", "myconjuraccount"),
|
|
|
|
|
|
|
+ store: makeJWTSecretStore(svcURL, "", jwtSecretName, jwtAuthnService, "", "myconjuraccount"),
|
|
|
err: nil,
|
|
err: nil,
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- store: makeJWTSecretStore(svcURL, "conjur", "", "jwt-auth-service", ""),
|
|
|
|
|
|
|
+ store: makeJWTSecretStore(svcURL, "conjur", "", jwtAuthnService, "", ""),
|
|
|
err: fmt.Errorf("missing Auth.Jwt.Account"),
|
|
err: fmt.Errorf("missing Auth.Jwt.Account"),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- store: makeJWTSecretStore(svcURL, "conjur", "", "", "myconjuraccount"),
|
|
|
|
|
|
|
+ store: makeJWTSecretStore(svcURL, "conjur", "", "", "", "myconjuraccount"),
|
|
|
err: fmt.Errorf("missing Auth.Jwt.ServiceID"),
|
|
err: fmt.Errorf("missing Auth.Jwt.ServiceID"),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- store: makeJWTSecretStore("", "conjur", "", "jwt-auth-service", "myconjuraccount"),
|
|
|
|
|
|
|
+ store: makeJWTSecretStore("", "conjur", "", jwtAuthnService, "", "myconjuraccount"),
|
|
|
err: fmt.Errorf("conjur URL cannot be empty"),
|
|
err: fmt.Errorf("conjur URL cannot be empty"),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- store: makeJWTSecretStore(svcURL, "", "", "jwt-auth-service", "myconjuraccount"),
|
|
|
|
|
|
|
+ store: makeJWTSecretStore(svcURL, "", "", jwtAuthnService, "", "myconjuraccount"),
|
|
|
err: fmt.Errorf("must specify Auth.Jwt.SecretRef or Auth.Jwt.ServiceAccountRef"),
|
|
err: fmt.Errorf("must specify Auth.Jwt.SecretRef or Auth.Jwt.ServiceAccountRef"),
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -175,7 +178,22 @@ func TestGetSecret(t *testing.T) {
|
|
|
"JwtWithServiceAccountRefReadSecretSuccess": {
|
|
"JwtWithServiceAccountRefReadSecretSuccess": {
|
|
|
reason: "Should read a secret successfully using a JWT auth secret store that references a k8s service account.",
|
|
reason: "Should read a secret successfully using a JWT auth secret store that references a k8s service account.",
|
|
|
args: args{
|
|
args: args{
|
|
|
- store: makeJWTSecretStore(svcURL, "my-service-account", "", "jwt-authenticator", "myconjuraccount"),
|
|
|
|
|
|
|
+ store: makeJWTSecretStore(svcURL, svcAccount, "", jwtAuthenticator, "", "myconjuraccount"),
|
|
|
|
|
+ kube: clientfake.NewClientBuilder().
|
|
|
|
|
+ WithObjects().Build(),
|
|
|
|
|
+ namespace: "default",
|
|
|
|
|
+ secretPath: "path/to/secret",
|
|
|
|
|
+ corev1: utilfake.NewCreateTokenMock().WithToken(createFakeJwtToken(true)),
|
|
|
|
|
+ },
|
|
|
|
|
+ want: want{
|
|
|
|
|
+ err: nil,
|
|
|
|
|
+ value: "secret",
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ "JwtWithServiceAccountRefWithHostIdReadSecretSuccess": {
|
|
|
|
|
+ reason: "Should read a secret successfully using a JWT auth secret store that references a k8s service account and uses a host ID.",
|
|
|
|
|
+ args: args{
|
|
|
|
|
+ store: makeJWTSecretStore(svcURL, svcAccount, "", jwtAuthenticator, "myhostid", "myconjuraccount"),
|
|
|
kube: clientfake.NewClientBuilder().
|
|
kube: clientfake.NewClientBuilder().
|
|
|
WithObjects().Build(),
|
|
WithObjects().Build(),
|
|
|
namespace: "default",
|
|
namespace: "default",
|
|
@@ -190,11 +208,11 @@ func TestGetSecret(t *testing.T) {
|
|
|
"JwtWithSecretRefReadSecretSuccess": {
|
|
"JwtWithSecretRefReadSecretSuccess": {
|
|
|
reason: "Should read a secret successfully using an JWT auth secret store that references a k8s secret.",
|
|
reason: "Should read a secret successfully using an JWT auth secret store that references a k8s secret.",
|
|
|
args: args{
|
|
args: args{
|
|
|
- store: makeJWTSecretStore(svcURL, "", "jwt-secret", "jwt-authenticator", "myconjuraccount"),
|
|
|
|
|
|
|
+ store: makeJWTSecretStore(svcURL, "", jwtSecretName, jwtAuthenticator, "", "myconjuraccount"),
|
|
|
kube: clientfake.NewClientBuilder().
|
|
kube: clientfake.NewClientBuilder().
|
|
|
WithObjects(&corev1.Secret{
|
|
WithObjects(&corev1.Secret{
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
- Name: "jwt-secret",
|
|
|
|
|
|
|
+ Name: jwtSecretName,
|
|
|
Namespace: "default",
|
|
Namespace: "default",
|
|
|
},
|
|
},
|
|
|
Data: map[string][]byte{
|
|
Data: map[string][]byte{
|
|
@@ -212,7 +230,7 @@ func TestGetSecret(t *testing.T) {
|
|
|
"JwtWithCABundleSuccess": {
|
|
"JwtWithCABundleSuccess": {
|
|
|
reason: "Should read a secret successfully using a JWT auth secret store that references a k8s service account.",
|
|
reason: "Should read a secret successfully using a JWT auth secret store that references a k8s service account.",
|
|
|
args: args{
|
|
args: args{
|
|
|
- store: makeJWTSecretStore(svcURL, "my-service-account", "", "jwt-authenticator", "myconjuraccount"),
|
|
|
|
|
|
|
+ store: makeJWTSecretStore(svcURL, svcAccount, "", jwtAuthenticator, "", "myconjuraccount"),
|
|
|
kube: clientfake.NewClientBuilder().
|
|
kube: clientfake.NewClientBuilder().
|
|
|
WithObjects().Build(),
|
|
WithObjects().Build(),
|
|
|
namespace: "default",
|
|
namespace: "default",
|
|
@@ -364,7 +382,7 @@ func makeAPIKeySecretStore(svcURL, svcUser, svcApikey, svcAccount string) *esv1b
|
|
|
return store
|
|
return store
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func makeJWTSecretStore(svcURL, serviceAccountName, secretName, jwtServiceID, conjurAccount string) *esv1beta1.SecretStore {
|
|
|
|
|
|
|
+func makeJWTSecretStore(svcURL, serviceAccountName, secretName, jwtServiceID, jwtHostID, conjurAccount string) *esv1beta1.SecretStore {
|
|
|
serviceAccountRef := &esmeta.ServiceAccountSelector{
|
|
serviceAccountRef := &esmeta.ServiceAccountSelector{
|
|
|
Name: serviceAccountName,
|
|
Name: serviceAccountName,
|
|
|
Audiences: []string{"conjur"},
|
|
Audiences: []string{"conjur"},
|
|
@@ -392,6 +410,7 @@ func makeJWTSecretStore(svcURL, serviceAccountName, secretName, jwtServiceID, co
|
|
|
ServiceID: jwtServiceID,
|
|
ServiceID: jwtServiceID,
|
|
|
ServiceAccountRef: serviceAccountRef,
|
|
ServiceAccountRef: serviceAccountRef,
|
|
|
SecretRef: secretRef,
|
|
SecretRef: secretRef,
|
|
|
|
|
+ HostID: jwtHostID,
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
@@ -402,7 +421,7 @@ func makeJWTSecretStore(svcURL, serviceAccountName, secretName, jwtServiceID, co
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func makeStoreWithCA(caSource, caData string) *esv1beta1.SecretStore {
|
|
func makeStoreWithCA(caSource, caData string) *esv1beta1.SecretStore {
|
|
|
- store := makeJWTSecretStore(svcURL, "conjur", "", "jwt-auth-service", "myconjuraccount")
|
|
|
|
|
|
|
+ store := makeJWTSecretStore(svcURL, "conjur", "", jwtAuthnService, "", "myconjuraccount")
|
|
|
if caSource == "secret" {
|
|
if caSource == "secret" {
|
|
|
store.Spec.Provider.Conjur.CAProvider = &esv1beta1.CAProvider{
|
|
store.Spec.Provider.Conjur.CAProvider = &esv1beta1.CAProvider{
|
|
|
Type: esv1beta1.CAProviderTypeSecret,
|
|
Type: esv1beta1.CAProviderTypeSecret,
|
|
@@ -502,7 +521,7 @@ func (c *ConjurMockAPIClient) NewClientFromKey(_ conjurapi.Config, _ authn.Login
|
|
|
return &fake.ConjurMockClient{}, nil
|
|
return &fake.ConjurMockClient{}, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (c *ConjurMockAPIClient) NewClientFromJWT(_ conjurapi.Config, _, _ string) (SecretsClient, error) {
|
|
|
|
|
|
|
+func (c *ConjurMockAPIClient) NewClientFromJWT(_ conjurapi.Config, _, _, _ string) (SecretsClient, error) {
|
|
|
return &fake.ConjurMockClient{}, nil
|
|
return &fake.ConjurMockClient{}, nil
|
|
|
}
|
|
}
|
|
|
|
|
|