Sub topic 5
How a workflow gets access to a cluster
This chapter assumes you know basic kubectl usage, what a kubeconfig file is, and how GitHub Actions secrets work. It covers the choices for giving a workflow access to a cluster. Later chapters implement each one.
The problem
A GitHub-hosted runner is a fresh virtual machine that starts empty. It has no kubeconfig and no network route that the cluster trusts. Before kubectl can do anything, the workflow must answer two questions.
- Where is the cluster? The runner needs the API server address and its certificate authority.
- Who is calling? The runner needs a credential that the cluster accepts, and that credential needs permissions.
A kubeconfig file holds both answers. The access methods below differ in how the file gets onto the runner and how long the credential inside it stays valid.
Two approaches
| Approach | Credential | Lifetime | Where it is stored |
|---|---|---|---|
| Kubeconfig secret | Token or client certificate | Long-lived | GitHub secret |
| OIDC federation | Short-lived token issued per run | Minutes | Nowhere |
Kubeconfig stored as a secret
You create a credential for the cluster, build a kubeconfig around it, and save the whole file as a GitHub secret such as KUBE_CONFIG. The workflow writes the secret to ~/.kube/config at the start of the deploy job.
This approach works with any cluster that the runner can reach, and it needs no setup on the cloud side. The cost is that the credential is valid until someone rotates it. If it leaks through a log, a fork, or a compromised action, an attacker can use it from anywhere.
OIDC federation
OIDC (OpenID Connect) lets the workflow prove who it is without a stored secret. When a job has the id-token: write permission, GitHub issues a signed token that names the repository, branch, and environment. A cloud provider can be configured to trust that token and exchange it for temporary credentials. For EKS, the exchange returns AWS credentials, and aws eks update-kubeconfig produces a kubeconfig that uses them.
Nothing long-lived is stored in GitHub. Even if the credentials leak, they expire within minutes to an hour. The cost is a one-time trust setup on the cloud side.
Authentication is not authorization
Both approaches only answer "who is calling." What the caller may do is decided by Kubernetes RBAC (role-based access control). A common mistake is to paste an admin kubeconfig into a secret because it works immediately. A leak of that secret then exposes the entire cluster.
Create a dedicated identity for the pipeline, such as a ServiceAccount, and bind it to a Role limited to one namespace. The RBAC chapter shows how.
Network reachability
The runner must be able to reach the API server over the network. This is easy when the endpoint is public. If the cluster's API server is private, GitHub-hosted runners cannot connect. You then need one of these:
- A self-hosted runner inside the cluster's network.
- A VPN or bastion path.
- A pull-based tool such as Argo CD or Flux, which avoids inbound access entirely.
Restricting a public endpoint to an IP allow-list is hard here, because GitHub-hosted runners use a large, changing set of addresses.
Choosing a method
- Use OIDC when your cloud provider supports it. EKS, GKE, and AKS all do.
- Use a kubeconfig secret when OIDC is not available, such as on a self-managed or on-premises cluster. Scope it with RBAC and plan for rotation.
- Whichever you pick, store the credential or role identifier in a GitHub environment so that production access needs approval.
Exercise
A team stores an admin kubeconfig in a GitHub secret and deploys with it. Name two separate risks, and say which access method would remove the first.
Show answer
First, the credential is long-lived, so a leak stays useful until someone rotates it. OIDC federation removes this risk by issuing short-lived credentials per run. Second, the admin identity has cluster-wide permissions, so a leak exposes everything. A namespaced Role bound to a dedicated ServiceAccount fixes that, whichever access method is used.