POST /_security/api_key
{
"name": "my-api-key",
"expiration": "1d",
"role_descriptors": {
"role-a": {
"cluster": ["all"],
"indices": [
{
"names": ["index-a*"],
"privileges": ["read"]
}
]
},
"role-b": {
"cluster": ["all"],
"indices": [
{
"names": ["index-b*"],
"privileges": ["all"]
}
]
}
},
"metadata": {
"application": "my-application",
"environment": {
"level": 1,
"trusted": true,
"tags": ["dev", "staging"]
}
}
}
resp = client.security.create_api_key(
name="my-api-key",
expiration="1d",
role_descriptors={
"role-a": {
"cluster": [
"all"
],
"indices": [
{
"names": [
"index-a*"
],
"privileges": [
"read"
]
}
]
},
"role-b": {
"cluster": [
"all"
],
"indices": [
{
"names": [
"index-b*"
],
"privileges": [
"all"
]
}
]
}
},
metadata={
"application": "my-application",
"environment": {
"level": 1,
"trusted": True,
"tags": [
"dev",
"staging"
]
}
},
)
const response = await client.security.createApiKey({
name: "my-api-key",
expiration: "1d",
role_descriptors: {
"role-a": {
cluster: ["all"],
indices: [
{
names: ["index-a*"],
privileges: ["read"],
},
],
},
"role-b": {
cluster: ["all"],
indices: [
{
names: ["index-b*"],
privileges: ["all"],
},
],
},
},
metadata: {
application: "my-application",
environment: {
level: 1,
trusted: true,
tags: ["dev", "staging"],
},
},
});
response = client.security.create_api_key(
body: {
"name": "my-api-key",
"expiration": "1d",
"role_descriptors": {
"role-a": {
"cluster": [
"all"
],
"indices": [
{
"names": [
"index-a*"
],
"privileges": [
"read"
]
}
]
},
"role-b": {
"cluster": [
"all"
],
"indices": [
{
"names": [
"index-b*"
],
"privileges": [
"all"
]
}
]
}
},
"metadata": {
"application": "my-application",
"environment": {
"level": 1,
"trusted": true,
"tags": [
"dev",
"staging"
]
}
}
}
)
$resp = $client->security()->createApiKey([
"body" => [
"name" => "my-api-key",
"expiration" => "1d",
"role_descriptors" => [
"role-a" => [
"cluster" => array(
"all",
),
"indices" => array(
[
"names" => array(
"index-a*",
),
"privileges" => array(
"read",
),
],
),
],
"role-b" => [
"cluster" => array(
"all",
),
"indices" => array(
[
"names" => array(
"index-b*",
),
"privileges" => array(
"all",
),
],
),
],
],
"metadata" => [
"application" => "my-application",
"environment" => [
"level" => 1,
"trusted" => true,
"tags" => array(
"dev",
"staging",
),
],
],
],
]);
curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"name":"my-api-key","expiration":"1d","role_descriptors":{"role-a":{"cluster":["all"],"indices":[{"names":["index-a*"],"privileges":["read"]}]},"role-b":{"cluster":["all"],"indices":[{"names":["index-b*"],"privileges":["all"]}]}},"metadata":{"application":"my-application","environment":{"level":1,"trusted":true,"tags":["dev","staging"]}}}' "$ELASTICSEARCH_URL/_security/api_key"
client.security().createApiKey(c -> c
.expiration(e -> e
.time("1d")
)
.metadata(Map.of("environment", JsonData.fromJson("{\"level\":1,\"trusted\":true,\"tags\":[\"dev\",\"staging\"]}"),"application", JsonData.fromJson("\"my-application\"")))
.name("my-api-key")
.roleDescriptors(Map.of("role-b", RoleDescriptor.of(r -> r
.cluster("all")
.indices(i -> i
.names("index-b*")
.privileges("all")
)),"role-a", RoleDescriptor.of(r -> r
.cluster("all")
.indices(i -> i
.names("index-a*")
.privileges("read")
))))
);