SAP-archive / karydia

Kubernetes Security Walnut
Other
77 stars 10 forks source link

Implicitly Change the Defaults on Kubernetes Resources #30

Open marwinski opened 5 years ago

marwinski commented 5 years ago

This is an idea to maybe get a better reception for project Karydia: instead of generally forbidding the deployment of pods that don't have automountServiceAccountToken set to false wouldn't it better to just add a setting to do that, e.g. automountServiceAccountToken: false?

We could assume that users who set this property to true know what they are doing and leave the setting untouched. On the other hand one could add the (maybe non default) option to deny this:

The policy might then look like this:

apiVersion: karydia.gardener.cloud/v1alpha1
kind: KarydiaSecurityPolicy
metadata:
  name: example-restrictive
spec:
  pod:
    # this would generally deny pods which try to get the token mounted
    automountServiceAccountToken: "forbidden"
    # this will automatically set the default in case nothing is specified
    setDefaultAutomountServiceAccountToken: "false"
    seccompProfile: "docker/default" 

We might consider setting a default seccomp profile with setDefaultSeccompProfile? We could also have a list of allowed seccomp profiles?

The same could be done for a lot of other settings, some ideas:

hostPID: "forbidden"
hostNetwork: "forbidden"
hostIPC: "forbidden"

Some Other candidates are from the security context or pod security context:

Note: I am not sure about the impact of the fsGroup setting.

This would lead to the following settings in the security policy:

    # this would generally deny pods which try to get the token mounted
    automountServiceAccountToken: "forbidden"
    # this will automatically set the default in case nothing is specified
    setDefaultAutomountServiceAccountToken: "false"
    # allowed seccomp profiles
    allowedSeccompProfiles: ["a","b "] 
    # automatically set seccomp profile if not set
    setDefaultSeccompProfile: "docker/default" 
    # deny hostPID, hostNetwork, hostIPC
    hostPID: "forbidden"
    hostNetwork: "forbidden"
    hostIPC: "forbidden"
    allowPrivilegeEscalation: "forbidden"
    setCapabilites: "forbidden"
    allowPrivileged: "forbidden"
    allowRoot: "forbidden
    setDefaultRunAsUser: 1000
    runAsUser0: "forbidden"

That written, a lot of this is covered by pod security policies (the list above would need to be adapted. It may nevertheless be useful because it would not require a user to be restricted and the evaluation could be done by a (mutating) webhook with a resticted user (to not have a double implementation).