Automating Deployment with CI/CD in Golang & Kubernetes
Automating Deployment with CI/CD in Golang & Kubernetes...
In recent years, supply-chain attacks have evolved into one of the most critical cybersecurity threats facing organizations today. These attacks don’t directly target your application code. Instead, they attack the third-party dependencies your app relies on, the CI/CD pipeline that builds it, or the containers you deploy it in.
For Go developers, this means ensuring that your CI/CD pipeline from source code repositories to artifact storage is as secure as the application itself.
By 2025, the growing reliance on Go modules, CI tools, and containerization will make Go ecosystems more attractive to cybercriminals looking to exploit the growing attack surface. Let’s explore the biggest threats and how you can secure your Go-based CI/CD pipelines against them.
Go modules have made dependency management easier, but they also make it possible for attackers to target your builds. Supply-chain attackers often inject malicious code into public repositories or even forked projects. Since Go is a language that relies heavily on external modules (e.g., github.com/*), these dependencies are prime targets.
In a typical Go development workflow, CI/CD pipelines are essential for building, testing, and deploying your application. Unfortunately, they also present a prime entry point for malicious actors. A compromised CI pipeline can:
Inject malicious code into your binaries
Alter build steps to steal credentials
Modify the final application without a trace
With regulations like NIST 800-53 and EU Cyber Resilience Act requiring Software Bill of Materials (SBOMs), tracking every dependency and ensuring its authenticity has become crucial. However, the growing complexity of Go dependencies makes it difficult to ensure that no compromised code is making its way into production.
Attackers can upload compromised versions of widely used Go modules to public repositories or other mirrors. When these modules are pulled into your project during the go get process, you may unknowingly integrate malicious code.
Attackers may alter your CI build scripts or introduce backdoor runners to your pipeline. These modifications can steal sensitive data, inject malware, or escalate privileges in your deployment environment.
Cloud-based CI/CD runners that aren’t isolated can pose a significant risk. If attackers gain access to one of these runners, they can execute commands that tamper with your builds, gain access to secrets, or modify source code repositories.
Using public or outdated Docker base images for building Go applications may unknowingly introduce vulnerabilities or compromise your build pipeline. Without validating base images’ integrity, attackers can inject malicious code directly into the build process.
The Go module system includes an important security feature: the Go checksum database (GOSUMDB). By enabling this feature, you ensure that only cryptographically verified modules are used in your project.
go mod verifyTo ensure your dependencies haven’t been tampered with, always pin versions and verify the integrity of your modules. This should be part of your CI/CD pipeline:
This ensures you’re using exactly what you expect, without unintended changes from upstream dependencies.
Go offers the -ldflags flag to make sure your builds are reproducible, preventing attackers from injecting hidden information during the build process:
By trimming build paths and removing sensitive information, you protect against metadata-based attacks.
You can use Sigstore to sign and verify your build artifacts. This ensures that the software you deploy is exactly what you expect, with no tampering during the build process.
Sign your build artifact with Cosign:
Verify in your CI pipeline:
This ensures that your artifacts are secure and verifiable.
Creating and managing SBOMs allows you to track every dependency used in your Go application, helping you identify vulnerabilities before they reach production.
Generate SBOM using Syft:
Then use Grype to scan the SBOM for vulnerabilities:
Your CI/CD runners should be treated as high-security assets. Follow these best practices to harden them:
Use ephemeral runners: Ensure CI runners are created and destroyed per job.
Isolate runners: No shared runners between different projects.
Apply the principle of least privilege to all CI actions.
Use secrets management tools to store sensitive data securely.
For example, in GitHub Actions:
This ensures the right level of access and prevents privilege escalation.
Pin Docker image digests to avoid using outdated or vulnerable versions:
Using multi-stage builds can reduce the attack surface by minimizing the final image:
Use tools like Dependabot to automatically update Go dependencies and ensure you’re always using the latest security patches. Dependabot will create pull requests for outdated dependencies, and you can review and merge them securely.
With supply-chain attacks on the rise, securing your Go CI/CD pipeline has never been more important. By following these best practices:
Enable Go module verification
Pin and verify dependencies
Use reproducible builds
Sign your build artifacts
Implement SBOMs
Harden your CI runners and Docker images
…you ensure that your Go applications stay secure in 2025 and beyond.
Now is the time to build secure, reproducible, and traceable Go applications. Stay ahead of the curve, and secure your supply chain today!