* 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>
15 KiB
Authorize API callers by role
This page describes how to limit what each caller of the NVIDIA Kubernetes Engine (NVKE) API can do, by giving it a role. Do this after Secure the NVKE API: authorization decides what an admitted caller may do, so it needs authentication on.
The NVKE controller checks every API operation before it serves it, by the operation's operationId, such as listClusters or deleteCluster. The API spec lists every operationId: it is controller/api/openapi.yaml in the checkout, and NVKE serves it without a token at <API_URL>/openapi.yaml. The paths that need no token, such as /healthz and /api/version, are not operations and are not checked.
The chart ships two roles. A role applies to every workload cluster: NVKE has no per-cluster permissions.
admin: may call every operation.viewer: may call thegetandlistoperations, such asgetClusterandlistNodePools.
A grant gives a role to the callers whose token matches it. A caller holds every role that any of its grants gives, and a caller with no role is refused every operation. You normally write only grants.
| Mode | Behavior |
|---|---|
| Off | Every admitted caller can call every operation. This is the default. |
| Permissive | Every request is checked, counted and logged, then served. Nothing is refused. |
| Enforcing | An admitted caller whose roles do not allow the operation gets 403 with {"message":"Not authorized"}. |
A token that authentication rejects still gets 401, or 403 with Not admitted: ..., before authorization runs.
Before you begin
- You have completed Secure the NVKE API, and its Helm values are in
auth-values.yaml, in the directory above thenvke/checkout. Authentication may still be permissive. - You run the commands on this page from the root of the
nvke/checkout, withKUBECONFIGset as in Before you begin on that page. - You know which group, or which service account, identifies each caller of the API.
Grant roles
Grants live under apiAuthz.authorizer.localBundle.config.issuers, keyed by the name of an issuer in apiAuth.config.issuers. Each issuer takes two kinds of grant:
claims: a token whose claim namednameequalsvalue, or is an array containing it, gets the roles ingrants. This is the same match asadmit.claimsin authentication. Grants have nogroupsshorthand: to grant by group, useclaimswithname: groups. Use a claim the identity provider (IdP) sets, not one users can edit.serviceAccounts: a Kubernetes service account token fromnamespacegets the roles ingrants. Setnameto match one service account; omitnameto match every service account in the namespace.
For the IdP from Secure the NVKE API, grant admin and viewer by group:
apiAuthz:
enabled: true
permissive: true
authorizer:
localBundle:
config:
issuers:
example-idp:
claims:
- {name: groups, value: <ADMITTED_GROUP>, grants: [admin]}
- {name: groups, value: <VIEWER_GROUP>, grants: [viewer]}
<ADMITTED_GROUP> is the group that authentication admits. <VIEWER_GROUP> is a group whose members get read-only access.
A grant applies only to callers that authentication admits, and authentication admits only <ADMITTED_GROUP>. Add <VIEWER_GROUP> to admit.groups of the existing example-idp issuer:
apiAuth:
config:
issuers:
- name: example-idp
# Keep issuer, jwks and algorithms as they are.
admit:
groups:
- <ADMITTED_GROUP>
- <VIEWER_GROUP>
Edit the issuer in place. Helm replaces a list as a whole, so a second issuers list drops every field you leave out of it.
NVKE checks the grants at startup and on every reload. It refuses an issuer that apiAuth does not configure, a grant of a role the bundle does not declare, and a value for the tenancy keys operatorTenant, tenant and operators, which this API does not use.
Grant a role to a service account
Once authorization enforces, every caller that authentication admits needs a role, including automation. One such caller is management-engine, a controller in the management-engine-system namespace that manages workload clusters through the NVKE API. The install on these pages does not deploy it. A service account's token has the subject system:serviceaccount:<NAMESPACE>:<SERVICE_ACCOUNT>. If that subject appears in the permissive-mode log in Find callers that enforcing mode would refuse, the service account calls the API and needs a grant.
Grant it under the issuer that admits it. The issuer key, local-kubernetes here, must equal the name of an apiAuth issuer that admits Kubernetes service account tokens. Secure the NVKE API does not set one up; Configuring NVKE API Authentication describes it.
apiAuthz:
enabled: true
permissive: true
authorizer:
localBundle:
config:
issuers:
example-idp:
claims:
- {name: groups, value: <ADMITTED_GROUP>, grants: [admin]}
- {name: groups, value: <VIEWER_GROUP>, grants: [viewer]}
local-kubernetes:
serviceAccounts:
- {namespace: <NAMESPACE>, name: <SERVICE_ACCOUNT>, grants: [admin]}
<NAMESPACE> and <SERVICE_ACCOUNT> are the namespace and name of the caller's service account.
Turn on authorization in permissive mode
-
Add the
apiAuthzandapiAuthvalues from Grant roles toauth-values.yaml. Merge them into the existing file rather than writing a second one. -
Run the install command again, with the same flags as in Secure the NVKE API, 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.yamlThe chart refuses to render if
apiAuthz.enabledis true whileapiAuth.enabledis false, or ifapiAuthz.permissiveis true whileapiAuthz.enabledis false. -
Wait for the rollout.
kubectl -n nvke-controller rollout status deploy/nvke-controller -
Check the startup log.
kubectl -n nvke-controller logs deploy/nvke-controller | grep 'API authorization'The output contains an
API authorization is enabledline with"mode":"permissive". If the pod does not become ready, its log containsFailed to set up API authorizationwith the problems it found in the bundle.
Find callers that enforcing mode would refuse
-
Read the authorization counter.
kubectl -n nvke-controller exec deploy/nvke-controller -- wget -qO- http://127.0.0.1:9090/metrics | grep '^nvke_authz_decisions_total'Every series with an
outcomeother thanallowcounts requests that enforcing mode would refuse, byaction. -
Find the caller behind each one in the log.
kubectl -n nvke-controller logs deploy/nvke-controller | grep -E 'would have refused this request|failed to authorize request'Each line names the
outcome, theactionand the request path asresource_id. NVKE never logs the token or its claims. Act on each line by itsoutcome:outcomeMeaning Fix denyThe caller, named by subjectandissuer, holds no role that allows the action.Grant it a role in the next step. unauthenticatedThe request has no authenticated caller, so the line names none. Fix the caller's authentication, as in Secure the NVKE API. errorNVKE could not decide. The line is failed to authorize request.Read its errorfield. -
In
auth-values.yaml, grant eachdenycaller the role it needs. For a user, look thesubjectup in the IdP and grant a group the user belongs to. For a service account, thesubjectissystem:serviceaccount:<NAMESPACE>:<SERVICE_ACCOUNT>; grant it underserviceAccounts, as in Grant a role to a service account. -
Run the install again with the same flags.
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.yamlNVKE picks up grants without a restart, as described in Change grants.
Continue when only outcome="allow" series increase.
Switch to enforcing mode
Authentication must enforce before authorization does. With authentication permissive, a request without a valid token reaches authorization with no caller, and enforcing authorization refuses it with 403 rather than 401, so the chart refuses to render apiAuthz.permissive: false while apiAuth.permissive is true. You can switch both in one install.
-
In
auth-values.yaml, setapiAuthz.permissive: false, andapiAuth.permissive: falseif it is not already. Run the install again with the same flags.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 -
Make sure NVKE restarted. NVKE reads the mode from the
nvke-controller-configConfigMap only at startup. The chart rolls the pod when that ConfigMap changes; without the chart, restart it:kubectl -n nvke-controller rollout restart deploy/nvke-controller -
Wait for the rollout.
kubectl -n nvke-controller rollout status deploy/nvke-controllerIn enforcing mode, NVKE logs each refused request as
refused request, with the same fields as the permissive-mode message, or asfailed to authorize requestwhen NVKE could not decide.
If callers get an unexpected 403 with {"message":"Not authorized"}, set apiAuthz.permissive: true, run the install again and restart NVKE, as in steps 1 to 3.
Verify
-
Check the mode NVKE reports.
kubectl -n nvke-controller exec deploy/nvke-controller -- wget -qO- http://127.0.0.1:9090/metrics | grep '^nvke_authz_enabled'The output is
nvke_authz_enabled{mode="enforcing"} 1. If the mode ispermissive, NVKE has not restarted since the change: restart it as in step 2 of Switch to enforcing mode. -
Run
kubectl oidc-login cleanto drop the cached token. Sign in to the IdP as a member of<VIEWER_GROUP>who is not in<ADMITTED_GROUP>, and get a token intoTOKENas in Secure the NVKE API, step 1 of "With curl".<API_URL>is the address described in step 2 of the same section. -
List the workload clusters.
curl -s -w '\n%{http_code}\n' -H "Authorization: Bearer ${TOKEN}" <API_URL>/api/clustersThe response is
200. -
Try to delete a cluster that does not exist.
curl -s -w '\n%{http_code}\n' -X DELETE -H "Authorization: Bearer ${TOKEN}" <API_URL>/api/clusters/00000000-0000-0000-0000-000000000000The response is
403with{"message":"Not authorized"}, because authorization runs before NVKE looks the cluster up. With a token from a member of<ADMITTED_GROUP>, the same delete returns404.
Change grants
NVKE applies grant changes without a restart: the kubelet updates the mounted bundle within a minute or two, and NVKE reloads it every 10 seconds.
-
Change the grants under
apiAuthz.authorizer.localBundle.configinauth-values.yaml. -
Run the install again with the same flags.
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 two minutes for the kubelet to update the bundle, then check that NVKE loaded the change.
kubectl -n nvke-controller logs deploy/nvke-controller --since=3m | grep 'authorization bundle' | tail -n 1The output is
Reloaded the authorization bundle, and requests from the callers you changed get the new decisions. A bundle that fails its checks does not replace the live one: NVKE keeps the last bundle that loaded, logsFailed to reload the authorization bundle; keeping the live one, and countsnvke_authz_bundle_reload_failures_total.
A change to apiAuth restarts NVKE instead: the chart rolls the pod, and NVKE loads the new bundle at startup.
Customize roles
To change what a role allows, or to add a role, set apiAuthz.authorizer.localBundle.policies (Cedar policies) and apiAuthz.authorizer.localBundle.roles (the role list) in auth-values.yaml. The defaults are in the chart's values.yaml. A policy names actions as NVKE::Action::"<operationId>", and NVKE refuses a policy that names an action the API does not have. NVKE reloads policies and roles the same way as grants, as in Change grants.
Use Teleport application access
This section applies only if callers reach the API through Teleport application access. Teleport signs a JSON Web Token (JWT) for each request to an application, with the user's Teleport roles in its roles claim, and has no groups claim. Admit those tokens by role in apiAuth, and grant NVKE roles by the same claim:
apiAuth:
config:
issuers:
- name: teleport
issuer: "<TELEPORT_CLUSTER_NAME>"
audiences: ["<APP_URI>"]
jwks:
uri: "https://<TELEPORT_PROXY_ADDRESS>/.well-known/jwks.json"
algorithms: [RS256, ES256]
admit:
claims:
- {name: roles, value: nvke-admin}
- {name: roles, value: nvke-viewer}
apiAuthz:
authorizer:
localBundle:
config:
issuers:
teleport:
claims:
- {name: roles, value: nvke-admin, grants: [admin]}
- {name: roles, value: nvke-viewer, grants: [viewer]}
<TELEPORT_CLUSTER_NAME>is the Teleport cluster name, not a URL. Teleport signs it into the token as the issuer.<APP_URI>is the application's URI in Teleport, and the token's audience. Give the application for each management cluster its own URI: two applications that share one accept each other's tokens.<TELEPORT_PROXY_ADDRESS>is the address of the Teleport proxy.
Add the teleport issuer to the existing apiAuth.config.issuers list, and its grants beside the existing ones, rather than replacing them.
In the Teleport application, leave rewrite.jwt_claims at its default, roles-and-traits, or set it to roles, so the token carries roles. Teleport sends the token in its Teleport-Jwt-Assertion header, so also rewrite the Authorization header. In teleport.yaml:
rewrite:
headers:
- "Authorization: Bearer {{internal.jwt}}"
In a dynamic app resource:
spec:
rewrite:
headers:
- name: Authorization
value: "Bearer {{internal.jwt}}"