Openshift Generate Token for Service Account

Published
Length
3 min read

Luis Felipe Dias

All posts

To run an openshift generate token for service account workflow, you request a bound API token. The cluster API server issues this time-bound credential to log in automated apps and external scripts. Teams often create these tokens so build pipelines can deploy apps into a namespace. Still, admins frequently attach broad cluster roles to get a pipeline working fast. When a token holds excess rights, any leaked credential puts the entire cluster at risk. How the openshift generate token for ser

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 run an openshift generate token for service account workflow, you request a bound API token. The cluster API server issues this time-bound credential to log in automated apps and external scripts. Teams often create these tokens so build pipelines can deploy apps into a namespace. Still, admins frequently attach broad cluster roles to get a pipeline working fast. When a token holds excess rights, any leaked credential puts the entire cluster at risk.

How the openshift generate token for service account workflow works

In OpenShift and Kubernetes, a service account gives an identity to processes running in pods. External tools can also use this identity to talk to the cluster API server. Modern clusters do not create permanent secret tokens for every service account by default. Instead, an admin or script requests a token from the API server on demand. The API server returns a signed token with a set expiration time.

A token alone only proves the identity of the caller to the API server. To let the token do real work, you must set up role-based access control. In Kubernetes RBAC, a Role sets permissions inside one specific namespace. A ClusterRole sets permissions across the whole cluster or for cluster-scoped resources like nodes. Permissions in this system are purely additive, meaning there are no deny rules.

Next, you connect the service account to those rules using a binding. A RoleBinding grants the permissions inside a single namespace. It can reference a local Role or a wider ClusterRole. A ClusterRoleBinding grants the permissions across all namespaces in the cluster. Once bound, the generated token can run any API call allowed by those rules.

Scoping subresources and namespace permissions

Teams should scope every service account to the smallest set of rules possible. RBAC refers to cluster objects by the exact name shown in the API URL. Some API calls target a subresource, such as reading pod logs or running commands. In RBAC rules, you write the subresource with a slash, like pods and log. If a script only needs to read logs, you grant access to that subresource alone.

Many teams make the mistake of granting pod execution rights to deployment tokens. When a token can run commands inside pods, it can read local files and secrets. Because RBAC has no deny rules, adding a second binding only increases what the token can do. You cannot write a rule to block one specific secret inside a shared namespace. You must carefully review every RoleBinding and ClusterRoleBinding linked to that service account.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native service account tokens solve and what they leave open

Native token generation solves the problem of identifying automated tools to the cluster API. Short-lived tokens reduce the danger of old credentials sitting in build systems forever. RBAC roles and bindings give teams a clear way to limit which API endpoints a token can reach. This native setup works well for controlling who can start pods or read status fields.

Still, native RBAC only checks permissions when the API call first arrives. It decides who logs in and which API resource they can touch. It does not inspect what individual commands or queries do inside a session. If a service account has rights to exec into a pod, RBAC steps aside once the shell opens. The native cluster logs will show that a session started, not the commands run inside it. Also, pod logs and command outputs often contain sensitive data like emails, phone numbers, or card numbers. Native RBAC cannot rewrite matched fields in results to hide this sensitive data from logs or users.

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

How do permissions work for an OpenShift service account token?

A token gets permissions through RBAC RoleBindings or ClusterRoleBindings linked to the service account. All rules in Kubernetes RBAC are purely additive, so there are no deny rules.

What is the difference between a RoleBinding and a ClusterRoleBinding?

A RoleBinding grants permissions to a service account inside one specific namespace only. A ClusterRoleBinding grants permissions to that service account across every namespace in the cluster.

Can native RBAC restrict what commands run inside a pod exec session?

No, native RBAC only checks if the token has permission to call the pod exec subresource. Once the API server allows the session, RBAC cannot filter or inspect the commands run inside.

The query runs. The emails stay hidden.