Skip to content

Commit 47827f4

Browse files
committed
kubelet: modify KubeletConfiguration API with image pull policies
Also adds PreloadedImagesVerificationAllowlist to API exceptions list for missing list type as this is not a part of the REST API.
1 parent ad96b3a commit 47827f4

File tree

7 files changed

+316
-164
lines changed

7 files changed

+316
-164
lines changed

pkg/kubelet/apis/config/helpers_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ var (
243243
"ImageGCLowThresholdPercent",
244244
"ImageMinimumGCAge.Duration",
245245
"ImageMaximumGCAge.Duration",
246+
"ImagePullCredentialsVerificationPolicy",
246247
"KernelMemcgNotification",
247248
"KubeAPIBurst",
248249
"KubeAPIQPS",
@@ -268,6 +269,7 @@ var (
268269
"PodPidsLimit",
269270
"PodsPerCore",
270271
"Port",
272+
"PreloadedImagesVerificationAllowlist[*]",
271273
"ProtectKernelDefaults",
272274
"ProviderID",
273275
"ReadOnlyPort",

pkg/kubelet/apis/config/types.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,25 @@ type KubeletConfiguration struct {
155155
// pulls to burst to this number, while still not exceeding registryPullQPS.
156156
// Only used if registryPullQPS > 0.
157157
RegistryBurst int32
158+
// imagePullCredentialsVerificationPolicy determines how credentials should be
159+
// verified when pod requests an image that is already present on the node:
160+
// - NeverVerify
161+
// - anyone on a node can use any image present on the node
162+
// - NeverVerifyPreloadedImages
163+
// - images that were pulled to the node by something else than the kubelet
164+
// can be used without reverifying pull credentials
165+
// - NeverVerifyAllowlistedImages
166+
// - like "NeverVerifyPreloadedImages" but only node images from
167+
// `preloadedImagesVerificationAllowlist` don't require reverification
168+
// - AlwaysVerify
169+
// - all images require credential reverification
170+
ImagePullCredentialsVerificationPolicy string
171+
// preloadedImagesVerificationAllowlist specifies a list of images that are
172+
// exempted from credential reverification for the "NeverVerifyAllowlistedImages"
173+
// `imagePullCredentialsVerificationPolicy`.
174+
// The list accepts a full path segment wildcard suffix "/*".
175+
// Only use image specs without an image tag or digest.
176+
PreloadedImagesVerificationAllowlist []string
158177
// eventRecordQPS is the maximum event creations per second. If 0, there
159178
// is no limit enforced.
160179
EventRecordQPS int32
@@ -770,6 +789,25 @@ type CrashLoopBackOffConfig struct {
770789
MaxContainerRestartPeriod *metav1.Duration
771790
}
772791

792+
// ImagePullCredentialsVerificationPolicy is an enum for the policy that is enforced
793+
// when pod is requesting an image that appears on the system
794+
type ImagePullCredentialsVerificationPolicy string
795+
796+
const (
797+
// NeverVerify will never require credential verification for images that
798+
// already exist on the node
799+
NeverVerify ImagePullCredentialsVerificationPolicy = "NeverVerify"
800+
// NeverVerifyPreloadedImages does not require credential verification for images
801+
// pulled outside the kubelet process
802+
NeverVerifyPreloadedImages ImagePullCredentialsVerificationPolicy = "NeverVerifyPreloadedImages"
803+
// NeverVerifyAllowlistedImages does not require credential verification for
804+
// a list of images that were pulled outside the kubelet process
805+
NeverVerifyAllowlistedImages ImagePullCredentialsVerificationPolicy = "NeverVerifyAllowlistedImages"
806+
// AlwaysVerify requires credential verification for accessing any image on the
807+
// node irregardless how it was pulled
808+
AlwaysVerify ImagePullCredentialsVerificationPolicy = "AlwaysVerify"
809+
)
810+
773811
// ImagePullIntent is a record of the kubelet attempting to pull an image.
774812
//
775813
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/kubelet/apis/config/v1beta1/defaults.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,10 @@ func SetDefaults_KubeletConfiguration(obj *kubeletconfigv1beta1.KubeletConfigura
313313
obj.CrashLoopBackOff.MaxContainerRestartPeriod = &metav1.Duration{Duration: MaxContainerBackOff}
314314
}
315315
}
316+
317+
if localFeatureGate.Enabled(features.KubeletEnsureSecretPulledImages) {
318+
if obj.ImagePullCredentialsVerificationPolicy == "" {
319+
obj.ImagePullCredentialsVerificationPolicy = kubeletconfigv1beta1.NeverVerifyPreloadedImages
320+
}
321+
}
316322
}

0 commit comments

Comments
 (0)