Configure authentication
By default, the Inventory API runs with authentication disabled. This guide walks through enabling OIDC authentication, requesting a bearer token, and testing authenticated calls. This is useful for verifying that your service can authenticate before deploying to a production environment.
How the authenticator chain works
Section titled “How the authenticator chain works”The Inventory API uses a configurable authenticator chain. Each authenticator in the chain is evaluated in order, and the first one that succeeds grants access.
| Type | Description | Typical use |
|---|---|---|
oidc | Validates JWT bearer tokens from an OIDC provider | API access with a service account |
allow-unauthenticated | Allows all requests without credentials | Local development and testing |
Each authenticator can be enabled or disabled per transport (http and grpc independently).
Prerequisites
Section titled “Prerequisites”- A running Kessel Inventory API instance (see Run locally with Docker Compose)
grpcurlinstalled (for testing authenticated gRPC calls)curlinstalled (for requesting tokens)- A service account with client credentials from your OIDC provider (client ID and client secret)
Enabling authentication locally
Section titled “Enabling authentication locally”-
Clone the Inventory API repository
Terminal window git clone https://github.com/project-kessel/inventory-api.gitcd inventory-api -
Update the config file
The config file depends on how you run the Inventory API:
- Binary (
make run): edit.inventory-api.yaml - Containers (
make inventory-up): editdevelopment/configs/base.yaml
Replace the
authnsection with:authn:authenticator:type: first_matchchain:- type: oidcenable: truetransport:http: truegrpc: trueconfig:authn-server-url: <ISSUER_URL>skip-client-id-check: trueskip-issuer-check: trueinsecure-client: falseSet
<ISSUER_URL>to the OIDC realm URL for your identity provider. For example, if you are using Keycloak locally, this would be something likehttp://localhost:8084/realms/kessel. - Binary (
-
Start the Inventory API
Run with
make run(binary) ormake inventory-up(containers).
Requesting a bearer token
Section titled “Requesting a bearer token”Use the OAuth 2.0 client credentials flow to request a token from your identity provider:
curl -s '<ISSUER_URL>/protocol/openid-connect/token' \ -H 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=client_credentials' \ --data-urlencode 'client_id=<CLIENT_ID>' \ --data-urlencode 'client_secret=<CLIENT_SECRET>'The response includes an access_token field. Use this as your bearer token in the next step.
Testing an authenticated call
Section titled “Testing an authenticated call”With a valid token, test an authenticated gRPC call to the Inventory API:
grpcurl -plaintext -H "Authorization: bearer <TOKEN>" \ localhost:9000 \ kessel.inventory.v1.KesselInventoryHealthService.GetReadyzExpected output:
{ "status": "STORAGE postgres and RELATIONS-API", "code": 200}If you see an Unauthenticated error, verify that:
- The
authn-server-urlin your config matches your OIDC provider’s realm URL - Your token has not expired
- The Inventory API was restarted after the config change