Skip to content

Commit 19a22d4

Browse files
authored
Merge pull request #37647 from andrewsykim/blog-kep-2133
Blog: Kubernetes v1.26: GA Support for Kubelet Credential Providers
2 parents fa72a2a + 655d4f3 commit 19a22d4

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
layout: blog
3+
title: 'Kubernetes v1.26: GA Support for Kubelet Credential Providers'
4+
date: 2022-12-22
5+
slug: kubelet-credential-providers
6+
---
7+
8+
**Authors:** Andrew Sy Kim (Google), Dixita Narang (Google)
9+
10+
Kubernetes v1.26 introduced generally available (GA) support for [_kubelet credential
11+
provider plugins_]( /docs/tasks/kubelet-credential-provider/kubelet-credential-provider/),
12+
offering an extensible plugin framework to dynamically fetch credentials
13+
for any container image registry.
14+
15+
## Background
16+
17+
Kubernetes supports the ability to dynamically fetch credentials for a container registry service.
18+
Prior to Kubernetes v1.20, this capability was compiled into the kubelet and only available for
19+
Amazon Elastic Container Registry, Azure Container Registry, and Google Cloud Container Registry.
20+
21+
{{< figure src="kubelet-credential-providers-in-tree.png" caption="Figure 1: Kubelet built-in credential provider support for Amazon Elastic Container Registry, Azure Container Registry, and Google Cloud Container Registry." >}}
22+
23+
Kubernetes v1.20 introduced alpha support for kubelet credential providers plugins,
24+
which provides a mechanism for the kubelet to dynamically authenticate and pull images
25+
for arbitrary container registries - whether these are public registries, managed services,
26+
or even a self-hosted registry.
27+
In Kubernetes v1.26, this feature is now GA
28+
29+
{{< figure src="kubelet-credential-providers-plugin.png" caption="Figure 2: Kubelet credential provider overview" >}}
30+
31+
## Why is it important?
32+
33+
Prior to Kubernetes v1.20, if you wanted to dynamically fetch credentials for image registries
34+
other than ACR (Azure Container Registry), ECR (Elastic Container Registry), or GCR
35+
(Google Container Registry), you needed to modify the kubelet code.
36+
The new plugin mechanism can be used in any cluster, and lets you authenticate to new registries without
37+
any changes to Kubernetes itself. Any cloud provider or vendor can publish a plugin that lets you authenticate with their image registry.
38+
39+
## How it works
40+
41+
The kubelet and the exec plugin binary communicate through stdio (stdin, stdout, and stderr) by sending and receiving
42+
json-serialized api-versioned types. If the exec plugin is enabled and the kubelet requires authentication information for an image
43+
that matches against a plugin, the kubelet will execute the plugin binary, passing the `CredentialProviderRequest` API via stdin. Then
44+
the exec plugin communicates with the container registry to dynamically fetch the credentials and returns the credentials in an
45+
encoded response of the `CredentialProviderResponse` API to the kubelet via stdout.
46+
47+
{{< figure src="kubelet-credential-providers-how-it-works.png" caption="Figure 3: Kubelet credential provider plugin flow" >}}
48+
49+
On receiving credentials from the kubelet, the plugin can also indicate how long credentials can be cached for, to prevent unnecessary
50+
execution of the plugin by the kubelet for subsequent image pull requests to the same registry. In cases where the cache duration
51+
is not specified by the plugin, a default cache duration can be specified by the kubelet (more details below).
52+
53+
```json
54+
{
55+
"apiVersion": "kubelet.k8s.io/v1",
56+
"kind": "CredentialProviderResponse",
57+
"auth": {
58+
"cacheDuration": "6h",
59+
"private-registry.io/my-app": {
60+
"username": "exampleuser",
61+
"password": "token12345"
62+
}
63+
}
64+
}
65+
```
66+
67+
In addition, the plugin can specify the scope in which cached credentials are valid for. This is specified through the `cacheKeyType` field
68+
in `CredentialProviderResponse`. When the value is `Image`, the kubelet will only use cached credentials for future image pulls that exactly
69+
match the image of the first request. When the value is `Registry`, the kubelet will use cached credentials for any subsequent image pulls
70+
destined for the same registry host but using different paths (for example, `gcr.io/foo/bar` and `gcr.io/bar/foo` refer to different images
71+
from the same registry). Lastly, when the value is `Global`, the kubelet will use returned credentials for all images that match against
72+
the plugin, including images that can map to different registry hosts (for example, gcr.io vs k8s.gcr.io). The `cacheKeyType` field is required by plugin
73+
implementations.
74+
75+
```json
76+
{
77+
"apiVersion": "kubelet.k8s.io/v1",
78+
"kind": "CredentialProviderResponse",
79+
"auth": {
80+
"cacheKeyType": "Registry",
81+
"private-registry.io/my-app": {
82+
"username": "exampleuser",
83+
"password": "token12345"
84+
}
85+
}
86+
}
87+
```
88+
89+
## Using kubelet credential providers
90+
91+
You can configure credential providers by installing the exec plugin(s) into
92+
a local directory accessible by the kubelet on every node. Then you set two command line arguments for the kubelet:
93+
* `--image-credential-provider-config`: the path to the credential provider plugin config file.
94+
* `--image-credential-provider-bin-dir`: the path to the directory where credential provider plugin binaries are located.
95+
96+
The configuration file passed into `--image-credential-provider-config` is read by the kubelet to determine which exec plugins should be invoked for a container image used by a Pod.
97+
Note that the name of each _provider_ must match the name of the binary located in the local directory specified in `--image-credential-provider-bin-dir`, otherwise the kubelet
98+
cannot locate the path of the plugin to invoke.
99+
100+
```yaml
101+
kind: CredentialProviderConfig
102+
apiVersion: kubelet.config.k8s.io/v1
103+
providers:
104+
- name: auth-provider-gcp
105+
apiVersion: credentialprovider.kubelet.k8s.io/v1
106+
matchImages:
107+
- "container.cloud.google.com"
108+
- "gcr.io"
109+
- "*.gcr.io"
110+
- "*.pkg.dev"
111+
args:
112+
- get-credentials
113+
- --v=3
114+
defaultCacheDuration: 1m
115+
```
116+
117+
Below is an overview of how the Kubernetes project is using kubelet credential providers for end-to-end testing.
118+
119+
{{< figure src="kubelet-credential-providers-enabling.png" caption="Figure 4: Kubelet credential provider configuration used for Kubernetes e2e testing" >}}
120+
121+
For more configuration details, see [Kubelet Credential Providers](https://kubernetes.io/docs/tasks/kubelet-credential-provider/kubelet-credential-provider/).
122+
123+
## Getting Involved
124+
125+
Come join SIG Node if you want to report bugs or have feature requests for the Kubelet Credential Provider. You can reach us through the following ways:
126+
* Slack: [#sig-node](https://kubernetes.slack.com/messages/sig-node)
127+
* [Mailing list](https://groups.google.com/forum/#!forum/kubernetes-sig-node)
128+
* [Open Community Issues/PRs](https://github.com/kubernetes/community/labels/sig%2Fnode)
129+
* [Biweekly meetings](https://github.com/kubernetes/community/tree/master/sig-node#meetings)
84.7 KB
Loading
82 KB
Loading
56 KB
Loading
70.7 KB
Loading

0 commit comments

Comments
 (0)