Inferensys

Prompt

RBAC Role and Binding Manifest Prompt Template

A practical prompt playbook for security engineers generating Kubernetes RBAC Role, ClusterRole, and RoleBinding YAML with least-privilege defaults, correct API group references, and audit checks for overly permissive wildcard rules.
Auditor reviewing AI-generated audit trail on laptop, blockchain-like immutable records visible, home office evening.
PROMPT PLAYBOOK

When to Use This Prompt

Defines the ideal user, required context, and operational boundaries for generating Kubernetes RBAC manifests from natural language access requirements.

This prompt is built for security engineers and platform operators who need to translate natural language access requirements into valid, least-privilege Kubernetes RBAC manifests. The primary job-to-be-done is generating production-ready YAML for Role, ClusterRole, and RoleBinding resources that will pass automated validation and security audit checks. The user is expected to have a clear understanding of the target namespace, the service account or user subject, and the specific Kubernetes API resources involved. Without this context, the model cannot scope rules correctly and will produce manifests that are either overly permissive or fail to grant necessary access.

The prompt enforces strict RBAC construction rules: correct apiGroups references (empty string for core resources, named groups for others), resource name scoping via resourceNames, and verb restrictions limited to the actual operations required. It actively flags wildcard rules—such as verbs: ['*'] or resources: ['*']—that would fail a security audit and suggests specific alternatives. The output is indentation-correct YAML with proper field ordering, making it suitable for direct piping into kubectl apply --dry-run=client or GitOps workflows. You should wire this prompt into a pipeline that includes a YAML linter and a kubectl auth can-i --list verification step before deployment.

Do not use this prompt for generating NetworkPolicy, PodSecurityPolicy, PodSecurityAdmission, or admission controller configurations. It is not designed for multi-tenancy policy generation, OPA/Rego rules, or dynamic RBAC controller setups. If your access requirements involve non-resource URLs (/healthz, /api/*), custom resource definitions (CRDs) with unknown API groups, or complex aggregated roles, you must provide explicit schema references and additional constraints. For high-risk production environments, always require human review of the generated manifests and run them through a policy-as-code evaluation tool before applying them to a cluster.

PRACTICAL GUARDRAILS

Use Case Fit

Where the RBAC Role and Binding Manifest prompt template works well, where it introduces risk, and what inputs and operational constraints you must plan for before putting it into a production pipeline.

01

Good Fit: Least-Privilege Scaffolding

Use when: you need to generate a Role or ClusterRole from a natural-language description of required access, and you want the model to default to the narrowest verb and resource scope. Guardrail: always diff the generated manifest against a wildcard deny rule and flag any rule containing * in verbs or resources for human review.

02

Bad Fit: Existing Cluster Policy Overlay

Avoid when: the target cluster already has complex aggregated ClusterRoles, custom API groups, or admission webhooks that modify effective permissions. The model cannot see live cluster state. Guardrail: run the generated manifest through a dry-run audit against the target cluster's RBAC authorizer before applying, and never generate bindings for cluster-admin without a break-glass justification.

03

Required Inputs: Namespace, ServiceAccount, and Resource Map

What the prompt needs: a target namespace, the ServiceAccount name, the list of API resources and verbs required, and any label selectors for resource-scoped rules. Guardrail: if any of these inputs are missing, the prompt must refuse to generate a binding rather than guessing the scope and accidentally granting cross-namespace access.

04

Operational Risk: Binding to Unvalidated Subjects

Risk: the prompt generates a RoleBinding that references a ServiceAccount that does not exist yet, or a user string that does not match the cluster's identity provider. Guardrail: validate subject existence before applying the binding. For user subjects, require an explicit identity provider prefix and reject bare usernames without a documented mapping.

05

Operational Risk: Silent Privilege Escalation via Aggregate Labels

Risk: the model may add an rbac.authorization.k8s.io/aggregate-to-* label that merges the generated Role into an existing ClusterRole, unintentionally granting broad access. Guardrail: strip all aggregate labels from generated output unless the operator explicitly requests aggregation, and log a warning when they are present.

06

Pipeline Integration: Schema Validation Before Apply

What to wire in: run the generated YAML through kubectl apply --dry-run=server --validate=true and a strict OpenAPI schema check before it reaches the cluster. Guardrail: if validation fails, route the output to a repair prompt rather than discarding it, and surface the exact schema error to the operator so they can decide whether to fix the prompt or the input.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A production-ready prompt for generating least-privilege Kubernetes RBAC Role, ClusterRole, and RoleBinding manifests from access requirements.

This prompt template generates Kubernetes RBAC YAML manifests from natural language access requirements. It is designed to produce manifests that follow least-privilege principles by default, scoping verbs and resources as narrowly as possible. The template includes explicit instructions to avoid wildcard rules, validate API group references, and flag any requested permissions that appear overly broad. Use this when you need to convert a security ticket, access request, or compliance requirement into a valid, audit-ready RBAC manifest that can pass kubectl auth can-i --dry-run checks.

code
You are a Kubernetes RBAC security engineer. Generate a valid Kubernetes RBAC manifest from the access requirements below.

## Input
[ACCESS_REQUIREMENTS]

## Constraints
- Follow least-privilege principles. Grant only the minimum verbs and resources needed.
- Do NOT use "*" for verbs or resources unless explicitly requested and justified.
- Use specific API group references. Do not assume the core group.
- For RoleBindings, include a specific namespace. For ClusterRoleBindings, confirm cluster-wide scope is intended.
- If the request is ambiguous, ask for clarification before generating the manifest.
- If the requested permissions appear overly broad, add a warning comment in the output.

## Output Schema
Return a single YAML document containing one or more Kubernetes resources. Use the following structure:
```yaml
---
apiVersion: rbac.authorization.k8s.io/v1
kind: [Role | ClusterRole | RoleBinding | ClusterRoleBinding]
metadata:
  name: [RESOURCE_NAME]
  namespace: [NAMESPACE if Role or RoleBinding]
[SPEC_FIELDS]

Validation Checks (perform internally before output)

  1. All apiGroups fields are non-empty strings, not "*".
  2. All resources fields list specific resource names.
  3. All verbs fields list specific verbs (get, list, watch, create, update, patch, delete).
  4. RoleBinding subjects have valid kind (User, Group, ServiceAccount) and name.
  5. No ClusterRoleBinding is generated unless cluster-wide scope is explicitly requested.

Output Format

Return ONLY the YAML manifest inside a fenced yaml code block. Include a brief audit note after the block if any permissions appear overly broad.

To adapt this template, replace [ACCESS_REQUIREMENTS] with the specific access request, such as "Allow the ci-bot ServiceAccount in namespace staging to read Pods and create Deployments." For high-risk environments, add a [RISK_LEVEL] placeholder that triggers additional scrutiny for cluster-admin or secrets access. After generation, always run the output through kubectl --dry-run=client -f - and kubectl auth can-i checks before applying. For production pipelines, pair this prompt with a validation harness that parses the YAML, checks for wildcard rules, and blocks any manifest that grants more than the requested permissions.

IMPLEMENTATION TABLE

Prompt Variables

Replace each placeholder before sending the prompt. Validation notes describe how to check the replacement value before generation.

PlaceholderPurposeExampleValidation Notes

[NAMESPACE]

Target Kubernetes namespace for the RBAC resources

production-api

Must match regex ^a-z0-9?$ and be 63 characters or fewer. Reject if empty or contains uppercase.

[RESOURCE_TYPE]

Kubernetes resource kind to scope permissions to

deployments

Must be a valid Kubernetes resource name (lowercase plural). Validate against known resource list or api-resources output. Reject wildcard * unless explicitly approved.

[API_GROUP]

API group for the target resource

apps

Must be a valid API group string. Use empty string for core group. Validate against kubectl api-resources -o wide. Reject unknown groups.

[VERBS]

Allowed actions on the resource

get, list, watch

Must be a comma-separated list of valid Kubernetes verbs. Reject if contains wildcard * or dangerous verbs like escalate, impersonate without explicit approval flag.

[SUBJECT_NAME]

Name of the user, group, or service account being bound

api-reader-sa

Must be a valid Kubernetes object name. For service accounts, validate format system:serviceaccount:[NAMESPACE]:[NAME]. Reject empty or unqualified names.

[SUBJECT_KIND]

Type of subject being bound

ServiceAccount

Must be one of: User, Group, ServiceAccount. Reject any other value. Case-sensitive check required.

[ROLE_NAME]

Name for the Role or ClusterRole resource

api-reader-role

Must be a valid Kubernetes object name. Check for naming convention compliance if org standards exist. Reject names exceeding 253 characters.

[BINDING_NAME]

Name for the RoleBinding or ClusterRoleBinding resource

api-reader-binding

Must be a valid Kubernetes object name. Should typically reference the role name. Reject if identical to an existing binding in the target namespace without override flag.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the RBAC manifest prompt into a secure, validated CI/CD or admission pipeline.

The RBAC prompt is designed to be called from a security review or platform engineering workflow, not from an open chatbot. The typical integration point is a CI/CD pipeline step, a GitOps pre-commit hook, or an internal platform API that accepts a natural-language access requirement and returns a validated manifest. The caller must provide the [NAMESPACE], [SUBJECT_TYPE], [SUBJECT_NAME], and [REQUESTED_ACCESS] placeholders. The prompt should be treated as a generation step, not a final approval step. Every generated manifest must pass automated validation and human review before it reaches a cluster.

Wire the prompt into an application by wrapping it in a function that enforces a strict contract. The function should: (1) accept typed input matching the placeholder schema; (2) call the model with the prompt template and a low temperature (0.0–0.2) to maximize structural consistency; (3) parse the response and validate it against the Kubernetes RBAC API schema using a tool like kubeconform or kubectl --dry-run=server; (4) run a set of policy checks that reject manifests containing wildcard verbs (*), wildcard resources (*), or missing namespace isolation for RoleBindings. If validation fails, the harness should retry once with the error message injected into the [CONSTRAINTS] block. If the retry also fails, the workflow must escalate to a human reviewer and log the full prompt, response, and validation errors for audit.

For production use, integrate an eval harness that runs a golden test suite of known access patterns (e.g., 'read-only Pod viewer in staging', 'read-write Deployment manager in production') and asserts that the generated rules match expected verbs, resources, and scope. Log every generation attempt with the input parameters, model version, generated YAML, validation result, and reviewer identity. Never allow a generated RBAC manifest to be applied automatically without a human approval step, because overly permissive rules can expand the blast radius of a compromised credential. The prompt is a productivity tool for security engineers, not a replacement for least-privilege review.

IMPLEMENTATION TABLE

Expected Output Contract

Validation rules and field specifications for the RBAC manifest generated by the prompt. Use this contract to build automated validation checks before applying manifests to a cluster.

Field or ElementType or FormatRequiredValidation Rule

apiVersion

string (e.g., rbac.authorization.k8s.io/v1)

Must match exactly one of: rbac.authorization.k8s.io/v1, rbac.authorization.k8s.io/v1beta1. Parse check against allowed list.

kind

string (e.g., Role, ClusterRole, RoleBinding, ClusterRoleBinding)

Must be one of: Role, ClusterRole, RoleBinding, ClusterRoleBinding. Enum check. Kind must be consistent with namespace presence (Role/RoleBinding require namespace; ClusterRole/ClusterRoleBinding must omit namespace).

metadata.name

string (RFC 1123 DNS subdomain)

Must be non-empty, <= 253 chars, match a-z0-9?. Regex parse check.

metadata.namespace

string or null

Required when kind is Role or RoleBinding. Must be omitted or null when kind is ClusterRole or ClusterRoleBinding. Conditional presence check.

rules[].apiGroups

array of strings

Must be an array. Empty array [""] indicates core API group. Wildcard ["*"] triggers audit warning. Schema check: array items must be strings.

rules[].resources

array of strings

Must be an array. Wildcard ["*"] triggers audit warning. Schema check: array items must be strings. Must not be empty.

rules[].verbs

array of strings

Must be an array. Wildcard ["*"] triggers audit warning. Must contain only valid verbs: get, list, watch, create, update, patch, delete, deletecollection. Enum check per item.

roleRef.apiGroup

string

Required for RoleBinding/ClusterRoleBinding. Must be rbac.authorization.k8s.io. Parse check.

roleRef.kind

string

Required for RoleBinding/ClusterRoleBinding. Must be Role or ClusterRole. Must match the kind of the referenced role. Consistency check.

roleRef.name

string

Required for RoleBinding/ClusterRoleBinding. Must match metadata.name of a Role or ClusterRole defined in the same manifest or documented as a dependency. Reference check.

subjects

array of objects

Required for RoleBinding/ClusterRoleBinding. Must contain at least one subject. Each subject must have kind (User, Group, ServiceAccount), name, and optional namespace (required for ServiceAccount). Schema check.

subjects[].namespace

string or null

Required when subject.kind is ServiceAccount. Must match the ServiceAccount namespace. Conditional presence check.

PRACTICAL GUARDRAILS

Common Failure Modes

RBAC manifests are high-stakes security objects. These failures turn a helpful prompt into a cluster-wide vulnerability. Each card pairs a common breakage with a concrete guardrail you can add to your prompt, test suite, or CI pipeline.

01

Wildcard Verbs in Production Roles

What to watch: The model defaults to verbs: ['*'] or verbs: ['get', 'list', 'watch', 'create', 'update', 'patch', 'delete'] when the user asks for 'full access' or 'admin access' without specifying exact operations. This grants far more power than intended, especially for sensitive resources like secrets or validating webhooks. Guardrail: Add a hard constraint in the prompt: Never use wildcard verbs. Always enumerate the minimum required verbs. If the user request is ambiguous, list the verbs you intend to use and ask for confirmation before output. Validate output with a regex check that rejects any manifest containing verbs: ['*'] or verbs: ['*'] in production-targeted namespaces.

02

Overly Broad Resource Scoping

What to watch: The model generates rules for resources: ['*'] or entire API groups like resources: ['deployments', 'services', 'secrets', 'configmaps'] when the user only needed access to a single resource type. This violates least-privilege and creates lateral movement risk. Guardrail: Instruct the prompt to scope resources to the narrowest possible set. If the user says 'manage deployments,' do not add pods, replicasets, or services unless explicitly requested. Add a post-generation check that flags any Role with more than 3 resource types and requires human review before applying.

03

Missing or Incorrect API Group References

What to watch: The model writes apiGroups: [''] for core resources but omits the empty string for non-core resources, or confuses apps/v1 with extensions/v1beta1. This produces manifests that fail to apply or silently grant access to the wrong API surface. Guardrail: Embed a reference table in the prompt: Core resources (pods, services, secrets, configmaps) use apiGroups: ['']. Deployments, StatefulSets, DaemonSets use apiGroups: ['apps']. Ingress uses apiGroups: ['networking.k8s.io']. Always verify the correct API group for each resource. Run kubectl auth can-i --dry-run as part of your eval suite.

04

RoleBinding Targeting Wrong Namespace or Subject

What to watch: The model binds a Role to a ServiceAccount in the wrong namespace, or creates a ClusterRoleBinding when a namespaced RoleBinding would suffice. This accidentally grants cluster-wide access when namespace isolation was intended. Guardrail: Add explicit namespace and subject constraints: If the user specifies a namespace, use a RoleBinding in that namespace. Only use ClusterRoleBinding when the user explicitly requests cluster-wide access. Always confirm the ServiceAccount name and namespace before generating the binding. Validate that metadata.namespace on the RoleBinding matches the intended target namespace.

05

Default Allow-All in NetworkPolicy-Adjacent RBAC

What to watch: When generating RBAC alongside NetworkPolicy or security contexts, the model sometimes compensates for restrictive network rules by loosening RBAC permissions, or vice versa. This creates a false sense of security where one control is tight but the other is wide open. Guardrail: Prompt the model to treat RBAC and NetworkPolicy as independent, additive controls. Do not relax one to compensate for the other. If the user requests both, generate each with least-privilege defaults independently. Add a cross-manifest validation step that checks for RBAC wildcards whenever a restrictive NetworkPolicy is present in the same namespace.

06

Unbounded Resource Names in Policy Rules

What to watch: The model generates resourceNames: [] (empty list, meaning all resources of that type) or omits resourceNames entirely when the user intended to grant access to a single named resource like a specific ConfigMap or Secret. This escalates a targeted grant to a blanket grant. Guardrail: Add a prompt rule: When the user mentions a specific resource name, always populate resourceNames with that exact name. If the user does not specify a name, ask whether they intend to grant access to all resources of that type or a specific named resource. Validate that any Role with sensitive resource types (secrets, configmaps) has a non-empty resourceNames list or a documented justification.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to test the RBAC manifest prompt before production deployment. Each criterion targets a specific failure mode common in Kubernetes RBAC generation.

CriterionPass StandardFailure SignalTest Method

API Group Correctness

All apiGroups fields use exact values (e.g., apps, batch, "" for core) with no hallucinated groups

Unknown API group string present; core group represented as v1 instead of ""

Parse YAML, extract all apiGroups values, validate against kubectl api-resources output for target cluster version

Verb Scoping

Verbs list contains only standard Kubernetes RBAC verbs with no wildcard * unless explicitly requested

Wildcard * in verbs field when least-privilege was specified; non-standard verbs like read or modify

Schema check: verbs array items must match regex ^(get|list|watch|create|update|patch|delete|deletecollection)$

Resource Name Specificity

resourceNames field is populated when scoping to named resources; empty or absent when scoping to all resources of a type

resourceNames missing when [TARGET_RESOURCE_NAME] was provided; resourceNames present with empty array

Parse YAML, check resourceNames presence against input [TARGET_RESOURCE_NAME] placeholder value

Subject Binding Accuracy

RoleBinding subjects array references correct kind, name, and namespace matching [SUBJECT_KIND], [SUBJECT_NAME], [SUBJECT_NAMESPACE]

Subject kind mismatch (e.g., User vs ServiceAccount); namespace missing for namespaced subject; name typo

Extract subjects array, validate kind in [User, Group, ServiceAccount], verify namespace presence for ServiceAccount

Namespace Consistency

Role and RoleBinding metadata.namespace match; ClusterRole and ClusterRoleBinding omit namespace field

RoleBinding in namespace default but Role in namespace production; ClusterRole contains namespace field

Parse both resources, assert Role.namespace equals RoleBinding.namespace; assert ClusterRole.metadata has no namespace key

Least-Privilege Default

When [LEAST_PRIVILEGE] is true, rules grant minimum verbs and resources needed for described workload; no blanket resources: ["*"]

Rules grant pods, deployments, services when workload only reads ConfigMaps; resources: ["*"] present

Diff generated rules against minimal required permissions derived from [WORKLOAD_DESCRIPTION]; flag any extra resource types or verbs

YAML Structural Validity

Output parses without errors; indentation uses consistent 2-space increments; no tab characters

YAML parser throws mapping or sequence errors; mixed indentation widths; tabs present

Run yq eval '.' or equivalent strict YAML parser; reject on non-zero exit code

Overly Broad RoleRef Detection

ClusterRoleBinding roleRef does not reference cluster-admin or system-critical roles unless explicitly requested

roleRef.name equals cluster-admin when [LEAST_PRIVILEGE] is true; roleRef references system:* aggregated roles unnecessarily

Extract roleRef.name, check against blocklist [cluster-admin, admin, edit] when least-privilege mode active

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a frontier model (GPT-4o, Claude 3.5 Sonnet). Remove strict schema validation from the prompt and rely on the model's native YAML generation. Drop eval checks and accept manual review of output.

Simplify the prompt to:

code
Generate a Kubernetes [RESOURCE_TYPE] YAML manifest for [NAMESPACE] with [DESCRIPTION].
Use least-privilege defaults. Output only the YAML.

Watch for

  • Missing apiVersion or kind fields
  • Wildcard verbs (*) or resources sneaking in
  • Indentation errors when copying into editors
  • No namespace field in RoleBinding subjects
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.