How to Configure Pydantic AI Kubernetes Approval

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a pydantic ai kubernetes approval workflow, combine agent tool checks with cluster role rules. You pause the agent before it runs cluster changes and wait for a human sign-off. Many teams start by giving their AI agent a broad cluster role for fast testing. This approach creates big risks if the agent picks the wrong tool or target. A wide role lets an agent delete pods or read secrets across the whole cluster. Setting up tight role rules and human checks stops bad commands before they

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To set up a pydantic ai kubernetes approval workflow, combine agent tool checks with cluster role rules. You pause the agent before it runs cluster changes and wait for a human sign-off. Many teams start by giving their AI agent a broad cluster role for fast testing. This approach creates big risks if the agent picks the wrong tool or target. A wide role lets an agent delete pods or read secrets across the whole cluster. Setting up tight role rules and human checks stops bad commands before they run.

How a pydantic ai kubernetes approval flow works

A safe setup splits the work between the agent framework and the cluster API server. In the agent app, you wrap cluster actions inside typed tool functions. These functions take clear inputs and build the API request for the cluster. Before the function sends the request, the app pauses the run and asks a person. A team member reads the planned action in a chat app or ticket tool. If the person clicks approve, the agent function sends the call to the cluster.

Next, the Kubernetes API server checks the identity of the agent service account. Kubernetes role-based access control uses pure additive rules to grant permissions. There are no deny rules in this system. You set up a Role to grant permissions inside one namespace. You use a ClusterRole for cluster-wide resources like nodes or rules across all namespaces. A RoleBinding links that role to the agent identity inside a single namespace. A ClusterRoleBinding grants the permissions across the whole cluster.

When the agent needs to read pod logs or run commands, it uses subresources. Kubernetes RBAC names these subresources with a slash, like the pod log or exec path. You must list these subresources in the role rules so the agent can use them. This native setup makes sure the agent only touches the parts you allow.

What native roles solve and what they miss

Native cluster roles are great at deciding which service account can call an API endpoint. They stop an agent from touching namespaces or resource types outside its job. Meanwhile, the app-level check lets a human review the tool inputs before the call leaves. Together, they form a solid first step for safe agent runs.

Still, static roles and basic app checks leave an operational gap during live runs. Kubernetes RBAC checks who logs in and what resource they want to touch. It does not check what individual commands or shell scripts do inside a pod. Once a role grants exec permissions on a pod, the agent can run any shell command inside. Also, Kubernetes RBAC cannot limit create calls on subresources by specific resource names. If an agent gets pod log permissions, those logs might hold user emails or phone numbers. Native roles do not rewrite matched fields like card numbers or national IDs in results.

Approval Chains & Escalation + Kubernetes RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why human checks need runtime guardrails

Building approval logic inside every agent app takes a lot of custom code. Each time you add a new cluster tool, your team must write new pause logic. If one developer forgets to add the check on a tool, the agent runs unchecked. Plus, storing cluster keys inside the agent app creates another risk if the host leaks.

A strong setup moves the approval step and data masking outside the agent code. Instead of trusting the app to pause itself, you check every command in flight. This way, human reviewers see the exact command before the cluster runs it. You also rewrite sensitive text like emails in the output before the model reads it.

Add request guardrails and response masking beside Kubernetes

Cluster roles and service accounts govern who reaches the Kubernetes API. Still, a broad role or agent can delete workloads or print sensitive values from ConfigMaps and logs. In practice, hoop.dev runs beside the API server as a sidecar for your Kubernetes API and checks every request and response alongside RBAC.

With hoop.dev Kubernetes controls, guardrails can allow listing Secret names while refusing reads of Secret data before execution. Data masking redacts matched keys in returned JSON responses and log streams in memory. Furthermore, hoop.dev holds SOC 2 Type II and is MIT licensed on GitHub.

Frequently asked questions

Can Kubernetes RBAC block specific shell commands inside an agent exec call?

No, native RBAC only checks if the identity can use the pod exec subresource. It does not inspect or filter the shell commands sent inside that stream.

Should an AI agent use a RoleBinding or a ClusterRoleBinding?

Use a RoleBinding whenever possible so the agent stays inside one single namespace. A ClusterRoleBinding gives cluster-wide reach, which raises the risk if the agent makes a mistake.

How do we keep sensitive data in pod logs out of the model prompt?

Native roles cannot filter text inside a log stream. You must pass the log output through a masking step that rewrites emails and card numbers first.

The query runs. The emails stay hidden.