Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mount secret with SSE-C key if needed, fix secret key read. Fixes #9867 #9870

Merged
merged 2 commits into from Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion workflow/artifacts/artifacts.go
Expand Up @@ -60,7 +60,7 @@ func newDriver(ctx context.Context, art *wfv1.Artifact, ri resource.Interface) (
return nil, fmt.Errorf("serverSideCustomerKeySecret and kmsKeyId cannot be set together")
}

serverSideCustomerKeyBytes, err := ri.GetSecret(ctx, art.S3.EncryptionOptions.ServerSideCustomerKeySecret.Name, art.S3.SecretKeySecret.Key)
serverSideCustomerKeyBytes, err := ri.GetSecret(ctx, art.S3.EncryptionOptions.ServerSideCustomerKeySecret.Name, art.S3.EncryptionOptions.ServerSideCustomerKeySecret.Key)
if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions workflow/controller/workflowpod.go
Expand Up @@ -1171,6 +1171,10 @@ func createSecretVolumesFromArtifactLocations(volMap map[string]apiv1.Volume, ar
if artifactLocation.S3 != nil {
createSecretVal(volMap, artifactLocation.S3.AccessKeySecret, keyMap)
createSecretVal(volMap, artifactLocation.S3.SecretKeySecret, keyMap)
sseCUsed := artifactLocation.S3.EncryptionOptions != nil && artifactLocation.S3.EncryptionOptions.EnableEncryption && artifactLocation.S3.EncryptionOptions.ServerSideCustomerKeySecret != nil
if sseCUsed {
createSecretVal(volMap, artifactLocation.S3.EncryptionOptions.ServerSideCustomerKeySecret, keyMap)
}
} else if artifactLocation.Git != nil {
createSecretVal(volMap, artifactLocation.Git.UsernameSecret, keyMap)
createSecretVal(volMap, artifactLocation.Git.PasswordSecret, keyMap)
Expand Down
87 changes: 87 additions & 0 deletions workflow/controller/workflowpod_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"path"
"path/filepath"
"strconv"
"testing"
Expand Down Expand Up @@ -1165,6 +1166,92 @@ func TestTmplLevelSecurityContext(t *testing.T) {
assert.Equal(t, runAsUser, *pod.Spec.SecurityContext.RunAsUser)
}

func Test_createSecretVolumesFromArtifactLocations_SSECUsed(t *testing.T) {
ctx := context.Background()

cancel, controller := newControllerWithComplexDefaults()
defer cancel()

wf := wfv1.MustUnmarshalWorkflow(helloWorldWf)
wf.Spec.Templates[0].Inputs = wfv1.Inputs{
Artifacts: []wfv1.Artifact{
{
Name: "foo",
Path: "/tmp/file",
ArtifactLocation: wfv1.ArtifactLocation{
S3: &wfv1.S3Artifact{
Key: "/foo/key",
},
},
Archive: &wfv1.ArchiveStrategy{
None: &wfv1.NoneStrategy{},
},
},
},
}
woc := newWorkflowOperationCtx(wf, controller)
setArtifactRepository(woc.controller,
&wfv1.ArtifactRepository{
S3: &wfv1.S3ArtifactRepository{
S3Bucket: wfv1.S3Bucket{
Bucket: "foo",
AccessKeySecret: &apiv1.SecretKeySelector{
LocalObjectReference: apiv1.LocalObjectReference{
Name: "accesskey",
},
Key: "aws-keys",
},
SecretKeySecret: &apiv1.SecretKeySelector{
LocalObjectReference: apiv1.LocalObjectReference{
Name: "secretkey",
},
Key: "aws-keys",
},
EncryptionOptions: &wfv1.S3EncryptionOptions{
EnableEncryption: true,
ServerSideCustomerKeySecret: &apiv1.SecretKeySelector{
LocalObjectReference: apiv1.LocalObjectReference{
Name: "enckey",
},
Key: "aws-sse-c",
},
},
},
},
},
)

wantVolume := apiv1.Volume{
Name: "enckey",
VolumeSource: apiv1.VolumeSource{
Secret: &apiv1.SecretVolumeSource{
SecretName: "enckey",
Items: []apiv1.KeyToPath{
{
Key: "aws-sse-c",
Path: "aws-sse-c",
},
},
},
},
}
wantInitContainerVolumeMount := apiv1.VolumeMount{
Name: "enckey",
ReadOnly: true,
MountPath: path.Join(common.SecretVolMountPath, "enckey"),
}

err := woc.setExecWorkflow(ctx)
require.NoError(t, err)
woc.operate(ctx)

mainCtr := woc.execWf.Spec.Templates[0].Container
pod, _ := woc.createWorkflowPod(ctx, wf.Name, []apiv1.Container{*mainCtr}, &wf.Spec.Templates[0], &createWorkflowPodOpts{})
assert.Contains(t, pod.Spec.Volumes, wantVolume)
assert.Len(t, pod.Spec.InitContainers, 1)
assert.Contains(t, pod.Spec.InitContainers[0].VolumeMounts, wantInitContainerVolumeMount)
}

var helloWorldWfWithPatch = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
Expand Down