A user token is a signed JWT token that contains:
- The name of the user
- The list of groups that a user belongs to
- The expiration date of the token
Groups in Kong Mesh allow you to manage API permissions for users. A user can be a part of multiple groups.
Kong Mesh adds two groups to a user automatically:
- Authenticated users are added to
mesh-system:authenticated.
- Unauthenticated users are added to
mesh-system:unauthenticated.
Kong Mesh creates an admin user token on the first start of the control plane.
The admin user token is a user token issued for users in the mesh-system:admin group.
This group is authorized by default to execute all administrative operations.
-
Use kubectl to extract the admin token:
kubectl get secret admin-user-token -n kong-mesh-system --template={{.data.value}} | base64 -d
- Expose the Kong Mesh control plane to make it accessible from your machine using one of the following methods:
- Port-forward port 5681.
- Expose port 5681 and protect it with TLS or expose port 5682 with built-in via a load balancer.
- Expose port 5681 using an
Ingress (for example Kong Ingress Controller) and protect it with TLS.
- Configure
kumactl with the admin user token:
kumactl config control-planes add \
--name my-control-plane \
--address https://$CONTROL_PLANE_ADDRESS:5682 \
--auth-type=tokens \
--auth-conf token=$GENERATED_TOKEN \
--ca-cert-file=$CA_FILE_PATH
If you are using the 5681 port, change the schema to http://. If you want to skip CP verification, use --skip-verify instead of --ca-cert-file.
- Run the following command on the machine where you deployed the control plane to generate the token:
curl http://localhost:5681/global-secrets/admin-user-token | jq -r .data | base64 -d
- Configure
kumactl with admin user token
kumactl config control-planes add \
--name my-control-plane \
--address https://$CONTROL_PLANE_ADDRESS:5682 \
--auth-type=tokens \
--auth-conf token=$GENERATED_TOKEN \
--ca-cert-file=$CA_FILE_PATH
If you are using the 5681 port, change the schema to http://. If you want to skip CP verification, use --skip-verify instead of --ca-cert-file.
- Disable localhost as admin. By default, all requests originating from the localhost are authenticated as a
mesh-system:admin user.
After you retrieve and store the admin token, configure a control plane with KUMA_API_SERVER_AUTHN_LOCALHOST_IS_ADMIN set to false.
To generate user tokens, you must provide the credentials of a user authorized to generate user tokens.
If you have configured kumactl with an admin user token, you can use the following command to create a user token:
kumactl generate user-token \
--name john \
--group team-a \
--valid-for 24h
With the API, you must provide a token in the Authorization header:
curl localhost:5681/tokens/user \
-H'authorization: Bearer eyJhbGc...' \
-H'content-type: application/json' \
--data '{"name": "john","groups": ["team-a"], "validFor": "24h"}'
Kong Mesh doesn’t keep a list of issued tokens. To invalidate a token, you must add it to the revocation list.
Every token has its own ID under the jti key.
You can extract the ID from the token using jwt.io or the jwt-cli tool.
To revoke user tokens, specify a comma-separated list of revoked IDs in a global secret named user-token-revocations.
REVOCATIONS=$(echo '0e120ec9-6b42-495d-9758-07b59fe86fb9' | base64) && echo "apiVersion: v1
kind: Secret
metadata:
name: user-token-revocations
namespace: kong-mesh-system
data:
value: $REVOCATIONS
type: system.kuma.io/global-secret" | kubectl apply -f -
echo "
type: GlobalSecret
name: user-token-revocations
data: " | kumactl apply --var revocations=$(echo '0e120ec9-6b42-495d-9758-07b59fe86fb9' | base64) -f -
A user token is signed by a signing key which is autogenerated on the first start of the control plane.
If the signing key is compromised, you must rotate it. You must also rotate all the tokens that were signed by it.
-
Generate a new signing key.
The signing key is stored as a global secret named in the following format: user-token-signing-key-<serial_number>.
When generating a new signing key, assign it a serial number greater than the current key’s serial number.
Get the current key’s serial number:
kubectl get secrets -n kong-mesh-system --field-selector='type=system.kuma.io/global-secret'
NAME TYPE DATA AGE
user-token-signing-key-1 system.kuma.io/global-secret 1 25m
In this example, the highest serial number is 1.
Generate a new signing key with a serial number of 2:
TOKEN="$(kumactl generate signing-key)" && echo "
apiVersion: v1
data:
value: $TOKEN
kind: Secret
metadata:
name: user-token-signing-key-2
namespace: kong-mesh-system
type: system.kuma.io/global-secret
" | kubectl apply -f -
Get the current key’s serial number:
kumactl get global-secrets
NAME AGE
user-token-signing-key-1 36m
In this example, the highest serial number is 1.
Generate a new signing key with a serial number of 2:
echo "
type: GlobalSecret
name: user-token-signing-key-2
data: " | kumactl apply --var key=$(kumactl generate signing-key) -f -
-
Generate new tokens.
New tokens are generated with the signing key that has the highest serial number.
At this point, tokens signed by either the new or old signing key are valid.
-
Remove the old signing key:
kubectl delete secret user-token-signing-key-1 -n kong-mesh-system
kumactl delete global-secret user-token-signing-key-1
All new connections to the control plane now require tokens signed with
the new signing key.
You can remove the default admin user token from storage and prevent it from being recreated.
Keep in mind that removing the admin user token doesn’t remove the signing key.
Anyone with access to the signing key can generate a new admin token.
- Delete the
admin-user-token secret
kubectl delete secret admin-user-token -n kuma-namespace
- Disable the token bootstrap by configuring your control plane with the
KUMA_API_SERVER_AUTHN_TOKENS_BOOTSTRAP_ADMIN_TOKEN variable set to false.
- Delete
admin-user-token global secret:
kumactl delete global-secret admin-user-token
- Disable the token bootstrap by configuring your control plane with the
KUMA_API_SERVER_AUTHN_TOKENS_BOOTSTRAP_ADMIN_TOKEN variable set to false.