Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kuma-dp): don't require NET_BIND_SERVICE capability #7276

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"reflect"
"regexp"
"strconv"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -206,34 +205,6 @@ func (r *GatewayInstanceReconciler) createOrUpdateService(
return obj.(*kube_core.Service), nil
}

var r = regexp.MustCompile("^[0-9]+")

func isUnprivilegedPortStartSysctlSupported(v kube_version.Info) bool {
major, err := strconv.Atoi(v.Major)
if err != nil {
return false
}

minorNum := r.FindString(v.Minor)
if minorNum == "" {
return false
}

minor, err := strconv.Atoi(minorNum)
if err != nil {
return false
}

switch {
case major > 1:
return true
case major == 1:
return minor >= 22
default:
return false
}
}

// createOrUpdateDeployment can either return an error, a created Deployment or
// neither if reconciliation shouldn't continue.
func (r *GatewayInstanceReconciler) createOrUpdateDeployment(
Expand Down Expand Up @@ -278,28 +249,14 @@ func (r *GatewayInstanceReconciler) createOrUpdateDeployment(

container.SecurityContext.AllowPrivilegeEscalation = pointer.To(false)

unprivilegedPortStartSupported := isUnprivilegedPortStartSysctlSupported(*r.K8sVersion)

var securityContext *kube_core.PodSecurityContext
if unprivilegedPortStartSupported {
securityContext = &kube_core.PodSecurityContext{
Sysctls: []kube_core.Sysctl{{
Name: "net.ipv4.ip_unprivileged_port_start",
Value: "0",
}},
}
} else {
secContext := container.SecurityContext
if secContext.Capabilities == nil {
secContext.Capabilities = &kube_core.Capabilities{}
}
secContext.Capabilities.Add = append(secContext.Capabilities.Add, "NET_BIND_SERVICE")
securityContext := &kube_core.PodSecurityContext{
Sysctls: []kube_core.Sysctl{{
Name: "net.ipv4.ip_unprivileged_port_start",
Value: "0",
}},
}

if fsGroup := gatewayInstance.Spec.PodTemplate.Spec.PodSecurityContext.FSGroup; fsGroup != nil {
if securityContext == nil {
securityContext = &kube_core.PodSecurityContext{}
}
securityContext.FSGroup = fsGroup
}

Expand Down
7 changes: 0 additions & 7 deletions tools/releases/dockerfiles/envoy.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,3 @@ FROM debian:12@sha256:3d868b5eb908155f3784317b3dda2941df87bbbbaa4608f84881de66d9
ARG ARCH

COPY /build/artifacts-linux-$ARCH/envoy/envoy /envoy

RUN apt-get update && \
apt-get install --no-install-recommends -y libcap2-bin=1:2.66-4 && \
# extended permissions are stored into file inode and copied by docker when using buildx
setcap cap_net_bind_service+ep /envoy \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*