Create a Key Set with a JSON Web Key
Create a Key Set with the /key-sets
endpoint, then create a Key and configure the set.id
or set.name
parameter to point to the Key Set.
Prerequisites
Kong Konnect
This is a Konnect tutorial and requires a Konnect personal access token.
-
Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Export your token to an environment variable:
export KONNECT_TOKEN='YOUR_KONNECT_PAT'
-
Run the quickstart script to automatically provision a Control Plane and Data Plane, and configure your environment:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -k $KONNECT_TOKEN --deck-output
This sets up a Konnect Control Plane named
quickstart
, provisions a local Data Plane, and prints out the following environment variable exports:export DECK_KONNECT_TOKEN=$KONNECT_TOKEN export DECK_KONNECT_CONTROL_PLANE_NAME=quickstart export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com export KONNECT_PROXY_URL='http://localhost:8000'
Copy and paste these into your terminal to configure your session.
Kong Gateway running
This tutorial requires Kong Gateway Enterprise. If you don’t have Kong Gateway set up yet, you can use the quickstart script with an enterprise license to get an instance of Kong Gateway running almost instantly.
-
Export your license to an environment variable:
export KONG_LICENSE_DATA='LICENSE-CONTENTS-GO-HERE'
-
Run the quickstart script:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -e KONG_LICENSE_DATA
Once Kong Gateway is ready, you will see the following message:
Kong Gateway Ready
JSON Web Key
This tutorial requires a JSON Web Key. You can generate your own or use this one for testing:
{
"kty": "RSA",
"e": "AQAB",
"use": "enc",
"kid": "my-key",
"alg": "RSA1_5",
"n": "n_03K8g2O_rarMBqBpbDKtRzrKede24g8UQ8Jc_x4-vsBnCFJw_xUcy-j4Ub9hYQZtyBZ5bWuEWC1crsorFgDbzoO1fF237XtCUCb0G6a8-3fbeSQZGwglK_vIy8-pHzZnOC2kgHp-rrNo9xZHnaOkrqqW4CI8izDuxboi_BlGqiNjKqGimj6fCPkiIEFlIrAtQCM9bUJDXv_iIs9blv9StqrfWnwxPIeIuoeruY_eC76twMweH5JHEAx_7BJdTdOXo9lrwmoUYwLAPp9w4E9Dc1lW1gQXh8aK4UUaJcsTjEztPtKsPHkQGSuP5WxM5uNH9Jo3-4wwuoA6BDxBS4sw"
}
Create a Key Set
Using the Admin API, create a Key Set to hold JSON Web keys:
curl -X POST "$KONNECT_CONTROL_PLANE_URL/key-sets" \
-H "Accept: application/json"\
-H "Content-Type: application/json" \
--json '{
"name": "my-key-set"
}'
curl -X POST "http://localhost:8001/key-sets" \
-H "Accept: application/json"\
-H "Content-Type: application/json" \
--json '{
"name": "my-key-set"
}'
You will get a 201 Created
response with details about the new Key Set. For example:
{
"name":"my-key-set",
"id":"539c3c53-b3ff-43f2-a500-2f812d1d3e09",
"created_at":1739270324,
"updated_at":1739270324,
"tags":null
}
Create a Key
Create a Key and use either the set.id
from the response in the previous step, or the set.name
parameter to add it to the Key Set:
curl -X POST "$KONNECT_CONTROL_PLANE_URL/keys" \
-H "Accept: application/json"\
-H "Content-Type: application/json"\
-H "Kong-Admin-Token: $KONG_ADMIN_TOKEN" \
--json '{
"name": "my-key",
"kid": "my-key",
"set": {
"name": "my-key-set"
},
"jwk": "{\"kty\":\"RSA\",\"e\":\"AQAB\",\"use\":\"enc\",\"kid\":\"my-key\",\"alg\":\"RSA1_5\",\"n\":\"n_03K8g2O_rarMBqBpbDKtRzrKede24g8UQ8Jc_x4-vsBnCFJw_xUcy-j4Ub9hYQZtyBZ5bWuEWC1crsorFgDbzoO1fF237XtCUCb0G6a8-3fbeSQZGwglK_vIy8-pHzZnOC2kgHp-rrNo9xZHnaOkrqqW4CI8izDuxboi_BlGqiNjKqGimj6fCPkiIEFlIrAtQCM9bUJDXv_iIs9blv9StqrfWnwxPIeIuoeruY_eC76twMweH5JHEAx_7BJdTdOXo9lrwmoUYwLAPp9w4E9Dc1lW1gQXh8aK4UUaJcsTjEztPtKsPHkQGSuP5WxM5uNH9Jo3-4wwuoA6BDxBS4sw\"}"
}'
curl -X POST "http://localhost:8001/keys" \
-H "Accept: application/json"\
-H "Content-Type: application/json"\
-H "Kong-Admin-Token: $KONG_ADMIN_TOKEN" \
--json '{
"name": "my-key",
"kid": "my-key",
"set": {
"name": "my-key-set"
},
"jwk": "{\"kty\":\"RSA\",\"e\":\"AQAB\",\"use\":\"enc\",\"kid\":\"my-key\",\"alg\":\"RSA1_5\",\"n\":\"n_03K8g2O_rarMBqBpbDKtRzrKede24g8UQ8Jc_x4-vsBnCFJw_xUcy-j4Ub9hYQZtyBZ5bWuEWC1crsorFgDbzoO1fF237XtCUCb0G6a8-3fbeSQZGwglK_vIy8-pHzZnOC2kgHp-rrNo9xZHnaOkrqqW4CI8izDuxboi_BlGqiNjKqGimj6fCPkiIEFlIrAtQCM9bUJDXv_iIs9blv9StqrfWnwxPIeIuoeruY_eC76twMweH5JHEAx_7BJdTdOXo9lrwmoUYwLAPp9w4E9Dc1lW1gQXh8aK4UUaJcsTjEztPtKsPHkQGSuP5WxM5uNH9Jo3-4wwuoA6BDxBS4sw\"}"
}'
You will get a 201 Created
response with details about the new Key, including the Key Set ID. For example:
{
"tags":null,
"jwk":"{\"kty\":\"RSA\",\"e\":\"AQAB\",\"use\":\"enc\",\"kid\":\"my-key\",\"alg\":\"RSA1_5\",\"n\":\"n_03K8g2O_rarMBqBpbDKtRzrKede24g8UQ8Jc_x4-vsBnCFJw_xUcy-j4Ub9hYQZtyBZ5bWuEWC1crsorFgDbzoO1fF237XtCUCb0G6a8-3fbeSQZGwglK_vIy8-pHzZnOC2kgHp-rrNo9xZHnaOkrqqW4CI8izDuxboi_BlGqiNjKqGimj6fCPkiIEFlIrAtQCM9bUJDXv_iIs9blv9StqrfWnwxPIeIuoeruY_eC76twMweH5JHEAx_7BJdTdOXo9lrwmoUYwLAPp9w4E9Dc1lW1gQXh8aK4UUaJcsTjEztPtKsPHkQGSuP5WxM5uNH9Jo3-4wwuoA6BDxBS4sw\"}",
"pem":null,
"name":"my-key",
"kid":"my-key",
"id":"03cc15ef-f157-42dd-a43b-9959550ca466",
"created_at":1739270335,
"updated_at":1739270335,
"set":
{
"id":"539c3c53-b3ff-43f2-a500-2f812d1d3e09"
}
}
Cleanup
Clean up Konnect environment
If you created a new control plane and want to conserve your free trial credits or avoid unnecessary charges, delete the new control plane used in this tutorial.
Destroy the Kong Gateway container
curl -Ls https://get.konghq.com/quickstart | bash -s -- -d