|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes 1.30:结构化身份认证配置进阶至 Beta" |
| 4 | +date: 2024-04-25 |
| 5 | +slug: structured-authentication-moves-to-beta |
| 6 | +author: > |
| 7 | + [Anish Ramasekar](https://github.com/aramase) (Microsoft) |
| 8 | +translator: > |
| 9 | + [Michael Yao](https://github.com/windsonsea) (DaoCloud) |
| 10 | +--- |
| 11 | +<!-- |
| 12 | +layout: blog |
| 13 | +title: "Kubernetes 1.30: Structured Authentication Configuration Moves to Beta" |
| 14 | +date: 2024-04-25 |
| 15 | +slug: structured-authentication-moves-to-beta |
| 16 | +author: > |
| 17 | + [Anish Ramasekar](https://github.com/aramase) (Microsoft) |
| 18 | +--> |
| 19 | + |
| 20 | +<!-- |
| 21 | +With Kubernetes 1.30, we (SIG Auth) are moving Structured Authentication Configuration to beta. |
| 22 | +
|
| 23 | +Today's article is about _authentication_: finding out who's performing a task, and checking |
| 24 | +that they are who they say they are. Check back in tomorrow to find about what's new in |
| 25 | +Kubernetes v1.30 around _authorization_ (deciding what someone can and can't access). |
| 26 | +--> |
| 27 | +在 Kubernetes 1.30 中,我们(SIG Auth)将结构化身份认证配置(Structured Authentication Configuration)进阶至 Beta。 |
| 28 | + |
| 29 | +今天的文章是关于**身份认证**:找出谁在执行任务,核查他们是否是自己所说的那个人。 |
| 30 | +本文还述及 Kubernetes v1.30 中关于 **鉴权**(决定某些人能访问什么,不能访问什么)的新内容。 |
| 31 | + |
| 32 | +<!-- |
| 33 | +## Motivation |
| 34 | +Kubernetes has had a long-standing need for a more flexible and extensible |
| 35 | +authentication system. The current system, while powerful, has some limitations |
| 36 | +that make it difficult to use in certain scenarios. For example, it is not |
| 37 | +possible to use multiple authenticators of the same type (e.g., multiple JWT |
| 38 | +authenticators) or to change the configuration without restarting the API server. The |
| 39 | +Structured Authentication Configuration feature is the first step towards |
| 40 | +addressing these limitations and providing a more flexible and extensible way |
| 41 | +to configure authentication in Kubernetes. |
| 42 | +--> |
| 43 | +## 动机 {#motivation} |
| 44 | + |
| 45 | +Kubernetes 长期以来都需要一个更灵活、更好扩展的身份认证系统。 |
| 46 | +当前的系统虽然强大,但有一些限制,使其难以用在某些场景下。 |
| 47 | +例如,不可能同时使用多个相同类型的认证组件(例如,多个 JWT 认证组件), |
| 48 | +也不可能在不重启 API 服务器的情况下更改身份认证配置。 |
| 49 | +结构化身份认证配置特性是解决这些限制并提供一种更灵活、更好扩展的方式来配置 Kubernetes 中身份认证的第一步。 |
| 50 | + |
| 51 | +<!-- |
| 52 | +## What is structured authentication configuration? |
| 53 | +Kubernetes v1.30 builds on the experimental support for configurating authentication based on |
| 54 | +a file, that was added as alpha in Kubernetes v1.30. At this beta stage, Kubernetes only supports configuring JWT |
| 55 | +authenticators, which serve as the next iteration of the existing OIDC |
| 56 | +authenticator. JWT authenticator is an authenticator to |
| 57 | +authenticate Kubernetes users using JWT compliant tokens. The authenticator |
| 58 | +will attempt to parse a raw ID token, verify it's been signed by the configured |
| 59 | +issuer. |
| 60 | +--> |
| 61 | +## 什么是结构化身份认证配置? {#what-is-structured-authentication-configuration} |
| 62 | + |
| 63 | +Kubernetes v1.30 针对基于文件来配置身份认证提供实验性支持,这是在 Kubernetes v1.30 中新增的 Alpha 特性。 |
| 64 | +在此 Beta 阶段,Kubernetes 仅支持配置 JWT 认证组件,这是现有 OIDC 认证组件的下一次迭代。 |
| 65 | +JWT 认证组件使用符合 JWT 标准的令牌对 Kubernetes 用户进行身份认证。 |
| 66 | +此认证组件将尝试解析原始 ID 令牌,验证其是否由配置的签发方签名。 |
| 67 | + |
| 68 | +<!-- |
| 69 | +The Kubernetes project added configuration from a file so that it can provide more |
| 70 | +flexibility than using command line options (which continue to work, and are still supported). |
| 71 | +Supporting a configuration file also makes it easy to deliver further improvements in upcoming |
| 72 | +releases. |
| 73 | +--> |
| 74 | +Kubernetes 项目新增了基于文件的配置,以便提供比使用命令行选项(命令行依然有效,仍受支持)更灵活的方式。 |
| 75 | +对配置文件的支持还使得在即将发布的版本中更容易提供更多改进措施。 |
| 76 | + |
| 77 | +<!-- |
| 78 | +### Benefits of structured authentication configuration |
| 79 | +Here's why using a configuration file to configure cluster authentication is a benefit: |
| 80 | +--> |
| 81 | +### 结构化身份认证配置的好处 {#benefits-of-structured-authentication-configuration} |
| 82 | + |
| 83 | +以下是使用配置文件来配置集群身份认证的好处: |
| 84 | + |
| 85 | +<!-- |
| 86 | +1. **Multiple JWT authenticators**: You can configure multiple JWT authenticators |
| 87 | + simultaneously. This allows you to use multiple identity providers (e.g., |
| 88 | + Okta, Keycloak, GitLab) without needing to use an intermediary like Dex |
| 89 | + that handles multiplexing between multiple identity providers. |
| 90 | +2. **Dynamic configuration**: You can change the configuration without |
| 91 | + restarting the API server. This allows you to add, remove, or modify |
| 92 | + authenticators without disrupting the API server. |
| 93 | +--> |
| 94 | +1. **多个 JWT 认证组件**:你可以同时配置多个 JWT 认证组件。 |
| 95 | + 这允许你使用多个身份提供程序(例如 Okta、Keycloak、GitLab)而无需使用像 |
| 96 | + Dex 这样的中间程序来处理多个身份提供程序之间的多路复用。 |
| 97 | +2. **动态配置**:你可以在不重启 API 服务器的情况下更改配置。 |
| 98 | + 这允许你添加、移除或修改认证组件而不会中断 API 服务器。 |
| 99 | + |
| 100 | +<!-- |
| 101 | +3. **Any JWT-compliant token**: You can use any JWT-compliant token for |
| 102 | + authentication. This allows you to use tokens from any identity provider that |
| 103 | + supports JWT. The minimum valid JWT payload must contain the claims documented |
| 104 | + in [structured authentication configuration](/docs/reference/access-authn-authz/authentication/#using-authentication-configuration) |
| 105 | + page in the Kubernetes documentation. |
| 106 | +4. **CEL (Common Expression Language) support**: You can use [CEL](/docs/reference/using-api/cel/) |
| 107 | + to determine whether the token's claims match the user's attributes in Kubernetes (e.g., |
| 108 | + username, group). This allows you to use complex logic to determine whether a |
| 109 | + token is valid. |
| 110 | +--> |
| 111 | +3. **任何符合 JWT 标准的令牌**:你可以使用任何符合 JWT 标准的令牌进行身份认证。 |
| 112 | + 这允许你使用任何支持 JWT 的身份提供程序的令牌。最小有效的 JWT 载荷必须包含 Kubernetes |
| 113 | + 文档中[结构化身份认证配置](/zh-cn/docs/reference/access-authn-authz/authentication/#using-authentication-configuration)页面中记录的申领。 |
| 114 | +4. **CEL(通用表达式语言)支持**:你可以使用 [CEL](/zh-cn/docs/reference/using-api/cel/) |
| 115 | + 来确定令牌的申领是否与 Kubernetes 中用户的属性(例如用户名、组)匹配。 |
| 116 | + 这允许你使用复杂逻辑来确定令牌是否有效。 |
| 117 | + |
| 118 | +<!-- |
| 119 | +5. **Multiple audiences**: You can configure multiple audiences for a single |
| 120 | + authenticator. This allows you to use the same authenticator for multiple |
| 121 | + audiences, such as using a different OAuth client for `kubectl` and dashboard. |
| 122 | +6. **Using identity providers that don't support OpenID connect discovery**: You |
| 123 | + can use identity providers that don't support [OpenID Connect |
| 124 | + discovery](https://openid.net/specs/openid-connect-discovery-1_0.html). The only |
| 125 | + requirement is to host the discovery document at a different location than the |
| 126 | + issuer (such as locally in the cluster) and specify the `issuer.discoveryURL` in |
| 127 | + the configuration file. |
| 128 | +--> |
| 129 | +5. **多个受众群体**:你可以为单个认证组件配置多个受众群体。 |
| 130 | + 这允许你为多个受众群体使用相同的认证组件,例如为 `kubectl` 和仪表板使用不同的 OAuth 客户端。 |
| 131 | +6. **使用不支持 OpenID 连接发现的身份提供程序**:你可以使用不支持 |
| 132 | + [OpenID 连接发现](https://openid.net/specs/openid-connect-discovery-1_0.html) 的身份提供程序。 |
| 133 | + 唯一的要求是将发现文档托管到与签发方不同的位置(例如在集群中本地),并在配置文件中指定 `issuer.discoveryURL`。 |
| 134 | + |
| 135 | +<!-- |
| 136 | +## How to use Structured Authentication Configuration |
| 137 | +To use structured authentication configuration, you specify |
| 138 | +the path to the authentication configuration using the `--authentication-config` |
| 139 | +command line argument in the API server. The configuration file is a YAML file |
| 140 | +that specifies the authenticators and their configuration. Here is an example |
| 141 | +configuration file that configures two JWT authenticators: |
| 142 | +--> |
| 143 | +## 如何使用结构化身份认证配置 {#how-to-use-structured-authentication-configuration} |
| 144 | + |
| 145 | +要使用结构化身份认证配置,你可以使用 `--authentication-config` 命令行参数在 |
| 146 | +API 服务器中指定身份认证配置的路径。此配置文件是一个 YAML 文件,指定认证组件及其配置。 |
| 147 | +以下是一个配置两个 JWT 认证组件的示例配置文件: |
| 148 | + |
| 149 | +<!-- |
| 150 | +# Someone with a valid token from either of these issuers could authenticate |
| 151 | +# against this cluster. |
| 152 | +# second authenticator that exposes the discovery document at a different location |
| 153 | +# than the issuer |
| 154 | +--> |
| 155 | + |
| 156 | +```yaml |
| 157 | +apiVersion: apiserver.config.k8s.io/v1beta1 |
| 158 | +kind: AuthenticationConfiguration |
| 159 | +# 如果某人具有这些 issuer 之一签发的有效令牌,则此人可以在集群上进行身份认证 |
| 160 | +jwt: |
| 161 | +- issuer: |
| 162 | + url: https://issuer1.example.com |
| 163 | + audiences: |
| 164 | + - audience1 |
| 165 | + - audience2 |
| 166 | + audienceMatchPolicy: MatchAny |
| 167 | + claimValidationRules: |
| 168 | + expression: 'claims.hd == "example.com"' |
| 169 | + message: "the hosted domain name must be example.com" |
| 170 | + claimMappings: |
| 171 | + username: |
| 172 | + expression: 'claims.username' |
| 173 | + groups: |
| 174 | + expression: 'claims.groups' |
| 175 | + uid: |
| 176 | + expression: 'claims.uid' |
| 177 | + extra: |
| 178 | + - key: 'example.com/tenant' |
| 179 | + expression: 'claims.tenant' |
| 180 | + userValidationRules: |
| 181 | + - expression: "!user.username.startsWith('system:')" |
| 182 | + message: "username cannot use reserved system: prefix" |
| 183 | +# 第二个认证组件将发现文档公布于与签发方不同的位置 |
| 184 | +- issuer: |
| 185 | + url: https://issuer2.example.com |
| 186 | + discoveryURL: https://discovery.example.com/.well-known/openid-configuration |
| 187 | + audiences: |
| 188 | + - audience3 |
| 189 | + - audience4 |
| 190 | + audienceMatchPolicy: MatchAny |
| 191 | + claimValidationRules: |
| 192 | + expression: 'claims.hd == "example.com"' |
| 193 | + message: "the hosted domain name must be example.com" |
| 194 | + claimMappings: |
| 195 | + username: |
| 196 | + expression: 'claims.username' |
| 197 | + groups: |
| 198 | + expression: 'claims.groups' |
| 199 | + uid: |
| 200 | + expression: 'claims.uid' |
| 201 | + extra: |
| 202 | + - key: 'example.com/tenant' |
| 203 | + expression: 'claims.tenant' |
| 204 | + userValidationRules: |
| 205 | + - expression: "!user.username.startsWith('system:')" |
| 206 | + message: "username cannot use reserved system: prefix" |
| 207 | +``` |
| 208 | +
|
| 209 | +<!-- |
| 210 | +## Migration from command line arguments to configuration file |
| 211 | +The Structured Authentication Configuration feature is designed to be |
| 212 | +backwards-compatible with the existing approach, based on command line options, for |
| 213 | +configuring the JWT authenticator. This means that you can continue to use the existing |
| 214 | +command-line options to configure the JWT authenticator. However, we (Kubernetes SIG Auth) |
| 215 | +recommend migrating to the new configuration file-based approach, as it provides more |
| 216 | +flexibility and extensibility. |
| 217 | +--> |
| 218 | +## 从命令行参数迁移到配置文件 {#migration-from-command-line-arguments-to-configuration-file} |
| 219 | +
|
| 220 | +结构化身份认证配置特性旨在与基于命令行选项配置 JWT 认证组件的现有方法向后兼容。 |
| 221 | +这意味着你可以继续使用现有的命令行选项来配置 JWT 认证组件。 |
| 222 | +但是,我们(Kubernetes SIG Auth)建议迁移到新的基于配置文件的方法,因为这种方法更灵活,更好扩展。 |
| 223 | +
|
| 224 | +{{% alert title="Note" color="primary" %}} |
| 225 | +<!-- |
| 226 | +If you specify `--authentication-config` along with any of the `--oidc-*` command line arguments, this is |
| 227 | +a misconfiguration. In this situation, the API server reports an error and then immediately exits. |
| 228 | + |
| 229 | +If you want to switch to using structured authentication configuration, you have to remove the `--oidc-*` |
| 230 | +command line arguments, and use the configuration file instead. |
| 231 | +--> |
| 232 | +如果你同时指定 `--authentication-config` 和任何 `--oidc-*` 命令行参数,这是一种错误的配置。 |
| 233 | +在这种情况下,API 服务器会报告错误,然后立即退出。 |
| 234 | + |
| 235 | +如果你想切换到使用结构化身份认证配置,你必须移除 `--oidc-*` 命令行参数,并改为使用配置文件。 |
| 236 | +{{% /alert %}} |
| 237 | + |
| 238 | +<!-- |
| 239 | +Here is an example of how to migrate from the command-line flags to the |
| 240 | +configuration file: |
| 241 | + |
| 242 | +### Command-line arguments |
| 243 | +--> |
| 244 | +以下是如何从命令行标志迁移到配置文件的示例: |
| 245 | + |
| 246 | +### 命令行参数 {#command-line-arguments} |
| 247 | + |
| 248 | +```bash |
| 249 | +--oidc-issuer-url=https://issuer.example.com |
| 250 | +--oidc-client-id=example-client-id |
| 251 | +--oidc-username-claim=username |
| 252 | +--oidc-groups-claim=groups |
| 253 | +--oidc-username-prefix=oidc: |
| 254 | +--oidc-groups-prefix=oidc: |
| 255 | +--oidc-required-claim="hd=example.com" |
| 256 | +--oidc-required-claim="admin=true" |
| 257 | +--oidc-ca-file=/path/to/ca.pem |
| 258 | +``` |
| 259 | + |
| 260 | +<!-- |
| 261 | +There is no equivalent in the configuration file for the `--oidc-signing-algs`. |
| 262 | +For Kubernetes v1.30, the authenticator supports all the asymmetric algorithms listed in |
| 263 | +[`oidc.go`](https://github.com/kubernetes/kubernetes/blob/b4935d910dcf256288694391ef675acfbdb8e7a3/staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/oidc/oidc.go#L222-L233). |
| 264 | + |
| 265 | +### Configuration file |
| 266 | +--> |
| 267 | +在配置文件中没有与 `--oidc-signing-algs` 相对应的配置项。 |
| 268 | +对于 Kubernetes v1.30,认证组件支持在 |
| 269 | +[`oidc.go`](https://github.com/kubernetes/kubernetes/blob/b4935d910dcf256288694391ef675acfbdb8e7a3/staging/src/k8s.io/apiserver/plugin/pkg/authenticator/token/oidc/oidc.go#L222-L233) |
| 270 | +中列出的所有非对称算法。 |
| 271 | + |
| 272 | +### 配置文件 {#configuration-file} |
| 273 | + |
| 274 | +<!-- |
| 275 | +certificateAuthority: <value is the content of file /path/to/ca.pem> |
| 276 | +--> |
| 277 | + |
| 278 | +```yaml |
| 279 | +apiVersion: apiserver.config.k8s.io/v1beta1 |
| 280 | +kind: AuthenticationConfiguration |
| 281 | +jwt: |
| 282 | +- issuer: |
| 283 | + url: https://issuer.example.com |
| 284 | + audiences: |
| 285 | + - example-client-id |
| 286 | + certificateAuthority: <取值是 /path/to/ca.pem 文件的内容> |
| 287 | + claimMappings: |
| 288 | + username: |
| 289 | + claim: username |
| 290 | + prefix: "oidc:" |
| 291 | + groups: |
| 292 | + claim: groups |
| 293 | + prefix: "oidc:" |
| 294 | + claimValidationRules: |
| 295 | + - claim: hd |
| 296 | + requiredValue: "example.com" |
| 297 | + - claim: admin |
| 298 | + requiredValue: "true" |
| 299 | +``` |
| 300 | + |
| 301 | +<!-- |
| 302 | +## What's next? |
| 303 | +For Kubernetes v1.31, we expect the feature to stay in beta while we get more |
| 304 | +feedback. In the coming releases, we want to investigate: |
| 305 | +- Making distributed claims work via CEL expressions. |
| 306 | +- Egress selector configuration support for calls to `issuer.url` and |
| 307 | + `issuer.discoveryURL`. |
| 308 | +--> |
| 309 | +## 下一步是什么? {#whats-next} |
| 310 | + |
| 311 | +对于 Kubernetes v1.31,我们预计该特性将保持在 Beta,我们要收集更多反馈意见。 |
| 312 | +在即将发布的版本中,我们希望调查以下内容: |
| 313 | + |
| 314 | +- 通过 CEL 表达式使分布式申领生效。 |
| 315 | +- 对 `issuer.url` 和 `issuer.discoveryURL` 的调用提供 Egress 选择算符配置支持。 |
| 316 | + |
| 317 | +<!-- |
| 318 | +You can learn more about this feature on the [structured authentication |
| 319 | +configuration](/docs/reference/access-authn-authz/authentication/#using-authentication-configuration) |
| 320 | +page in the Kubernetes documentation. You can also follow along on the |
| 321 | +[KEP-3331](https://kep.k8s.io/3331) to track progress across the coming |
| 322 | +Kubernetes releases. |
| 323 | +--> |
| 324 | +你可以在 Kubernetes |
| 325 | +文档的[结构化身份认证配置](/zh-cn/docs/reference/access-authn-authz/authentication/#using-authentication-configuration)页面上了解关于此特性的更多信息。 |
| 326 | +你还可以通过 [KEP-3331](https://kep.k8s.io/3331) 跟踪未来 Kubernetes 版本中的进展。 |
| 327 | + |
| 328 | +<!-- |
| 329 | +## Try it out |
| 330 | +In this post, I have covered the benefits the Structured Authentication |
| 331 | +Configuration feature brings in Kubernetes v1.30. To use this feature, you must specify the path to the |
| 332 | +authentication configuration using the `--authentication-config` command line |
| 333 | +argument. From Kubernetes v1.30, the feature is in beta and enabled by default. |
| 334 | +If you want to keep using command line arguments instead of a configuration file, |
| 335 | +those will continue to work as-is. |
| 336 | +--> |
| 337 | +## 试用一下 {#try-it-out} |
| 338 | + |
| 339 | +在本文中,我介绍了结构化身份认证配置特性在 Kubernetes v1.30 中带来的好处。 |
| 340 | +要使用此特性,你必须使用 `--authentication-config` 命令行参数指定身份认证配置的路径。 |
| 341 | +从 Kubernetes v1.30 开始,此特性处于 Beta 并默认启用。 |
| 342 | +如果你希望继续使用命令行参数而不想用配置文件,原来的命令行参数也将继续按原样起作用。 |
| 343 | + |
| 344 | +<!-- |
| 345 | +We would love to hear your feedback on this feature. Please reach out to us on the |
| 346 | +[#sig-auth-authenticators-dev](https://kubernetes.slack.com/archives/C04UMAUC4UA) |
| 347 | +channel on Kubernetes Slack (for an invitation, visit [https://slack.k8s.io/](https://slack.k8s.io/)). |
| 348 | +--> |
| 349 | +我们很高兴听取你对此特性的反馈意见。请在 Kubernetes Slack 上的 |
| 350 | +[#sig-auth-authenticators-dev](https://kubernetes.slack.com/archives/C04UMAUC4UA) |
| 351 | +频道与我们联系(若要获取邀请,请访问 [https://slack.k8s.io/](https://slack.k8s.io/))。 |
| 352 | + |
| 353 | +<!-- |
| 354 | +## How to get involved |
| 355 | +If you are interested in getting involved in the development of this feature, |
| 356 | +share feedback, or participate in any other ongoing SIG Auth projects, please |
| 357 | +reach out on the [#sig-auth](https://kubernetes.slack.com/archives/C0EN96KUY) |
| 358 | +channel on Kubernetes Slack. |
| 359 | +--> |
| 360 | +## 如何参与 {#how-to-get-involved} |
| 361 | + |
| 362 | +如果你有兴趣参与此特性的开发、分享反馈意见或参与任何其他 SIG Auth 项目, |
| 363 | +请在 Kubernetes Slack 上的 [#sig-auth](https://kubernetes.slack.com/archives/C0EN96KUY) 频道联系我们。 |
| 364 | + |
| 365 | +<!-- |
| 366 | +You are also welcome to join the bi-weekly [SIG Auth |
| 367 | +meetings](https://github.com/kubernetes/community/blob/master/sig-auth/README.md#meetings) |
| 368 | +held every-other Wednesday. |
| 369 | +--> |
| 370 | +我们也欢迎你参加 [SIG Auth 双周会议](https://github.com/kubernetes/community/blob/master/sig-auth/README.md#meetings)。 |
0 commit comments