-
Notifications
You must be signed in to change notification settings - Fork 48
security: disable anonymous auth on kube-apiserver (MK8S-187) #4900
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
Open
g-carre
wants to merge
7
commits into
development/132.0
Choose a base branch
from
bugfix/MK8S-187-disable-kube-apiserver-anonymous-auth
base: development/132.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f39d88d
security: disable anonymous auth on kube-apiserver (MK8S-187)
g-carre 8517e33
tests: assert kube-apiserver rejects anonymous requests (MK8S-187)
g-carre 68189f9
fix: authenticate kube-apiserver health probes on healthz endpoint (M…
g-carre 250a7d0
security: scope kube-apiserver anonymous auth to health endpoints (MK…
g-carre 18e87cc
review: address code review on MK8S-187 kube-apiserver authn config
g-carre b3184f4
review: added changelog entry
g-carre 0459545
review: Set ca_pem in same if/else code as for oidc_config (MK8S-187)
g-carre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Generate the AuthenticationConfiguration file consumed by kube-apiserver | ||
| # via --authentication-config. | ||
| # | ||
| # It carries: | ||
| # * `anonymous` -- limits anonymous access to the kubelet probe endpoints | ||
| # (/livez, /readyz, /healthz) so kubelet httpGet probes keep working, | ||
| # while every other path (/version, /api/*, ...) still requires | ||
| # authentication. | ||
| # * `jwt` -- the OIDC issuer (Dex by default, or a pillar override). This | ||
| # replaces the legacy --oidc-* command-line flags, which are mutually | ||
| # exclusive with --authentication-config in Kubernetes 1.32+ | ||
| # (pkg/kubeapiserver/options/authentication.go: "authentication-config | ||
| # file and oidc-* flags are mutually exclusive"). | ||
| # | ||
| # Relies on the AnonymousAuthConfigurableEndpoints and | ||
| # StructuredAuthenticationConfiguration feature gates, both beta and | ||
| # on-by-default in Kubernetes 1.32+. | ||
| {%- from "metalk8s/map.jinja" import kube_api with context %} | ||
|
|
||
| include: | ||
| - .installed | ||
| - metalk8s.addons.nginx-ingress.ca.advertised | ||
|
|
||
| {%- set authn_config_path = kube_api.authn_config_path %} | ||
|
|
||
| {#- Build the OIDC issuer config, mirroring the historical --oidc-* selection | ||
| logic that used to live in installed.sls. #} | ||
| {%- set oidc_config = {} %} | ||
| {%- if pillar.kubernetes.get("apiServer", {}).get("oidc") %} | ||
| {%- do oidc_config.update(pillar.kubernetes.apiServer.oidc) %} | ||
| {%- elif pillar.addons.dex.enabled and salt.metalk8s_network.get_control_plane_ingress_endpoint() %} | ||
| {%- do oidc_config.update({ | ||
| "issuerURL": salt.metalk8s_network.get_control_plane_ingress_endpoint() ~ "/oidc", | ||
| "clientID": "oidc-auth-client", | ||
| "CAFile": "/etc/metalk8s/pki/nginx-ingress/ca.crt", | ||
| "usernameClaim": "email", | ||
| "groupsClaim": "groups", | ||
| }) %} | ||
| {%- endif %} | ||
|
|
||
| {#- AuthenticationConfiguration's `jwt[].issuer.certificateAuthority` field | ||
| expects PEM content inline, not a file path. For the default Dex case the | ||
|
g-carre marked this conversation as resolved.
Outdated
|
||
| Ingress CA is published in the salt mine as `ingress_ca_b64` by | ||
| `metalk8s.addons.nginx-ingress.ca.installed`, which avoids any ordering | ||
| dependency on the on-disk file. For a pillar-provided OIDC override we | ||
| fall back to reading the user-specified CAFile from the salt master. #} | ||
| {%- set ca_pem = '' %} | ||
| {%- if oidc_config %} | ||
| {%- set ingress_ca_path = '/etc/metalk8s/pki/nginx-ingress/ca.crt' %} | ||
| {%- if oidc_config.get('CAFile') == ingress_ca_path %} | ||
| {%- set ingress_ca_mine = salt['mine.get'](pillar.metalk8s.ca.minion, 'ingress_ca_b64') %} | ||
| {%- if ingress_ca_mine %} | ||
| {%- set ca_pem = salt['hashutil.base64_b64decode'](ingress_ca_mine[pillar.metalk8s.ca.minion]) %} | ||
| {%- endif %} | ||
| {%- elif oidc_config.get('CAFile') %} | ||
| {%- set ca_pem = salt['file.read'](oidc_config.CAFile) %} | ||
| {%- endif %} | ||
|
g-carre marked this conversation as resolved.
Outdated
|
||
| {%- endif %} | ||
|
|
||
|
|
||
| Create kube-apiserver authentication configuration: | ||
| file.serialize: | ||
| - name: {{ authn_config_path }} | ||
| - mode: '0600' | ||
| - user: root | ||
| - group: root | ||
| - makedirs: True | ||
| - dataset: | ||
| {#- TODO(MK8S-258): bump apiVersion to apiserver.config.k8s.io/v1 once metalk8s | ||
| pins Kubernetes >= 1.34. AuthenticationConfiguration is registered in | ||
| v1beta1 in 1.32/1.33 and promotes to v1 (GA) in 1.34. | ||
| it will also continue to be supported in v1beta1 until 1.36 #} | ||
| apiVersion: apiserver.config.k8s.io/v1beta1 | ||
| kind: AuthenticationConfiguration | ||
| anonymous: | ||
| enabled: true | ||
| conditions: | ||
| - path: /livez | ||
| - path: /readyz | ||
| - path: /healthz | ||
| {%- if oidc_config and ca_pem %} | ||
| jwt: | ||
| - issuer: | ||
| url: {{ oidc_config.issuerURL }} | ||
| audiences: | ||
| - {{ oidc_config.clientID }} | ||
| certificateAuthority: {{ ca_pem }} | ||
| claimMappings: | ||
| username: | ||
| claim: {{ oidc_config.usernameClaim }} | ||
| prefix: "oidc:" | ||
| groups: | ||
| claim: {{ oidc_config.groupsClaim }} | ||
| prefix: "oidc:" | ||
| {%- if oidc_config.usernameClaim == 'email' %} | ||
| claimValidationRules: | ||
| - expression: "claims.?email_verified.orValue(true) == true" | ||
| message: "email_verified claim must be true when set" | ||
| {%- endif %} | ||
| {%- endif %} | ||
| - require_in: | ||
| - metalk8s: Create kube-apiserver Pod manifest | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.