Skip to content

Commit ba3a309

Browse files
informalictajanikow
authored andcommitted
Drop all capabilities to security context (#497)
1 parent 27775eb commit ba3a309

File tree

6 files changed

+36
-11
lines changed

6 files changed

+36
-11
lines changed

pkg/util/k8sutil/pods.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ func arangodContainer(image string, imagePullPolicy v1.PullPolicy, args []string
340340
Protocol: v1.ProtocolTCP,
341341
},
342342
},
343-
VolumeMounts: arangodVolumeMounts(),
343+
VolumeMounts: arangodVolumeMounts(),
344+
SecurityContext: SecurityContextWithoutCapabilities(),
344345
}
345346
if noFilterResources {
346347
c.Resources = resources // if volumeclaimtemplate is specified
@@ -381,7 +382,8 @@ func arangosyncContainer(image string, imagePullPolicy v1.PullPolicy, args []str
381382
Protocol: v1.ProtocolTCP,
382383
},
383384
},
384-
Resources: resources,
385+
Resources: resources,
386+
SecurityContext: SecurityContextWithoutCapabilities(),
385387
}
386388
for k, v := range env {
387389
c.Env = append(c.Env, v.CreateEnvVar(k))
@@ -825,3 +827,11 @@ func createPod(kubecli kubernetes.Interface, pod *v1.Pod, ns string, owner metav
825827
}
826828
return nil
827829
}
830+
831+
func SecurityContextWithoutCapabilities() *v1.SecurityContext {
832+
return &v1.SecurityContext{
833+
Capabilities: &v1.Capabilities{
834+
Drop: []v1.Capability{"all"},
835+
},
836+
}
837+
}

scripts/kube_create_backup_remote_secret.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
NS=$1
44

@@ -12,7 +12,14 @@ if [ -z "$2" ]; then
1212
exit 0
1313
fi
1414

15-
SECRET=$(echo -n $2 | base64 -w 0)
15+
case $(uname) in
16+
Darwin)
17+
SECRET=$(echo -n $2 | base64 -b 0)
18+
;;
19+
*)
20+
SECRET=$(echo -n $2 | base64 -w 0)
21+
;;
22+
esac
1623

1724
kubectl apply -f - <<EOF
1825
apiVersion: v1

scripts/kube_create_license_key_secret.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
NS=$1
44

@@ -12,7 +12,14 @@ if [ -z "$2" ]; then
1212
exit 0
1313
fi
1414

15-
LICENSE=$(echo -n "$2" | base64 -w 0)
15+
case $(uname) in
16+
Darwin)
17+
LICENSE=$(echo -n "$2" | base64 -b 0)
18+
;;
19+
*)
20+
LICENSE=$(echo -n "$2" | base64 -w 0)
21+
;;
22+
esac
1623

1724
kubectl apply -f - <<EOF
1825
apiVersion: v1

tests/backup_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ package tests
2525
import (
2626
"context"
2727
"fmt"
28-
"github.com/arangodb/kube-arangodb/pkg/backup/utils"
2928
"os"
3029
"strings"
3130
"testing"
3231
"time"
3332

33+
"github.com/arangodb/kube-arangodb/pkg/backup/utils"
34+
3435
backupClient "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/backup/v1"
3536

3637
"github.com/rs/zerolog/log"
@@ -434,6 +435,8 @@ func TestBackupCluster(t *testing.T) {
434435
})
435436

436437
t.Run("create-upload backup", func(t *testing.T) {
438+
skipOrRemotePath(t)
439+
437440
backup := newBackup(fmt.Sprintf("my-backup-%s", uniuri.NewLen(4)), depl.GetName(), nil)
438441
_, err := backupClient.Create(backup)
439442
require.NoError(t, err, "failed to create backup: %s", err)
@@ -669,7 +672,7 @@ func TestBackupCluster(t *testing.T) {
669672
// Assert that all of the backups are in valid state
670673
backups, err = backupClient.List(metav1.ListOptions{LabelSelector: metav1.FormatLabelSelector(&labels)})
671674
require.NoError(t, err)
672-
require.Len(t, backups.Items, size + 1)
675+
require.Len(t, backups.Items, size+1)
673676

674677
for _, b := range backups.Items {
675678
require.Equal(t, backupApi.ArangoBackupStateReady, b.Status.State, b.Status.Message)

tests/load_balancer_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
driver "github.com/arangodb/go-driver"
3434
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3535
"github.com/arangodb/kube-arangodb/pkg/client"
36-
"github.com/arangodb/kube-arangodb/pkg/util"
3736
)
3837

3938
func TestLoadBalancingCursorVST(t *testing.T) {
@@ -68,7 +67,6 @@ func loadBalancingCursorSubtest(t *testing.T, useVst bool) {
6867
}
6968
depl := newDeployment(namePrefix + uniuri.NewLen(4))
7069
depl.Spec.Mode = api.NewMode(api.DeploymentModeCluster)
71-
depl.Spec.Image = util.NewString("arangodb/arangodb:3.3.13") // Note: 3.3.13 is the first version supporting the cursor forwarding feature.
7270

7371
// Create deployment
7472
_, err := c.DatabaseV1().ArangoDeployments(ns).Create(depl)

tests/pc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func waitForPriorityOfServerGroup(kube kubernetes.Interface, c versioned.Interfa
3636
}
3737

3838
if *pod.Spec.Priority != priority {
39-
return fmt.Errorf("Wrong pod priority, expected %d, found %d", priority, pod.Spec.Priority)
39+
return fmt.Errorf("Wrong pod priority, expected %d, found %d", priority, *pod.Spec.Priority)
4040
}
4141
}
4242

0 commit comments

Comments
 (0)