Kubernetes audit

Kubernetes audit answers "who did what to this cluster, and when?" from your Managed Kubernetes cluster's own audit log: every request to the cluster's API server, with the user, verb, object, source IP, and response. Events are kept for 365 days.

This is separate from the audit log, which records actions taken in your Lightning Cloud account through the console and the API.

Permission: Kubernetes audit read

Needs an Application Principal with Kubernetes audit read access. Metrics and logs access never includes it.

Rolling out by region

Kubernetes audit is rolling out region by region. Where it isn't enabled yet, its operations return 501 Not Implemented. Contact support to request it.

How a query works

Queries run in the background, so a large window doesn't hold a connection open:

  1. Start a query with a time window and optional filters. It returns a queryId at once.
  2. Wait for it to finish. waitSeconds holds the call for up to 20 seconds and returns as soon as the state changes, so a loop of these calls doesn't busy-poll.
  3. Read the events, page by page.
  4. Cancel a query you no longer need, to free its slot.

Results stay readable for 24 hours. Every query reads the archive fresh, so running the same query later can include events that arrived since.

Python SDK

import datetime
import uuid
import vpcloud_client
from vpcloud_client.models.create_audit_query_request import CreateAuditQueryRequest
from vpcloud_client.models.observatory_v1_audit_order import ObservatoryV1AuditOrder
from vpcloud_client.results import decode_json_lines

DONE = {"AUDIT_QUERY_STATE_SUCCEEDED", "AUDIT_QUERY_STATE_FAILED", "AUDIT_QUERY_STATE_CANCELLED"}
configuration = vpcloud_client.Configuration()
end = datetime.datetime.now(datetime.timezone.utc)

with vpcloud_client.ApiClient(configuration) as api_client:
    audit = vpcloud_client.KubernetesAuditApi(api_client)

    # 1. Start: who deleted anything in the "training" namespace in the last day, newest first
    query = audit.create_audit_query(CLUSTER_ID, CreateAuditQueryRequest(
        start=end - datetime.timedelta(days=1),
        end=end,
        verbs=["delete"],
        namespaces=["training"],
        order=ObservatoryV1AuditOrder.AUDIT_ORDER_DESCENDING,
        request_id=str(uuid.uuid4()),
    ))

    # 2. Wait
    status = audit.get_audit_query(CLUSTER_ID, query.query_id, wait_seconds=20)
    while status.state not in DONE:
        status = audit.get_audit_query(CLUSTER_ID, query.query_id, wait_seconds=20)
    if status.state != "AUDIT_QUERY_STATE_SUCCEEDED":
        raise RuntimeError(f"{status.state}: {status.error}")

    # 3. Read
    page_token = None
    while True:
        page = audit.get_audit_query_results(CLUSTER_ID, query.query_id, page_size=500, page_token=page_token)
        for event in decode_json_lines(page.events_json):
            ref = event.get("objectRef", {})
            print(event["stageTimestamp"], event["user"].get("username"), event["verb"],
                  ref.get("resource"), ref.get("namespace"), ref.get("name"))
        page_token = page.next_page_token
        if not page_token:
            break

REST API

# 1. Start
curl -X POST "$OBS_URL/v1/clusters/$CLUSTER_ID/audit/queries" -H "Authorization: Bearer $OBS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"start": "2026-11-09T00:00:00Z", "end": "2026-11-10T00:00:00Z",
       "verbs": ["delete"], "namespaces": ["training"], "order": "AUDIT_ORDER_DESCENDING",
       "requestId": "6c1e8f0a-2b6d-4f5e-9a3c-7d2e1b0f4a58"}'

# 2. Wait: repeat until state is AUDIT_QUERY_STATE_SUCCEEDED, _FAILED, or _CANCELLED
curl "$OBS_URL/v1/clusters/$CLUSTER_ID/audit/queries/$QUERY_ID?waitSeconds=20" -H "Authorization: Bearer $OBS_TOKEN"

# 3. Read: pass nextPageToken as pageToken until it's empty
curl "$OBS_URL/v1/clusters/$CLUSTER_ID/audit/queries/$QUERY_ID/results?pageSize=500" -H "Authorization: Bearer $OBS_TOKEN"

# 4. Cancel
curl -X POST "$OBS_URL/v1/clusters/$CLUSTER_ID/audit/queries/$QUERY_ID/cancel" -H "Authorization: Bearer $OBS_TOKEN" \
  -H "Content-Type: application/json" -d '{}'

Each item in eventsJson is the base64 of one event. Decode them with base64 -d, or with the SDK's decode_json_lines.

Filters

start and end are required. The window [start, end) is at most 31 days long and within the last 365 days. Back-to-back windows neither miss nor repeat an event. Every other filter is optional: an event must match each filter you set, and any one of a filter's values (at most 20).

Filter Keeps events... Example
verbs with one of these verbs ["delete", "patch"]
usernames by one of these users or service accounts ["system:serviceaccount:ci:deployer"]
namespaces in one of these namespaces ["training"]
resources on one of these resource types ["deployments", "secrets"]
names on objects with one of these names ["trainer-0"]
apiGroups in one of these API groups ("" for the core group) ["apps"]
responseCodes with one of these HTTP response codes [403]
sourceIps from one of these source IPs ["10.10.34.2"]
stages at one of these request stages ["ResponseComplete"]
auditIds with one of these audit IDs, to follow a single request

order is AUDIT_ORDER_ASCENDING (the default, oldest first) or AUDIT_ORDER_DESCENDING. Sending the same requestId again returns the same query instead of starting another, so a retry after a timeout is safe.

Events

Each event is a standard Kubernetes audit event (audit.k8s.io/v1), exactly as the cluster recorded it. Useful fields:

Field Contents
stageTimestamp When this stage of the request was logged. Windows and ordering use it.
user.username Who made the request
verb get, list, create, update, patch, delete, ...
objectRef The object: resource, namespace, name, apiGroup
responseStatus.code The HTTP status the API server returned
sourceIPs Where the request came from
auditID Identifies one request across its stages

Coverage

Every query reports a coverage verdict for its window, so an empty result tells you whether nothing happened or the archive is missing part of the window. GET /v1/clusters/{cluster_id}/audit/coverage (get_audit_coverage in the SDK) reports the whole archive's span and gaps without running a query.

verdict Meaning
AUDIT_COVERAGE_VERDICT_NO_KNOWN_GAPS The whole window is archived, with no known gap.
AUDIT_COVERAGE_VERDICT_PARTIAL Part of the window has nothing archived. gaps lists where.
AUDIT_COVERAGE_VERDICT_NOT_SETTLED No known gap, but the window reaches past the coverage's settledTime (about the last hour), so events from that time may still arrive. Query again later for a complete answer.
AUDIT_COVERAGE_VERDICT_NOT_ARCHIVED Nothing is archived for this cluster yet.

Errors and limits

Limit Default
Active queries per organization, in each region 3
New queries 1 per second, bursts of 5
Data scanned per organization per day 1 TB
Window 31 days, within the last 365
Values per filter 20
Data scanned per query 150 GB
Running time per query 10 minutes
Events per query 100,000. Past that, truncated is true: narrow the window or add filters.
Status When What to do
400 Bad Request The window or a filter is invalid, the cluster has nothing archived yet (AUDIT_ARCHIVE_EMPTY), the window ends before the archive starts (AUDIT_WINDOW_BEFORE_ARCHIVE), or results were requested before the query succeeded. Fix the request, or wait for the query.
403 Forbidden The Application Principal lacks Kubernetes audit read access, or the cluster isn't in your organization. See Access.
404 Not Found The query ID is unknown or its results have expired. Start a new query.
409 Conflict The requestId was used before with different filters. Use a new requestId.
429 Too Many Requests A limit was reached. With Retry-After, wait and retry. Without it, the query would scan too much: narrow the window.
501 Not Implemented Kubernetes audit isn't enabled in this region yet. Contact support.

A query that runs past its time limit ends AUDIT_QUERY_STATE_FAILED with the error DEADLINE_EXCEEDED. Narrow the window or add filters.

Was this page helpful?

What went wrong?

↑↓ Navigate↵ Open⌘↵ New tabesc Close