content/influxdb3/cloud-dedicated/admin/tokens/database/create.md
Use the Admin UI, the influxctl CLI,
or the Management HTTP API to create a database token with permissions for reading and writing data in your {{< product-name omit=" Clustered" >}} cluster.
{{< tabs-wrapper >}} {{% tabs %}} Admin UI influxctl Management API {{% /tabs %}} {{% tab-content %}}
<!------------------------------- BEGIN ADMIN UI ------------------------------->The InfluxDB Cloud Dedicated administrative UI includes a portal for creating and managing database tokens.
{{< admin-ui-access >}}
In the Database Tokens portal, click the New Database Token button. The Create Database Token dialog displays.
{{< img-hd src="/img/influxdb3/cloud-dedicated-admin-ui-create-database-token.png" alt="Create database token dialog" />}}
{{% /tab-content %}} {{% tab-content %}}
<!------------------------------- BEGIN INFLUXCTL ----------------------------->Use the influxctl token create command
to create a token that grants access to databases in your {{% product-name omit=" Clustered" %}} cluster.
If you haven't already, download and install the influxctl CLI, and then configure an influxctl connection profile for your cluster.
In your terminal, run the influxctl token create command and provide the following:
Token permissions (read and write)
--read-database: Grants read permissions to the specified database. Repeatable.--write-database: Grants write permissions to the specified database. Repeatable.Both of these flags support the * wildcard which grants read or write
permissions to all databases. Enclose wildcards in single or double
quotes--for example: '*' or "*".
Optional: the --expires-at flag with an RFC3339 date string that defines the
token expiration date and time--for example, {{< datetime/current-date offset=1 >}}.
If an expiration isn't set, the token does not expire until revoked.
Token description
{{% code-placeholders "DATABASE_NAME|TOKEN_DESCRIPTION|RFC3339_TIMESTAMP" %}}
influxctl token create \
--read-database DATABASE_NAME \
--write-database DATABASE_NAME \
--expires-at RFC3339_TIMESTAMP \
"Read/write token for DATABASE_NAME"
{{% /code-placeholders %}}
Replace the following:
DATABASE_NAME{{% /code-placeholder-key %}}:
your {{% product-name %}} databaseRFC3339_TIMESTAMP{{% /code-placeholder-key %}}:
the token expiration date and time in
RFC3339 format.The output is the token ID and the token string. This is the only time the token string is available in plain text.
<!-------------------------------- END INFLUXCTL ------------------------------>{{% /tab-content %}} {{% tab-content %}}
<!------------------------------- BEGIN cURL ---------------------------------->This example uses cURL to send a Management HTTP API request, but you can use any HTTP client.
If you haven't already, follow the instructions to install cURL for your system.
In your terminal, use cURL to send a request to the following {{% product-name %}} endpoint:
{{% api-endpoint endpoint="https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" method="post" api-ref="/influxdb3/cloud-dedicated/api/management/#operation/CreateDatabaseToken" %}}
In the URL, provide the following credentials:
ACCOUNT_ID: The ID of the account that the cluster belongs to (see how to list cluster details).CLUSTER_ID: The ID of the cluster that you want to manage (see how to list cluster details).Provide the following request headers:
Accept: application/json to ensure the response body is JSON contentContent-Type: application/json to indicate the request body is JSON contentAuthorization: Bearer and a Management API token for your cluster (see how to create a management token for Management API requests).In the request body, provide the following parameters:
permissions: an array of token permissions (read or write) objects:
"action": Specify read or write permission to the database."resource": Specify the database name.description: Provide a description of the token.
expirationType: Specify datetime or noExpiration token expiration type.
expiresAt: Specify the token expiration date and time in
RFC3339 format.
[!Note]
expiresAtis only required whenexpirationTypeisdatetime.
The following example shows how to use the Management API to create a database token:
{{% code-placeholders "DATABASE_NAME|ACCOUNT_ID|CLUSTER_ID|MANAGEMENT_TOKEN" %}}
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" \
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data '{
"description": "Read/write token for DATABASE_NAME",
"permissions": [
{
"action": "write",
"resource": "DATABASE_NAME"
},
{
"action": "read",
"resource": "DATABASE_NAME"
}
],
"expirationType": "datetime",
"expiresAt": "2030-01-01T00:00:00Z"
}'
{{% /code-placeholders %}}
Replace the following in your request:
ACCOUNT_ID{{% /code-placeholder-key %}}: the ID of the {{% product-name %}} account to create the database token forCLUSTER_ID{{% /code-placeholder-key %}}: the ID of the {{% product-name %}} cluster to create the database token forMANAGEMENT TOKEN{{% /code-placeholder-key %}}: a management token for your {{% product-name %}} clusterDATABASE_NAME{{% /code-placeholder-key %}}: a {{% product-name %}} database that the token will have read or write permission toThe response body contains the token ID and the token string. This is the only time the token string is available in plain text.
<!------------------------------- END cURL ------------------------------------>{{% /tab-content %}} {{< /tabs-wrapper >}}
401 Unauthorized error) for querying or writing, wait and then try again.[!Note]
Store secure tokens in a secret store
Token strings are viewable only on token creation and aren't stored by InfluxDB. We recommend storing database tokens in a secure secret store. For example, see how to authenticate Telegraf using tokens in your OS secret store.
If you lose a token, delete the token from InfluxDB and create a new one.
The influxctl token create command supports the --format json option.
By default, the command outputs the token string.
For token details and easier programmatic access to the command output, include --format json
with your command to format the output as JSON.
The Management API outputs JSON format in the response body.
In the examples below, replace the following:
DATABASE_NAME{{% /code-placeholder-key %}}: your {{< product-name >}} databaseDATABASE2_NAME{{% /code-placeholder-key %}}: your {{< product-name >}} databaseACCOUNT_ID{{% /code-placeholder-key %}}: the ID of the {{% product-name %}} account to create the database token forCLUSTER_ID{{% /code-placeholder-key %}}: the ID of the {{% product-name %}} cluster to create the database token forMANAGEMENT TOKEN{{% /code-placeholder-key %}}: a management token for your {{% product-name %}} cluster{{% code-placeholders "DATABASE_NAME|ACCOUNT_ID|CLUSTER_ID|MANAGEMENT_TOKEN" %}} {{% code-tabs-wrapper %}} {{% code-tabs %}} influxctl Management API {{% /code-tabs %}} {{% code-tab-content %}}
influxctl token create \
--read-database DATABASE_NAME \
--write-database DATABASE_NAME \
"Read/write token for DATABASE_NAME"
{{% /code-tab-content %}} {{% code-tab-content %}}
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" \
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data '{
"description": "Read/write token for DATABASE_NAME",
"permissions": [
{
"action": "write",
"resource": "DATABASE_NAME"
},
{
"action": "read",
"resource": "DATABASE_NAME"
}
],
"expirationType": "noExpiration"
}'
{{% /code-tab-content %}} {{< /code-tabs-wrapper >}} {{% /code-placeholders %}}
{{% code-tabs-wrapper %}} {{% code-tabs %}} influxctl Management API {{% /code-tabs %}} {{% code-tab-content %}}
influxctl token create \
--read-database "*" \
--write-database "*" \
"Read/write token for all databases"
{{% /code-tab-content %}} {{% code-tab-content %}}
{{% code-placeholders "ACCOUNT_ID|CLUSTER_ID|MANAGEMENT_TOKEN" %}}
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" \
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data '{
"description": "Read/write token for all databases",
"permissions": [
{
"action": "write",
"resource": "*"
},
{
"action": "read",
"resource": "*"
}
]
}'
{{% /code-placeholders %}} {{% /code-tab-content %}} {{% /code-tabs-wrapper %}}
{{% code-tabs-wrapper %}} {{% code-tabs %}} influxctl Management API {{% /code-tabs %}} {{% code-tab-content %}}
{{% code-placeholders "DATABASE_NAME" %}}
influxctl token create \
--read-database DATABASE_NAME \
"Read-only token for DATABASE_NAME"
{{% /code-placeholders %}} {{% /code-tab-content %}} {{% code-tab-content %}}
{{% code-placeholders "DATABASE_NAME|ACCOUNT_ID|CLUSTER_ID|MANAGEMENT_TOKEN" %}}
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" \
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data '{
"description": "Read-only token for DATABASE_NAME",
"permissions": [
{
"action": "read",
"resource": "DATABASE_NAME"
}
]
}'
{{% /code-placeholders %}} {{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
{{% code-tabs-wrapper %}} {{% code-tabs %}} influxctl Management API {{% /code-tabs %}} {{% code-tab-content %}} {{% code-placeholders "DATABASE_NAME|DATABASE2_NAME" %}}
influxctl token create \
--read-database DATABASE_NAME \
--read-database DATABASE2_NAME \
"Read-only token for DATABASE_NAME and DATABASE2_NAME"
{{% /code-placeholders %}} {{% /code-tab-content %}} {{% code-tab-content %}} {{% code-placeholders "DATABASE2_NAME|DATABASE_NAME|ACCOUNT_ID|CLUSTER_ID|MANAGEMENT_TOKEN" %}}
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" \
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data '{
"description": "Read-only token for DATABASE_NAME and DATABASE2_NAME",
"permissions": [
{
"action": "read",
"resource": "DATABASE_NAME"
},
{
"action": "read",
"resource": "DATABASE2_NAME"
}
]
}'
{{% /code-placeholders %}} {{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
{{% code-tabs-wrapper %}} {{% code-tabs %}} influxctl Management API {{% /code-tabs %}} {{% code-tab-content %}} {{% code-placeholders "DATABASE_NAME|DATABASE2_NAME" %}}
influxctl token create \
--read-database DATABASE_NAME \
--read-database DATABASE2_NAME \
--write-database DATABASE2_NAME \
"Read-only on DATABASE_NAME, read/write on DATABASE2_NAME"
{{% /code-placeholders %}} {{% /code-tab-content %}} {{% code-tab-content %}} {{% code-placeholders "DATABASE2_NAME|DATABASE_NAME|ACCOUNT_ID|CLUSTER_ID|MANAGEMENT_TOKEN" %}}
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" \
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data '{
"description": "Read-only on DATABASE_NAME, read/write on DATABASE2_NAME",
"permissions": [
{
"action": "read",
"resource": "DATABASE_NAME"
},
{
"action": "read",
"resource": "DATABASE2_NAME"
},
{
"action": "write",
"resource": "DATABASE2_NAME"
}
]
}'
{{% /code-placeholders %}} {{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
{{< tabs-wrapper >}} {{% tabs "small" %}} Linux macOS {{% /tabs %}} {{% tab-content %}}
{{< code-tabs-wrapper >}} {{% code-tabs %}} influxctl Management API {{% /code-tabs %}}
{{% code-tab-content %}} {{% code-placeholders "DATABASE_NAME" %}}
<!-- pytest.mark.skip -->influxctl token create \
--read-database DATABASE_NAME \
--write-database DATABASE_NAME \
--expires-at $(date -d "+7 days" +"%Y-%m-%dT%H:%M:%S%z") \
"Read/write token for DATABASE_NAME with 7d expiration"
{{% /code-placeholders %}}
{{% /code-tab-content %}} {{% code-tab-content %}}
{{% code-placeholders "DATABASE_NAME" %}}
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" \
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data "{
\"description\": \"Read/write token for DATABASE_NAME\",
\"permissions\": [
{
\"action\": \"write\",
\"resource\": \"DATABASE_NAME\"
},
{
\"action\": \"read\",
\"resource\": \"DATABASE_NAME\"
}
],
\"expirationType\": \"datetime\",
\"expiresAt:\" \"$(date -d "+7 days" +"%Y-%m-%dT%H:%M:%S%z")\"
}"
{{% /code-placeholders %}} {{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
{{% /tab-content %}} {{% tab-content %}}
{{< code-tabs-wrapper >}} {{% code-tabs %}} influxctl Management API {{% /code-tabs %}}
{{% code-tab-content %}} {{% code-placeholders "DATABASE_NAME" %}}
<!-- pytest.mark.skip -->influxctl token create \
--read-database DATABASE_NAME \
--write-database DATABASE_NAME \
--expires-at $(gdate -d "+7 days" +"%Y-%m-%dT%H:%M:%S%z") \
"Read/write token for DATABASE_NAME with 7d expiration"
{{% /code-placeholders %}}
{{% /code-tab-content %}} {{% code-tab-content %}}
{{% code-placeholders "DATABASE_NAME" %}}
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/tokens" \
--header "Accept: application/json" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--data "{
\"description\": \"Read/write token for DATABASE_NAME\",
\"permissions\": [
{
\"action\": \"write\",
\"resource\": \"DATABASE_NAME\"
},
{
\"action\": \"read\",
\"resource\": \"DATABASE_NAME\"
}
],
\"expirationType\": \"datetime\",
\"expiresAt:\" \"$(gdate -d "+7 days" +"%Y-%m-%dT%H:%M:%S%z")\"
}"
{{% /code-placeholders %}} {{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
{{% /tab-content %}} {{< /tabs-wrapper >}}