Tag: Kubernetes security automation

  • GitOps vs GitHub Actions: Security-First in Production

    GitOps vs GitHub Actions: Security-First in Production

    Last month I migrated two production clusters from GitHub Actions-only deployments to a hybrid GitOps setup with ArgoCD. The trigger? A misconfigured workflow secret that exposed an AWS key for 11 minutes before our scanner caught it. Nothing happened — this time. But it made me rethink how we handle the boundary between CI and CD.

    Here’s what I learned about running both tools securely in production, and when each one actually makes sense.

    GitOps: Let Git Be the Only Way In

    GitOps treats Git as the single source of truth for your cluster state. You define what should exist in a repo, and an agent like ArgoCD or Flux continuously reconciles reality to match. No one SSHs into production. No one runs kubectl apply by hand.

    The security model here is simple: the cluster pulls config from Git. The agent runs inside the cluster with the minimum permissions needed to apply manifests. Your developers never need direct cluster access — they open a PR, it gets reviewed, merged, and the agent picks it up.

    This is a massive reduction in attack surface. In a traditional CI/CD model, your pipeline needs credentials to push to the cluster. With GitOps, those credentials stay inside the cluster.

    Here’s a basic ArgoCD Application manifest:

    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: my-app
    spec:
      source:
        repoURL: https://github.com/my-org/my-app-config
        targetRevision: HEAD
        path: .
      destination:
        server: https://kubernetes.default.svc
        namespace: my-app-namespace
      syncPolicy:
        automated:
          prune: true
          selfHeal: true

    The selfHeal: true setting is important — if someone does manage to modify a resource directly in the cluster, ArgoCD will revert it to match Git. That’s drift detection for free.

    One gotcha: make sure you enforce branch protection on your GitOps repos. I’ve seen teams set up ArgoCD perfectly, then leave the main branch unprotected. Anyone with repo write access can then deploy anything. Always require reviews and status checks.

    GitHub Actions: Powerful but Exposed

    GitHub Actions is a different animal. It’s event-driven — push code, open a PR, hit a schedule, and workflows fire. That flexibility is exactly what makes it harder to secure.

    Every GitHub Actions workflow that deploys to production needs some form of credential. Even with OIDC federation (which you should absolutely be using — see my guide on securing GitHub Actions with OIDC), there are still risks. Third-party actions can be compromised. Workflow files can be modified in feature branches. Secrets can leak through step outputs if you’re not careful.

    Here’s a typical deployment workflow:

    name: Deploy to Kubernetes
    on:
      push:
        branches:
          - main
    jobs:
      deploy:
        runs-on: ubuntu-latest
        environment: production
        steps:
          - name: Checkout code
            uses: actions/checkout@v4
          - name: Configure kubectl
            uses: azure/setup-kubectl@v3
          - name: Deploy application
            run: kubectl apply -f k8s/deployment.yaml

    Notice the environment: production — that enables environment protection rules, so deployments require manual approval. Without it, any push to main goes straight to prod. I always set this up, even on small projects.

    The bigger issue is that GitHub Actions workflows are imperative. You’re writing step-by-step instructions that execute on a runner with network access. Compare that to GitOps where you declare “this is what should exist” and an agent figures out the rest. The imperative model has more moving parts, and more places for things to go wrong.

    Where Each One Wins on Security

    After running both in production, here’s how I’d break it down:

    Access control — GitOps wins. The agent pulls from Git, so your CI system never needs cluster credentials. With GitHub Actions, your workflow needs some path to the cluster, whether that’s a kubeconfig, OIDC token, or service account. That’s another secret to manage.

    Secret handling — GitOps is cleaner. You pair it with something like External Secrets Operator or Sealed Secrets and your Git repo never contains actual credentials. GitHub Actions has encrypted secrets, but they’re injected into the runner environment at build time — a compromise of the runner means a compromise of those secrets.

    Audit trail — GitOps. Every change is a Git commit with an author, timestamp, and review trail. GitHub Actions logs exist, but they expire and they’re harder to query when you need to answer “who deployed what, and when?” during an incident.

    Flexibility — GitHub Actions. Not everything fits the GitOps model. Running test suites, building container images, scanning for vulnerabilities, sending notifications — these are CI tasks, and GitHub Actions handles them well. Trying to force these into a GitOps workflow is pain.

    Speed of setup — GitHub Actions. You can go from zero to deployed in an afternoon. GitOps requires more upfront investment: installing the agent, structuring your config repos, setting up GitOps security patterns.

    The Hybrid Approach (What Actually Works)

    Most teams I’ve worked with end up running both, and honestly it’s the right call. Use GitHub Actions for CI — build, test, scan, push images. Use GitOps for CD — let ArgoCD or Flux handle what’s running in the cluster.

    The boundary is important: GitHub Actions should never directly kubectl apply to production. Instead, it updates the image tag in your GitOps repo (via a PR or direct commit to a deploy branch), and the GitOps agent picks it up.

    This gives you:

    • Full Git audit trail for all production changes
    • No cluster credentials in your CI system
    • Automatic drift detection and self-healing
    • The flexibility of GitHub Actions for everything that isn’t deployment

    One thing to watch: make sure your GitHub Actions workflow doesn’t have permissions to modify the GitOps repo directly without review. Use a bot account with limited scope, and still require PR approval for production changes.

    Adding Security Scanning to the Pipeline

    Whether you use GitOps, GitHub Actions, or both, you need automated security checks. I run Trivy on every image build and OPA/Gatekeeper for policy enforcement in the cluster.

    Here’s how I integrate Trivy into a GitHub Actions workflow:

    name: Security Scan
    on:
      pull_request:
    jobs:
      scan:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - name: Build image
            run: docker build -t my-app:${{ github.sha }} .
          - name: Trivy scan
            uses: aquasecurity/trivy-action@master
            with:
              image-ref: my-app:${{ github.sha }}
              severity: CRITICAL,HIGH
              exit-code: 1

    The exit-code: 1 means the workflow fails if critical or high vulnerabilities are found. No exceptions. I’ve had developers complain about this blocking their PRs, but it’s caught real issues — including a supply chain problem in a base image that would have made it to prod otherwise.

    What I’d Do Starting Fresh

    If I were setting up a new production Kubernetes environment today:

    1. ArgoCD for all cluster deployments, with strict branch protection and required reviews on the config repo
    2. GitHub Actions for CI only — build, test, scan, push to registry
    3. External Secrets Operator for credentials, never stored in Git
    4. OPA Gatekeeper for policy enforcement (no privileged containers, required resource limits, etc.)
    5. Trivy in CI, plus periodic scanning of running images

    The investment in GitOps pays off fast once you’re past the initial setup. The first time you need to answer “what changed?” during a 2 AM incident and the answer is right there in the Git log, you’ll be glad you did it.

    🛠️ Recommended Resources:

    Get daily AI-powered market intelligence. Join Alpha Signal — free market briefs, security alerts, and dev tool recommendations.
    📋 Disclosure: Some links in this article are affiliate links. If you purchase through these links, I earn a small commission at no extra cost to you. I only recommend products I’ve personally used or thoroughly evaluated. This helps support orthogonal.info and keeps the content free.
  • Pod Security Standards: A Security-First Guide

    Pod Security Standards: A Security-First Guide

    Kubernetes Pod Security Standards

    📌 TL;DR: I enforce PSS restricted on all production namespaces: runAsNonRoot: true, allowPrivilegeEscalation: false, all capabilities dropped, read-only root filesystem. Start with warn mode to find violations, then switch to enforce. This single change blocks the majority of container escape attacks.
    🎯 Quick Answer: Enforce Pod Security Standards (PSS) at the restricted level on all production namespaces: require runAsNonRoot, block privilege escalation with allowPrivilegeEscalation: false, and mount root filesystems as read-only.

    Imagine this: your Kubernetes cluster is humming along nicely, handling thousands of requests per second. Then, out of nowhere, you discover that one of your pods has been compromised. The attacker exploited a misconfigured pod to escalate privileges and access sensitive data. If this scenario sends chills down your spine, you’re not alone. Kubernetes security is a moving target, and Pod Security Standards (PSS) are here to help.

    Pod Security Standards are Kubernetes’ answer to the growing need for solid, declarative security policies. They provide a framework for defining and enforcing security requirements for pods, ensuring that your workloads adhere to best practices. But PSS isn’t just about ticking compliance checkboxes—it’s about aligning security with DevSecOps principles, where security is baked into every stage of the development lifecycle.

    Kubernetes security policies have evolved significantly over the years. From PodSecurityPolicy (deprecated in Kubernetes 1.21) to the introduction of Pod Security Standards, the focus has shifted toward simplicity and usability. PSS is designed to be developer-friendly while still offering powerful controls to secure your workloads.

    At its core, PSS is about enabling teams to adopt a “security-first” mindset. This means not only protecting your cluster from external threats but also mitigating risks posed by internal misconfigurations. By enforcing security policies at the namespace level, PSS ensures that every pod deployed adheres to predefined security standards, reducing the likelihood of accidental exposure.

    For example, consider a scenario where a developer unknowingly deploys a pod with an overly permissive security context, such as running as root or using the host network. Without PSS, this misconfiguration could go unnoticed until it’s too late. With PSS, such deployments can be blocked or flagged for review, ensuring that security is never compromised.

    💡 From experience: Run kubectl label ns YOUR_NAMESPACE pod-security.kubernetes.io/warn=restricted first. This logs warnings without blocking deployments. Review the warnings for 1-2 weeks, fix the pod specs, then switch to enforce. I’ve migrated clusters with 100+ namespaces using this process with zero downtime.

    Key Challenges in Securing Kubernetes Pods

    Pod security doesn’t exist in isolation—network policies and service mesh provide the complementary network-level controls you need.

    Securing Kubernetes pods is easier said than done. Pods are the atomic unit of Kubernetes, and their configurations can be a goldmine for attackers if not properly secured. Common vulnerabilities include overly permissive access controls, unbounded resource limits, and insecure container images. These misconfigurations can lead to privilege escalation, denial-of-service attacks, or even full cluster compromise.

    The core tension: developers want their pods to “just work,” and adding runAsNonRoot: true or dropping capabilities breaks applications that assume root access. I’ve seen teams disable PSS entirely because one service needed NET_BIND_SERVICE. The fix isn’t to weaken the policy — it’s to grant targeted exceptions via a namespace with Baseline level for that specific workload, while keeping Restricted everywhere else.

    Consider the infamous Tesla Kubernetes breach in 2018, where attackers exploited a misconfigured pod to mine cryptocurrency. The pod had access to sensitive credentials stored in environment variables, and the cluster lacked proper monitoring. This incident underscores the importance of securing pod configurations from the outset.

    Another challenge is the dynamic nature of Kubernetes environments. Pods are ephemeral, meaning they can be created and destroyed in seconds. This makes it difficult to apply traditional security practices, such as manual reviews or static configurations. Instead, organizations must adopt automated tools and processes to ensure consistent security across their clusters.

    For instance, a common issue is the use of default service accounts, which often have more permissions than necessary. Attackers can exploit these accounts to move laterally within the cluster. By implementing PSS and restricting service account permissions, you can minimize this risk and ensure that pods only have access to the resources they truly need.

    ⚠️ Common Pitfall: Ignoring resource limits in pod configurations can lead to denial-of-service attacks. Always define resources.limits and resources.requests in your pod manifests to prevent resource exhaustion.

    Implementing Pod Security Standards in Production

    Before enforcing pod-level standards, make sure your container images are hardened—start with Docker container security best practices.

    So, how do you implement Pod Security Standards effectively? Let’s break it down step by step:

    1. Understand the PSS levels: Kubernetes defines three Pod Security Standards levels—Privileged, Baseline, and Restricted. Each level represents a stricter set of security controls. Start by assessing your workloads and determining which level is appropriate.
    2. Apply labels to namespaces: PSS operates at the namespace level. You can enforce specific security levels by applying labels to namespaces. For example:
      apiVersion: v1
      kind: Namespace
      metadata:
        name: secure-apps
        labels:
          pod-security.kubernetes.io/enforce: restricted
          pod-security.kubernetes.io/audit: baseline
          pod-security.kubernetes.io/warn: baseline
    3. Audit and monitor: Use Kubernetes audit logs to monitor compliance. The audit and warn labels help identify pods that violate security policies without blocking them outright.
    4. Supplement with OPA/Gatekeeper for custom rules: PSS covers the basics, but you’ll need Gatekeeper for custom policies like “no images from Docker Hub” or “all pods must have resource limits.” Deploy Gatekeeper’s constraint templates for the rules PSS doesn’t cover — in my clusters, I run 12 custom Gatekeeper constraints on top of PSS.

    The migration path I use: Week 1: apply warn=restricted to all production namespaces. Week 2: collect and triage warnings — fix pod specs that can be fixed, identify workloads that genuinely need exceptions. Week 3: move fixed namespaces to enforce=restricted, exception namespaces to enforce=baseline. Week 4: add CI validation with kube-score to catch new violations before they hit the cluster.

    For development namespaces, I use enforce=baseline (not privileged). Even in dev, you want to catch the most dangerous misconfigurations. Developers should see PSS violations in dev, not discover them when deploying to production.

    CI integration is non-negotiable: run kubectl --dry-run=server against a namespace with enforce=restricted in your pipeline. If the manifest would be rejected, fail the build. This catches violations at PR time, not deploy time.

    💡 Pro Tip: Use kubectl explain to understand the impact of PSS labels on your namespaces. It’s a lifesaver when debugging policy violations.

    Battle-Tested Strategies for Security-First Kubernetes Deployments

    Over the years, I’ve learned a few hard lessons about securing Kubernetes in production. Here are some battle-tested strategies:

    • Integrate PSS into CI/CD pipelines: Shift security left by validating pod configurations during the build stage. Tools like kube-score and kubesec can analyze your manifests for security risks.
    • Monitor pod activity: Use tools like Falco to detect suspicious activity in real-time. For example, Falco can alert you if a pod tries to access sensitive files or execute shell commands.
    • Limit permissions: Always follow the principle of least privilege. Avoid running pods as root and restrict access to sensitive resources using Kubernetes RBAC.

    Security isn’t just about prevention—it’s also about detection and response. Build solid monitoring and incident response capabilities to complement your Pod Security Standards.

    Another effective strategy is to use network policies to control traffic between pods. By defining ingress and egress rules, you can limit communication to only what is necessary, reducing the attack surface of your cluster. For example:

    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: restrict-traffic
      namespace: secure-apps
    spec:
      podSelector:
        matchLabels:
          app: my-app
      policyTypes:
      - Ingress
      - Egress
      ingress:
      - from:
        - podSelector:
            matchLabels:
              app: trusted-app
    ⚠️ Real incident: Kubernetes default SecurityContext allows privilege escalation, running as root, and full Linux capabilities. I’ve audited clusters where every pod was running as root with all capabilities because nobody set a SecurityContext. The default is insecure. PSS Restricted mode is the fix — it makes the secure configuration the default, not the exception.

    Future Trends in Kubernetes Pod Security

    Kubernetes security is constantly evolving, and Pod Security Standards are no exception. Here’s what the future holds:

    Emerging security features: Kubernetes is introducing new features like ephemeral containers and runtime security profiles to enhance pod security. These features aim to reduce attack surfaces and improve isolation.

    AI and machine learning: AI-driven tools are becoming more prevalent in Kubernetes security. For example, machine learning models can analyze pod behavior to detect anomalies and predict potential breaches.

    Integration with DevSecOps: As DevSecOps practices mature, Pod Security Standards will become integral to automated security workflows. Expect tighter integration with CI/CD tools and security scanners.

    Looking ahead, we can also expect greater emphasis on runtime security. While PSS focuses on pre-deployment configurations, runtime security tools like Falco and Sysdig will play a crucial role in detecting and mitigating threats in real-time.

    💡 Worth watching: Kubernetes SecurityProfile (seccomp) and AppArmor profiles are graduating from beta. I’m already running custom seccomp profiles that restrict system calls per workload type — web servers get a different profile than batch processors. This is the next layer beyond PSS that will become standard for production hardening.

    Strengthening Kubernetes Security with RBAC

    RBAC is just one layer of a comprehensive security posture. For the full checklist, see our Kubernetes security checklist for production.

    Role-Based Access Control (RBAC) is a cornerstone of Kubernetes security. By defining roles and binding them to users or service accounts, you can control who has access to specific resources and actions within your cluster.

    For example, you can create a role that allows read-only access to pods in a specific namespace:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      namespace: secure-apps
      name: pod-reader
    rules:
    - apiGroups: [""]
      resources: ["pods"]
      verbs: ["get", "list", "watch"]

    By combining RBAC with PSS, you can achieve a full security posture that addresses both access control and workload configurations.

    💡 From experience: Run kubectl auth can-i --list --as=system:serviceaccount:NAMESPACE:default for every namespace. If the default ServiceAccount can list secrets or create pods, you have a problem. I strip all permissions from default ServiceAccounts and create dedicated ServiceAccounts per workload with only the verbs and resources they actually need.
    🛠️ Recommended Resources:

    Tools and books mentioned in (or relevant to) this article:

    main points

    • Pod Security Standards provide a declarative way to enforce security policies in Kubernetes.
    • Common pod vulnerabilities include excessive permissions, insecure images, and unbounded resource limits.
    • Use tools like OPA, Gatekeeper, and Falco to automate enforcement and monitoring.
    • Integrate Pod Security Standards into CI/CD pipelines to shift security left.
    • Stay updated on emerging Kubernetes security features and trends.

    Have you implemented Pod Security Standards in your Kubernetes clusters? Share your experiences or horror stories—I’d love to hear them. Next week, we’ll dive into Kubernetes RBAC and how to avoid common pitfalls. Until then, remember: security isn’t optional, it’s foundational.

    Keep Reading

    More Kubernetes security content from orthogonal.info:

    🛠️ Recommended Tools

    Frequently Asked Questions

    What is Pod Security Standards: A Security-First Guide about?

    Kubernetes Pod Security Standards Imagine this: your Kubernetes cluster is humming along nicely, handling thousands of requests per second. Then, out of nowhere, you discover that one of your pods has

    Who should read this article about Pod Security Standards: A Security-First Guide?

    Anyone interested in learning about Pod Security Standards: A Security-First Guide and related topics will find this article useful.

    What are the key takeaways from Pod Security Standards: A Security-First Guide?

    The attacker exploited a misconfigured pod to escalate privileges and access sensitive data. If this scenario sends chills down your spine, you’re not alone. Kubernetes security is a moving target, an

    References

    1. Kubernetes Documentation — “Pod Security Standards”
    2. Kubernetes Documentation — “Pod Security Admission”
    3. OWASP — “Kubernetes Security Cheat Sheet”
    4. NIST — “Application Container Security Guide”
    5. GitHub — “Pod Security Policies Deprecated”
    📦 Disclosure: Some links in this article are affiliate links. If you purchase through these links, I earn a small commission at no extra cost to you. I only recommend products I’ve personally used or thoroughly evaluated. This helps support orthogonal.info and keeps the content free.

Also by us: StartCaaS — AI Company OS · Hype2You — AI Tech Trends