Audit and Observability
This runbook covers the signals kornercode emits for auditing and incident response: Kubernetes Events written by the gateway, the gateway’s structured audit log, its Prometheus counters, and the NetworkPolicyDisabled Workspace condition. It ends with suggested alerts and triage steps.
Audit sinks
All gateway audit records go through AuditService.Append (gateway/internal/services/audit.go). Each record has an actor (the caller’s OIDC sub), an action, a subject, an outcome and optional metadata, and is written to up to three sinks:
| Sink | Written for | Failure behavior |
|---|---|---|
Structured log line (audit) | Every record | Cannot fail |
| Kubernetes Event | Tenant workspace actions and admin IDE access | Retried; failures are logged and counted, never block the user action |
Counter gateway_admin_handler_audited_total | Admin API handlers | In-process, cannot fail |
Kubernetes Events
| Reason | Emitted when |
|---|---|
WorkspaceCreated | A user creates their workspace |
WorkspaceTTLExtended | A user extends their workspace’s TTL |
WorkspaceRestarted | A user restarts their workspace |
WorkspaceDeleted | A user deletes their workspace |
AdminOpenedIDE | An admin obtains a ticket to open another user’s IDE (“View IDE”); see Authentication |
Each Event is created in the Workspace’s namespace with involvedObject set to the Workspace, type Normal, source component kornercode-gateway, and reportingInstance set to the actor. The message has the form [<actor>] <description>, with control characters removed and brackets in the actor escaped (sanitizeAuditEventMessage in gateway/internal/services/audit_message.go); it is truncated to 128 bytes. Workspace owners see these Events in the Events tab of their workspace.
List the audit Events for a namespace:
kubectl get events -n <team-namespace> \
--field-selector involvedObject.kind=Workspace,source=kornercode-gatewayList admin IDE openings:
kubectl get events -A --field-selector reason=AdminOpenedIDEKubernetes Events are short-lived: the API server deletes them after its --event-ttl (one hour by default). Export Events to your log pipeline if you need to retain them.
Structured audit log
Every record is also written to the gateway’s log as an audit line whose entry attribute is the record as JSON (timestamp, actor, subject, action, outcome, metadata). Admin API calls produce actions of the form admin.<handler> (for example admin.createTeam or admin.listTeams) with the admin’s username and email in metadata; workspace patches and deletions by an admin additionally produce admin.workspace.patch and admin.workspace.delete.
kubectl -n <gateway-namespace> logs deployment/kornercode-gateway | grep ' audit 'Admin API actions do not create Kubernetes Events. Ship the gateway logs to durable storage to keep an audit trail of admin activity.
Other actions in the audit log:
| Action | Recorded when |
|---|---|
AdminIDEAccessRefused | An admin asks to open the IDE of a workspace whose team has blockAdminIDEAccess on. Not a Kubernetes Event; the owner sees nothing. |
auth.certificate | With the client-certificate gate on: every certificate refusal by the gate, at sign-in or at /auth/bridge (outcome: failure). The reason is one of no_certificate, certificate_malformed, certificate_header_ambiguous, certificate_expired, certificate_untrusted, certificate_cn_ambiguous, certificate_revoked, revocation_unavailable, identity_claim_missing, certificate_identity_mismatch (with the token’s identity) or certificate_session_mismatch. With onUnavailable: allow, a request let through without a revocation check is recorded with outcome: success and revocation: unchecked. The subject is client-certificate, the actor certificate:<cn> (certificate:unknown without a readable CN). |
auth.break_glass.login | The break-glass button only: every break-glass login (outcome: success, actor the mapped sub) and every refusal of a CN not in the mapping (outcome: failure, reason: cn_not_allowed, actor break-glass:<cn>). The subject is break-glass. |
Both certificate actions carry the metadata cn, serial, issuer, clientIP (the ingress), method, the host and path of the request and, when present, forwardedFor. Identical refusals for the same CN and reason, and unchecked requests for the same CN, are written once a minute.
Admin actions taken in a break-glass session carry breakGlass: "true" in their metadata. The AdminOpenedIDE Event does not show it; the audit log does. State-changing dashboard requests refused for coming from another site are logged as gateway warnings with reason cross_origin, not as audit entries.
The entry attribute is JSON escaped inside a text log line. To list certificate refusals, break-glass logins and the admin actions of break-glass sessions as a table:
kubectl -n <gateway-namespace> logs deployment/kornercode-gateway | grep ' audit ' \
| sed -E 's/^.* entry="(.*)"$/\1/; s/\\"/"/g' \
| jq -rR 'fromjson? | select(.metadata.breakGlass=="true" or .action=="auth.certificate" or .action=="auth.break_glass.login")
| [.timestamp[0:19], .action, .outcome, (.metadata.cn // .actor), (.metadata.reason // "-")] | @tsv'Prometheus counters (gateway)
The gateway registers three counters in gateway/internal/metrics/metrics.go and serves them on a dedicated listener at :9090/metrics (METRICS_PORT). The chart does not expose this port through a Service or create a ServiceMonitor; configure scraping of the pod’s port 9090 yourself, and restrict network access to it, since the endpoint is unauthenticated.
| Counter | Labels | Meaning |
|---|---|---|
gateway_audit_events_total | result: success, failure | Outcome of each Kubernetes Event write. failure covers permanent errors (Forbidden, Invalid), a canceled request, and exhausted retries. Individual retries are not counted. |
gateway_session_store_errors_total | op: save, clear, mint_bridge | Session failures. save: writing the session during /auth/login, /auth/callback or /auth/bridge. clear: clearing the session on /auth/logout. mint_bridge: minting a bridge ticket on /api/v1/bridge/ticket. Each failure returns 500 to the user. |
gateway_admin_handler_audited_total | handler (for example listTeams, createTeam) | Incremented when an admin API handler starts. The workspace patch and delete handlers increment it a second time after the change succeeds. |
A series appears only after its first increment, so a freshly started gateway exposes none of these names until the corresponding path is used.
Session cookies that fail to decode, for example after a SESSION_SECRET rotation, are not counted. They are logged as session decode error warnings and the user is asked to sign in again.
The operator exposes controller metrics on the metrics port (8080) through the kornercode-operator-kornercode-controller-metrics Service. Set operator.metrics.serviceMonitor.enabled: true to create a ServiceMonitor.
NetworkPolicyDisabled condition
ReconcileNetworkPolicy maintains the NetworkPolicyDisabled condition on every Workspace:
| Status | Reason | When |
|---|---|---|
True | Disabled | The Team’s SecurityProfile sets networkPolicy.disabled: true, or the WorkspaceProfile sets disableNetworkPolicy: true |
False | Enforced | Neither flag is set |
Enforced means only that no disable flag is set. A Workspace whose Team has no SecurityProfile, or whose SecurityProfile lists no policyRefs, also reports Enforced while no policy selects its pod. See Network isolation.
List the Workspaces running with network policy disabled:
kubectl get workspaces -A -o json | jq -r '
.items[]
| select(any(.status.conditions[]?; .type == "NetworkPolicyDisabled" and .status == "True"))
| "\(.metadata.namespace)/\(.metadata.name)"'Suggested alerts
# A Kubernetes audit Event could not be written. Investigate promptly:
# the action succeeded but its Event is missing.
increase(gateway_audit_events_total{result="failure"}[5m]) > 0
# Users are getting 500s on login, bridge or logout.
increase(gateway_session_store_errors_total[5m]) > 0The result="success" series is not alerted on; it confirms that Events are being written at all.
Investigation playbook
Audit Event writes failing
Find the failure mode in the gateway logs:
kubectl -n <gateway-namespace> logs deployment/kornercode-gateway | grep 'audit event write'audit event write permanently failedindicates an authorization or validation error, which is not retried.audit event write failed after retriesindicates a transient API server problem that outlasted the retries.Check that the gateway’s ServiceAccount can create Events in the Workspace’s namespace:
kubectl auth can-i create events -n <team-namespace> \ --as=system:serviceaccount:<gateway-namespace>:kornercode-gatewayThe chart grants this cluster-wide through the
kornercode-gatewayClusterRole.Check API server health and the network path between the gateway and the API server.
Each write is attempted three times, with backoff delays of 200 ms, 400 ms and 800 ms (constants.AuditRetryBaseDelay, capped at constants.AuditRetryMaxDelay), about 1.4 seconds in total. The structured log line is written before the Event, so the record is never lost from the logs.
Session store errors
- Identify the operation from the
oplabel. op="clear": a user’s logout failed because the session cookie could not be decoded, which typically follows aSESSION_SECRETrotation. Signing in again replaces the cookie. See Session secret rotation.op="save": the session could not be encoded. The usual cause is a cookie larger than the 4096-byte limit of gorilla/securecookie, which happens when the IdP returns very large claims (for example, a user in hundreds of groups). The log line containssecurecookie: the value is too long. Reduce the groups emitted in the ID token, for example with a group filter in the IdP’s group-membership mapper.op="mint_bridge": the gateway could not encode a bridge ticket; the same size limit applies.
kubectl -n <gateway-namespace> logs deployment/kornercode-gateway | grep -iE 'session|SaveClaims|SaveBridgeSession|MintBridgeTicket'Workspace running without network policy
Find the Team’s SecurityProfile and inspect its network policy settings:
kubectl get team <team> -o jsonpath='{.spec.securityProfileRef}{"\n"}' kubectl get securityprofile <name> -o yamlCheck the WorkspaceProfile referenced by the Workspace for
spec.disableNetworkPolicy.If a flag is set unintentionally, set it to
false. The SecurityProfile or WorkspaceProfile change triggers a reconcile of the affected Workspaces; the activation labels are restored on the running pods and the condition changes toFalse/Enforced.The disable flags are deliberate escape hatches for workspaces that must not be restricted, such as administrator workspaces. Treat
Trueas a configuration decision to review rather than as a fault, and confirm it with the Team’s owner.
Related documentation
- Security overview
- Authentication and sessions
- Network isolation
- Gateway architecture
- The Event delivery counters make a lost audit Event visible, and the
NetworkPolicyDisabledcondition makes a workspace without network isolation visible.