Home / Docs / Release 0.6.2 / Reference / API Token
In this section, the management of the API token of a Keptn installation is explained.
To retrieve the API token of a running Keptn installation, execute:
kubectl get secret keptn-api-token -n keptn -ojsonpath='{.data.keptn-api-token}'
To decode the retrieved API token, use means provided by the operating system:
on Linux / macOS
kubectl get secret keptn-api-token -n keptn -ojsonpath='{.data.keptn-api-token}' | base64 --decode
Please expand the corresponding section matching your CLI tool. For the Windows PowerShell, a small script is provided that installs the Copy the following snippet and paste it in the PowerShell. The snippet will be automatically executed line by line. In the Windows Command Line, a couple of steps are necessary. Get the Keptn API Token encoded in base64: Take the encoded API token; it is the value from the key Decode the file using Open the newly created file on Windows
PowerShell
PSYaml
module and sets the environment variables. Please note that the PowerShell might have to be started with Run as Administrator privileges to install the module.
$tokenEncoded = $(kubectl get secret keptn-api-token -n keptn -ojsonpath='{.data.keptn-api-token}')
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($tokenEncoded))
Command Line
kubectl get secret keptn-api-token -n keptn -ojsonpath={.data.keptn-api-token}
abcdefghijkladfaea
keptn-api-token
(in this example, it is abcdefghijkladfaea
) and save it in a text file, e.g.: keptn-api-token-base64.txt
certutil
:certutil -decode keptn-api-token-base64.txt keptn-api-token.txt
keptn-api-token.txt
, in which you find the API token.
To create an API token, use means provided by the operating system:
To generate a base64 encoded token use the following command and store it into the environment variable To create an API token, execute:on Linux / macOS
KEPTN_API_TOKEN
:KEPTN_API_TOKEN=$(head -c 16 /dev/urandom | base64)
kubectl create secret generic -n keptn keptn-api-token --from-literal=keptn-api-token="$KEPTN_API_TOKEN"
Please expand the corresponding section matching your CLI tool. To generate a base64 encoded token use the following command and store it into the environment variable To create an API token, execute: In the Windows Command Line, a couple of steps are necessary. Generate a random token with at least 16 characters and save it in a text file: Encode the file using Open the newly created file To create an API token, execute:on Windows
PowerShell
$Env:KEPTN_API_TOKEN
:[Reflection.Assembly]::LoadWithPartialName("System.Web")
$token_bytes = [System.Text.Encoding]::Unicode.GetBytes([System.Web.Security.Membership]::GeneratePassword(16,2))
$Env:KEPTN_API_TOKEN = [Convert]::ToBase64String($token_bytes)
kubectl create secret generic -n keptn keptn-api-token --from-literal=keptn-api-token="$Env:KEPTN_API_TOKEN"
Command Line
keptn-api-token.txt
certutil
:certutil -encode keptn-api-token.txt keptn-api-token-base64.txt
keptn-api-token-base64.txt
, in which you find the base64 encoded API token. Then set the environment variable KEPTN_API_TOKEN
:set KEPTN_API_TOKEN=
kubectl create secret generic -n keptn keptn-api-token --from-literal=keptn-api-token="%KEPTN_API_TOKEN%"
To reset an API token of a Keptn installation, first delete the secret:
kubectl delete secret -n keptn keptn-api-token
Create API token as explained above.
Re-start API service since it requires the new token:
kubectl delete pods -n keptn --selector=run=api-service
Re-authenticate Keptn CLI as explained here.
Don’t forget to replace the API token at tools that interact with the Keptn API, e.g., Problem Notification setting in Dynatrace or WebHook in Prometheus.