API Keys

API keys are long-lived authentication tokens that make it more convenient to authenticate with Sensu-adjacent applications. API keys are generated by the Sensu backend, and you can provide them to applications that want to interact with the Sensu API.

Use the APIKey API to create, retrieve, and delete API keys.

API key compatibility

API keys are 100% backward-compatible with Sensu’s authentication token system, but API keys do not need to be refreshed every 15 minutes like the auth tokens.

When you specify an API key in a request, the system resolves it to an authentication token and continues through the regular authentication process.

NOTE: The API key resource is not compatible with sensuctl create.

API key resource structure

type: APIKey
api_version: core/v2
metadata:
  name: 19803eb8-36a6-4203-a225-28ec4e9f4444
spec:
  created_at: 1570732266
  username: admin
{
  "type": "APIKey",
  "api_version": "core/v2",
  "metadata" : {
    "name": "19803eb8-36a6-4203-a225-28ec4e9f4444"
  },
  "spec": {
    "created_at": 1570732266,
    "username": "admin"    
  }
}

API key specification

Top-level attributes

type
description Top-level attribute specifying the resource type. API keys should always be of type APIKey.
required true
type String
example
"type": "APIKey"
api_version
description Top-level attribute specifying the Sensu API group and version. This attribute should always be core/v2.
required true
type String
example
"api_version": "core/v2"
metadata
description Top-level collection of metadata about the API key, including the name. The metadata map is always at the top level of the API key definition. This means that in wrapped-json and yaml formats, the metadata scope occurs outside the spec scope.
required true
type Map of key-value pairs
example
"metadata": {
  "name": "19803eb8-36a6-4203-a225-28ec4e9f4444"
}
spec
description Top-level map that includes the API key’s spec attributes.
required true
type Map of key-value pairs
example
"spec": {
    "created_at": 1570732266,
    "username": "admin"
  }

Metadata attributes

name
description A unique string used to identify the API key. Sensu randomly generates a UUID for the name value (i.e. users cannot provide a name for an API key).
required true
type String
example
"name": "19803eb8-36a6-4203-a225-28ec4e9f4444"

Spec attributes

username
description The user associated with the API key.
required true
type Array
example
"username": "admin"
created_at
description The time at which the API key was created. Unix timestamp automatically generated when the API key is created.
required true
type Integer
example
"created_at": 1234567890

Examples

type: APIKey
api_version: core/v2
metadata:
  name: 19803eb8-36a6-4203-a225-28ec4e9f4444
spec:
  created_at: 1570732266
  username: admin
{
  "type": "APIKey",
  "api_version": "core/v2",
  "metadata": {
    "name": "19803eb8-36a6-4203-a225-28ec4e9f4444"
  },
  "spec": {
    "created_at": 1570732266,
    "username": "admin"
  }
}