Configuring NVKE API Authentication
How to make NVKE require a token on its API, using an identity provider you already run.
This is the operator’s side. For getting a token and making a call once it is on, see Call the API in Secure the NVKE API.
What you are setting up
NVKE can require a signed JWT on every /api/* request, in one of these states:
Permissive exists so you can turn this on somewhere that already has callers and find out who would break before they do. Use it.
A token is accepted when its issuer is one you configured, its signature
verifies, it names your deployment in its aud claim, it has not expired, and
its subject matches a rule you wrote. The first four failing gives a 401. The
last one gives a 403: the token was real, the caller just isn’t on the list.
NVKE does no authorization. Every admitted caller can call every endpoint.
issuers is a list. Add an entry for each identity provider. name and issuer
are each unique in the file. An issuer’s audiences replaces the top-level
list for that issuer. An issuer carries one of serviceAccounts, spiffe,
groups, or claims.
Before you start
You need permission to set Helm values on the NVKE release, and a cluster running
a chart version with an apiAuth section:
On an existing site, the controller runs under the name it was installed with:
nke-controller for a site installed before the nvke rename,
cloud-workflow-engine for anything older. Replace nvke-controller with that
name in every command on this page.
The commands below use $NS for the namespace NVKE runs in:
Recipe: your cluster’s own API server
This is the common case, and it needs no extra infrastructure. Kubernetes already signs tokens for service accounts and publishes the keys to verify them.
1. Read your cluster’s issuer
Read it rather than assuming it:
Take the issuer value.
Do not take jwks_uri. It is built from the API server’s advertise address,
so it is a node IP or a load-balancer address that can change. Use the
in-cluster name instead, which is stable and serves the same thing:
2. Create the identity your callers will use
NVKE admits callers by name, so the account has to exist before you name it in the configuration. The Helm chart does not create these objects.
nvkectl mints this pair and no other. The names nke-clients /
nke-client are fixed in the CLI, and so are the ConfigMaps it reads the
audience from. It looks first for the controller’s settings ConfigMap,
nvke-controller-config, then nke-controller-config for a site that pins the
older name, and mints for the first entry of its apiAuth.audiences when
apiAuth.enabled is true. When that section is off or absent, as it is for a
controller from before the chart stopped rendering an authentication ConfigMap,
it falls back to that ConfigMap: nvke-auth-config, then nke-auth-config for
a site that kept the older name. A current chart renders neither, so the
fallback finds nothing there. Each search tries both names in namespace
nvke-controller, then both in nke-controller for a site installed before the
nvke rename, then both in cloud-workflow-engine, and uses the first it can
read.
A ConfigMap it is not permitted to read does not stop the command: the search
moves to the next candidate, so a kubeconfig scoped to the pinned names alone
still works. The denial is reported only if nothing readable turns
authentication on. Any other error reading a ConfigMap stops the command. In any other
namespace, nvkectl finds no ConfigMap and sends no token.
Other names work for curl and hack/nvke-token.sh if you override
them; they will not work for nvkectl. One account per caller is still easier
to revoke when those callers are not the CLI.
Minting a token for that account needs create on serviceaccounts/token in
its namespace, and nvkectl also needs get on the controller’s settings
ConfigMap, and on a site running an older controller the authentication
ConfigMap, to find the audience. A cluster
administrator already has both. To let something else
mint it, such as nvkectl under a least-privilege kubeconfig, a CI job, or an
application that renews its own token, grant it:
resourceNames holds that grant to the one account, so it does not become a way
to mint tokens for anything else in the namespace. Bind it to whoever is doing
the minting: the user or group in the kubeconfig nvkectl uses.
3. Write the configuration
audiences is what callers must name in their token. Pick something unique
to this deployment; its external URL is a good choice. Do not reuse your issuer
or a kubernetes.default.svc address: every pod in the cluster already carries
those, so the check would admit everything.
admit is the allow-list, and it is what makes this safe. Anyone who can
create a pod can have Kubernetes mint a token for their own service account
naming any audience they like. Verifying the signature is not enough on its own;
the allow-list is what stops every service account in the cluster from being an
NVKE administrator. Omitting name admits every service account in that
namespace. A name with no value is refused.
The two CA and token paths are files Kubernetes puts in every pod, so they work as written.
4. Set the chart values
Start permissive. The next section covers going enforcing.
The chart renders apiAuth.config into the apiAuth section of
nvke-controller-config, which is the only place NVKE reads the configuration
from. Setting enabled without config, config without enabled, or
permissive without enabled fails the install rather than silently ignoring
one of them.
Upgrading from an authentication ConfigMap you managed
Earlier charts could mount a ConfigMap you managed yourself
(apiAuth.configMap.create: false), which NVKE read through AUTH_CONFIG_PATH.
Both are gone: the chart refuses apiAuth.configMap and an env entry named
AUTH_CONFIG_PATH, and NVKE refuses to start when that variable is set. Before
upgrading such a site:
- Move the document into
apiAuth.config. Drop itsapiVersionandkind; keepaudiencesandissuersonly. - Move any CA bundle that was in
extraFilesor in your ConfigMap into the issuer asjwks.caBundle. AcaBundlePathunder/etc/nke/auth/fails the install, because nothing is mounted there any more. - Set
apiAuth.enabled: trueand removeapiAuth.configMap.
A site with apiAuth.permissive: true and enabled: false drops permissive.
Deploy the chart and the image together. Helm deletes the chart-owned
nvke-auth-config on the upgrade; a ConfigMap you created yourself is left for
you to delete once nothing reads it.
5. Check it came up
You want one fetched issuer signing keys line per issuer. If one is missing,
fix it now: while permissive, a failed fetch is only a warning; enforcing, it
stops NVKE from starting at all.
6. Tell callers what to ask for
nvkectl mints on its own once config set-site --kubeconfig points at this
cluster. The kubeconfig identity needs the Role above, the service
account must exist, and the admit rule must list nke-clients/nke-client.
For curl and scripts:
This has to be kubectl create token. The older approach, reading a
ServiceAccount Secret, produces a token with no audience, which NVKE refuses.
Recipe: SPIRE
Use this if you already run SPIRE. The shape is the same; the differences are that subjects are SPIFFE IDs rather than service accounts, and you have to supply a CA certificate yourself.
1. Read the issuer, and check the certificate
As above, take issuer and be careful about the keys URL. Whatever address you
choose has to appear in the certificate SPIRE serves, or the connection fails:
If the only usable name is an IP address, use it, but know you’re pinning something that may move.
2. Get the CA certificate into NVKE
SPIRE’s endpoint uses its own certificate, not one from a public CA, so NVKE needs the CA to trust it:
The simplest place for it is inline in the issuer, as jwks.caBundle, shown in
step 3. A CA bundle is a public certificate, not a secret, so it can sit in the
chart values with the rest of the configuration.
jwks.caBundlePath is the alternative for a file the pod already has, or one
you mount yourself through the chart’s volumes and volumeMounts. It cannot
point under /etc/nke/auth/: nothing is mounted there.
3. Write the issuer
pathPrefixes is required and cannot be /. A trust domain on its own would
admit every workload in it, which is rarely what you want.
An issuer uses one of serviceAccounts, spiffe, groups, or claims.
4. Tell callers what to ask for
-ttl takes a duration like 10m, not a number of seconds.
Recipe: an external identity provider
Use this when callers get tokens from an identity provider you already run.
NVKE reads group membership only from the token’s groups claim.
1. Write the issuer
Add this issuer to a configuration that already contains at least one top-level audiences value. The block below is not a complete configuration. NVKE refuses to start when audiences is missing.
A token is admitted when its groups claim contains any listed group. The
group names are matched exactly.
For a token with no groups claim, admit by another top-level claim instead:
A token is admitted when, for any listed rule, its claim name is the string
value or a string array holding it. Use a claim the identity provider sets,
not one users can edit. iss, aud, nonce, jti, exp, nbf, iat and
typ can’t be used: they describe the token, not the caller, so a rule on one
admits every token from the issuer or a value the caller chooses.
Teleport application access signs a JWT with the user’s Teleport roles in
roles, so admit it by that claim. The token carries roles only when the
app’s rewrite.jwt_claims is roles-and-traits, the default, or roles.
Teleport sends the JWT in its Teleport-Jwt-Assertion header, and NVKE reads
only Authorization, so rewrite the header in the Teleport app. In
teleport.yaml:
In a dynamic app resource:
On the NVKE side:
issueris the Teleport cluster name, not a URL.- The audience is the app’s URI.
jwks.uriishttps://<proxy>/.well-known/jwks.json, the application access keys. Teleport’s OIDC discovery keys are a different set.algorithmsis[RS256, ES256]: Teleport signs with RS256 under thelegacysignature_algorithm_suiteand ES256 under the others.
When the identity provider’s certificate is signed by a private CA, put the
PEM bundle inline as jwks.caBundle, as in the SPIRE recipe. Omit both when a public CA signs the certificate.
Going enforcing without breaking callers
Do not skip permissive. It is the only way to find callers you did not know about.
Watch the counter, not the log. Successful reads are logged at debug level, so the log will undercount them:
Every would_reject series is a caller that enforcing would break. The reason
label says what each one needs: usually a token, or a subject added to your
allow-list. Rejections are also logged in full:
When would_reject stops climbing, set apiAuth.permissive: false.
Add new issuers while still permissive. Enforcing NVKE will not start if it cannot reach every issuer’s keys, so a bad issuer becomes an outage rather than a warning.
Reference
Configuration fields
The configuration is read once at startup, so restart NVKE after you change it:
Values are matched exactly: leading or trailing whitespace is an error, not something NVKE trims.
Chart values
Why a request was rejected
Everything is a 401 except not_admitted, which is a 403.
Responses name the reason and nothing else. Issuer names and configuration stay in the log.
Endpoints that need no token
/healthz, /readyz, /api/version, /openapi.yaml, /openapi-public.yaml, /docs, and the Swagger
UI under /api/docs/.
Everything else needs one, including paths that route nowhere, so a caller
cannot probe for endpoints without authenticating. This is also why a successful
call to /api/version tells you nothing about whether authentication is on.
Troubleshooting
NVKE will not start, and the log says it could not set up authentication.
When enforcing, every issuer’s keys must be reachable at startup. The message
names the issuer and the error. Check the keys URL is reachable from inside the
pod, and that any caBundlePath points at a file that is actually mounted; an
inline caBundle avoids the file altogether.
Everything returns 401, including tokens that look right.
Check the audience first: it’s the usual cause. A token minted for the wrong
audience is rejected identically to no token at all. Compare its aud claim
against the audiences NVKE logs at startup.
NVKE does not start, and the log never says “API authentication is”.
An invalid inline configuration fails before that log line, on stderr, as
Error loading configuration: invalid controller config "<path>": apiAuth: ....
Read the container’s previous log:
A caller gets 403.
Its token is fine and its subject is not on the allow-list. The log names the
subject; compare it to your admit rules. Re-minting the token will not help.
NVKE rejected the configuration at startup.
The error names the offending field. Usual causes: an audience that matches one
of your issuers, a value with stray whitespace, serviceAccounts and spiffe
on the same issuer, a keys URL that is not https, or both caBundle and
caBundlePath on one issuer. permissiveMode moved to apiAuth.permissive means
nvke-controller-config came from a chart older than the image: deploy the
chart and image together. AUTH_CONFIG_PATH is set means the Deployment still
points NVKE at an authentication file it no longer reads; see
Upgrading from an authentication ConfigMap you managed.
Config changes have no effect.
NVKE reads only apiAuth in its settings ConfigMap: the one
controllerConfig.name names, nvke-controller-config unless your site pins
nke-controller-config. It reads it once at startup. A helm upgrade that
changes the chart values rolls the controller; an edit to the ConfigMap itself
takes effect only after a restart, or once Reloader restarts it. A leftover
nvke-auth-config is not read.
You cannot tell whether authentication is on. NVKE says so at startup, with the mode, audiences and issuers:
API authentication is disabled means apiAuth.enabled is false in
nvke-controller-config.
See also
- Secure the NVKE API: the operator path, and the caller’s side including
nvkectl.