FleetEnrollmentClient¶
Client for the Kibana Fleet enrollment keys and tokens API.
This namespace covers the Fleet APIs used to enroll Elastic Agents and Fleet Servers: enrollment API keys, Fleet Server service tokens, Logstash API keys, uninstall tokens for tamper-protected agents, the message signing service key pair, and the Kubernetes agent manifest.
All operations are space-aware: every method accepts an optional space_id
to target a specific space.
- class kibana._sync.client.fleet_enrollment.FleetEnrollmentClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
NamespaceClientClient for the Kibana Fleet enrollment keys and tokens API.
Covers the Fleet APIs used to enroll Elastic Agents and Fleet Servers:
Enrollment API keys: tokens that Elastic Agents present to Fleet Server to enroll into an agent policy (list, create, get, revoke).
Service tokens: Elasticsearch service tokens used to enroll Fleet Server instances with Kibana.
Logstash API keys: API keys for Logstash to receive data from Elastic Agents via a Fleet Logstash output.
Uninstall tokens: per-policy tokens required to uninstall tamper-protected Elastic Agents.
Message signing service: rotate the key pair Fleet uses to sign messages sent to Elastic Agents.
Kubernetes manifests: fetch or download the manifest for deploying Elastic Agent on Kubernetes.
All operations are space-aware: every method accepts an optional
space_idto target a specific space (Nonetargets the default space or the space the client is scoped to).Example
>>> from kibana import Kibana >>> client = Kibana("http://localhost:5601", api_key="...") >>> >>> # Create an enrollment API key for an agent policy >>> created = client.fleet_enrollment.create_key( ... policy_id="agent-policy-id", name="my-enrollment-key" ... ) >>> key_id = created.body["item"]["id"] >>> >>> # List keys, then revoke the one we created >>> keys = client.fleet_enrollment.get_keys(per_page=50) >>> client.fleet_enrollment.delete_key(key_id=key_id)
Managing Enrollment API Keys
Enrollment API keys are tied to an agent policy; agents present the key to Fleet Server to enroll into that policy:
from kibana import Kibana client = Kibana("http://localhost:5601", api_key="your_api_key") # Create an enrollment API key for an agent policy created = client.fleet_enrollment.create_key( policy_id="agent-policy-id", name="my-enrollment-key" ) key_id = created.body["item"]["id"] enrollment_token = created.body["item"]["api_key"] # List keys (optionally filtered with KQL) and fetch one by ID keys = client.fleet_enrollment.get_keys( per_page=50, kuery='policy_id:"agent-policy-id"' ) key = client.fleet_enrollment.get_key(key_id=key_id) # Revoke the key (it is marked inactive, not removed) client.fleet_enrollment.delete_key(key_id=key_id)
Service Tokens and Logstash API Keys
# Service token for enrolling a Fleet Server (remote=True for the # elastic/fleet-server-remote service account) token = client.fleet_enrollment.create_service_token() remote_token = client.fleet_enrollment.create_service_token(remote=True) # API key for a Logstash output. Note: requires basic (user) # authentication - Elasticsearch cannot derive an API key from # another API key. logstash_key = client.fleet_enrollment.create_logstash_api_key()
Uninstall Tokens
Uninstall tokens are generated per agent policy and are required to uninstall tamper-protected Elastic Agents:
# List token metadata (no decrypted values) tokens = client.fleet_enrollment.get_uninstall_tokens( policy_id="agent-policy-id" ) token_id = tokens.body["items"][0]["id"] # Fetch one decrypted token decrypted = client.fleet_enrollment.get_uninstall_token( uninstall_token_id=token_id ) print(decrypted.body["item"]["token"])
Message Signing and Kubernetes Manifests
# Rotate the Fleet message signing key pair (irreversible; all agents # must be re-enrolled afterwards, hence the explicit acknowledge) client.fleet_enrollment.rotate_message_signing_key_pair(acknowledge=True) # Kubernetes manifest as JSON ({"item": "<yaml>"}) with the Fleet URL # and enrollment token substituted in manifest = client.fleet_enrollment.get_kubernetes_manifest( fleet_server="https://fleet.example.com:8220", enrol_token=enrollment_token, ) # ... or as a raw YAML download (response body is the YAML string) yaml_text = client.fleet_enrollment.download_kubernetes_manifest().body
- __init__(client, default_space_id=None, validate_spaces=True)[source]¶
Initialize the FleetEnrollmentClient.
- Parameters:
Example
>>> fleet_enrollment_client = FleetEnrollmentClient(kibana_client)
- get_keys(*, page=None, per_page=None, kuery=None, space_id=None, validate_spaces=None)[source]¶
Get enrollment API keys.
Lists all enrollment API keys. Requires the
fleet-agents-allorfleet-setupprivilege.- Parameters:
page (int | None) – Page number (default: 1).
per_page (int | None) – Number of results per page (default: 20).
kuery (str | None) – A KQL query string to filter results (for example,
'policy_id:"my-policy-id"').space_id (str | None) – Optional space ID to list enrollment API keys from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
items: List of enrollment API keys (
id,api_key_id,api_key,name,policy_id,active,created_at,hidden)list: Deprecated duplicate of
itemstotal / page / perPage: pagination metadata
- Return type:
ObjectApiResponse containing
- Raises:
BadRequestError – If the query parameters are invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> keys = client.fleet_enrollment.get_keys( ... per_page=50, kuery='policy_id:"my-policy-id"' ... ) >>> for key in keys.body["items"]: ... print(key["id"], key["name"], key["active"])
- create_key(*, policy_id, name=None, expiration=None, space_id=None, validate_spaces=None)[source]¶
Create an enrollment API key.
Creates an enrollment API key for a given agent policy. Elastic Agents use the returned
api_keyto enroll into the policy. Requires thefleet-agents-allprivilege.Note: Kibana appends the generated key ID to the provided
name(the stored name looks like"my-name (<key-id>)").- Parameters:
policy_id (str) – The ID of the agent policy the Elastic Agent will be enrolled in.
name (str | None) – The name of the enrollment API key.
expiration (str | None) – Expiration timestamp for the key (for example,
"2025-01-01T00:00:00.000Z").space_id (str | None) – Optional space ID to create the enrollment API key in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
item: The created enrollment API key (
id,api_key_id,api_key,name,policy_id,active,created_at)action:
"created"
- Return type:
ObjectApiResponse containing
- Raises:
BadRequestError – If the agent policy does not exist or the body is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> created = client.fleet_enrollment.create_key( ... policy_id="agent-policy-id", name="my-enrollment-key" ... ) >>> print(created.body["item"]["api_key"])
- get_key(*, key_id, space_id=None, validate_spaces=None)[source]¶
Get an enrollment API key.
Gets an enrollment API key by ID. Requires the
fleet-agents-allorfleet-setupprivilege.- Parameters:
- Returns:
ObjectApiResponse containing the enrollment API key under
item(id,api_key_id,api_key,name,policy_id,active,created_at,hidden).- Raises:
NotFoundError – If no enrollment API key exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> key = client.fleet_enrollment.get_key(key_id="key-id-1") >>> print(key.body["item"]["policy_id"])
- delete_key(*, key_id, space_id=None, validate_spaces=None)[source]¶
Revoke an enrollment API key.
Revokes an enrollment API key by ID by marking it as inactive. The key is not removed, but it can no longer be used to enroll Elastic Agents. Requires the
fleet-agents-allprivilege.- Parameters:
- Returns:
ObjectApiResponse containing
{"action": "deleted"}on success.- Raises:
NotFoundError – If no enrollment API key exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = client.fleet_enrollment.delete_key(key_id="key-id-1") >>> print(result.body["action"]) deleted
- create_service_token(*, remote=None, space_id=None, validate_spaces=None)[source]¶
Create a service token.
Creates a Fleet Server service token. The token is used to enroll Fleet Server instances with Kibana. Requires the
fleet-agents-allprivilege.- Parameters:
remote (bool | None) – When True, generates a token for a remote Fleet Server (service account
elastic/fleet-server-remote) instead of the defaultelastic/fleet-serveraccount.space_id (str | None) – Optional space ID to create the service token in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
name: The name of the generated service token
value: The service token secret value
- Return type:
ObjectApiResponse containing
- Raises:
BadRequestError – If the request is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> token = client.fleet_enrollment.create_service_token() >>> print(token.body["name"], token.body["value"])
- create_logstash_api_key(*, space_id=None, validate_spaces=None)[source]¶
Generate a Logstash API key.
Generates an Elasticsearch API key for Logstash to use with a Fleet Logstash output (the
logstash-outputpermission set). Requires thefleet-settings-allprivilege.- Parameters:
- Returns:
ObjectApiResponse containing the generated key under
api_keyin theid:secretformat expected by the Logstashelastic_agentinput.- Raises:
BadRequestError – If the request is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> key = client.fleet_enrollment.create_logstash_api_key() >>> print(key.body["api_key"])
- get_uninstall_tokens(*, policy_id=None, search=None, per_page=None, page=None, space_id=None, validate_spaces=None)[source]¶
Get metadata for the latest uninstall tokens.
Lists the metadata for the latest uninstall tokens per agent policy. Uninstall tokens are required to uninstall tamper-protected Elastic Agents. Token values are not included; use
get_uninstall_token()to get a decrypted token. Requires thefleet-agents-allprivilege.Note:
policy_idandsearchcannot be used at the same time.- Parameters:
policy_id (str | None) – Partial match filtering for policy IDs (max length 50).
search (str | None) – Partial match filtering for uninstall token values (max length 50).
per_page (int | None) – The number of items to return (minimum 5).
page (int | None) – Page number (minimum 1).
space_id (str | None) – Optional space ID to list uninstall tokens from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
items: List of token metadata (
id,policy_id,policy_name,created_at,namespaces)total / page / perPage: pagination metadata
- Return type:
ObjectApiResponse containing
- Raises:
BadRequestError – If both
policy_idandsearchare provided, or the parameters are otherwise invalid.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> tokens = client.fleet_enrollment.get_uninstall_tokens() >>> for token in tokens.body["items"]: ... print(token["id"], token["policy_id"])
- get_uninstall_token(*, uninstall_token_id, space_id=None, validate_spaces=None)[source]¶
Get a decrypted uninstall token.
Gets one decrypted uninstall token by its ID. The returned
tokenvalue can be used to uninstall a tamper-protected Elastic Agent enrolled in the token’s agent policy. Requires thefleet-agents-allprivilege.- Parameters:
- Returns:
ObjectApiResponse containing the decrypted token under
item(id,policy_id,policy_name,token,created_at,namespaces).- Raises:
NotFoundError – If no uninstall token exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> token = client.fleet_enrollment.get_uninstall_token( ... uninstall_token_id="token-id-1" ... ) >>> print(token.body["item"]["token"])
- rotate_message_signing_key_pair(*, acknowledge=None, space_id=None, validate_spaces=None)[source]¶
Rotate the Fleet message signing key pair.
Rotates the key pair used by Fleet to sign messages sent to Elastic Agents. This operation is irreversible and requires all agents in the Fleet to be re-enrolled after rotation. You must explicitly acknowledge the risk by passing
acknowledge=True; the server rejects the request with a 400 warning otherwise. Requires thefleet-agents-all,fleet-agent-policies-allandfleet-settings-allprivileges.- Parameters:
- Returns:
ObjectApiResponse containing a confirmation
message("Key pair rotated successfully.").- Raises:
BadRequestError – If
acknowledgeis not set to True.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
ApiError – If the message signing service is unavailable (500).
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = client.fleet_enrollment.rotate_message_signing_key_pair( ... acknowledge=True ... ) >>> print(result.body["message"]) Key pair rotated successfully.
- get_kubernetes_manifest(*, download=None, fleet_server=None, enrol_token=None, space_id=None, validate_spaces=None)[source]¶
Get a full Kubernetes agent manifest.
Gets the Kubernetes manifest for deploying Elastic Agent as a DaemonSet, as a JSON object with the YAML document under
item. Requires thefleet-agent-policies-readorfleet-setupprivilege.- Parameters:
download (bool | None) – If True, returns the manifest as a downloadable file.
fleet_server (str | None) – Fleet Server host URL to include in the manifest (substituted for the
FLEET_URLplaceholder).enrol_token (str | None) – Enrollment token to include in the manifest (substituted for the
FLEET_ENROLLMENT_TOKENplaceholder).space_id (str | None) – Optional space ID to get the manifest from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the manifest YAML string under
item.- Raises:
BadRequestError – If the query parameters are invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> manifest = client.fleet_enrollment.get_kubernetes_manifest( ... fleet_server="https://fleet.example.com:8220", ... enrol_token="my-enrollment-token", ... ) >>> print(manifest.body["item"][:22])
- download_kubernetes_manifest(*, download=None, fleet_server=None, enrol_token=None, space_id=None, validate_spaces=None)[source]¶
Download a Kubernetes agent manifest.
Downloads the Kubernetes manifest for deploying Elastic Agent as a raw YAML document (content type
text/x-yaml); the response body is the YAML string itself. Requires thefleet-agent-policies-readorfleet-setupprivilege.- Parameters:
download (bool | None) – If True, returns the manifest as a downloadable file.
fleet_server (str | None) – Fleet Server host URL to include in the manifest (substituted for the
FLEET_URLplaceholder).enrol_token (str | None) – Enrollment token to include in the manifest (substituted for the
FLEET_ENROLLMENT_TOKENplaceholder).space_id (str | None) – Optional space ID to download the manifest from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
Response whose
bodyis the manifest YAML document as a string.- Raises:
BadRequestError – If the query parameters are invalid.
NotFoundError – If no manifest is found.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> manifest = client.fleet_enrollment.download_kubernetes_manifest() >>> yaml_text = manifest.body >>> print(yaml_text.splitlines()[0]) ---
AsyncFleetEnrollmentClient¶
Asynchronous version of the FleetEnrollmentClient for use with async/await syntax.
- class kibana._async.client.fleet_enrollment.AsyncFleetEnrollmentClient(client, default_space_id=None, validate_spaces=True)[source]¶
Bases:
AsyncNamespaceClientAsync client for the Kibana Fleet enrollment keys and tokens API.
Covers the Fleet APIs used to enroll Elastic Agents and Fleet Servers:
Enrollment API keys: tokens that Elastic Agents present to Fleet Server to enroll into an agent policy (list, create, get, revoke).
Service tokens: Elasticsearch service tokens used to enroll Fleet Server instances with Kibana.
Logstash API keys: API keys for Logstash to receive data from Elastic Agents via a Fleet Logstash output.
Uninstall tokens: per-policy tokens required to uninstall tamper-protected Elastic Agents.
Message signing service: rotate the key pair Fleet uses to sign messages sent to Elastic Agents.
Kubernetes manifests: fetch or download the manifest for deploying Elastic Agent on Kubernetes.
All operations are space-aware: every method accepts an optional
space_idto target a specific space (Nonetargets the default space or the space the client is scoped to).Example
>>> from kibana import AsyncKibana >>> client = AsyncKibana("http://localhost:5601", api_key="...") >>> >>> # Create an enrollment API key for an agent policy >>> created = await client.fleet_enrollment.create_key( ... policy_id="agent-policy-id", name="my-enrollment-key" ... ) >>> key_id = created.body["item"]["id"] >>> >>> # List keys, then revoke the one we created >>> keys = await client.fleet_enrollment.get_keys(per_page=50) >>> await client.fleet_enrollment.delete_key(key_id=key_id)
Usage
The AsyncFleetEnrollmentClient provides the same methods as FleetEnrollmentClient but all methods are async and must be awaited:
from kibana import AsyncKibana import asyncio async def main(): async with AsyncKibana("http://localhost:5601") as client: # Create and revoke an enrollment API key (async) created = await client.fleet_enrollment.create_key( policy_id="agent-policy-id", name="async-enrollment-key" ) key_id = created.body["item"]["id"] keys = await client.fleet_enrollment.get_keys(per_page=50) await client.fleet_enrollment.delete_key(key_id=key_id) # Tokens and manifests (async) tokens = await client.fleet_enrollment.get_uninstall_tokens() manifest = await client.fleet_enrollment.get_kubernetes_manifest() asyncio.run(main())
- __init__(client, default_space_id=None, validate_spaces=True)[source]¶
Initialize the AsyncFleetEnrollmentClient.
- Parameters:
client (AsyncKibana) – The parent AsyncKibana client instance to delegate requests to.
default_space_id (str | None) – Optional default space ID for all operations.
validate_spaces (bool) – Whether to validate space existence before space-scoped operations (default: True).
Example
>>> fleet_enrollment_client = AsyncFleetEnrollmentClient(kibana_client)
- async get_keys(*, page=None, per_page=None, kuery=None, space_id=None, validate_spaces=None)[source]¶
Get enrollment API keys.
Lists all enrollment API keys. Requires the
fleet-agents-allorfleet-setupprivilege.- Parameters:
page (int | None) – Page number (default: 1).
per_page (int | None) – Number of results per page (default: 20).
kuery (str | None) – A KQL query string to filter results (for example,
'policy_id:"my-policy-id"').space_id (str | None) – Optional space ID to list enrollment API keys from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
items: List of enrollment API keys (
id,api_key_id,api_key,name,policy_id,active,created_at,hidden)list: Deprecated duplicate of
itemstotal / page / perPage: pagination metadata
- Return type:
ObjectApiResponse containing
- Raises:
BadRequestError – If the query parameters are invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> keys = await client.fleet_enrollment.get_keys( ... per_page=50, kuery='policy_id:"my-policy-id"' ... ) >>> for key in keys.body["items"]: ... print(key["id"], key["name"], key["active"])
- async create_key(*, policy_id, name=None, expiration=None, space_id=None, validate_spaces=None)[source]¶
Create an enrollment API key.
Creates an enrollment API key for a given agent policy. Elastic Agents use the returned
api_keyto enroll into the policy. Requires thefleet-agents-allprivilege.Note: Kibana appends the generated key ID to the provided
name(the stored name looks like"my-name (<key-id>)").- Parameters:
policy_id (str) – The ID of the agent policy the Elastic Agent will be enrolled in.
name (str | None) – The name of the enrollment API key.
expiration (str | None) – Expiration timestamp for the key (for example,
"2025-01-01T00:00:00.000Z").space_id (str | None) – Optional space ID to create the enrollment API key in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
item: The created enrollment API key (
id,api_key_id,api_key,name,policy_id,active,created_at)action:
"created"
- Return type:
ObjectApiResponse containing
- Raises:
BadRequestError – If the agent policy does not exist or the body is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> created = await client.fleet_enrollment.create_key( ... policy_id="agent-policy-id", name="my-enrollment-key" ... ) >>> print(created.body["item"]["api_key"])
- async get_key(*, key_id, space_id=None, validate_spaces=None)[source]¶
Get an enrollment API key.
Gets an enrollment API key by ID. Requires the
fleet-agents-allorfleet-setupprivilege.- Parameters:
- Returns:
ObjectApiResponse containing the enrollment API key under
item(id,api_key_id,api_key,name,policy_id,active,created_at,hidden).- Raises:
NotFoundError – If no enrollment API key exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> key = await client.fleet_enrollment.get_key(key_id="key-id-1") >>> print(key.body["item"]["policy_id"])
- async delete_key(*, key_id, space_id=None, validate_spaces=None)[source]¶
Revoke an enrollment API key.
Revokes an enrollment API key by ID by marking it as inactive. The key is not removed, but it can no longer be used to enroll Elastic Agents. Requires the
fleet-agents-allprivilege.- Parameters:
- Returns:
ObjectApiResponse containing
{"action": "deleted"}on success.- Raises:
NotFoundError – If no enrollment API key exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = await client.fleet_enrollment.delete_key(key_id="key-id-1") >>> print(result.body["action"]) deleted
- async create_service_token(*, remote=None, space_id=None, validate_spaces=None)[source]¶
Create a service token.
Creates a Fleet Server service token. The token is used to enroll Fleet Server instances with Kibana. Requires the
fleet-agents-allprivilege.- Parameters:
remote (bool | None) – When True, generates a token for a remote Fleet Server (service account
elastic/fleet-server-remote) instead of the defaultelastic/fleet-serveraccount.space_id (str | None) – Optional space ID to create the service token in.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
name: The name of the generated service token
value: The service token secret value
- Return type:
ObjectApiResponse containing
- Raises:
BadRequestError – If the request is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> token = await client.fleet_enrollment.create_service_token() >>> print(token.body["name"], token.body["value"])
- async create_logstash_api_key(*, space_id=None, validate_spaces=None)[source]¶
Generate a Logstash API key.
Generates an Elasticsearch API key for Logstash to use with a Fleet Logstash output (the
logstash-outputpermission set). Requires thefleet-settings-allprivilege.- Parameters:
- Returns:
ObjectApiResponse containing the generated key under
api_keyin theid:secretformat expected by the Logstashelastic_agentinput.- Raises:
BadRequestError – If the request is invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> key = await client.fleet_enrollment.create_logstash_api_key() >>> print(key.body["api_key"])
- async get_uninstall_tokens(*, policy_id=None, search=None, per_page=None, page=None, space_id=None, validate_spaces=None)[source]¶
Get metadata for the latest uninstall tokens.
Lists the metadata for the latest uninstall tokens per agent policy. Uninstall tokens are required to uninstall tamper-protected Elastic Agents. Token values are not included; use
get_uninstall_token()to get a decrypted token. Requires thefleet-agents-allprivilege.Note:
policy_idandsearchcannot be used at the same time.- Parameters:
policy_id (str | None) – Partial match filtering for policy IDs (max length 50).
search (str | None) – Partial match filtering for uninstall token values (max length 50).
per_page (int | None) – The number of items to return (minimum 5).
page (int | None) – Page number (minimum 1).
space_id (str | None) – Optional space ID to list uninstall tokens from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
items: List of token metadata (
id,policy_id,policy_name,created_at,namespaces)total / page / perPage: pagination metadata
- Return type:
ObjectApiResponse containing
- Raises:
BadRequestError – If both
policy_idandsearchare provided, or the parameters are otherwise invalid.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
Example
>>> tokens = await client.fleet_enrollment.get_uninstall_tokens() >>> for token in tokens.body["items"]: ... print(token["id"], token["policy_id"])
- async get_uninstall_token(*, uninstall_token_id, space_id=None, validate_spaces=None)[source]¶
Get a decrypted uninstall token.
Gets one decrypted uninstall token by its ID. The returned
tokenvalue can be used to uninstall a tamper-protected Elastic Agent enrolled in the token’s agent policy. Requires thefleet-agents-allprivilege.- Parameters:
- Returns:
ObjectApiResponse containing the decrypted token under
item(id,policy_id,policy_name,token,created_at,namespaces).- Raises:
NotFoundError – If no uninstall token exists with the given ID.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> token = await client.fleet_enrollment.get_uninstall_token( ... uninstall_token_id="token-id-1" ... ) >>> print(token.body["item"]["token"])
- async rotate_message_signing_key_pair(*, acknowledge=None, space_id=None, validate_spaces=None)[source]¶
Rotate the Fleet message signing key pair.
Rotates the key pair used by Fleet to sign messages sent to Elastic Agents. This operation is irreversible and requires all agents in the Fleet to be re-enrolled after rotation. You must explicitly acknowledge the risk by passing
acknowledge=True; the server rejects the request with a 400 warning otherwise. Requires thefleet-agents-all,fleet-agent-policies-allandfleet-settings-allprivileges.- Parameters:
- Returns:
ObjectApiResponse containing a confirmation
message("Key pair rotated successfully.").- Raises:
BadRequestError – If
acknowledgeis not set to True.AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
ApiError – If the message signing service is unavailable (500).
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> result = await client.fleet_enrollment.rotate_message_signing_key_pair( ... acknowledge=True ... ) >>> print(result.body["message"]) Key pair rotated successfully.
- async get_kubernetes_manifest(*, download=None, fleet_server=None, enrol_token=None, space_id=None, validate_spaces=None)[source]¶
Get a full Kubernetes agent manifest.
Gets the Kubernetes manifest for deploying Elastic Agent as a DaemonSet, as a JSON object with the YAML document under
item. Requires thefleet-agent-policies-readorfleet-setupprivilege.- Parameters:
download (bool | None) – If True, returns the manifest as a downloadable file.
fleet_server (str | None) – Fleet Server host URL to include in the manifest (substituted for the
FLEET_URLplaceholder).enrol_token (str | None) – Enrollment token to include in the manifest (substituted for the
FLEET_ENROLLMENT_TOKENplaceholder).space_id (str | None) – Optional space ID to get the manifest from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
ObjectApiResponse containing the manifest YAML string under
item.- Raises:
BadRequestError – If the query parameters are invalid.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> manifest = await client.fleet_enrollment.get_kubernetes_manifest( ... fleet_server="https://fleet.example.com:8220", ... enrol_token="my-enrollment-token", ... ) >>> print(manifest.body["item"][:22])
- async download_kubernetes_manifest(*, download=None, fleet_server=None, enrol_token=None, space_id=None, validate_spaces=None)[source]¶
Download a Kubernetes agent manifest.
Downloads the Kubernetes manifest for deploying Elastic Agent as a raw YAML document (content type
text/x-yaml); the response body is the YAML string itself. Requires thefleet-agent-policies-readorfleet-setupprivilege.- Parameters:
download (bool | None) – If True, returns the manifest as a downloadable file.
fleet_server (str | None) – Fleet Server host URL to include in the manifest (substituted for the
FLEET_URLplaceholder).enrol_token (str | None) – Enrollment token to include in the manifest (substituted for the
FLEET_ENROLLMENT_TOKENplaceholder).space_id (str | None) – Optional space ID to download the manifest from.
validate_spaces (bool | None) – Override space validation setting for this operation.
- Returns:
Response whose
bodyis the manifest YAML document as a string.- Raises:
BadRequestError – If the query parameters are invalid.
NotFoundError – If no manifest is found.
AuthenticationException – If authentication fails.
AuthorizationException – If insufficient privileges.
SpaceNotFoundError – If the space doesn’t exist and validation is enabled.
- Return type:
Example
>>> manifest = await client.fleet_enrollment.download_kubernetes_manifest() >>> yaml_text = manifest.body >>> print(yaml_text.splitlines()[0]) ---