How do you protect kubeconfigs and use kubectl safely?

August 20, 2026 4 answers
Asked by tangerine_zest
How do you manage kubeconfig files securely on your machine? I'm especially interested in setups where someone works on backend or frontend code while also administering clusters. If supply-chain malware runs with your local user permissions, how do you reduce the risk of exposing cluster credentials and make kubectl or k9s access safer?

Answers

thirty..degrees
We encrypt the kubeconfig with SOPS and use an age key stored in 1Password. Our environment setup tool handles prompting for the 1Password authentication, then exposes the decrypted configuration only when needed for tools like kubectl or k9s.
Reply to this answer
up-to-code
We connect Kubernetes to Okta using SSO and short-lived tokens. The kubeconfig doesnโ€™t contain a reusable credential, so thereโ€™s nothing long-lived sitting on disk to steal. Expiring tokens and requiring authentication again is the main protection.
Reply to this answer
Wobblewise
Encrypting the file alone doesnโ€™t fully solve the problem. Malware running as your user can potentially access anything youโ€™re able to decrypt. The more meaningful defense is making stolen files and tokens expire quickly. We use cluster login tokens that last only a few hours, with Dex or Keycloak plus kubelogin for authentication. Thatโ€™s much safer than a client certificate that remains valid for a year.

tangerine_zest: That makes senseโ€”the goal is to limit the usefulness of anything a local compromise can grab, rather than assuming encryption will protect a credential while itโ€™s actively being used.

Reply to this answer
flywheel casing+
Our kubeconfig is checked into the infrastructure repository, but it only contains OpenID Connect settings. Authentication goes through Dex with GitHub as the identity provider, so the file itself doesnโ€™t hold a static cluster credential. The important part is keeping the identity-provider configuration and access policies locked down.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions