How to Configure OpenAI Agents SDK Kubernetes Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openai agents sdk kubernetes read only access by binding a restricted role. This role gives your agent service account view verbs on safe cluster resources. Many teams start by giving an AI agent a broad admin role during tests. That wide role lets an agent delete pods or read secret keys by mistake. A strict setup limits the agent to safe read actions from day one. How to set up openai agents sdk kubernetes read only access First, you create a dedicated service account for the age

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.

You set up openai agents sdk kubernetes read only access by binding a restricted role. This role gives your agent service account view verbs on safe cluster resources. Many teams start by giving an AI agent a broad admin role during tests. That wide role lets an agent delete pods or read secret keys by mistake. A strict setup limits the agent to safe read actions from day one.

How to set up openai agents sdk kubernetes read only access

First, you create a dedicated service account for the agent inside your cluster. The OpenAI Agents SDK runs custom Python functions as tools to inspect your state. Those tool functions use the service account token to talk to the cluster API. Next, you define a Role or a ClusterRole with read verbs like get and list. In Kubernetes RBAC, rules are additive, and there are no deny rules at all. You must list every resource the agent is allowed to view in your rules. A Role sets permissions inside one single namespace for your agent tools to use. A ClusterRole can cover resources across all namespaces or cluster nodes as well.

Then, you link the role to the service account with a binding object. A RoleBinding grants those read rules inside one specific namespace for the agent. You can also reference a shared ClusterRole inside a single namespace RoleBinding. That pattern keeps the agent inside one namespace without copying role rules everywhere. If the agent must inspect every namespace, you use a ClusterRoleBinding instead. For pod logs, you must grant access to the pods and log subresource. In RBAC, subresources use a slash format in the rule resource list. Do not include secret objects or exec subresources in your read role definition.

What native RBAC solves and what it leaves open

Native RBAC stops an agent from changing workloads or deleting cluster resources. It blocks write calls at the API server before any change can happen. Still, RBAC only checks who makes the call and which resource type they touch. It does not inspect the content returned inside pod logs or config maps. Pod logs and config maps often hold user emails, phone numbers, or card numbers. When an agent reads a log, those raw fields go straight to the model. Masking tools can rewrite matched fields in results so sensitive data stays safe.

Static service account keys also create a risk when stored on agent worker hosts. If an attacker steals the key file, they get the same cluster view. Native roles also lack a step to pause a risky call for human review. Teams must pair Kubernetes RBAC with runtime checks on every single agent request. You also want full logs of which tool call triggered each cluster API read.

Auditor Read-Only Access + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Best practices for scoping agent tool functions

Keep your agent tool functions narrow so the model cannot form arbitrary API requests. Instead of one generic cluster query tool, write separate tools for pods and events. Each tool should accept simple inputs like a namespace name or a pod label. Limit the output size in your code before sending text back to the model. Large log dumps waste tokens and raise the chance of leaking national IDs. Combine narrow Python functions with strict namespace roles for a safer agent deployment.

Govern kubectl and API calls in flight

Identity providers and Kubernetes RBAC decide who logs into a cluster. They cannot redact keys inside returned JSON objects or hold a risky delete call for review. By design, hoop.dev runs as an open-source proxy, a sidecar for your Kubernetes API, checking requests and responses without replacing RBAC.

First, hoop.dev guardrails refuse banned methods, paths, or headers before they run. Next, hoop.dev data masking rewrites sensitive keys in returned Secret, ConfigMap, and log responses in memory, and writes each decision to the audit trail. Explore the repo on GitHub.

Frequently asked questions

Can Kubernetes RBAC block an agent from reading one specific secret?

RBAC rules are additive and do not support deny rules on single objects. To hide secrets, omit the secrets resource from the agent role definition.

How do I let the OpenAI Agents SDK read pod logs safely?

Grant get and list verbs on both pods and the pod log subresource. Bind that role to one namespace so the agent only reads relevant logs.

Should I use a Role or a ClusterRole for an AI agent?

Use a Role and RoleBinding when the agent only checks one single namespace. Use a ClusterRole with a RoleBinding to reuse read rules across selected namespaces.

The query runs. The emails stay hidden.