Skip to content

kubelet: don't fetch image credentials if the image is present and if we don't need to check if the pod is allowed to pull it #133079

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

Merged

Conversation

atykhyy
Copy link
Contributor

@atykhyy atykhyy commented Jul 19, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:

Commit 3793bec changed kubelet's behavior such that it always looks up container registry credentials - even if the image is already present on the node, the image pull policy is Never or IfNotPresent, and the experimental feature gate KubeletEnsureSecretPulledImages is disabled or configured to not verify pod image access. This change creates a problem for network management solutions such as Cilium, as credentials provider plugins may not be able to acquire credentials while the network management daemonset pod is being recreated (e.g. after an update):

kubelet[4649]: E0715 08:08:30.537102    4649 plugin.go:440] Failed getting credential from external registry credential provider: error execing credential provider plugin acr-credential-provider for image xxxxxxx.azurecr.io/cilium/cilium-dev: exit status 1: E0715 08:08:30.536082  659403 azure_credentials.go:209] failed to receive challenge: error reaching registry endpoint https://xxxxxxx.azurecr.io/v2/, error: Get "https://xxxxxxx.azurecr.io/v2/": dial tcp: lookup xxxxxxx.azurecr.io on 168.63.129.16:53: read udp 172.25.64.35:34236->168.63.129.16:53: i/o timeout
kubelet[4649]: E0715 08:08:30.536136  659403 azure_credentials.go:146] error getting credentials from ACR for xxxxxxx.azurecr.io: error reaching registry endpoint https://xxxxxxx.azurecr.io/v2/, error: Get "https://xxxxxxx.azurecr.io/v2/": dial tcp: lookup xxxxxxx.azurecr.io on 168.63.129.16:53: read udp 172.25.64.35:34236->168.63.129.16:53: i/o timeout
kubelet[4649]: E0715 08:08:30.536146  659403 main.go:59] Error running acr credential provider: error reaching registry endpoint https://xxxxxxx.azurecr.io/v2/, error: Get "https://xxxxxxx.azurecr.io/v2/": dial tcp: lookup xxxxxxx.azurecr.io on 168.63.129.16:53: read udp 172.25.64.35:34236->168.63.129.16:53: i/o timeout

This problem should not normally be fatal, because DockerConfigProvider.Provide() just returns an empty set of credentials when the credential provider fails. However, depending on DNS and other connection timeouts configured in the credential provider (a component external to kubelet), the new behavior leads to potentially long delays in network management daemonset pod startup, especially when such pods use many init containers to tighten up the main container's security context. In my testing, a standard Cilium daemonset with 6 init containers, a main agent container and a sidecar takes 3 minutes to restart (8 x 20s spent in the credential provider plugin waiting for the DNS request to time out, plus a few seconds for containers to actually run/start), during which interval the whole node is not fully functional.

This PR restores the original behavior. There appears to be no reason to look up container registry credentials if they are not going to be used.

Which issue(s) this PR is related to:

N/A

Special notes for your reviewer:

None

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

… we don't need to check if the pod is allowed to pull it
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 19, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @atykhyy. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 19, 2025
@k8s-ci-robot k8s-ci-robot added area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. labels Jul 19, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jul 19, 2025
@HirazawaUi
Copy link
Contributor

/ok-to-test
/cc @stlaz

@k8s-ci-robot k8s-ci-robot requested a review from stlaz July 20, 2025 07:52
@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 20, 2025
@k8s-ci-robot
Copy link
Contributor

@atykhyy: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-unit-windows-master 30e5cdd link false /test pull-kubernetes-unit-windows-master

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@@ -178,6 +178,12 @@ func (m *imageManager) EnsureImageExists(ctx context.Context, objRef *v1.ObjectR
return "", message, err
}

if imageRef != "" && !utilfeature.DefaultFeatureGate.Enabled(features.KubeletEnsureSecretPulledImages) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks fine and likely restores the old behavior. The issue will still exist when the KubeletEnsureSecretPulledImages feature gate is enabled by default.

@stlaz we should think about how to avoid calling credential provider plugins when the image is preloaded or the pull policy is Never.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@atykhyy atykhyy Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue will still exist when the KubeletEnsureSecretPulledImages feature gate is enabled by default.

Yes. I made a note to myself to configure it to not verify when it goes GA.

avoid calling credential provider plugins when the image is preloaded

As I see it, this must rely on some kind of declared dependency between pods such that pod A being allowed to access an image means that pod B (somehow linked to A, perhaps with an annotation) is also allowed without additional checks. The upgrade workflow I stumbled upon this already requires a preflight daemonset, which runs while the previous version of the main daemonset is still running, to pull the new version image, because when the main daemonset pod stops, the kubelet won't be able to pull the new image any more than it will be able to acquire credentials. There is no problem with kubelet checking pod image accessibility for preflight daemonset pods.

It is of course possible to add the critical image to preloadedImagesVerificationAllowlist, but that allows access to it to every pod.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Narrowly moving this if block up is ~fine for now, but I expect the credential verification feature to go to get and default-enable ~soon, at which point credential providers will be called again.

as credentials provider plugins may not be able to acquire credentials while the network management daemonset pod is being recreated

that seems like a potential deadlock issue with those credential plugins that needs resolving independent of the credential reverification feature

Copy link
Contributor Author

@atykhyy atykhyy Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

credential plugins that needs resolving independent of the credential reverification feature

I.e. to authenticate to CR and pull the image? That's handled by preflight daemonsets, as I mentioned above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at which point credential providers will be called again

Yes, but that's not correct behavior, isn't it? E.g. if the image pull credential verification policy is NeverVerify, there is no reason to call them. I added an early check for decisions of this type: #133114

@aramase
Copy link
Member

aramase commented Jul 21, 2025

/triage accepted
/sig auth
/cc aramase stlaz

@k8s-ci-robot k8s-ci-robot requested a review from aramase July 21, 2025 16:23
@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 21, 2025
@aramase aramase moved this to In Review in SIG Auth Jul 21, 2025
@liggitt
Copy link
Member

liggitt commented Jul 21, 2025

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 21, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 7aedc56db3836b3cfc20fe9fae2863404775e188

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: atykhyy, liggitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 21, 2025
@k8s-ci-robot k8s-ci-robot merged commit 6a51472 into kubernetes:master Jul 21, 2025
13 of 14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.34 milestone Jul 21, 2025
@github-project-automation github-project-automation bot moved this from In Review to Closed / Done in SIG Auth Jul 21, 2025
atykhyy added a commit to Apptane/kubernetes that referenced this pull request Jul 21, 2025
Some decisions about image pull credential verification can be applied
without reference to image pull credentials: if the policy is
NeverVerify, or if it is NeverVerifyPreloadedImages and the image is
preloaded, or if is NeverVerifyAllowListedImages and the image is
white-listed. In these cases, there is no need to look up credentials.

Related PR: kubernetes#133079
atykhyy added a commit to Apptane/kubernetes that referenced this pull request Jul 22, 2025
Some decisions about image pull credential verification can be applied
without reference to image pull credentials: if the policy is
NeverVerify, or if it is NeverVerifyPreloadedImages and the image is
preloaded, or if is NeverVerifyAllowListedImages and the image is
white-listed. In these cases, there is no need to look up credentials.

Related PR: kubernetes#133079
atykhyy added a commit to Apptane/kubernetes that referenced this pull request Jul 22, 2025
Some decisions about image pull credential verification can be applied
without reference to image pull credentials: if the policy is
NeverVerify, or if it is NeverVerifyPreloadedImages and the image is
preloaded, or if is NeverVerifyAllowListedImages and the image is
white-listed. In these cases, there is no need to look up credentials.

Related PR: kubernetes#133079
atykhyy added a commit to Apptane/kubernetes that referenced this pull request Jul 22, 2025
Some decisions about image pull credential verification can be applied
without reference to image pull credentials: if the policy is
NeverVerify, or if it is NeverVerifyPreloadedImages and the image is
preloaded, or if is NeverVerifyAllowListedImages and the image is
white-listed. In these cases, there is no need to look up credentials.

Related PR: kubernetes#133079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/node Categorizes an issue or PR as relevant to SIG Node. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Closed / Done
Development

Successfully merging this pull request may close these issues.

5 participants