Zum Inhalt springen
Plugins

tooling Plugin

Kubernetes Cluster Viewer

The `k8s_cluster` plugin (`plugins/k8s_cluster/`) lets an operator register external Kubernetes/k3s clusters and manage their connections from an admin-only sidebar page. It is a self-contained Rails engine plugin, installed but disabled by default (`default_enabled: false`, `disableable: true`, category `tooling`) - the plugin's own `PluginRecord.enabled` toggle is the feature gate, same as `mysql_db_browser`. There is no separate `Feature` flag. Every controller action checks `K8sCluster.enabled?` and `Current.user.admin?`. The foundation Jobs scaffolded connection management (register a cluster from a pasted kubeconfig, test the connection, edit, and delete), the read-only Kubernetes API client - one service object per resource kind, and the JSON API endpoints those services back: namespaces, pods (including per-container log tail), deployments, StatefulSets, DaemonSets, Jobs, services, events, PersistentVolumeClaims, nodes, CronJobs, and a cluster overview backed by the `metrics.k8s.io` API. A follow-up Job added the tabbed cluster-browsing UI that consumes those endpoints - see "Cluster-browsing UI" below, then a further Job added gated, read-only agentic access (MCP tools) - see "Agentic access" below. This Job adds a short, explicit allowlist of write/mutating MCP tools - restart a deployment rollout, scale a deployment, delete a pod, cordon/uncordon a node - gated by a separate, stricter `allow_writes` opt-in behind the stricter write-access phase; see "Write-capable agentic tools" and "Minimal RBAC for agentic access" below. The plugin also depends on `credential_store` for registered cluster credentials and credential-backed kubectl access; see "Credential storage" and "Credential-backed kubectl" below.

k8s_clusterQuellcode

K8s Cluster Viewer

The k8s_cluster plugin (plugins/k8s_cluster/) lets an operator register external Kubernetes/k3s clusters and manage their connections from an admin-only sidebar page. It is a self-contained Rails engine plugin, installed but disabled by default (default_enabled: false, disableable: true, category tooling) - the plugin's own PluginRecord.enabled toggle is the feature gate, same as mysql_db_browser. There is no separate Feature flag. Every controller action checks K8sCluster.enabled? and Current.user.admin?.

The foundation Jobs scaffolded connection management (register a cluster from a pasted kubeconfig, test the connection, edit, and delete), the read-only Kubernetes API client - one service object per resource kind, and the JSON API endpoints those services back: namespaces, pods (including per-container log tail), deployments, StatefulSets, DaemonSets, Jobs, services, events, PersistentVolumeClaims, nodes, CronJobs, and a cluster overview backed by the metrics.k8s.io API. A follow-up Job added the tabbed cluster-browsing UI that consumes those endpoints - see "Cluster-browsing UI" below, then a further Job added gated, read-only agentic access (MCP tools) - see "Agentic access" below. This Job adds a short, explicit allowlist of write/mutating MCP tools - restart a deployment rollout, scale a deployment, delete a pod, cordon/uncordon a node - gated by a separate, stricter allow_writes opt-in behind the stricter write-access phase; see "Write-capable agentic tools" and "Minimal RBAC for agentic access" below. The plugin also depends on credential_store for registered cluster credentials and credential-backed kubectl access; see "Credential storage" and "Credential-backed kubectl" below.

Clusters (KubernetesCluster)

app/models/kubernetes_cluster.rb stores label, api_server_url, a credential_store_credential_id reference, and legacy encrypted credentials only for temporary backward compatibility with rows that have not yet been migrated. New and rotated cluster secrets are written as Credential Store k8s_cluster.kubeconfig payloads; the cluster row keeps only non-secret metadata. Three independent booleans, all default false:

  • agentic_access_enabled - reserved for a later Job that adds MCP tools

mirroring mysql_db_browser's per-connection agentic gating. Not wired to anything yet.

  • allow_writes - reserved the same way, for the narrowly scoped write

actions described below.

  • insecure_skip_tls_verify - skips TLS certificate verification when

connecting to the cluster's API server, for self-signed k3s API servers. Always defaults to false and is rendered as a clearly-labeled opt-in checkbox on the connection form; it is never inferred from a pasted kubeconfig.

Managed from Admin -> K8s Clusters (/k8s_clusters, admin-only sidebar page, K8sCluster::SidebarPages) via GET/POST/PATCH/DELETE /api/v1/app/admin/kubernetes_clusters and a connect-test endpoint (POST .../test or .../:id/test, backed by K8sCluster::ConnectionTester) that never persists a draft cluster.

In the cluster browser's Workloads -> CronJobs table, the Schedule column keeps the raw Kubernetes cron expression visible for copy/paste and adds a localized hover tooltip for common five-field schedules and CronJob macros.

Kubeconfig parsing (K8sCluster::KubeconfigParser)

The create/update actions never accept api_server_url or credential fields directly - only a pasted kubeconfig YAML string (as the kubernetes_cluster[kubeconfig] param). KubeconfigParser.parse(yaml):

  1. Parses the YAML (YAML.safe_load, permitting Date/Time) and requires

a current-context.

  1. Resolves that context's cluster and user entries by name.
  2. Requires cluster.server to be an absolute http:// or https:// URL

with a host, then extracts it as api_server_url. Relative paths, malformed URLs, URLs without a host, and other schemes are rejected.

  1. Extracts whichever of the user's credentials are present: a bearer

token, or client-certificate-data + client-key-data (both must be present together). cluster.certificate-authority-data, when present, is attached to the credentials hash as ca_data regardless of which user auth type was used.

  1. Raises KubeconfigParser::ParseError with a specific, user-facing

message for every unresolvable case: blank/invalid YAML, a missing or unmatched current-context/cluster/user reference, a cluster with no server or an invalid/non-HTTP(S) server URL, an exec-based credential plugin (aws-iam-authenticator, gke-gcloud-auth-plugin, etc. - Syrus cannot run those), or credentials that reference external files (client-certificate, client-key, tokenFile) instead of inline -data fields.

On create, a kubeconfig is required. On update, omitting kubeconfig leaves the cluster's existing api_server_url/credential reference untouched (the same "leave blank to keep the current value" pattern MysqlConnectionsController uses for password rotation); supplying a new one re-parses and replaces both the metadata and the Credential Store payload. Responses never include the kubeconfig or extracted token/key material. Invalid server URLs fail create/update validation before either the cluster or Credential Store payload is changed, and draft connection tests report the parse error without attempting a network connection.

Credential storage

Cluster registration requires the credential_store dependency to be enabled. Pasted kubeconfigs are stored as CredentialStore::Credential records with type k8s_cluster.kubeconfig, instance scope, safe metadata limited to the resolved cluster name, context name, and API host, and no target constraints. The Kubernetes browsing API and MCP tools materialize that payload through CredentialStore::Broker; workflow/chat tool access therefore records normal Credential Store lease audit events without including payload material in responses, logs, or transcripts.

The migration path preserves existing configured clusters by backfilling legacy encrypted token/cert hashes into Credential Store kubeconfig payloads and stamping credential_store_credential_id. Runtime code still supports a legacy encrypted hash when no credential reference is present, so a cluster is not stranded if backfill cannot create a credential before an operator rotates it.

Connection testing (K8sCluster::ConnectionTester)

ConnectionTester attempts a lightweight, unauthenticated-shape GET /version against the cluster's API server using Faraday, mirroring MysqlDbBrowser::ConnectionTester's shape (a stubbable connection_factory class attribute, .test(cluster) for a persisted row, .test_params(...) for a draft). It never persists anything. SSL options are built per call:

  • verify: !insecure_skip_tls_verify.
  • A client certificate/key pair (OpenSSL::X509::Certificate /

OpenSSL::PKey.read, both Base64-decoded from the stored kubeconfig -data fields) when the cluster authenticates via client cert.

  • A cert_store built from ca_data, when present, so a cluster with a

private CA verifies without needing insecure_skip_tls_verify.

A bearer token, when present, is sent as an Authorization: Bearer <token> header. test_connection reports { success: true } on any successful HTTP response, or { success: false, error: "..." } on an HTTP error status, raised Faraday::Error, or an OpenSSL error (bad certificate/key data) - it never raises out to the controller.

Kubernetes API client (K8sCluster::ApiClient)

K8sCluster::ApiClient builds authenticated Kubeclient::Client instances (the kubeclient gem) per Kubernetes API group for a KubernetesCluster: #core (/api, v1 - namespaces, pods, services, events, PersistentVolumeClaims, nodes), #apps (apis/apps/v1 - deployments, StatefulSets, DaemonSets), #batch (apis/batch/v1 - CronJobs, Jobs), #networking (apis/networking.k8s.io/v1 - ingresses), and #metrics (apis/metrics.k8s.io/v1beta1 - see Overview below). Each client is built with as: :parsed, so entity calls (get_pods, get_deployment, ...) hand back plain parsed JSON hashes instead of RecursiveOpenStruct wrappers - resource services just dig into hashes, the same style as the rest of Syrus. Credentials are leased through Credential Store and then translated the same way ConnectionTester already does: a bearer token becomes auth_options: { bearer_token: }; client cert/key and CA data are base64-decoded into OpenSSL::X509::Certificate / OpenSSL::PKey / OpenSSL::X509::Store ssl_options; insecure_skip_tls_verify maps to OpenSSL::SSL::VERIFY_NONE. Clients are memoized per ApiClient instance, one per Kubernetes API group, but a fresh ApiClient (and fresh Kubeclient discovery round-trip - see below) is built per request; there is no persistent connection pool.

Kubeclient (4.x) discovers each API group's available resources lazily - the first get_pods/get_deployments/etc. call against a freshly built client triggers a GET against the group's own root (e.g. /api/v1 or /apis/apps/v1) to fetch its APIResourceList before dispatching the actual entity request. Service specs stub both requests against a fake API server via WebMock (plugins/k8s_cluster/spec/support/kube_api_stubs.rb) - no real cluster involved.

Resource services (one per Kubernetes kind)

Mirroring mysql_db_browser's schema/query service split, each Kubernetes resource kind gets its own read-only service class under K8sCluster::, all inheriting from K8sCluster::ResourceService (shared Unavailable/NotFound errors, mapped from Kubeclient::ResourceNotFoundError/ Kubeclient::HttpError plus raw connection failures - timeouts, TLS errors, DNS/connection-refused - the same two-outcome shape SchemaInspector uses):

  • Namespaces, Nodes - cluster-scoped: #list and #describe(name).
  • Pods, Deployments, StatefulSets, DaemonSets, Jobs, Services,

Ingresses, Endpoints, PersistentVolumeClaims, CronJobs - namespace-scoped: #list(namespace: nil) (omitting namespace lists across every namespace, matching kubectl get <kind> -A) and #describe(name, namespace:) (namespace is required to describe a single object, since Kubernetes has no cross-namespace "get by name" for these kinds). Pods additionally has #logs(name, namespace:, container: nil, tail_lines: 200, previous: false, timestamps: false) for a per-container log tail (Kubeclient#get_pod_log) - container is required once a pod has more than one container, the same way the raw Kubernetes API itself requires it. Pods#list's summary row also includes container_names (from spec.containers) so the browsing UI's Logs tab can populate a container picker without a second request. Nodes#list's summary row includes allocatable_cpu/allocatable_memory alongside capacity_cpu/capacity_memory (from status.allocatable). Endpoints summarizes each object's ready_addresses/not_ready_addresses counts (summed across subsets) and its ports - by core v1 API convention an Endpoints object shares its Service's (namespace, name), which is how the Services tab pairs the two without a separate lookup field; a Service with no selector (e.g. ExternalName) simply has no matching Endpoints row, which the UI treats as "not applicable" rather than an error. Ingresses#list's summary row carries hosts, rules (each rule's host plus its paths with backend service_name/service_port), tls_hosts, and ingress_class so the browsing UI can trace an external URL to its backing Service without a second request.

  • Events - namespace-scoped, #list(namespace: nil) only; an individual

Event has no useful "describe" beyond its list row. Sorted most-recent-first by lastTimestamp/eventTime/firstTimestamp.

#list returns a compact summary row per item (name/namespace plus the handful of fields a browsing table needs - phase, ready count, replica counts, capacity, schedule, etc.); #describe returns the full raw parsed Kubernetes object under a single key (pod:, deployment:, ...) rather than a curated subset, since a "describe" view is meant to show everything kubectl get -o json would. Every list/describe payload is wrapped with available: true, generated_at: (and truncated: for list, capped at 500- 1000 rows depending on kind) so the shape matches SchemaInspector's sections.

Cluster overview / metrics (K8sCluster::Overview)

Overview#call queries the metrics.k8s.io API (via ApiClient#metrics) for aggregate node and pod CPU/memory, returning { generated_at:, nodes: {...}, pods: {...} }. Because metrics.k8s.io is an aggregated API with only "nodes"/"pods" resources (no create/update/ etc.) and often isn't installed at all (a bare k3s box, a fresh cluster), Overview bypasses Kubeclient's entity-method discovery entirely and hits the REST path directly via the client's own public rest_client/ get_headers (client.rest_client["nodes"].get(client.get_headers)). CPU/memory quantity strings ("250m", "23148330n", "512Mi", "128974848") are parsed by K8sCluster::ResourceQuantity into millicores and bytes so per-item and aggregate totals can be summed and compared.

Any failure fetching either resource - metrics-server not installed (a 404 from the aggregation layer), any other HTTP error, or a connection failure - soft-fails to { available: false, reason: "metrics_unavailable", message: "..." } for that resource. Overview never raises: this is the same soft-fail posture the prepare step uses for guessed commands (CLAUDE.md) - a cluster with no metrics-server is a normal, expected configuration, not an error condition the operator needs a 502 for.

JSON API endpoints

Api::V1::App::Admin::KubernetesResourcesController, admin-only (inherits Admin::BaseController's require_admin), resolves the KubernetesCluster by :id per request exactly like MysqlSchemaController/MysqlQueryController resolve a MysqlConnection, and 404s with plugin_disabled when the plugin itself is off:

GET .../kubernetes_clusters/:id/namespaces[?name=]
GET .../kubernetes_clusters/:id/pods[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/pods/:name/logs?namespace=[&container=&tail_lines=&previous=&timestamps=]
GET .../kubernetes_clusters/:id/deployments[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/statefulsets[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/daemonsets[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/jobs[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/services[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/ingresses[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/endpoints[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/events[?namespace=]
GET .../kubernetes_clusters/:id/pvcs[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/configmaps[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/secrets[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/nodes[?name=]
GET .../kubernetes_clusters/:id/cronjobs[?namespace=][?name=&namespace=]
GET .../kubernetes_clusters/:id/overview

Each namespace-scoped/cluster-scoped resource kind is a single route: a name param switches that same action from list to describe (cluster-scoped kinds need only name; namespace-scoped kinds need name and namespace together, rejected with 422 namespace_required otherwise) - one route per resource kind, matching the plugin's declared route list one-for-one, rather than a separate nested /:name route per kind. ResourceService::Unavailable renders 502 connection_unavailable; ResourceService::NotFound renders 404 not_found.

Credential-backed kubectl

k8s_cluster declares a dependency on the bundled credential_store plugin and registers the credential type name k8s_cluster.kubeconfig. The plugin does not store, encrypt, parse, or broker these credentials itself. Credential Store owns the encrypted payload, scoped management API/UI, lease authorization, audit events, and redaction. The Kubernetes plugin owns only the Kubernetes-facing MCP tool and command policy.

k8s_cluster_kubectl accepts:

credential: "prod-k3s" or 123
kube_context: "prod"
namespace: "default"
args: ["get", "pods"]

The tool requests a k8s_cluster.kubeconfig lease from CredentialStore::Broker, writes the payload to a restrictive temporary file, invokes kubectl with a replacement environment containing only KUBECONFIG, PATH, and HOME, and removes the file after the command completes or raises. Returned stdout, stderr, and errors are scrubbed through Credential Store redaction, and Credential Store records the lease attempt as an access event. MCP usage records and transcripts receive only the redacted tool result plus safe metadata such as credential id/name/type, cluster/context/host labels, target context, and namespace. An optional cluster input is accepted as a validation label for credentials that use cluster target constraints; it is not passed to kubectl.

Operators adding a k3s credential should create a Credential Store record:

  • Type: k8s_cluster.kubeconfig.
  • Payload: the service-account kubeconfig YAML.
  • Safe metadata: non-secret labels such as cluster, context,

namespace, and host.

  • Target constraints: usually allowed_kube_contexts, optionally

allowed_kube_clusters and allowed_kube_namespaces, for example ["prod"] and ["default"].

  • Allowed tools: include only k8s_cluster_kubectl unless another tool is

deliberately authorized.

  • Allowed surfaces: choose workflow, chat, or both based on where agents

should use the credential.

The tool rejects the kubectl executable, leading global flags, and flags in args that can override the kubeconfig, API server, context, cluster, user, impersonated identity, TLS settings, proxy, cache directory, or profiling output. Callers pass context and namespace through the dedicated inputs so the broker can validate target constraints; -A/--all-namespaces cannot override a supplied namespace. Only the read commands get, describe, logs, top, events, api-resources, api-versions, version, explain, wait, and diff are allowed; auth is limited to can-i and whoami. This allowlist also prevents arbitrary kubectl-<name> plugins, configuration commands, streaming or interactive modes, and all mutating commands. Secret-value exposure patterns such as get secrets -o yaml, named or comma-separated Secret resources, get secrets -o=jsonpath=..., Secret projections via custom-columns/custom-columns-file, describe secret, or get --raw Kubernetes API paths whose segments target secrets, unless explicit allowance is supplied by a non-agent caller. get ... -o name is the only Secret-read exception; client verbosity at level 6 or higher remains protected. Chat and workflow agents cannot self-authorize secret-output allowance. When the credential belongs to a registered cluster, every command also requires that cluster's agentic_access_enabled opt-in. Standalone Credential Store kubeconfigs remain governed by their explicit scope, surface, tool, and target constraints. The local runner also enforces a timeout and bounded output capture so a missed policy case cannot keep the temporary kubeconfig materialized or grow memory use indefinitely.

Cluster-browsing UI

Admin -> K8s Clusters now has a Browse action per row (next to Test/Edit/Delete) that opens a tabbed, read-only viewer for that cluster (plugins/k8s_cluster/app/frontend/components/ClusterBrowser.tsx), mirroring mysql_db_browser's connections-list-to-schema-browser flow:

  • Overview - node count and ready/not-ready status (from Nodes#list)

plus aggregate node/pod CPU and memory (from Overview#call), with a graceful "metrics unavailable" message per section instead of an error when metrics.k8s.io isn't installed. Also lists namespaces (from Namespaces#list) with status and age, since namespaces otherwise appear only in the namespace-filter dropdown and would have no clickable row.

  • Workloads - a workload-kind switcher

(Pods/Deployments/StatefulSets/DaemonSets/Jobs/CronJobs) over the shared namespace filter, with status/ready/restart-count (pods), ready/available/updated replica counts (deployments), ready/current/updated replica counts (StatefulSets), scheduled/ready/available counts (DaemonSets), completions/active/succeeded/failed counts (Jobs), or schedule/suspended/active-count (CronJobs) columns, plus an age column computed client-side from created_at.

  • Services - a network-kind switcher (Services/Ingresses, the same

toolbar-dropdown pattern as the Workloads tab) over the shared namespace filter. Services show type, cluster IP, and ports, plus an Endpoints column (fetched alongside, paired by (namespace, name)) showing ready/not-ready backing-address counts; a Service with no matching Endpoints row (e.g. ExternalName) shows a dash, and an Endpoints fetch failure degrades that column to a dash instead of failing the whole tab. Kubernetes' newer EndpointSlice API is not fetched - the older Endpoints object covers the same summary-level readiness data this tab needs. Ingresses show hosts, a flattened backend Service/port column (so an external URL traces to its backing Service), a TLS badge, ingress class, and age.

  • Storage - PersistentVolumeClaims with bound status, capacity, and

storage class.

  • Config - ConfigMaps and Secrets over the shared namespace filter,

each with key counts, expandable key names, and an age column. Secret values are never displayed: the API returns metadata only (name, namespace, type, key names, created_at), stated in a note above the Secrets table.

  • Nodes - the cluster-scoped node list with readiness, roles,

capacity, and allocatable capacity.

  • Events - namespaced/cluster events as returned by Events#list

(already sorted most-recent-first server-side).

  • Logs - a pod picker (scoped by the shared namespace filter) and,

once a pod with more than one container is selected, a container picker populated from that pod's container_names; fetches a fixed 200-line tail per Pods#logs and offers a manual Refresh button rather than auto-polling.

  • Live - a polling tab over two canned queries (pod status, recent

events) with a 10s refetchInterval, directly mirroring plugins/mysql_db_browser/app/frontend/components/MysqlLiveTab.tsx's canned-query shape rather than a bespoke live feed.

A shared namespace filter (ClusterBrowser's NamespacePicker, populated from Namespaces#list) appears only for the namespace-scoped tabs (Workloads/Services/Storage/Config/Events/Logs); Overview and Nodes are always cluster-wide. The top-level tab switcher and the namespace/workload-kind/ pod/container pickers all use the same toolbar dropdown control (components/Dropdown.tsx, a button+listbox pattern) per CLAUDE.md's convention for small fixed-choice toolbar controls - never a native <select> for this kind of in-page switcher. All frontend strings are translated across en/de/la (app/frontend/i18n/locales/*/k8s_cluster.json).

Clicking any row (pods, deployments, StatefulSets, DaemonSets, Jobs, CronJobs, services, ingresses, ConfigMaps, Secrets, PVCs, nodes, namespaces) opens one shared read-only detail drawer (components/ResourceDetailDrawer.tsx, driven by useResourceDetail in each tab). The drawer shows key fields taken from the clicked row plus a read-only YAML view of the full describe object, fetched through the describe fetchers in api/kubernetesResources.ts - the same list routes with ?name= (plus ?namespace= for namespace-scoped kinds) that previously no UI called. The YAML is rendered by a small dependency-free serializer (lib/toYaml.ts) covering the plain-JSON subset the describe endpoints return. Secret detail stays redacted by construction: the backend describe returns the metadata summary only, never values. The drawer has loading/error states, closes via its close button, backdrop click, or Escape, and never issues anything but the describe GET - no editing, no apply.

Agentic access

The plugin publishes canonical permission descriptors for every agentic tool. k8s.observe@v1 covers ordinary cluster observation and may be authorized for an invocation, chat session, Job, or permanently: observation only reads, so a standing grant is available to an operator who wants one. Secret metadata is separated into k8s.secret_access@v1 and is capped at a chat session, because what it returns is credential material rather than a description of it. Workload mutations, node administration, and raw kubectl calls use distinct capabilities and are always authorized for one exact invocation only. Their resource scopes form a cluster / namespace / kind / object hierarchy; raw kubectl scope uses its credential or declared cluster as the cluster identifier. Defaults ask the operator rather than granting access. The connection's agentic_access_enabled and allow_writes settings remain independent, non-delegable ceilings, so enabling a connection never creates permission.

Coworkers are deny-by-default. The plugin declares a scoped k8s.read grant with a default confirm approval policy. An owner may select one agentic-access-enabled cluster for the grant. The coworker then receives only the read-only cluster catalog, resource browsing, pod-log, and metrics tools listed below, and every lookup is restricted to that cluster. Secret browsing, raw kubectl, pod deletion, rollout restart, deployment scaling, and node cordon changes are permanently excluded from the coworker surface regardless of grants. Coworker pod logs retain the normal 1,000-line and 64 KiB limits and are redacted server-side before entering the tool response. Audit entries for every coworker call include both the coworker identity and owning user.

Each KubernetesCluster carries its own agentic_access_enabled opt-in (surfaced as a checkbox on the connection create/edit form, default false), independent of the plugin's own enable/disable toggle. When set, that specific cluster becomes browsable read-only by workflow and chat agents through seventeen read-only MCP tools (plus four write tools gated separately - see "Write-capable agentic tools" below) exposed via mcp_tool_set/chat_mcp_tool_set (K8sCluster::WorkflowToolSet / K8sCluster::ChatToolSet, plugins/k8s_cluster/app/services/k8s_cluster/{workflow,chat}_tool_set.rb), mirroring mysql_db_browser's own MCP tool sets:

  • k8s_cluster_list_clusters - lists registered clusters using safe

metadata only: id, label, agentic_access_enabled, allow_writes, created_at, and updated_at. It deliberately omits api_server_url and all credential fields. Agents should call this first to discover the correct cluster_id before using any other tool.

  • k8s_cluster_namespaces / k8s_cluster_nodes - list or describe the two

cluster-scoped kinds. Omitting name lists; passing name describes that one object.

  • k8s_cluster_pods / k8s_cluster_deployments /

k8s_cluster_statefulsets / k8s_cluster_daemonsets / k8s_cluster_jobs / k8s_cluster_services / k8s_cluster_ingresses / k8s_cluster_pvcs / k8s_cluster_cronjobs / k8s_cluster_configmaps - list or describe the namespace-scoped kinds. Omitting namespace lists across every namespace (matching kubectl get <kind> -A); passing name describes a single object and requires namespace alongside it (rejected with a namespace is required tool error otherwise) - the same list-vs-describe contract KubernetesResourcesController uses for the browsing UI's endpoints.

  • k8s_cluster_secrets - list or describe Secrets redacted server-side:

metadata only (name, namespace, type, key names, created_at) - secret data values never appear in any payload, log, or tool response.

  • k8s_cluster_events - list-only, namespace optional, most-recent-first

(an individual Event has no useful describe beyond its list row).

  • k8s_cluster_pod_logs - a pod's log tail via Pods#logs; container is

required once a pod has more than one container, tail_lines defaults to 200 (maximum 1,000), responses are limited to 64 KiB, and previous/timestamps pass through to the same Kubernetes API flags the Logs tab uses. Coworker responses are additionally redacted server-side.

  • k8s_cluster_overview - the aggregate CPU/memory metrics overview via

Overview#call; soft-fails per-section (available: false) rather than erroring when metrics-server isn't installed, same as the UI's Overview tab.

Every tool call takes a cluster_id param and every read wraps the matching K8sCluster:: resource service directly (Namespaces, Pods, Deployments, StatefulSets, DaemonSets, Jobs, Services, Ingresses, Events, PersistentVolumeClaims, Nodes, CronJobs, Overview) - no separate agentic-only code path, so the agent sees exactly what the browsing UI sees.

Chat transcripts render these read-only results through plugin-owned tool cards instead of generic JSON. Workload cards show readiness, desired/current counts, selectors, rollout/condition signals, and warning counts; network cards show ports, endpoint readiness, hosts, TLS/class metadata, and missing target warnings; pod-log cards keep the raw result available while showing a searchable preview. Secret cards only render server-redacted metadata and key names, never secret data values.

Gating combines each cluster's flags with its backing credential scope. Admins choose a user, repository, team, or instance scope when registering a cluster. Agents only see or use a cluster when their current chat/workflow context can use that credential; repository-scoped workflow access is also narrowed by the run token's allowed repositories. Existing instance-scoped credentials keep their prior visibility, while legacy inline credentials are admin-only until migrated. Cluster management remains admin-only.

There is no framework hook to resolve an individual tool call's params from available_for?/available_for_context? - those are only checked once, at MCP manifest-build time, before any call happens. So available_for?/ available_for_context? only decide whether the tool set appears in the manifest at all (plugin enabled, WORKFLOW_IMPLEMENT role for workflow runs, and at least one configured KubernetesCluster so an agent can inspect safe cluster metadata); the actual per-cluster authorization happens inside each tool's own #call, via K8sCluster::AgenticAccess.cluster!(id) - it resolves the cluster_id named in that call's params and raises unless that specific row has agentic_access_enabled: true, mirroring MysqlDbBrowser::AgenticAccess.connection!(id) and Mcp::Tools::AuthorizationSupport's find_job!/find_run! pattern for first-party tools. AgenticAccess.cluster!/.cluster_with_write_access! delegate their gating logic to the shared Syrus::Host::AgenticConnection concern (lib/syrus/plugin/agentic_connection.rb), which MysqlDbBrowser::AgenticAccess also extends - the two plugins' near-identical find-by-id/raise-if-disabled classes and credential visibility predicate live in that one concern rather than parallel, drifting implementations. A cluster hidden by credential scope raises the same not-found error as an unknown id. K8sCluster::ResourceService::Unavailable/NotFound and a missing-namespace validation error are all normalized into an MCP::Tool::Response with error: true rather than raising out of the MCP sidecar process.

Write-capable agentic tools

A cluster with agentic_access_enabled on is browsable, but read-only. Turning on the cluster's separate allow_writes flag (also a checkbox on the connection form, default false, independent of agentic_access_enabled) additionally exposes a short, explicit allowlist of four mutating MCP tools - not a general kubectl proxy. Expanding this allowlist is deliberately a separate, explicitly-scoped follow-up, never an implicit consequence of turning allow_writes on:

  • k8s_cluster_restart_rollout - restarts a deployment's rollout

(Deployments#restart_rollout), equivalent to kubectl rollout restart: a strategic-merge patch stamping the pod template with a kubectl.kubernetes.io/restartedAt annotation, which rolls every pod even though no real spec content changed. Requires cluster_id, namespace, name.

  • k8s_cluster_scale_deployment - scales a deployment's replica count

(Deployments#scale), equivalent to kubectl scale --replicas=N. Requires cluster_id, namespace, name, replicas (a non-negative integer - validated before any API call, raising K8sCluster::ResourceService::InvalidArgument otherwise).

  • k8s_cluster_delete_pod - deletes a pod to force it to be rescheduled

(Pods#delete), equivalent to kubectl delete pod <name>. A pod owned by a Deployment/ReplicaSet/StatefulSet/DaemonSet is recreated by its controller; a bare unowned pod is simply removed. Requires cluster_id, namespace, name.

  • k8s_cluster_set_node_cordon - cordons (cordoned: true) or uncordons

(cordoned: false) a node (Nodes#set_cordon), equivalent to kubectl cordon/kubectl uncordon: a strategic-merge patch on spec.unschedulable. Cordoning only stops new pods from being scheduled onto the node - it never evicts pods already running there. Requires cluster_id, name, cordoned.

Deliberately excluded, and out of scope for this allowlist entirely: namespace deletion, any CRD/RBAC mutation, arbitrary manifest apply, and kubectl exec into a pod - anything irreversible or with a broad blast radius.

Gating is a strict superset of the read gate. Each write tool calls K8sCluster::AgenticAccess.cluster_with_write_access!(cluster_id) instead of the read tools' .cluster!(cluster_id). That method first runs the same agentic_access_enabled check as .cluster! (raising AccessDisabled with the existing read-access wording if that's off), then additionally requires allow_writes?, raising a distinct K8sCluster::AgenticAccess::WriteAccessDisabled with its own actionable message ("An admin must enable \"Allow writes\" for this cluster...") when read access is on but writes are not - so an agent gets a clear, specific reason rather than a generic auth failure that reads like the cluster isn't accessible at all. MysqlDbBrowser::QueryExecutor gates writes at this same layer, via an explicit MysqlDbBrowser::AgenticAccess.connection_with_write_access!(connection) - see the MySQL DB Browser docs' Read-only guardrails section.

All four write tools are registered in the same ChatToolSet::TOOL_CLASSES / WorkflowToolSet list as the read-only tools (there is no separate write tool set) - the per-cluster allow_writes check inside each tool's #call is the only gate, the same "no manifest-build-time hook sees per-call params" reasoning that applies to the read tools' per-cluster gate above.

Audit logging

Every agentic tool call - successful or not - is logged by K8sCluster::AgenticAudit.log! as a single structured line: cluster_id, tool, params, and either outcome: "success" with the result's serialized byte size, or outcome: "error" with the exception class and message. This deliberately never logs the resolved result's actual content (pod logs, full manifests) - only its size - so the audit trail can't become a second, un-redacted copy of cluster data sitting in the Rails log. This is the same spirit as the JobLog audit lines other MCP tool submissions leave behind, but logged rather than persisted to a DB table: JobLog itself requires a Run, while agentic k8s calls can equally come from a chat session that has no Run at all.

The four write tools are the one exception to "never logs the resolved result": each write resource-service method (Deployments#restart_rollout, Deployments#scale, Pods#delete, Nodes#set_cordon) returns a result hash with curated before:/after: keys - a small structured summary (a replica count, a restart timestamp, a schedulable flag), never a full object - and AgenticAudit.log! includes those two keys verbatim in the audit line when present, so the log line itself shows the mutation's effect (e.g. "before":{"replicas":2},"after":{"replicas":4}) without becoming a copy of full pod/deployment/node manifests.

Minimal RBAC for agentic access

The credential pasted into a cluster's kubeconfig should be scoped to the minimum the plugin actually needs, via a dedicated ServiceAccount and RBAC binding rather than a cluster-admin token:

Read-only clusters (agentic_access_enabled on, allow_writes off) only need a view-equivalent ClusterRole:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: syrus-k8s-cluster-viewer
rules:
  - apiGroups: [""]
    resources: [namespaces, pods, pods/log, services, endpoints, events, persistentvolumeclaims, nodes]
    verbs: [get, list]
  - apiGroups: [apps]
    resources: [deployments]
    verbs: [get, list]
  - apiGroups: [batch]
    resources: [cronjobs]
    verbs: [get, list]
  - apiGroups: [networking.k8s.io]
    resources: [ingresses]
    verbs: [get, list]
  - apiGroups: [metrics.k8s.io]
    resources: [nodes, pods]
    verbs: [get, list]
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: syrus-k8s-cluster-viewer
  namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: syrus-k8s-cluster-viewer
subjects:
  - kind: ServiceAccount
    name: syrus-k8s-cluster-viewer
    namespace: default
roleRef:
  kind: ClusterRole
  name: syrus-k8s-cluster-viewer
  apiGroup: rbac.authorization.k8s.io

Write-enabled clusters (allow_writes also on) additionally need patch/delete scoped to exactly the resources/verbs the four write tools use - deployment rollout restart/scale (patch on deployments), pod deletion (delete on pods), and node cordon/uncordon (patch on nodes). Grant this as an additional ClusterRole bound to the same ServiceAccount, not by widening the read role above:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: syrus-k8s-cluster-writer
rules:
  - apiGroups: [apps]
    resources: [deployments]
    verbs: [patch]
  - apiGroups: [""]
    resources: [pods]
    verbs: [delete]
  - apiGroups: [""]
    resources: [nodes]
    verbs: [patch]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: syrus-k8s-cluster-writer
subjects:
  - kind: ServiceAccount
    name: syrus-k8s-cluster-viewer
    namespace: default
roleRef:
  kind: ClusterRole
  name: syrus-k8s-cluster-writer
  apiGroup: rbac.authorization.k8s.io

Generate the ServiceAccount's bearer token (e.g. a long-lived Secret of type kubernetes.io/service-account-token, or kubectl create token syrus-k8s-cluster-viewer --duration=... for a short-lived one) and paste a kubeconfig built from it - see "Kubeconfig parsing" above. Syrus derives expiry from JWT exp claims and inline client certificates and shows the credential health without returning secret material. Bearer tokens and client certificates cannot be refreshed: edit the existing cluster and paste a replacement kubeconfig when prompted. Rotation preserves cluster identity, access settings, credential scope, and audit history.

OIDC auth-provider kubeconfigs containing an id-token, refresh-token, client-id, and idp-issuer-url are refreshed within 15 minutes of expiry. The five-minute plugin tick enqueues K8sCluster::RefreshCredentialsJob on the consumed low_priority_maintenance queue. A cluster row lock serializes attempts. Success replaces the encrypted kubeconfig and expiry atomically; failure keeps the prior encrypted payload and exposes a redacted actionable status. Operator and automatic rotations append Credential Store audit events with the actor/source and result, but never credential material. Already-expired replacement or refreshed credentials are rejected. Credential Store continues to reject expired credentials until a rotation or successful refresh recovers the cluster. Exec credential plugins remain unsupported.

What's not here yet

Still out of scope: per-repository cluster association or auto-detection of "which cluster does this repo deploy to," an in-cluster relay agent for clusters Syrus can't reach directly (NAT/firewalled), any general-purpose kubectl exec or arbitrary manifest apply via the agent, cluster provisioning/teardown, and watch-API streaming (v1 uses 10s polling for the Live tab; only worth building if that proves insufficient in practice). Expanding the write tool allowlist itself beyond the four actions above is also explicitly deferred to a future, separately-scoped Job rather than an implicit consequence of this one.