Skip to content

Commit 38e3ce8

Browse files
authored
[Bugfix] Fix ID Pod security (#1093)
1 parent ad03acb commit 38e3ce8

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- (Bugfix) Proper agent cleanout
2222
- (Bugfix) Fix ClusterScaling integration
2323
- (Feature) Sensitive information protection
24+
- (Bugfix) Propagate SecurityContext to the ID Containers
2425

2526
## [1.2.15](https://github.com/arangodb/kube-arangodb/tree/1.2.15) (2022-07-20)
2627
- (Bugfix) Ensure pod names not too long

pkg/deployment/images.go

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ var _ interfaces.ContainerCreator = &ContainerIdentity{}
5252
// ImageUpdatePod describes how to launch the ID ArangoD POD.
5353
type ImageUpdatePod struct {
5454
spec api.DeploymentSpec
55+
status api.DeploymentStatus
5556
apiObject k8sutil.APIObject
56-
containerCreator interfaces.ContainerCreator
57+
containerCreator *ArangoDIdentity
5758
}
5859

5960
// ContainerIdentity helps to resolve the container identity, e.g.: image ID, version of the entrypoint.
@@ -66,6 +67,7 @@ type ContainerIdentity struct {
6667
// ArangoDIdentity helps to resolve the ArangoD identity, e.g.: image ID, version of the entrypoint.
6768
type ArangoDIdentity struct {
6869
interfaces.ContainerCreator
70+
input pod.Input
6971
License *string
7072
ipAddress string
7173
}
@@ -226,6 +228,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac
226228

227229
imagePod := ImageUpdatePod{
228230
spec: ib.Spec,
231+
status: ib.Status,
229232
apiObject: ib.APIObject,
230233
containerCreator: &ArangoDIdentity{
231234
ContainerCreator: &ContainerIdentity{
@@ -237,6 +240,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac
237240
ipAddress: ib.Spec.GetListenAddr(),
238241
},
239242
}
243+
imagePod.containerCreator.input = imagePod.AsInput()
240244

241245
pod, err = resources.RenderArangoPod(ctx, cachedStatus, ib.APIObject, role, id, podName, &imagePod)
242246
if err != nil {
@@ -297,7 +301,7 @@ func (i *ImageUpdatePod) GetAffinityRole() string {
297301
}
298302

299303
func (i *ImageUpdatePod) GetVolumes() []core.Volume {
300-
return getVolumes().Volumes()
304+
return getVolumes(i.AsInput()).Volumes()
301305
}
302306

303307
func (i *ImageUpdatePod) GetSidecars(*core.Pod) error {
@@ -381,7 +385,10 @@ func (i *ImageUpdatePod) Validate(_ interfaces.Inspector) error {
381385
return nil
382386
}
383387

384-
func (i *ImageUpdatePod) ApplyPodSpec(_ *core.PodSpec) error {
388+
func (i *ImageUpdatePod) ApplyPodSpec(p *core.PodSpec) error {
389+
if id := i.spec.ID; id != nil {
390+
p.SecurityContext = i.spec.ID.SecurityContext.NewPodSecurityContext()
391+
}
385392
return nil
386393
}
387394

@@ -442,12 +449,16 @@ func (a *ContainerIdentity) GetVolumeMounts() []core.VolumeMount {
442449

443450
// GetArgs returns the list of arguments for the ArangoD container identification.
444451
func (a *ArangoDIdentity) GetArgs() ([]string, error) {
445-
return []string{
446-
"--server.authentication=false",
447-
fmt.Sprintf("--server.endpoint=tcp://%s:%d", a.ipAddress, shared.ArangoPort),
448-
"--database.directory=" + shared.ArangodVolumeMountDir,
449-
"--log.output=+",
450-
}, nil
452+
options := k8sutil.CreateOptionPairs(64)
453+
options.Add("--server.authentication", "false")
454+
options.Addf("--server.endpoint", "tcp://%s:%d", a.ipAddress, shared.ArangoPort)
455+
options.Add("--database.directory", shared.ArangodVolumeMountDir)
456+
options.Add("--log.output", "+")
457+
458+
// Security
459+
options.Merge(pod.Security().Args(a.input))
460+
461+
return options.Copy().Sort().AsArgs(), nil
451462
}
452463

453464
func (a *ArangoDIdentity) GetEnvs() []core.EnvVar {
@@ -468,18 +479,30 @@ func (a *ArangoDIdentity) GetEnvs() []core.EnvVar {
468479

469480
// GetVolumeMounts returns volume mount for the ArangoD data.
470481
func (a *ArangoDIdentity) GetVolumeMounts() []core.VolumeMount {
471-
return getVolumes().VolumeMounts()
482+
return getVolumes(a.input).VolumeMounts()
483+
}
484+
485+
func (a *ImageUpdatePod) AsInput() pod.Input {
486+
return pod.Input{
487+
ApiObject: a.apiObject,
488+
Deployment: a.spec,
489+
Status: a.status,
490+
Group: api.ServerGroupImageDiscovery,
491+
}
472492
}
473493

474494
// GetExecutor returns the fixed path to the ArangoSync binary in the container.
475495
func (a *ArangoSyncIdentity) GetExecutor() string {
476496
return resources.ArangoSyncExecutor
477497
}
478498

479-
func getVolumes() pod.Volumes {
499+
func getVolumes(input pod.Input) pod.Volumes {
480500
volumes := pod.NewVolumes()
481501
volumes.AddVolume(k8sutil.CreateVolumeEmptyDir(shared.ArangodVolumeName))
482502
volumes.AddVolumeMount(k8sutil.ArangodVolumeMount())
483503

504+
// Security
505+
volumes.Append(pod.Security(), input)
506+
484507
return volumes
485508
}

pkg/deployment/images_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,10 @@ func TestEnsureImages(t *testing.T) {
473473

474474
func createTestCommandForImageUpdatePod() []string {
475475
return []string{resources.ArangoDExecutor,
476-
"--server.authentication=false",
477-
fmt.Sprintf("--server.endpoint=tcp://[::]:%d", shared.ArangoPort),
478476
"--database.directory=" + shared.ArangodVolumeMountDir,
479477
"--log.output=+",
478+
"--server.authentication=false",
479+
fmt.Sprintf("--server.endpoint=tcp://[::]:%d", shared.ArangoPort),
480480
}
481481
}
482482

0 commit comments

Comments
 (0)