Create a Key Set with a PEM 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. If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.
-
The following Konnect items are required to complete this tutorial:
- Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
- Control Plane ID: You can use an existing Control Plane or create a new one to use for this tutorial. You can find your control plane UUID by navigating to the control plane in the Konnect UI or by sending a
GET
request to the/control-planes
endpoint. - Control Plane URL:
https://us.api.konghq.com
. If needed, replaceus
with your organization’s region (for example,eu
orau
). - Konnect Proxy URL: By default, a self-hosted Data Plane uses
http://localhost:8000
. You can set up Data Plane nodes for your Control Plane from the Gateway Manager in Konnect.
-
Set the personal access token, the Control Plane name, the Control Plane URL, and the Konnect proxy URL as environment variables:
export KONNECT_TOKEN='YOUR KONNECT TOKEN' export KONNECT_CONTROL_PLANE_ID='YOUR CONTROL PLANE ID' export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com export KONNECT_PROXY_URL='KONNECT PROXY URL'
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
PEM key pair
This tutorial requires a public key and private key. You can generate them using OpenSSL:
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
Create a Key Set
Using the Admin API, create a Key Set to hold PEM keys:
curl -X POST "$KONNECT_CONTROL_PLANE_URL/key-sets" \
-H "Accept: application/json"\
-H "Content-Type: application/json" \
--json '{
"name": "my-pem-key-set"
}'
curl -X POST "http://localhost:8001/key-sets" \
-H "Accept: application/json"\
-H "Content-Type: application/json" \
--json '{
"name": "my-pem-key-set"
}'
You will get a 201 Created
response with details about the new Key Set.
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.
To avoid errors, the private and public keys should be strings, and newlines should replaced with \n
:
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-pem-key",
"kid": "my-pem-key",
"set": {
"name": "my-pem-key-set"
},
"pem": {
"private_key": "-----BEGIN PRIVATE KEY-----\nprivate-key-content\n-----END PRIVATE KEY-----",
"public_key": "-----BEGIN PUBLIC KEY-----\npublic-key-content\n-----END PUBLIC KEY-----"
}
}'
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-pem-key",
"kid": "my-pem-key",
"set": {
"name": "my-pem-key-set"
},
"pem": {
"private_key": "-----BEGIN PRIVATE KEY-----\nprivate-key-content\n-----END PRIVATE KEY-----",
"public_key": "-----BEGIN PUBLIC KEY-----\npublic-key-content\n-----END PUBLIC KEY-----"
}
}'
You will get a 201 Created
response with details about the new Key, including the Key Set ID.
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