Manage the keys of an integration
Agents and collectors authenticate to a Grepr integration with a key, such as a Datadog API key, a New Relic license key, or a Splunk HTTP Event Collector token. Grepr authenticates to the vendor with a key too. Each credential that your agents send with holds a list of named keys instead of one key. You can keep a separate key for each team or environment, rotate a key without interrupting ingestion, and have Grepr generate keys for your agents.
This page describes how keys work, what is specific to each integration, and how to manage keys in the Grepr UI, with the REST API, and with Terraform. The page of each integration links here for its keys.
How keys work
Key lists and the main key
A key list holds the keys of one credential, such as the license keys of a New Relic integration. Every list that holds a key has a key named mainKey, the main key. You can’t delete the main key, except when you remove every Datadog client token. To replace the main key, make another key the main key.
Ingest keys and send keys
Every key in a list is an ingest key: your agents and collectors can send data to Grepr with it, the main key included. The main key is also the send key: your pipelines send data to the vendor with the main key and with no other key. An OpenTelemetry integration sends with its secret headers, never with a key in its list.
A collector that expands environment variables can read a key from the environment, so that the key stays out of its configuration file. For example, set licenseKey ${NR_LICENSE_KEY} in Fluent Bit, or x-grepr-token: ${env:GREPR_TOKEN} in the OpenTelemetry Collector, and put the key in that environment variable.
Generated keys
Grepr can generate a key for your agents, so that you don’t create one in the vendor. A generated key is a random value that Grepr shows once. The vendor doesn’t accept a generated key, so use it only to ingest, and keep it out of mainKey when the integration sends to the vendor.
Rotation
To rotate the main key without interrupting ingestion, add the new key beside the old one, move your agents to the new key, make it the main key, and remove the old key last. Grepr accepts every key in the list, so an agent that still sends the old key keeps working until you remove it. See Rotate the main key without interrupting ingestion. A key that only your agents use skips the step that makes it the main key. See Rotate a key that only your agents use.
What Grepr does with a change
- A key you add is accepted within one minute.
- A key you remove stops being accepted within five minutes.
- A new main key reaches the pipelines that send to the vendor within about three minutes, and you don’t restart them. Pipelines read the key again immediately after the vendor rejects the old one.
- When you change the value of the main key, Grepr first checks the new value with the vendor and refuses it if the vendor rejects it. For a Sumo Logic integration, the check is the format of the collector URL. An OpenTelemetry integration has no check. Other keys aren’t checked. When Grepr refuses a new main key in the UI, click Use it anyway to skip the check, except for Sumo Logic. Use it only when nothing is sent to the vendor or you know the key is valid.
Names and limits
- A key name has 1 to 64 characters: letters, digits, periods, underscores, and hyphens. A name that starts with
previousis reserved. - Two keys can hold the same value. Grepr keeps accepting a value while any key holds it.
- A list holds up to 10 keys by default. The
previousMainKeykey that a single-key save leaves behind doesn’t count toward the limit. To raise the limit, contact Grepr support.
Keys by integration
| Integration | Key list | Agents send to Grepr with | Pipelines send to the vendor with | Credential that holds one value, and its Terraform attribute |
|---|---|---|---|---|
| Datadog | API keys, and client tokens for browser logs | An API key, or a client token for browser logs | The main API key, and the main client token for browser logs | Application key, app_key |
| New Relic | License keys | A license key | The main license key | User key, api_key |
| Splunk | HTTP Event Collector tokens | A token | The main token | REST API token, rest_auth_token |
| Sumo Logic | Collector URLs | The collector code of a URL | The main URL | None |
| OpenTelemetry | Grepr ingest tokens | A token, in the x-grepr-token header | Secret headers, never a token | Secret headers, secret_headers |
Datadog
A Datadog integration holds a list of API keys and a list of client tokens, and one application key.
- Your Datadog Agents, collectors, and forwarders send with an API key. Set it as
api_keyin the Datadog Agent. When you create the integration, the key you enter in the API Key field becomes the main key. Create the new key in Datadog first when you rotate, and revoke the old key there last. - Browser logs authenticate with a client token. The list of client tokens is optional and starts empty. The first token you add is the main key, and Grepr sends browser data to Datadog with it. With the REST API or Terraform, name the first token
mainKey. To remove every client token, including the main key, click Remove all client tokens in the UI and confirm, send aDELETErequest withdeleteAll=true, or setclient_token_keys = {}andgenerated_client_token_keys = []in Terraform and remove thebrowser_keyoutput and every other output that reads a removed token. - The application key is one value, and Grepr reads monitors, dashboards, and logs from Datadog with it. See Requirements for its scopes.
Datadog doesn’t know a key that Grepr generates, and the Datadog Agent’s api_key authenticates everything that the Agent sends to Datadog directly, such as metrics, events, and flares, not only logs. Use a generated key as the api_key of an Agent only when everything that the Agent sends goes through Grepr. Otherwise keep an API key that Datadog knows as the Agent’s api_key. An Agent that uses a generated key can’t send a flare to Datadog support, even through Grepr.
For an Agent on Kubernetes whose data all goes through Grepr, store the value of the agents_key output from Generate a key for your agents in the secret that the Datadog Helm chart reads for its API key, without putting the value on a command line, and set datadog.apiKeyExistingSecret to the secret’s name in the chart’s values:
terraform output -raw agents_key | kubectl create secret generic datadog-agents-key --namespace <datadog-namespace> --from-file=api-key=/dev/stdinTo send browser logs through Grepr, set clientToken in the Datadog browser SDK to a token of the integration, site to your Datadog site such as datadoghq.com, and proxy to your ingestion URL followed by /api/v2/browser-logs. A token that Grepr generates works only through this proxy, because Datadog doesn’t know it. See Datadog’s proxy guide for the SDK versions that support proxy:
datadogLogs.init({
clientToken: '<client-token>',
site: '<dd-site>',
proxy: '<ingestion-url>/api/v2/browser-logs',
})A pipeline sends browser logs to Datadog’s browser intake only if the integration had a client token when the pipeline started. Before that, browser logs go to the main logs intake. After you add the first client token, stop and start each pipeline that sends to the integration. After a pipeline starts with a client token, a new main token reaches it within about three minutes, and you don’t restart it.
With Terraform, client_token_keys, generated_client_token_keys, and generated_client_token_key_values hold the client tokens, and they work like the attributes for API keys:
variable "datadog_client_token" {
type = string
sensitive = true
}
# ...
resource "grepr_datadog_integration" "main" {
# ...
# Client tokens authenticate the browser SDK, which sends logs from your users' browsers.
client_token_keys = {
mainKey = var.datadog_client_token
}
generated_client_token_keys = ["browser"]
}
# ...
output "browser_key" {
value = grepr_datadog_integration.main.generated_client_token_key_values["browser"]
sensitive = true
}New Relic
A New Relic integration holds a list of license keys and one user key.
- Your log forwarders send with a license key. When you create the integration, the key you enter in the License Key field becomes the main key. Don’t enter a user key in this field. The original license key of a New Relic account can’t be deleted. To replace it, ask New Relic support to regenerate it.
- Your New Relic user key is one value, and Grepr reads dashboards and alerts from New Relic with it, for automatic exception parsing. It is a separate credential from the license keys, and it doesn’t have to match a key that your collectors use. In Terraform, it is the
api_keyattribute, not a license key.
When you move your collectors to a new license key, collectors such as Fluent Bit read the key when they start, so restart them after you change their configuration. The New Relic Lambda extension reads the key when a new execution environment starts. To make a function start new execution environments, update the function’s configuration, such as an environment variable. If the function runs from a published version or an alias, publish a new version with the updated configuration and point the alias to it.
The New Relic Lambda extension doesn’t retry logs that Grepr rejects, so wait one minute after you add the new key before you move a function to it.
Splunk
A Splunk integration holds a list of HTTP Event Collector tokens, the HEC tokens, and one REST API token.
- Your collectors send with a HEC token. When you create the integration, the token you enter in the HEC token for Splunk collector authentication field becomes the main token. The setting that holds the token is
Splunk_Token,hec_token,token, orhttpEventCollectorToken, depending on the collector. When you rotate, disable the old token in Splunk last. - The REST API token is one value, a Bearer token for the Splunk REST API that a Splunk HTTP source needs. It isn’t a HEC token and isn’t part of the list. See Ingest log data from Splunk using the Splunk HTTP source.
Sumo Logic
Each key of a Sumo Logic integration is the URL of a Sumo Logic HTTP Logs and Metrics Source. Your collectors send to Grepr with the collector code at the end of the URL of any key in the list, so each team or environment can keep its own source. Pipelines send to Sumo Logic with the URL of the main key. When you create the integration, the URL you enter in the HTTP collector URL field becomes the main key.
- A Sumo Logic source doesn’t change its URL, so to rotate, create a new HTTP Logs and Metrics Source in Sumo Logic, and delete the old source last.
- Grepr checks the format of a new main URL, and doesn’t call Sumo Logic. A URL can’t end with
/. - A key that Grepr generates is a bare collector code instead of a URL. Collectors send with it as the last part of the collector URL. Sumo Logic doesn’t know it, so keep it out of
mainKey.
OpenTelemetry
An OpenTelemetry integration holds a list of Grepr ingest tokens. Your collectors send with a token in the x-grepr-token header. No vendor accepts these tokens, and no pipeline sends them, because the integration sends to your destination with its secret headers. The main token is the token that Grepr generates when you create the integration.
- Because there is no vendor, rotating a token has no vendor steps, no check of a new main token, and no wait for the pipelines.
- The secret headers, such as
Authorization, stay single values, andsecret_headersholds them in Terraform. When your destination issues a new value, change it. The pipelines send with the new value within about three minutes, without a restart. Revoke the old value in your destination after that. - To read the main token again, send a
GETrequest to/v1/integrations/otlp/{id}/token. The request requires edit access to the integration, and Grepr records each call in the audit log. See the OpenTelemetry Integration specification.
With Terraform, the ingestion_token attribute holds the main token. To keep the old token under the name old while you rotate it, read it with terraform output -raw main_token before the apply that makes the new token the main token. The create excerpt in Create the integration and read its URL outputs it. Give it to keys through a sensitive variable.
Add keys
To keep a separate key for each team or environment, add each key to the integration under its own name.
Grepr UI
- Go to the Integrations page. On the card for the integration, click the three-dot menu and select Edit.
- In the keys section, such as License keys, click the button that adds a key, such as Add license key. Enter a name and the key, and then click Add.
The first key that you add to an empty list is the main key. The keys section saves each change immediately. Grepr never shows the full value of an existing key. The list of keys shows each key’s name, the last two characters of its value, and the date you added it or last changed its value.
Generate a key for your agents
A generated key is a random value that agents can send to Grepr with. See Generated keys.
Grepr UI
- Go to the Integrations page. On the card for the integration, click the three-dot menu and select Edit.
- In the keys section, click the button that generates a key, such as Generate license key. Enter a name for the key, and then click Generate. The button appears after the list holds a key, so add the first key before you generate more.
- Copy the key from the dialog. Grepr shows a generated key once, and you can’t see it again.
Rotate the main key without interrupting ingestion
Rotate the main key, the key that your pipelines send to the vendor with, in an order that never leaves a sender with a key that Grepr rejects. With Terraform, apply the configuration after each step that changes keys:
-
In the vendor, create the new key. Keep the old key active. For OpenTelemetry, choose the new token value.
-
Add the new key to the integration under a new name, such as
next. See Add keys for the three ways. If the list holds its maximum number of keys, delete a key that you no longer use first. -
Wait one minute. Grepr can take that long to accept the new key, and a sender that presents it earlier can be refused.
-
Move your agents and collectors to the new key. Agents that still send the old key keep working.
-
Make the new key the main key.
-
In the UI, on the new key, click Make main, and then confirm.
-
With the REST API, send a
POSTrequest with{"copyFrom": {"mainKey": "next"}}. Grepr copies the value ofnexttomainKey. -
With Terraform, set
mainKeyto the new key’s value in thekeysattribute. The excerpt keeps the old key under the nameold, for a sender that still uses it. That adds a name, and Terraform adds names before it removes any, so the list needs a free slot even thoughnextis about to go. If the list is full, remove a key that you no longer use first. If every sender already uses the new key, leaveoldout:variable "datadog_new_api_key" { type = string sensitive = true } # ... resource "grepr_datadog_integration" "main" { # ... # The new key becomes the main key. The old key stays under the name `old` while senders still use it, # and `next` holds the new key. keys = { mainKey = var.datadog_new_api_key old = var.datadog_api_key next = var.datadog_new_api_key team = var.datadog_team_api_key } # ... }
Grepr checks the new main key with the vendor first and refuses it if the vendor rejects it. Within about three minutes, the pipelines send to the vendor with the new key.
-
-
Wait at least three minutes, so that every pipeline sends with the new main key. An OpenTelemetry integration has no pipeline that sends its tokens, so it skips this step.
-
Delete the extra
nextkey and every other key that holds the old key’s value. Grepr keeps accepting a value while any key holds it, so a key left behind keeps its value accepted after a later rotation. See Remove keys for the three ways. -
In the vendor, revoke the old key.
Move your agents to the new key before you make it the main key. Making it the main key replaces the old key, and Grepr stops accepting the old key from agents within five minutes, unless another key holds the same value.
If the list holds its maximum number of keys and you can’t delete one to make room, change the value of the main key instead. In the UI, click Replace main key. With the REST API, send a PATCH request that changes the value of mainKey. With Terraform, change the value of mainKey in keys. None of these adds a name, so the limit doesn’t refuse them, and none can keep both keys accepted: some requests with the old key are refused as soon as the change saves, and all of them within five minutes, unless another key holds the same value. Move your agents to the new key right after the replace, and expect a sender that doesn’t retry to lose data until it moves. Then delete every other key that holds the old value, and revoke the old key in the vendor.
Rotate a key that only your agents use
A key other than the main key is one that only your agents send with, so rotating it involves neither your pipelines nor the main key. If the old key is also the main key, rotate the main key instead. If the vendor issued the key, create the new key in the vendor first, and revoke the old key there after the last step.
- Add the new key under a new name. If the list holds its maximum number of keys, delete a key that you no longer use first.
- Wait one minute.
- Move the agents that send the old key to the new key.
- Delete the key that holds the old value, and every other key that holds the same value. Grepr keeps accepting a value while any key holds it.
To rotate a generated key with Terraform, add a new name to generated_keys and read its value from a new output. Wait one minute, and move your agents to the new value. Then remove the old name from generated_keys and the output that reads its value, because the output fails without its key, and apply. Grepr stops accepting the old key within five minutes:
resource "grepr_datadog_integration" "main" {
# ...
generated_keys = ["agents", "agents-2"]
# ...
}
# ...
output "agents_2_key" {
value = grepr_datadog_integration.main.generated_key_values["agents-2"]
sensitive = true
} generated_keys = ["agents-2"]Remove keys
To remove a key from an integration:
- In the UI, in the keys section, click the delete icon on the key, and then confirm. You can’t delete the main key.
- With the REST API, send a
DELETErequest with the key names in repeatednamequery parameters, or withdeleteAll=trueto remove every key that the list lets you remove. - With Terraform, remove the name from
keysorgenerated_keys, and every output that reads its value, because an output fails without its key.
Agents that send a deleted key are refused within five minutes, unless another key holds the same value.
Manage keys with Terraform
Starting with provider version 1.4.0, the integration resources manage every key of a credential with three attributes:
| Attribute | Type | What it holds |
|---|---|---|
keys | Map of strings, sensitive | The keys you provide, by name. |
generated_keys | Set of strings | The names of keys whose values Grepr generates. |
generated_key_values | Map of strings, sensitive, read-only | The values that Grepr generated, by name. |
The grepr_datadog_integration, grepr_newrelic_integration, grepr_splunk_integration, grepr_sumo_integration, and grepr_otlp_integration resources have these attributes. Datadog has two credentials. The attributes for its client tokens are client_token_keys, generated_client_token_keys, and generated_client_token_key_values.
Pass every key through a sensitive variable, as the excerpts do, so that no key is in your .tf files or your version control. Set the variables with TF_VAR_<name> environment variables or read them from your secrets manager. Terraform keeps every key in its state, so protect the state too. Grepr’s end-to-end tests apply every excerpt, so the attributes and outputs work as shown. In an excerpt, # ... stands for the lines that the excerpt leaves out.
How Terraform applies the keys
When you set keys or generated_keys, Terraform manages the credential and makes the integration hold exactly the names in the two attributes. Terraform adds and changes the keys in keys, asks Grepr to generate the names in generated_keys that are new, and removes every other name. This includes a key that you or someone else added outside Terraform, and previousMainKey. A credential whose attributes you don’t set isn’t touched.
keysmust includemainKey, the key that Grepr sends to the vendor with. The attribute of Datadog client tokens needs it only when the list holds a key. OpenTelemetry integrations create their own main token, sokeyscan leave outmainKeyand keep it. GivingmainKeyreplaces it.- A name can’t be in both
keysandgenerated_keys, andmainKeycan’t be generated. - Terraform adds and changes keys first and removes keys last. At the key limit, a configuration that swaps one name for another fails because the integration can’t hold both. Remove the old name in one apply and add the new name in the next.
- Terraform never sends a generated value to Grepr. Grepr returns each value once, when it generates it, and Terraform keeps it in
generated_key_valuesin the state. A name ingenerated_keysthat the integration already holds is adopted as it is, and has no value ingenerated_key_values, so an output that reads it fails. To get a value for that key, add a new name and remove the old one. - Grepr generates a name only when you change
generated_keys. A generated key that someone deleted outside Terraform comes back with a new value the next time you changegenerated_keys, for example when you add another name. Agents that still send the old value are refused. - If someone else changes the keys during an apply, Terraform writes its configuration over the change. If a conflict remains, run
terraform applyagain. - A plan doesn’t read the keys from Grepr, so it doesn’t show a key that someone added or removed outside Terraform. The next change to
keysorgenerated_keysremoves the names that aren’t in them, and the apply lists the keys it removed.
Create the integration and read its URL
Create the integration with your vendor key as the main key, and output the URL that your agents send to. The name_prefix variable holds a prefix for the integration’s name, and the others hold the vendor’s site or endpoint, such as datadoghq.com, and the key or the header that Grepr sends with. OpenTelemetry has no vendor key, so its excerpt also outputs the main token that Grepr makes:
Datadog
variable "name_prefix" {
type = string
}
variable "datadog_site" {
type = string
}
variable "datadog_api_key" {
type = string
sensitive = true
}
resource "grepr_datadog_integration" "main" {
name = "${var.name_prefix}_datadog"
site = var.datadog_site
keys = {
mainKey = var.datadog_api_key
}
}
# ...
# The URL your Datadog Agents send to: the integration's id and its organization's id.
output "ingest_url" {
value = "https://${grepr_datadog_integration.main.id}-${grepr_datadog_integration.main.organization_id}.ingest.grepr.ai"
}To create a New Relic, Splunk, or Sumo Logic integration the same way, give your vendor key as mainKey and use the arguments that the resource’s page in the OpenTofu registry lists, such as site = "newrelic.com" for New Relic. Build the URL that your agents send to as in the Datadog excerpt, and end it with the path that the integration’s page gives. See the log forwarding steps of New Relic, Splunk, and Sumo Logic.
After you run terraform apply, read the URL with terraform output -raw ingest_url. If Grepr’s check rejects the main key while Terraform creates the integration, the apply fails and Terraform marks the integration tainted. To learn which integrations check the key, see What Grepr does with a change. Fix the key, or for Splunk set secure = false when its certificate is self-signed, run terraform untaint with the address of the resource, such as grepr_datadog_integration.main, and apply again.
Move from the single-key attributes
The single-key attributes and the Datadog api_keys attribute are deprecated, and each conflicts with the keys and generated_keys attributes of its credential:
| Resource | Deprecated attributes |
|---|---|
grepr_datadog_integration | api_key and api_keys |
grepr_newrelic_integration | license_key |
grepr_splunk_integration | auth_token |
grepr_sumo_integration | endpoint |
The ingestion_token attribute of grepr_otlp_integration isn’t deprecated. It holds the main token and follows mainKey when keys gives it.
To move to keys, replace the single-key attribute with keys that holds the same key under mainKey. A configuration with api_keys names each key and marks the one that sends data to Datadog:
# The deprecated way to hold several API keys: exactly one of them sends data to Datadog.
api_keys = {
send = { value = var.datadog_api_key, send_key = true }
backup = { value = var.datadog_new_api_key }
}In Grepr, the key that sends data to Datadog is named mainKey, a key with a label is named by it, and a key without one is named by its id, not by its name in api_keys. Read the names in the UI or with a GET request before you list a key in keys. Under the name it has, the key stays as it is. Under another name, Terraform adds the key first and removes the earlier name, which needs a free slot. Replace api_keys with keys that lists every key you keep, and the apply removes the others:
# Only the keys listed here stay: the backup key is removed.
keys = {
mainKey = var.datadog_api_key
}The first apply after you move to keys removes every key that isn’t in keys or generated_keys. This includes previousMainKey, the key that a rotation with a single-key attribute leaves behind, so a sender that still uses the earlier key is refused within five minutes. To keep a key, list it in keys under a name of its own before you apply.
The same holds when you import an integration that has more than one key. Import can’t read values, so the next apply writes every value in keys again and removes the other names.
If an apply fails partway
If an apply fails partway, apply the same configuration again before you change keys or generated_keys. Until then, a key that the failed apply added, or one added outside Terraform that the apply was removing, can stay accepted. A revert alone might not restore a key that the failed apply removed or replaced, and the plan doesn’t show either.
The keys endpoints
Each credential has its own keys endpoint under its integration, and every endpoint takes the same operations. The endpoints are in the REST API specification under the tag of the integration:
| Credential | Endpoint | API specification |
|---|---|---|
| Datadog API keys | /v1/integrations/datadog/{id}/api-key-map | Datadog Integration |
| Datadog client tokens | /v1/integrations/datadog/{id}/client-tokens | Datadog Integration |
| New Relic license keys | /v1/integrations/newrelic/{id}/license-keys | New Relic Integration |
| Splunk HEC tokens | /v1/integrations/splunk/{id}/auth-tokens | Splunk Integration |
| Sumo Logic collector URLs | /v1/integrations/sumo/{id}/endpoints | Sumo Logic Integration |
| OpenTelemetry ingest tokens | /v1/integrations/otlp/{id}/tokens | OpenTelemetry Integration |
Each endpoint supports the following operations:
| Operation | What it does |
|---|---|
GET | Returns each key with its name, the last two characters of its value, and when you set it. The response never holds a full value. |
PUT | Replaces the list with the names and values in the request body. The body must include mainKey, and any name that you leave out is removed. |
PATCH | Adds the names in the request body, or changes their values, and leaves the other keys alone. The first key in an empty list must be named mainKey. |
DELETE | Removes the keys that the repeated name query parameters list, or every key that the list lets you remove when you set deleteAll=true. |
POST | Copies values between names with copyFrom, which maps each target name to a source name, and generates random values for the names in generate. A copy reads the list as it was before the request, so you can swap two keys. |
The PUT and PATCH bodies are a JSON object of names and values. A value can’t be empty and can’t start with {. A Sumo Logic collector URL can’t end with /. When a request changes the value of mainKey, Grepr checks the new value with the vendor first. To skip the check, add force=true to the request. Use it only when nothing is sent to the vendor, for example, to make a generated key the main key of an integration that you use only as a source.
Guard against concurrent changes
Every response carries an ETag header with the version of the list. To make a write apply only to the version you read, send the tag in an If-Match header. Grepr answers 412 Precondition Failed if the keys changed since you read them.
A write that would take the list over its limit returns 409 Conflict. Changing the value of a key and removing a key are never refused for the limit.
Single-key endpoints
The endpoints that set one key for a credential, such as PUT /v1/integrations/newrelic/{id}/license-key, keep working and are deprecated. Saving a different key with one of them makes it the main key and keeps the earlier main key as previousMainKey. Saving the same key again removes previousMainKey.