Skip to content

Commit

Permalink
fix: mount secret with SSE-C key if needed, fix secret key read. Fixes
Browse files Browse the repository at this point in the history
…argoproj#9867 (argoproj#9870)

Signed-off-by: Michal Raška <[email protected]>
Co-authored-by: Michal Raška <[email protected]>
  • Loading branch information
michal-raska and michal-raska authored Nov 3, 2022
1 parent 82ea580 commit b91606a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion workflow/artifacts/artifacts.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit b91606a

Please sign in to comment.