Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/inject/secrets-provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ func TestSecretsProviderSidecarInjection(t *testing.T) {
"conjurSslCertificate": "-----BEGIN CERTIFICATE-----tVw0ZnjsOV2ZeIBRalX/72RplPzkmWKAw==\n-----END CERTIFICATE-----\n",
},
},
{
description: "SecretsProvider k8s_secrets sidecar - no conjur-secrets volume injected",
annotatedPodTemplateSpecPath: "./testdata/secrets-provider-k8s-annotated-pod.json",
expectedInjectedPodTemplateSpecPath: "./testdata/secrets-provider-k8s-mutated-pod.json",
env: map[string]string{
"CONJUR_ACCOUNT": "myConjurAccount",
"CONJUR_APPLIANCE_URL": "https://conjur-oss.conjur-oss.svc.cluster.local",
"CONJUR_AUTHENTICATOR_ID": "my-authenticator-id",
"CONJUR_AUTHN_URL": "https://conjur-oss.conjur-oss.svc.cluster.local/authn-k8s/my-authenticator-id",
"CONJUR_SSL_CERTIFICATE": "-----BEGIN CERTIFICATE-----tVw0ZnjsOV2ZeIBRalX/72RplPzkmWKAw==\n-----END CERTIFICATE-----\n",
},
},
{
description: "SecretsProvider k8s_secrets init - no conjur-secrets volume injected",
annotatedPodTemplateSpecPath: "./testdata/secrets-provider-k8s-init-annotated-pod.json",
expectedInjectedPodTemplateSpecPath: "./testdata/secrets-provider-k8s-init-mutated-pod.json",
env: map[string]string{
"CONJUR_ACCOUNT": "myConjurAccount",
"CONJUR_APPLIANCE_URL": "https://conjur-oss.conjur-oss.svc.cluster.local",
"CONJUR_AUTHENTICATOR_ID": "my-authenticator-id",
"CONJUR_AUTHN_URL": "https://conjur-oss.conjur-oss.svc.cluster.local/authn-k8s/my-authenticator-id",
"CONJUR_SSL_CERTIFICATE": "-----BEGIN CERTIFICATE-----tVw0ZnjsOV2ZeIBRalX/72RplPzkmWKAw==\n-----END CERTIFICATE-----\n",
},
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
Expand Down
9 changes: 6 additions & 3 deletions pkg/inject/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,21 @@ func HandleAdmissionRequest(
containerVolumeMounts := ContainerVolumeMounts{}

for _, receiveContainerName := range conjurInjectVolume {
containerVolumeMounts[receiveContainerName] = []corev1.VolumeMount{
mounts := []corev1.VolumeMount{
{
Name: "conjur-status",
ReadOnly: false,
MountPath: "/conjur/status",
},
{
}
if secretsDestination == "file" {
mounts = append(mounts, corev1.VolumeMount{
Name: "conjur-secrets",
ReadOnly: false,
MountPath: "/conjur/secrets",
},
})
}
containerVolumeMounts[receiveContainerName] = mounts
}
sidecarConfig.ContainerVolumeMounts = containerVolumeMounts
default:
Expand Down
42 changes: 42 additions & 0 deletions pkg/inject/testdata/secrets-provider-k8s-annotated-pod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"metadata": {
"generateName": "nginx-deployment-6c54bd5869-",
"labels": {
"app": "nginx",
"pod-template-hash": "2710681425"
},
"annotations": {
"conjur.org/inject": "true",
"conjur.org/inject-type": "secrets-provider",
"conjur.org/container-name" : "secrets-provider-name",
"conjur.org/container-mode": "sidecar",
"conjur.org/secrets-destination": "k8s_secrets",
"conjur.org/conjur-inject-volumes": "nginx-1",
"my-company": "my-project"
}
},
"spec": {
"volumes": [
{
"name": "default-token-tq5lq",
"secret": {
"secretName": "default-token-tq5lq"
}
}
],
"containers": [
{
"name": "nginx-1",
"image": "nginx:1.7.9",
"volumeMounts": [
{
"name": "default-token-tq5lq",
"readOnly": true,
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
}
]
}
]
}
}

42 changes: 42 additions & 0 deletions pkg/inject/testdata/secrets-provider-k8s-init-annotated-pod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"metadata": {
"generateName": "nginx-deployment-6c54bd5869-",
"labels": {
"app": "nginx",
"pod-template-hash": "2710681425"
},
"annotations": {
"conjur.org/inject": "true",
"conjur.org/inject-type": "secrets-provider",
"conjur.org/container-name" : "secrets-provider-name",
"conjur.org/container-mode": "init",
"conjur.org/secrets-destination": "k8s_secrets",
"conjur.org/conjur-inject-volumes": "nginx-1",
"my-company": "my-project"
}
},
"spec": {
"volumes": [
{
"name": "default-token-tq5lq",
"secret": {
"secretName": "default-token-tq5lq"
}
}
],
"containers": [
{
"name": "nginx-1",
"image": "nginx:1.7.9",
"volumeMounts": [
{
"name": "default-token-tq5lq",
"readOnly": true,
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
}
]
}
]
}
}

119 changes: 119 additions & 0 deletions pkg/inject/testdata/secrets-provider-k8s-init-mutated-pod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"metadata": {
"generateName": "nginx-deployment-6c54bd5869-",
"labels": {
"app": "nginx",
"pod-template-hash": "2710681425"
},
"annotations": {
"conjur.org/container-mode": "init",
"conjur.org/secrets-destination": "k8s_secrets",
"my-company": "my-project",
"conjur.org/status": "injected"
}
},
"spec": {
"volumes": [
{
"name": "default-token-tq5lq",
"secret": {
"secretName": "default-token-tq5lq"
}
},
{
"name": "podinfo",
"downwardAPI": {
"items": [
{
"path": "annotations",
"fieldRef": {
"fieldPath": "metadata.annotations"
}
}
]
}
},
{
"name": "conjur-status",
"emptyDir": {
"medium": "Memory"
}
}
],
"containers": [
{
"name": "nginx-1",
"image": "nginx:1.7.9",
"volumeMounts": [
{
"name": "default-token-tq5lq",
"readOnly": true,
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
},
{
"name": "conjur-status",
"mountPath": "/conjur/status"
}
]
}
],
"initContainers": [
{
"name": "secrets-provider-name",
"image": "secrets-provider-image",
"resources": {},
"imagePullPolicy": "Always",
"env": [
{
"name": "MY_POD_NAME",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.name"
}
}
},
{
"name": "MY_POD_NAMESPACE",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.namespace"
}
}
},
{
"name": "CONJUR_ACCOUNT",
"value": "myConjurAccount"
},
{
"name": "CONJUR_APPLIANCE_URL",
"value": "https://conjur-oss.conjur-oss.svc.cluster.local"
},
{
"name": "CONJUR_AUTHENTICATOR_ID",
"value": "my-authenticator-id"
},
{
"name": "CONJUR_AUTHN_URL",
"value": "https://conjur-oss.conjur-oss.svc.cluster.local/authn-k8s/my-authenticator-id"
},
{
"name": "CONJUR_SSL_CERTIFICATE",
"value": "-----BEGIN CERTIFICATE-----tVw0ZnjsOV2ZeIBRalX/72RplPzkmWKAw==\n-----END CERTIFICATE-----\n"
}
],
"volumeMounts": [
{
"name": "podinfo",
"readOnly": true,
"mountPath": "/conjur/podinfo"
},
{
"name": "conjur-status",
"mountPath": "/conjur/status"
}
]
}
]
}
}

117 changes: 117 additions & 0 deletions pkg/inject/testdata/secrets-provider-k8s-mutated-pod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"metadata": {
"generateName": "nginx-deployment-6c54bd5869-",
"labels": {
"app": "nginx",
"pod-template-hash": "2710681425"
},
"annotations": {
"conjur.org/container-mode": "sidecar",
"conjur.org/secrets-destination": "k8s_secrets",
"my-company": "my-project",
"conjur.org/status": "injected"
}
},
"spec": {
"volumes": [
{
"name": "default-token-tq5lq",
"secret": {
"secretName": "default-token-tq5lq"
}
},
{
"name": "podinfo",
"downwardAPI": {
"items": [
{
"path": "annotations",
"fieldRef": {
"fieldPath": "metadata.annotations"
}
}
]
}
},
{
"name": "conjur-status",
"emptyDir": {
"medium": "Memory"
}
}
],
"containers": [
{
"name": "nginx-1",
"image": "nginx:1.7.9",
"volumeMounts": [
{
"name": "default-token-tq5lq",
"readOnly": true,
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
},
{
"name": "conjur-status",
"mountPath": "/conjur/status"
}
]
},
{
"name": "secrets-provider-name",
"image": "secrets-provider-image",
"resources": {},
"imagePullPolicy": "Always",
"env": [
{
"name": "MY_POD_NAME",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.name"
}
}
},
{
"name": "MY_POD_NAMESPACE",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.namespace"
}
}
},
{
"name": "CONJUR_ACCOUNT",
"value": "myConjurAccount"
},
{
"name": "CONJUR_APPLIANCE_URL",
"value": "https://conjur-oss.conjur-oss.svc.cluster.local"
},
{
"name": "CONJUR_AUTHENTICATOR_ID",
"value": "my-authenticator-id"
},
{
"name": "CONJUR_AUTHN_URL",
"value": "https://conjur-oss.conjur-oss.svc.cluster.local/authn-k8s/my-authenticator-id"
},
{
"name": "CONJUR_SSL_CERTIFICATE",
"value": "-----BEGIN CERTIFICATE-----tVw0ZnjsOV2ZeIBRalX/72RplPzkmWKAw==\n-----END CERTIFICATE-----\n"
}
],
"volumeMounts": [
{
"name": "podinfo",
"readOnly": true,
"mountPath": "/conjur/podinfo"
},
{
"name": "conjur-status",
"mountPath": "/conjur/status"
}
]
}
]
}
}