Openshift Service Account Token

Published
Length
3 min read

Luis Felipe Dias

All posts

You manage an openshift service account token by binding a role to a service account. This token lets apps or scripts talk to the cluster API. Teams often make one account per app and attach a broad role. When roles are too wide, any leaked token can alter or read extra pods. How an openshift service account token works with RBAC OpenShift runs on Kubernetes and uses role-based rules to control API requests. Each service account lives inside a single namespace. When a workload runs, it presen

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 manage an openshift service account token by binding a role to a service account. This token lets apps or scripts talk to the cluster API. Teams often make one account per app and attach a broad role. When roles are too wide, any leaked token can alter or read extra pods.

How an openshift service account token works with RBAC

OpenShift runs on Kubernetes and uses role-based rules to control API requests. Each service account lives inside a single namespace. When a workload runs, it presents its token to the API server. The API server checks what rules apply to that specific account.

A Role holds rules that represent a set of permissions within one namespace. A ClusterRole is not namespaced and can cover resources across the whole cluster. It can also cover cluster-scoped resources like nodes or non-resource endpoints. Permissions in this system are additive, so there are no deny rules.

To grant these permissions, you create a binding object. A RoleBinding grants permissions inside one namespace and can reference a Role or ClusterRole. A ClusterRoleBinding grants permissions across the entire cluster. When the token reaches the API server, the server checks these bindings before running the request.

Scoping subresources and namespace permissions

Good token hygiene starts with small, tight roles. Instead of using a ClusterRoleBinding for every tool, teams should prefer a single-namespace RoleBinding. This limits what a token can touch if a script fails or leaks.

You also need to watch how rules handle subresources. The API refers to resources by the name in the API URL. Some actions use a subresource, such as reading pod logs or running commands inside a pod. In RBAC rules, you write the subresource with a slash after the main resource name.

Teams often grant pod permissions without checking subresource rules. If a role allows pod exec subresources, the token holder can open a shell in containers. By separating log reading from exec permissions, you cut down the risk of unwanted container changes.

K8s Service Account Tokens + Token Rotation: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native token rules solve and what they leave open

Native roles and bindings do a great job of deciding who can reach an API endpoint. They stop an app in one namespace from deleting pods in another namespace. They also let platform teams separate read-only tools from deployment scripts.

Still, native RBAC stops at the API door. Once a token has permission to run pod exec, RBAC does not check what happens inside. It cannot see or block the specific shell commands an engineer or script runs inside the container. It also cannot mask sensitive data like emails, phone numbers, or card numbers in command output.

Long-lived tokens stored in automation tools create another risk. If a team shares one service account across many users, the cluster logs only show the account name. You lose track of which person ran a specific command during an incident.

Check Kubernetes API requests and responses on the wire

Kubernetes RBAC decides who may call the API server. RBAC does not check response payloads or split listing Secret names from reading Secret values when a role grants get access. With hoop.dev, you run an open-source HTTP proxy, a sidecar for your Kubernetes API. The kubectl client changes only the server address it talks to while RBAC stays in place.

On each call, hoop.dev guardrails read the method, normalized path, and headers to refuse bad deletes or full Secret reads with a 403 error. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs. Every request and verdict is logged without storing bearer tokens. View the project on GitHub.

Frequently asked questions

Can I add a deny rule to restrict an openshift service account token?

No, you cannot create a deny rule in Kubernetes RBAC. All permissions are additive, so you must start with zero permissions and only bind the exact roles needed.

What is the difference between a RoleBinding and a ClusterRoleBinding?

A RoleBinding grants permissions to a service account inside one specific namespace. A ClusterRoleBinding grants permissions across all namespaces and cluster-scoped resources like nodes.

Why do container shell sessions need extra care in RBAC?

Shell sessions use the pod exec subresource. Once RBAC allows that subresource call, the native API server does not inspect or filter the shell commands run inside the pod.

The query runs. The emails stay hidden.