Skip to content

Cannot overwrite existing securityContext in podTemplate #344

Open

Description

@sampritipanda

For some web challenges where I don't need a nsjail, I would like to start the container without CAP_SYS_ADMIN. As a result, I modify the securityContext to remove any capabilities using the following:

spec:
  ...
  podTemplate:
    template:
      spec:
        containers:
          - name: challenge
            securityContext:
              capabilities: {}

However, this does not remove the capabilities and the container is still deployed with CAP_SYS_ADMIN. This is because of a bug in kctf-operator code here:

https://github.com/google/kctf/blob/v1/kctf-operator/pkg/controller/challenge/deployment/deployment.go#L73

	if deployment.Spec.Template.Spec.Containers[idx_challenge].SecurityContext.Capabilities == nil {
		deployment.Spec.Template.Spec.Containers[idx_challenge].SecurityContext.Capabilities = &corev1.Capabilities{};
	}

	deployment.Spec.Template.Spec.Containers[idx_challenge].SecurityContext.Capabilities.Add =
		append(deployment.Spec.Template.Spec.Containers[idx_challenge].SecurityContext.Capabilities.Add, "SYS_ADMIN")

In the existing code, regardless of what the Capabilities is set to, it adds the CAP_SYS_ADMIN capability. I understand that this is needed by nsjail, but if I manually specify some capabiltiies, then it should not be overwritten by the kctf-operator.

I'm not sure what the best solution is here, but we should definitely be given an option to not start containers with CAP_SYS_ADMIN.

Activity

  1. sirdarckcat commented on Apr 15, 2022

    @sirdarckcat
    Member

    @sroettger fixed this on #301

  2. sirdarckcat commented on Apr 15, 2022

    @sirdarckcat
    Member

    Actually looking at this more closely, the fix we made forces cap_sys_admin on you.

  3. sirdarckcat commented on Apr 15, 2022

    @sirdarckcat
    Member

    Idea: add a nsjail: false to challenge.yaml or something to tell the operator to ignore cap_sys_admim

  4. sroettger commented on Apr 19, 2022

    @sroettger
    Collaborator

    Idea: add a nsjail: false to challenge.yaml or something to tell the operator to ignore cap_sys_admim

    that sounds good to me, but it should probably not say nsjail. Something like: "kctf_default_caps" or so?

    Can you drop privileges in your CMD as a workaround?

  5. sirdarckcat commented on Apr 20, 2022

    @sirdarckcat
    Member

    Yep! That sounds good. We can bikesched the name a bit. I assume kctf is kindof redundant? What about:

        extra_hardening:
         - apparmor_policy
         - no_capabilities

    I dont like the ´no_capabilities´ is a negative, but wdyt of this? @sroettger

  6. sroettger commented on Apr 21, 2022

    @sroettger
    Collaborator

    Maybe no_default_capabilities?
    no_capabilities would imply that we always run without capabilities, but I think it should control that we don't add any capabilities for kctf itself.

    For example

    capabilities: CAP_NET_ADMIN
    extra_hardening:
     - no_capabilities

    should still have net_admin at the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions