From 01684ef2c45693282a2d7def131dc449b34b45f8 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Tue, 19 May 2026 16:29:03 -0400 Subject: [PATCH] Restore ability to plumb binary data through envvar values --- pkg/kubelet/container/runtime.go | 2 +- pkg/kubelet/kubelet_pods.go | 5 ++++- pkg/kubelet/kuberuntime/kuberuntime_container.go | 3 ++- staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.pb.go | 8 ++++---- staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index 291560643d3..95f7954fe4d 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -478,7 +478,7 @@ type Image struct { // EnvVar represents the environment variable. type EnvVar struct { Name string - Value string + Value string // TODO: switch to []byte } // Annotation represents an annotation. diff --git a/pkg/kubelet/kubelet_pods.go b/pkg/kubelet/kubelet_pods.go index c7e9cd69de2..e5c7a2387cc 100644 --- a/pkg/kubelet/kubelet_pods.go +++ b/pkg/kubelet/kubelet_pods.go @@ -782,7 +782,7 @@ func (kl *Kubelet) makeEnvironmentVariables(ctx context.Context, pod *v1.Pod, co var ( configMaps = make(map[string]*v1.ConfigMap) secrets = make(map[string]*v1.Secret) - tmpEnv = make(map[string]string) + tmpEnv = make(map[string]string) // TODO: switch to map[string][]byte ) // Env will override EnvFrom variables. @@ -814,6 +814,7 @@ func (kl *Kubelet) makeEnvironmentVariables(ctx context.Context, pod *v1.Pod, co k = envFrom.Prefix + k } + // TODO: validate no NUL bytes tmpEnv[k] = v } case envFrom.SecretRef != nil: @@ -841,6 +842,7 @@ func (kl *Kubelet) makeEnvironmentVariables(ctx context.Context, pod *v1.Pod, co k = envFrom.Prefix + k } + // TODO: validate no NUL bytes tmpEnv[k] = string(v) } } @@ -934,6 +936,7 @@ func (kl *Kubelet) makeEnvironmentVariables(ctx context.Context, pod *v1.Pod, co } return result, fmt.Errorf("couldn't find key %v in Secret %v/%v", key, pod.Namespace, name) } + // TODO: validate no NUL bytes runtimeVal = string(runtimeValBytes) case utilfeature.DefaultFeatureGate.Enabled(features.EnvFiles) && envVar.ValueFrom.FileKeyRef != nil: f := envVar.ValueFrom.FileKeyRef diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index d5bdcb0a7d8..5b11c6e7f5b 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -34,6 +34,7 @@ import ( "time" codes "google.golang.org/grpc/codes" + crierror "k8s.io/cri-api/pkg/errors" "github.com/opencontainers/selinux/go-selinux" @@ -398,7 +399,7 @@ func (m *kubeGenericRuntimeManager) generateContainerConfig(ctx context.Context, e := opts.Envs[idx] envs[idx] = &runtimeapi.KeyValue{ Key: e.Name, - Value: e.Value, + Value: []byte(e.Value), } } config.Envs = envs diff --git a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.pb.go b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.pb.go index 6cbfdd7a481..e8664c10384 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.pb.go +++ b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.pb.go @@ -4268,7 +4268,7 @@ func (x *ImageSpec) GetImageRef() string { type KeyValue struct { state protoimpl.MessageState `protogen:"open.v1"` Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -4310,11 +4310,11 @@ func (x *KeyValue) GetKey() string { return "" } -func (x *KeyValue) GetValue() string { +func (x *KeyValue) GetValue() []byte { if x != nil { return x.Value } - return "" + return nil } // LinuxContainerResources specifies Linux specific configuration for @@ -11823,7 +11823,7 @@ const file_staging_src_k8s_io_cri_api_pkg_apis_runtime_v1_api_proto_rawDesc = "" "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"2\n" + "\bKeyValue\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + - "\x05value\x18\x02 \x01(\tR\x05value\"\x95\x04\n" + + "\x05value\x18\x02 \x01(\fR\x05value\"\x95\x04\n" + "\x17LinuxContainerResources\x12\x1d\n" + "\n" + "cpu_period\x18\x01 \x01(\x03R\tcpuPeriod\x12\x1b\n" + diff --git a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto index 269b805d0cc..f05a5e05fdd 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto +++ b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto @@ -951,7 +951,7 @@ message ImageSpec { message KeyValue { string key = 1; - string value = 2; + bytes value = 2; } // LinuxContainerResources specifies Linux specific configuration for