* docs: document controller API authorization Add an operator guide for API authorization: the admin and viewer roles, granting them by claim and by service account, turning authorization on in permissive mode, finding the callers enforcing mode would refuse, switching to enforcing, and the metrics to watch. Link it from the docs index, the controller README and docs, and the observability page. Pages that said NVKE does no authorization now say every admitted caller can call every endpoint until authorization is on. Signed-off-by: dbudris <dbudris@nvidia.com> * docs(operate): name the Teleport app settings the roles claim needs The token carries roles only when rewrite.jwt_claims includes them, and the header rewrite is written differently in teleport.yaml and in a dynamic app resource. Signed-off-by: dbudris <dbudris@nvidia.com> * docs: use the apiAuthz.authorizer.localBundle values paths The chart now holds the authorization bundle under apiAuthz.authorizer.localBundle, beside apiAuthz.authorizer.backend. Update the operator guide, the controller README and the troubleshooting table to match. Signed-off-by: dbudris <dbudris@nvidia.com> * docs(operate): say the chart refuses permissive authorization while it is off Signed-off-by: dbudris <dbudris@nvidia.com> * docs(operate): restructure the API authorization page after review Explain grants and the shipped roles up front, and show the apiAuth admit change a viewer grant needs. Restart NVKE when switching to enforcing mode, since only nvke-controller-config changes, and add a rollback. Name the failed-to-authorize log line, act on each outcome, and give success signals for grant changes. Split steps to one command each, move Teleport and role customization to the end, drop the metrics table that observe.md already covers, and add next steps. Signed-off-by: dbudris <dbudris@nvidia.com> --------- Signed-off-by: dbudris <dbudris@nvidia.com>
18 KiB
Secure the NVKE API
This page describes how to make the NVIDIA Kubernetes Engine (NVKE) API require a signed JSON Web Token (JWT) from an OpenID Connect (OIDC) identity provider (IdP) that you already run. Do this after you install the management-plane services and before you give anyone else access to the API.
Authentication has three modes. Off is the default.
| Mode | Behavior |
|---|---|
| Off | Every request is served. This is the default. |
| Permissive | Every request is checked and counted, then served. Nothing is rejected. |
| Enforcing | A request without a valid token gets 401. A valid token that no admission rule matches gets 403. |
Until you turn on authorization, as described in Authorize API callers by role, every caller that NVKE admits can call every endpoint, including the ones that create and delete workload clusters. With authorization enforcing, an admitted caller whose roles do not allow the operation gets 403 with {"message":"Not authorized"}.
Warning: The NVKE API serves plain HTTP on NodePort 30080, and neither NVKE nor its chart serves it over TLS. Every bearer token a caller sends to
http://<MANAGEMENT_ADDRESS>:30080crosses the network unencrypted, and anyone who captures it can call the API until it expires. Send tokens only to a TLS endpoint that you put in front of the API, such as a reverse proxy that terminates TLS and forwards to port 30080, or admit to the API, in the NetworkPolicy from Admit your networks to the NVKE API, only clients on a trusted, isolated network.
Before you begin
-
You have completed Install the management plane. You can do this before or after Configure an infrastructure provider: NICo.
-
You run the install and
kubectlcommands on the host you installed from, from the root of the samenvke/checkout, with the site spec,<CLUSTER_NAME>.kubeconfigand, if you installed from one,release.jsonin the directory above it, as in Install the management plane. SetKUBECONFIGforkubectl:export KUBECONFIG="$PWD/../<CLUSTER_NAME>.kubeconfig"The install created the Helm release
nvke-controllerand the Deploymentnvke-controller, both in thenvke-controllernamespace. -
The shell you run the install from has the
NVKECTL_*variables from Set the install inputs exported. -
Your IdP publishes an OIDC discovery document over HTTPS, and the management cluster can reach its signing-key endpoint.
-
Your IdP has a group for the people and automation allowed to call the NVKE API, and puts it in a token claim named
groups, a list of strings. NVKE reads group membership only from that claim. -
Your IdP has an OIDC client for
nvkectlthat needs no client secret. -
The
kubectl oidc-loginplugin,jqandpython3are installed on the workstation you call the API from.
Collect the identity provider values
-
Read the IdP's discovery document.
curl -s <ISSUER_URL>/.well-known/openid-configuration | jq '{issuer, jwks_uri, id_token_signing_alg_values_supported}'<ISSUER_URL>is your IdP's issuer URL, such ashttps://idp.example.com/realms/example.Record the output:
issuer: use this exact string as<ISSUER_URL>. NVKE compares it with the token'sissclaim byte for byte, including any trailing slash.jwks_uriis<JWKS_URI>, where NVKE fetches the signing keys. It must usehttps.id_token_signing_alg_values_supportedlists the signing algorithms. NVKE accepts only asymmetric algorithms, such asRS256andES256.
-
Get a token from the IdP and read its claims.
TOKEN="$(kubectl oidc-login get-token --oidc-issuer-url=<ISSUER_URL> --oidc-client-id=<CLIENT_ID> | jq -r .status.token)"echo "$TOKEN" | cut -d. -f2 | python3 -c 'import sys,base64,json; s=sys.stdin.read().strip(); print(json.dumps(json.loads(base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))), indent=2))'<CLIENT_ID>is the ID of the OIDC client fornvkectl.kubectl oidc-loginasks you to log in to the IdP the first time.Record two claims:
audis<AUDIENCE>, the value callers must present. For a token fromkubectl oidc-loginit is usually<CLIENT_ID>.groupsmust contain the group you will admit,<ADMITTED_GROUP>. If it is missing, configure the IdP to release it. Some IdPs release it only when the client asks for a scope such asgroups; pass that with--oidc-extra-scope. Use the value exactly as the claim shows it.
Turn on authentication in permissive mode
-
Write the Helm values to a file named
auth-values.yaml, in the directory above thenvke/checkout.apiAuth: enabled: true permissive: true config: audiences: ["<AUDIENCE>"] issuers: - name: example-idp issuer: "<ISSUER_URL>" jwks: uri: "<JWKS_URI>" algorithms: [RS256] admit: groups: - <ADMITTED_GROUP>audiences: everyaudvalue NVKE accepts. A token is accepted if it names any of them, so list a second value for callers whose tokens carry a different audience. An audience must not equal an issuer URL.name: a label of your choice. It appears in logs and in theissuerlabel of the metrics.algorithms: the algorithms from step 1 that you accept.admit.groups: a token is admitted if itsgroupsclaim contains any listed group. For a token without agroupsclaim, useadmit.claimsinstead, a list of{name, value}: a token is admitted if its top-level claimnameisvalue, or a string array holding it. Use a claim the IdP sets, not one users can edit.iss,aud,nonce,jti,exp,nbf,iatandtypdescribe the token rather than the caller, so NVKE refuses to start with a rule on them.
issuersis a list. Add another entry for a second IdP.nameandissuerare unique in the file. Setaudienceson an issuer to replace the top-levelaudiencesfor that issuer.NVKE uses each value exactly as written. A value with leading or trailing whitespace stops NVKE from starting.
-
If the IdP's certificate is signed by a private certificate authority (CA), add the CA certificate to the same file, inline in the issuer's
jwks. A CA certificate is public, so it needs no Secret.apiAuth: config: issuers: - name: example-idp jwks: caBundle: | -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----Merge
caBundleinto the existing issuer'sjwksfrom step 1, rather than adding a secondapiAuthblock or issuer.caBundlemust contain at least one PEM certificate. Without it, NVKE trusts the system CAs.jwks.caBundlePathis the alternative for a CA file the pod already has or that you mount through the chart'svolumesandvolumeMounts. SetcaBundleorcaBundlePath, not both. -
Run the install command again, as described in Run the install again, with the same flags, including any
--values-for nktp=<FILE>, and--values-for controller=../auth-values.yamladded.deploy/nvke-deploy.sh install --deploy-path deploy/nico --sitespec ../sitespec.yaml --stack-config ../stack-config.json --kubeconfig ../<CLUSTER_NAME>.kubeconfig \ --values-for controller=../auth-values.yamlAdd
--release ../release.jsonif you installed from a release. The same stack config keeps the controller and profile images the ones you installed. The install upgrades each component in place, and appliesauth-values.yamlto the controller after the deploy path's own values, which turn authentication off. The chart rendersconfiginto theapiAuthsection of thenvke-controller-configConfigMap, which is the only place NVKE reads it from. The chart refuses to render ifenabledis set withoutconfigorconfigwithoutenabled, ifpermissiveis set withoutenabled, ifconfigcarriesenabledorpermissive, which belong directly underapiAuth, or ifcaBundlePathnames a file under/etc/nke/auth/, where nothing is mounted. -
Wait for the new pods and check the startup log.
kubectl -n nvke-controller rollout status deploy/nvke-controllerkubectl -n nvke-controller logs deploy/nvke-controller | grep -E 'fetched issuer signing keys|API authentication'The output contains a
fetched issuer signing keysline forexample-idpand anAPI authentication is enabledline with"mode":"permissive".If the keys line is missing, look for a
JWKS fetch failedwarning and fix the URI, the CA bundle or the network path now. In permissive mode NVKE starts without the keys, counts that issuer's tokens asjwks_stale, and retries as they arrive. In enforcing mode it does not start.
Call the API
Configure your callers now, while NVKE still serves every request. From the moment the install creates the authentication configuration, nvkectl configured with <CLUSTER_NAME>.kubeconfig fails before it sends a request, with an error that contains minting token for nke-clients/nke-client: with that kubeconfig it requests a token for a service account that the install does not create.
With nvkectl
-
Generate a kubeconfig that gets tokens from your IdP.
nvkectl generate oidc-kubeconfig --kubeconfig ../<CLUSTER_NAME>.kubeconfig \ --oidc-issuer-url <ISSUER_URL> \ --oidc-client-id <CLIENT_ID> \ --output-file ../oidc.kubeconfigThe command copies the cluster address and CA from
<CLUSTER_NAME>.kubeconfigand replaces the user withkubectl oidc-login. Add--oidc-extra-scope <SCOPE>for each scope your IdP needs to release thegroupsclaim. On a machine with no browser, add--headless.kubectl oidc-loginthen prints a URL to open on another machine. The IdP client must allow the device authorization grant. -
Point
nvkectlat the API with that kubeconfig.nvkectl config set-site --name <CLUSTER_NAME> --url <API_URL> --kubeconfig "$PWD/../oidc.kubeconfig"nvkectlstores the kubeconfig path as you give it, so give an absolute path; a relative one works only from the directory you ranset-sitein.<API_URL>is the base address of the NVKE API without/api:http://<MANAGEMENT_ADDRESS>:30080, as in Install the management plane, or thehttpsaddress of the TLS endpoint you put in front of it. A token sent to thehttpaddress crosses the network unencrypted; see the warning at the top of this page.nvkectl get kubeconfig,nvkectl get providers, and the machine image, cluster release and node pool release commands, such asnvkectl get nodepoolreleases, read the management cluster's Kubernetes API directly with this kubeconfig. The bootstrap does not configure that API server to accept tokens from your IdP, so these commands fail. Usekubectlwith<CLUSTER_NAME>.kubeconfigfor them instead, as described in Access a workload cluster and Create a workload cluster. -
Call the API.
nvkectl get clusterskubectl oidc-loginasks you to log in to the IdP if it has no valid token, then the command lists the workload clusters.
With curl
-
Get a token.
TOKEN="$(kubectl oidc-login get-token --oidc-issuer-url=<ISSUER_URL> --oidc-client-id=<CLIENT_ID> | jq -r .status.token)"Automation that gets its tokens another way works the same, as long as each token carries an accepted
audand an admitted group. -
Call the API with the token in the
Authorizationheader.<API_URL>ishttp://<MANAGEMENT_ADDRESS>:30080, or thehttpsaddress of the TLS endpoint you put in front of it. Other pages write this header as-H "Authorization: Bearer <TOKEN>", where<TOKEN>is a token like the one inTOKEN.curl -H "Authorization: Bearer ${TOKEN}" <API_URL>/api/clustersThe response is the list of workload clusters in JSON.
Find callers that enforcing mode would reject
Leave NVKE in permissive mode while your existing callers keep working, and watch which of them would fail.
-
Read the authentication counter.
kubectl -n nvke-controller exec deploy/nvke-controller -- wget -qO- http://127.0.0.1:9090/metrics | grep '^nvke_auth_requests_total'nvke_auth_requests_total{issuer="unknown",outcome="would_reject",reason="no_token"} 7Requests that pass are counted with
outcome="authenticated". Eachwould_rejectseries represents requests that enforcing mode would reject. Use the logs to trace the source requests. -
Read the
reasonlabel and fix each caller.reasonStatus when enforcing Fix no_token401The caller sends no Authorization: Bearerheader. Give it a token.unknown_issuer401The token's issmatches no configuredissuerbyte for byte. Fix issuer, or give the caller a token from your IdP.audience_mismatch401The token's audis not inaudiences. Add it, or give the caller a token for an accepted audience.expired,not_yet_valid401The token is outside its validity period. Get a new one, or check the caller's clock. bad_signature,algorithm_not_allowed401The token does not verify against the issuer's keys and algorithms.jwks_stale401NVKE cannot refresh the issuer's keys. Fix the key endpoint, not the caller. not_admitted403The token is valid, but its groupsclaim contains no admitted group. Add the caller to the group. -
Find the caller behind each rejection in the log.
kubectl -n nvke-controller logs deploy/nvke-controller | grep 'authentication would have rejected this request'Each line names the
reason,issuer,method,pathandremote_addrof the request.
Continue when would_reject stops increasing.
Switch to enforcing mode
-
In
auth-values.yaml, setpermissive: false, then run the install again with the same flags as in Turn on authentication in permissive mode, step 3.deploy/nvke-deploy.sh install --deploy-path deploy/nico --sitespec ../sitespec.yaml --stack-config ../stack-config.json --kubeconfig ../<CLUSTER_NAME>.kubeconfig \ --values-for controller=../auth-values.yaml -
Wait for the rollout.
kubectl -n nvke-controller rollout status deploy/nvke-controllerIn enforcing mode NVKE does not start unless it fetches the signing keys of every configured issuer. If the new pod does not become ready, its log contains
Failed to set up API authenticationwith the issuer and the error.In enforcing mode, NVKE logs each rejected request as
rejected request, with the same fields as the permissive-mode message.
NVKE reads the authentication configuration once, at startup. If you later change only apiAuth.config, restart the Deployment with kubectl -n nvke-controller rollout restart deploy/nvke-controller. Add a new issuer in permissive mode first, because an issuer whose keys NVKE cannot fetch stops an enforcing NVKE from starting.
The deploy path's own values turn authentication off. Every time you run the install again, for any reason, add --values-for controller=../auth-values.yaml, along with the other inputs listed in Run the install again.
Verify
-
Check the mode the controller reports.
kubectl -n nvke-controller exec deploy/nvke-controller -- wget -qO- http://127.0.0.1:9090/metrics | grep '^nvke_auth_enabled'The output is
nvke_auth_enabled{mode="enforcing"} 1. -
Call the API without a token.
curl -s -w '\n%{http_code}\n' <API_URL>/api/clustersThe response is
401with the messageAuthentication required: no bearer token was presented.A200means authentication is still off or permissive.Test with
/api/clusters, not/api/version./healthz,/readyz,/api/version,/openapi.yaml,/docsand the API documentation under/api/docs/need no token, so a successful call to them tells you nothing about authentication. -
Call the API with a token from a user who is not in
<ADMITTED_GROUP>. The response is403with the messageNot admitted: the authenticated identity matches no admission rule.
Upgrade from an authentication ConfigMap you managed
Earlier charts could mount an authentication ConfigMap that you managed yourself (apiAuth.configMap.create: false), which NVKE read through the AUTH_CONFIG_PATH environment variable. The chart now refuses apiAuth.configMap and an env entry named AUTH_CONFIG_PATH, and NVKE does not start while that variable is set. Before you upgrade such a site, change its controller values:
- Move the configuration into
apiAuth.config. Keepaudiencesandissuers, and dropapiVersionandkind. - Move any CA bundle from
apiAuth.configMap.extraFilesor from your ConfigMap into the issuer asjwks.caBundle. - Set
apiAuth.enabled: trueand removeapiAuth.configMap. - If
apiAuth.permissiveistruewhileapiAuth.enabledisfalse, removepermissive.
Upgrade the chart and the controller image together. Helm deletes the chart-owned nvke-auth-config ConfigMap during the upgrade. An nvkectl release that does not read nvke-controller-config sends no token after the upgrade and gets 401; upgrade nvkectl.