leviboroditsky
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Five Common Mistakes in Kubernetes Secret Management and How to Fix Them ======================================================================== ![growtika-ZfVyuV8l7WU-unsplash](https://hackmd.io/_uploads/Skw7VYtole.jpg) As teams scale their cloud-native apps, Kubernetes often becomes the go-to for managing containers. It's powerful and flexible, but when it comes to handling sensitive data like API keys, tokens, and credentials, things can get tricky fast. [Red Hat's 2024 State of Kubernetes Security report](https://www.redhat.com/en/engage/state-kubernetes-security-report-2024) found that over half of Kubernetes security incidents came down to simple misconfigurations. Many of those involved secrets being stored or shared the wrong way, opening the door to data breaches, compliance headaches, and reputational damage. [Kubernetes secret management](https://www.groundcover.com/blog/kubernetes-secret-management) isn't optional. It's a core part of keeping your systems secure. Still, it's easy to get wrong. In this article, we'll break down five common mistakes teams make when managing secrets in Kubernetes and how you can fix them before they become real problems. Common Mistakes and How to Fix Them =================================== Even the most experienced engineers can use patterns that compromise the way secrets are stored, accessed, or rotated. Below are common mistakes in managing secrets in Kubernetes, along with recommendations on how to address them. 1\. Storing Secrets as Plaintext in ConfigMap --------------------------------------------- One critical mistake is using Kubernetes ConfigMap to store sensitive data, such as tokens, API keys, or even database credentials. Although ConfigMap and [Secret objects](https://kubernetes.io/docs/concepts/configuration/secret/) look similar, they are fundamentally different. While the Secret object is used to store sensitive data, the ConfigMap is used to store non-confidential configuration data without any form of encoding. The use of ConfigMap to store sensitive data significantly increases the risk of unauthorized access to Kubernetes clusters and resources. For example, if you're deploying a MongoDB database in your cluster and mistakenly store the MongoDB secrets, such as MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD, in the ConfigMap. Then, anyone with even the slightest privilege to the ConfigMap can retrieve the database credentials in plain text and compromise the database. Generally, it's best practice to always store critical and sensitive information in a Kubernetes Secret configuration file. It features a security enhancement that can improve [Role-Based Access Control (RBAC)](https://www.techtarget.com/searchsecurity/definition/role-based-access-control-RBAC). When you store sensitive credentials in Secret, Kubernetes treats them differently at the API level and makes sure they are better protected during API access. Additionally, for enhanced security, it's best practice to pair the Kubernetes Secret with external secret management solutions, such as Hashicorp Vault, AWS Secrets Manager, and Google Cloud Secret Manager. #### Best Practices - Always use **Kubernetes Secret objects** instead of ConfigMaps for sensitive data. - Apply **RBAC restrictions** on Secrets to limit who can view them. - Combine Kubernetes Secrets with **external secret managers** for added encryption and access control. 2\. Overly Permissive RBAC Policies ----------------------------------- This is another common oversight in managing Kubernetes secrets. This involves granting excessive privileges to users, service accounts, or applications through Kubernetes Role-Based Access Control. For example, if a role lets someone read all secrets in a namespace, that's a problem. If that account is compromised, your secrets are exposed. Additionally, if RBAC is not distributed correctly, a breach in a single pod within a Kubernetes cluster can lead to lateral movement across pods, services, and the exposure of sensitive data outside the initial scope of control. The principle of least privilege should always be applied when configuring RBAC in secret. Access should only be given to users, services, or applications that explicitly require it, and strict restrictions should be imposed on the smallest namespace or scoped resources if possible. Also, instead of using ClusterRole and ClusterRoleBinding, use Role and RoleBinding unless otherwise. Also, regularly audit RBAC policies and secret access logs using commands like kubectl auth can-i and audit integrations. #### Best Practices - Follow the **principle of least privilege**; only grant access to Secrets if absolutely necessary. - Use **Role/RoleBinding** instead of ClusterRole when possible. - Periodically audit RBAC permissions with `kubectl auth can-i` and remove unused roles. 3\. Putting Secrets Directly in Manifests or Code ------------------------------------------------- A common risk is including sensitive information, such as API keys, tokens, database credentials, and passwords, directly within Kubernetes manifest files or application code. Even if it might be convenient to write secrets directly in the manifest configuration, it bypasses secret management features and exposes critical data. For example, directly hardcoding secrets in your Kubernetes deployment manifest file can expose your cluster to several risks, such as: - Exposing the secrets in the GitHub repository if version control is implemented - Access to secret keys if anyone has access to the cluster or deployment manifest - Inability to rotate secrets since secrets will be baked into the container runtime environment\ However, a simple solution to mitigate these potential threats is to externalize all secrets in a Kubernetes Secret object or an external secret management solution and reference them in your Kubernetes manifest. This approach enhances security in the cluster by centralizing secret storage, improves fine-grained access control, and makes secret rotation much easier. #### Best Practices - Never hardcode credentials in manifests, Git repositories, or application code. - Reference secrets in manifests via **environment variables** or **volume mounts**. - Implement **code scans (e.g., TruffleHog, GitLeaks)** to detect accidental secret commits. 4\. Failure to Encrypt Secrets at Rest -------------------------------------- Kubernetes stores Secrets in etcd by default. These Secrets in Kubernetes are encoded but not encrypted unless explicitly configured. So if you don't give proper access and a user has access to etcd, they can see sensitive data in plain text, which is a big security risk. Most of the time, teams assume Kubernetes automatically encrypts secrets, which often leads to this issue. However, secrets at rest must be enabled manually through the Kubernetes API server configuration. To fix this flaw, it's vital to enable [encryption at rest](https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/) in your Kubernetes clusters. This is made possible by configuring an encryption provider in the EncryptionConfiguration file alongside updating the encryption-provider-config flag in your API server. With this approach, secrets stored in the etcd are encrypted with the use of industry-standard methods such as Secretbox or AES-GCM. Furthermore, it's also essential to make sure your secrets are tightly restricted and audit logging is enabled to track unauthorized access attempts. This approach keeps your sensitive data safe even if the etcd is compromised. #### Best Practices - Enable **Encryption at Rest** in etcd using Secretbox or AES-GCM. - Rotate encryption keys regularly using Kubernetes' encryption provider. - Restrict etcd access and enable **audit logging** for secret reads/writes. 5\. Static Secrets Without Rotation ----------------------------------- This is another common mistake by engineers when managing Kubernetes secrets. This involves failing to implement secret rotation on a regular basis. Static and long-lived secrets such as tokens, database credentials, and passwords can pose a significant risk if exposed. This mistake makes it possible for users with access to the key to have indefinite access to the Kubernetes clusters, except these keys are revoked or rotated. Many teams often view secrets as a set-and-forget value, which means hardcoding them once and not updating them on a regular basis. This creates a vulnerability that can result in unauthorized access to critical data and insider threats. To fix this mistake, it's vital to implement a strategy that automatically rotates secrets. One of the most efficient ways to do this is with the use of an external secret management tool. These tools help in the automation of scheduled secret rotation without downtime. In addition, you can use an automation pipeline that detects secret changes and triggers the redeployment of affected pods in the cluster. For example, in a Gitops workflow, when a database credential is changed for a Postgres database, it automatically redeploys the Postgres pods and implements the new secrets. This approach ensures secrets are up-to-date and reduces the attack surface if there is a breach. #### Best Practices - Implement **automatic secret rotation** using external secret managers. - Design workflows to redeploy pods when secrets are updated. - Rotate passwords, tokens, and keys at a **fixed interval** to reduce exposure. Wrapping Up =========== Managing Kubernetes secrets is a crucial component in cloud-native applications, but it's often not treated with high priority. Avoiding common mistakes like plaintext in ConfigMap, elevated RBAC permissions, hardcoded secrets, and non-rotation of secrets, teams can efficiently reduce risk in a Kubernetes cluster. Paying attention to secure, automated, and auditable secrets handling can both strengthen Kubernetes security posture and ensure compliance and operational resilience.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully