Skip to content

Commit

Permalink
Mount the home volume in the completion container
Browse files Browse the repository at this point in the history
If a build utilizing image signing is run on a stack with a different user than the completion image the container will not have access to the home directory.
This allows the container to always have a writeable HOME directory which is the same as build-init.
  • Loading branch information
matthewmcnew committed Oct 25, 2021
1 parent e379af6 commit f0b68eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/apis/build/v1alpha2/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor
Name: "completion",
Image: images.completion(buildContext.os()),
Command: []string{"/cnb/process/web"},
Env: []corev1.EnvVar{
homeEnv,
},
Args: args(
b.notaryArgs(),
secretArgs,
Expand All @@ -240,10 +243,11 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor
[]corev1.VolumeMount{
reportVolume,
notaryV1Volume,
homeVolume,
},
),
ImagePullPolicy: corev1.PullIfNotPresent,
}, ifWindows(buildContext.os(), addNetworkWaitLauncherVolume(), useNetworkWaitLauncher(dnsProbeHost))...)
}, ifWindows(buildContext.os(), addNetworkWaitLauncherVolume(), useNetworkWaitLauncher(dnsProbeHost), userprofileHomeEnv())...)
}),
SecurityContext: podSecurityContext(buildContext.BuildPodBuilderConfig),
InitContainers: steps(func(step func(corev1.Container, ...stepModifier)) {
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/build/v1alpha2/build_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,12 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
},
},
})
require.Contains(t, pod.Spec.Containers[0].Env, corev1.EnvVar{Name: "HOME", Value: "/builder/home"})
require.Contains(t, pod.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
Name: "home-dir",
ReadOnly: false,
MountPath: "/builder/home",
})
})
})

Expand Down Expand Up @@ -1792,6 +1798,13 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
},
})

require.Contains(t, pod.Spec.Containers[0].Env, corev1.EnvVar{Name: "HOME", Value: "/builder/home"})
require.Contains(t, pod.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
Name: "home-dir",
ReadOnly: false,
MountPath: "/builder/home",
})

require.Equal(t,
[]string{
"-notary-v1-url=some-notary-url",
Expand Down Expand Up @@ -2115,6 +2128,12 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
}, completionContainer.Args)

assert.Equal(t, "/networkWait/network-wait-launcher", completionContainer.Command[0])
assert.Subset(t, completionContainer.Env, []corev1.EnvVar{
{
Name: "USERPROFILE",
Value: "/builder/home",
},
})
assert.Subset(t, pod.Spec.Volumes, []corev1.Volume{
{
Name: "network-wait-launcher-dir",
Expand Down Expand Up @@ -2150,6 +2169,13 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
"-cosign-annotations=buildTimestamp=19440606.133000",
"-cosign-annotations=buildNumber=12",
}, completionContainer.Args)

assert.Subset(t, completionContainer.Env, []corev1.EnvVar{
{
Name: "USERPROFILE",
Value: "/builder/home",
},
})
})

it("does not use cache on windows", func() {
Expand Down

0 comments on commit f0b68eb

Please sign in to comment.