<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thomas Segura</title>
    <description>The latest articles on DEV Community by Thomas Segura (@segudev).</description>
    <link>https://dev.to/segudev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F141347%2Fb91f2fe0-45b4-43a1-8002-190823082da8.png</url>
      <title>DEV Community: Thomas Segura</title>
      <link>https://dev.to/segudev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/segudev"/>
    <language>en</language>
    <item>
      <title>Pipeline Integrity and Security in DevSecOps</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Wed, 05 Jun 2024 13:58:30 +0000</pubDate>
      <link>https://dev.to/gitguardian/pipeline-integrity-and-security-in-devsecops-2p81</link>
      <guid>https://dev.to/gitguardian/pipeline-integrity-and-security-in-devsecops-2p81</guid>
      <description>&lt;p&gt;This is the third blog post in a series that is taking a deep dive into DevSecOps program architecture. The goal of this series is to provide a holistic overview of DevSecOps as a collection of technology-driven, automated processes. Make sure to check out the first and second parts too!&lt;/p&gt;

&lt;p&gt;At this point in the series, we have covered how to manage existing vulnerabilities and how to prevent the introduction of new vulnerabilities. We now have a software development lifecycle (SDLC) that produces software that is secure-by-design. All we have left to cover is how to enforce and protect this architecture that we’ve built.&lt;/p&gt;

&lt;p&gt;In this article, we will be learning how to add integrity and security to the systems involved in our SDLC. These processes should be invisible to our software engineers. They should simply exist as guardrails that ensure the rest of our architecture is utilized and not interfered with.&lt;/p&gt;

&lt;p&gt;With that in mind, I want to reiterate my DevSecOps mission statement:&lt;/p&gt;

&lt;p&gt;“My job is to implement a secure-by-design software development process that empowers engineering teams to own the security for their own digital products. We will ensure success through controls and training, and we will reduce friction and maintain velocity through a technology-driven, automated DevSecOps architecture.”&lt;/p&gt;

&lt;h2&gt;
  
  
  Threat landscape
&lt;/h2&gt;

&lt;p&gt;Whenever we talk about securing something, we need to answer the question, “From what?” Threat modeling is the practice of identifying things that could go wrong based on what we are trying to protect and who/what we are protecting it from. We can’t possibly cover every scenario, but in the context of our DevSecOps architecture there are a handful of threats that we should be considering broadly.&lt;/p&gt;

&lt;p&gt;The diagram below is a threat model of the software development process that I like a lot:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh7-us.googleusercontent.com%2FfkX6Cjuinitl_dpwApv7AOEPfCyaK3V9l6UggI7gyA3-V-99tfYfMNlIVvzZq3rRYznH_bEHn2FXrcZQQnGRIwq7vy-diJ1XI2J_WYZB1KwHm6XXmxIhXf2fv6y32jYGy7apfQEbMO1cAuwkZPftsQ" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh7-us.googleusercontent.com%2FfkX6Cjuinitl_dpwApv7AOEPfCyaK3V9l6UggI7gyA3-V-99tfYfMNlIVvzZq3rRYznH_bEHn2FXrcZQQnGRIwq7vy-diJ1XI2J_WYZB1KwHm6XXmxIhXf2fv6y32jYGy7apfQEbMO1cAuwkZPftsQ" alt="Supply Chain Threats v1.0 (source: OpenSSF)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of the threats listed above, “use compromised dependency” (Threat D) is the most challenging to mitigate. We usually have little control over the external dependencies that we use in our code. The xz utils backdoor was an eye-opening spotlight on the widespread impact that a single compromised dependency can have.&lt;/p&gt;

&lt;p&gt;Unfortunately, malicious insiders in the open-source ecosystem are an unsolved problem at this time. Personally, I don’t think anything will improve until well-resourced consumers of open-source software become more involved in improving the security and support of their open-source dependencies.&lt;/p&gt;

&lt;p&gt;In this article, we will be focusing on the things that we can control. For dependency threats, we can look out for malicious look-alike packages, and we can use SCA tools to identify when we are using outdated, vulnerable versions of our dependencies.&lt;/p&gt;

&lt;p&gt;In the following sections, we will explore ways to mitigate source threats and build threats through integrity checks. Then, we will examine the assumptions we are making about the integrity checks and discuss how we can use security to build trust in those assumptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pipeline integrity
&lt;/h2&gt;

&lt;p&gt;When we think about integrity in software, we often default to thinking of it as signing binaries. In our DevSecOps architecture, we go beyond verifying individual software artifacts. We need to be able to verify the integrity of our pipeline. You might be wondering, “We set up the software development pipeline ourselves… Why would we need to verify its integrity?” It turns out that the assumptions we make about our SDLC can be wrong. We have security gates, but that doesn’t guarantee that we have no gaps.&lt;/p&gt;

&lt;p&gt;In software development environments, there are usually ways to skip steps or bypass controls. For one, it’s common for software engineers to be able to publish artifacts like container images directly to our registry. Even innocent intentions can help vulnerabilities slip around security checks that would have otherwise caught them. In a worse scenario, a compromised developer account could allow a threat actor to push backdoored packages directly to our registry.&lt;/p&gt;

&lt;p&gt;To verify that our software artifacts are the product of the DevSecOps systems that we have in place, we must improve the integrity of our software development pipeline.&lt;/p&gt;

&lt;h3&gt;
  
  
  Branch protection
&lt;/h3&gt;

&lt;p&gt;One of the most important controls in our software development pipeline is branch protection. Branch protection rules protect our integrity against the source threats in our threat model (Figure 1).&lt;/p&gt;

&lt;p&gt;By requiring a Pull Request (PR) to merge code into our production branch, we are ensuring that humans are authorizing changes (Threat A) and verifying that the source code is free from vulnerabilities and backdoors (Threat B). We can also trigger automatic builds when there are changes to our production branch, which will produce builds that come from the source code that has been reviewed (Threat C).&lt;/p&gt;

&lt;h3&gt;
  
  
  Reproducible builds
&lt;/h3&gt;

&lt;p&gt;In the Solarwinds supply chain attack, it was the compromise of Solarwinds’ build servers that led to the injection of the Sunburst backdoor. Injecting malicious code late in the software development pipeline is an effective way to reduce the chance that a human will catch the backdoor.&lt;/p&gt;

&lt;p&gt;In the long run, the best mitigation strategy we have against compromised builds (Threat E) is to make our software builds reproducible. Having reproducible builds means that we can run the same steps against the same source code on a different system and end up with the exact same binary result. We would then have a way to verify that a binary was not tampered with. If we rebuilt and the resulting binary was different, it would raise some questions and warrant investigation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Artifact signing
&lt;/h3&gt;

&lt;p&gt;Signing software has been a common practice for a long time because it provides a way for consumers to verify that the software came from us. This protects software consumers even if our package registry is compromised (Threat G).&lt;/p&gt;

&lt;p&gt;Unfortunately, this still leaves us with a lot of assumptions because a binary signature doesn’t say anything about how the software was built. For example, a software engineer or threat actor might have write access to our container registry and the ability to sign container images. By pushing a locally built container image directly to our registry, they would still be bypassing the automated checks and human reviews that happen in our PRs.&lt;/p&gt;

&lt;h3&gt;
  
  
  SLSA framework
&lt;/h3&gt;

&lt;p&gt;To provide a way for us to verify how and where a piece of software was built, the Open Source Security Foundation (OpenSSF) created the Supply-chain Levels for Software Artifacts (SLSA) framework. What does SLSA do for us in practice? If we reuse the earlier example of a software engineer pushing a container directly to our registry, we could have a verification step before deployment that would detect that the container wasn’t built in our CI pipeline.&lt;/p&gt;

&lt;p&gt;SLSA ranks our software build process on a 0-3 scale to determine how verifiable it is. A whole article could be written about SLSA, but to keep things short, here is a summary of the 4 levels and what they aim to protect against:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Level 0&lt;/strong&gt; – Nothing is done to verify the build process. We don’t have any way to verify who built the software artifact nor how they built it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Level 1&lt;/strong&gt; – Software artifacts are distributed with a provenance that contains detailed information about the build process. Before using or deploying the software, we can use the information in the provenance to make sure that the components, tools, and steps used in the build are what we expect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Level 2&lt;/strong&gt; – The provenance is generated at build time by a dedicated build platform that also signs the provenance. Adding a signature to the provenance allows us to verify that the documentation came from our build platform and hasn’t been forged nor tampered with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Level 3&lt;/strong&gt; – The build platform is hardened to prevent the build process from having access to the secret used to sign the provenance. This means that a tampered build process cannot modify the provenance in a way that would hide its anomalous characteristics.&lt;/p&gt;

&lt;p&gt;At SLSA level 3, we have a way to verify that we aren’t falling for build threats E-H in our threat model (Figure 1). However, you might notice that we start placing some trust in the build platform to be hardened in an adequately secure way.&lt;/p&gt;

&lt;p&gt;Trust in the platforms that make up our SDLC is one of the guiding principles of SLSA. The purpose of SLSA is to verify that our software artifacts came from the expected systems and processes rather than individuals with write access to our package registries. How do we build trust in the systems that produce our software? By securing them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pipeline security
&lt;/h2&gt;

&lt;p&gt;Our DevSecOps architecture is technology-driven, which means there are multiple systems that compose our software development pipeline. At this point in our DevSecOps journey, we have confidence that our SDLC is producing reasonably secure software, and we have ways to verify that our pipeline is being used and not skipping steps. The final threat we have to deal with is the compromise of our deployed services or the systems involved in our software development pipeline.&lt;/p&gt;

&lt;h3&gt;
  
  
  Securing development systems
&lt;/h3&gt;

&lt;p&gt;If a system involved in development or CI gets compromised by a threat actor, they may be able to inject backdoors into our software, steal secrets from our development environment, or even steal data from the downstream consumers of our software by injecting malicious logic. It’s common for us to put a lot of energy into securing the production systems that we deploy our software to, but we need to treat the systems that build our software like they are also production systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Workstation security
&lt;/h3&gt;

&lt;p&gt;On the “left” side of our SDLC, our developers are writing code on their workstations. This isn’t an article about enterprise security, but endpoint protection solutions such as antivirus and EDR play an important role in securing these systems. If we are concerned about our source code being leaked or exfiltrated, we might also consider data-loss prevention (DLP) tools or user and entity behavior analytics (UEBA).&lt;/p&gt;

&lt;h3&gt;
  
  
  Remote development
&lt;/h3&gt;

&lt;p&gt;If we want to go a step further in protecting our source code, we can create remote development environments that our developers use to write the code. Development tools like Visual Studio Code and Jetbrains IDEs support connecting to remote systems for remote development. This is not the same thing as dev containers which can run on our local host. Remote development refers to connecting our IDE to a completely separate development server that hosts our source code.&lt;/p&gt;

&lt;p&gt;This isolation of the software development process separates our source code from high-risk activity like email and browsing the internet. We can combine remote development with a zero-trust networking solution that requires human verification (biometrics, hardware keys, etc) to connect to the remote development environment. If a developer’s main device gets compromised, remote development makes it much harder to steal or tamper with the source code they have access to.&lt;/p&gt;

&lt;p&gt;Remote development obviously adds friction to the software development process, but if our threat model requires it, this is a very powerful way to protect our source code at the earliest stages of development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build platform hardening
&lt;/h3&gt;

&lt;p&gt;The SolarWinds supply chain attack that we covered earlier is a prime example of why we need to treat build systems with great scrutiny. Reproducible builds are a way to verify the integrity of our build platform, but we still want to secure these systems to the best of our ability.&lt;/p&gt;

&lt;p&gt;Similarly to workstation security, endpoint protection and other enterprise security solutions can help monitor and protect our build platform. We can also take additional steps like limiting administrator access to the build platform and restricting file system permissions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Securing deployment systems
&lt;/h3&gt;

&lt;p&gt;If our software is deployed as a service for others to use, we need to make sure that we are securing our deployment systems. A compromised service can leak information about our users and allow a threat actor to pivot to other systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Zero-trust networking
&lt;/h3&gt;

&lt;p&gt;A powerful control against the successful exploitation of our applications is restricting outbound network access. Historically, it’s been very common for public-facing applications to be in a DMZ, a section of our internal network that can’t initiate outbound network connections to the internet or any other part of our network (except for maybe a few necessary services). Inbound connections from our users are allowed through, but in the event of a remote code execution exploit, the server is unable to download malware or run a reverse shell.&lt;/p&gt;

&lt;p&gt;If we use Kubernetes for our container workloads, we can utilize modern zero-trust networking tools like Cilium to connect our services and disallow everything else. Cilium comes with a UI called Hubble that visualizes our services in a diagram to assist us in building and troubleshooting our network policies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Privilege dropping and seccomp
&lt;/h3&gt;

&lt;p&gt;If we run our services inside Linux containers, we can easily limit their access to various system resources. Seccomp is a Linux kernel feature that works with container runtimes to restrict the syscalls that can be made to the kernel. By default, most container deployments run using “Unconfined” (seccomp disabled) mode.&lt;/p&gt;

&lt;p&gt;At a minimum, we can use the “RuntimeDefault” seccomp filter in Kubernetes workloads to utilize the default seccomp profile of our container runtime. Here is an example of the syscalls blocked by Docker’s default seccomp filter. The list of syscalls in a default filter are typically blocked to prevent privilege escalation from the container to the host. There may be certain low-level or observability workloads that do need to run “unconstrained,” but in general, the default seccomp filter is intended to be safe for most applications.&lt;/p&gt;

&lt;p&gt;If we wanted to be even more restrictive, we could create our own seccomp filters that only allow the syscalls needed by our application. In some cases, restricting syscalls at this level could even prevent the successful exploitation of a vulnerable system. I did a talk on this back in 2022 that explains how to automate the creation of seccomp allowlist filters in a way that fits nicely into existing DevOps workflows. Be aware, however, that seccomp allowlist filters can introduce instability into our application if we aren’t performing the necessary testing when creating the filter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Container drift monitoring
&lt;/h3&gt;

&lt;p&gt;Another powerful security feature that container deployments enable is container drift monitoring. Many container applications are “stateless,” which means that we wouldn’t expect them to be changing in any way. We can take advantage of this expectation and monitor our stateless containers for any drift from their default state using tools like Falco. When a stateless container starts doing things that it wouldn’t normally do, it could indicate that our app has been exploited.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identity
&lt;/h2&gt;

&lt;p&gt;Lastly, let’s look at a few identity-related practices that can meaningfully improve the security of the systems in our software development pipeline.&lt;/p&gt;

&lt;h3&gt;
  
  
  Secrets management
&lt;/h3&gt;

&lt;p&gt;There is a lot of complexity in DevSecOps around identity and access management because we are dealing with both human and machine identities at multiple stages of our SDLC. When our services talk to one another, they need access to credentials that will let them in.&lt;/p&gt;

&lt;p&gt;Managing the lifecycle of these credentials is a bigger topic than what we will be covering here, but having a strategy for secret management is one of the most important things we can do for the security of the systems in our SDLC. For detailed advice on this topic, check out GitGuardian’s secret management maturity model whitepaper.&lt;/p&gt;

&lt;h3&gt;
  
  
  Leaked secret prevention
&lt;/h3&gt;

&lt;p&gt;No matter how mature our secret management process is, secrets always seem to find a way into places they shouldn’t be. Whether they are in source code, Jira tickets, chats, or anywhere else, it’s impossible to prevent all our secrets from ever being exposed. For that reason, it’s important to be able to find secrets where they shouldn’t be and have a process to rotate leaked secrets so they are no longer valid.&lt;/p&gt;

&lt;h3&gt;
  
  
  Honeytokens
&lt;/h3&gt;

&lt;p&gt;Leaked secrets are a very sought-after target for threat actors because of their prevalence and impact. We can take advantage of this temptation and intentionally leak special secrets called honeytokens that would never be used except by malicious hackers that are looking for them. By putting honeytokens in convincing locations like source code and Jira tickets, we are setting deceptive traps with high-fidelity alerts that catch even the stealthiest attackers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Others
&lt;/h3&gt;

&lt;p&gt;We could list more ways to secure our infrastructure, but, like I said earlier, this isn’t an article about enterprise security. The topics we covered were included because of the special considerations we must take in the context of the software development environment.&lt;/p&gt;

&lt;p&gt;Ultimately, collaboration between product and enterprise security is an important factor in protecting the integrity of our DevSecOps architecture. It is our collective duty to prevent threats from impacting us and those downstream who use our software products.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;DevSecOps architecture is driven by the technologies involved in the development process. Securing these systems builds trust in our software development pipeline, and adding ways to verify the integrity of our pipeline is what ultimately allows us to mitigate many of the supply-chain threats that we and our customers face.&lt;/p&gt;

&lt;p&gt;There will always be new things to learn and new ways to iterate on these strategies. The DevSecOps architecture described in this series is meant to provide a holistic and modern approach to application security that can be built upon. I hope that you are leaving with goals that will set your development teams up for success in securing their digital products.&lt;/p&gt;

</description>
      <category>devsecops</category>
      <category>security</category>
      <category>cybersecurity</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Secure-by-Design Software in DevSecOps</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Wed, 22 May 2024 12:56:46 +0000</pubDate>
      <link>https://dev.to/gitguardian/secure-by-design-software-in-devsecops-4459</link>
      <guid>https://dev.to/gitguardian/secure-by-design-software-in-devsecops-4459</guid>
      <description>&lt;p&gt;This is the second blog post in a series that is taking a deep dive into DevSecOps program architecture. The goal of this series is to provide a &lt;strong&gt;holistic&lt;/strong&gt; overview of DevSecOps as a collection of &lt;strong&gt;technology-driven, automated processes&lt;/strong&gt;. If you didn’t read &lt;a href="https://blog.gitguardian.com/vulnerability-management-lifecycle-in-devsecops/"&gt;&lt;u&gt;the first blog post&lt;/u&gt;&lt;/a&gt;, make sure to check that out too! &lt;/p&gt;

&lt;p&gt;This entry will be less about the “decision-making” side of things, and more about the developer experience. We will learn how to equip our software engineers with the tools they need to successfully own the security for their own code, and how to support them through automation. Before getting started here, I want to reiterate my mission statement for DevSecOps:&lt;/p&gt;

&lt;p&gt;“My job is to implement a secure-by-design software development process that empowers engineering teams to own the security for their own digital products. We will ensure success through controls and training, and we will reduce friction and maintain velocity through a technology-driven, automated DevSecOps architecture.”&lt;/p&gt;

&lt;h2&gt;
  
  
  What does “secure-by-design” mean?
&lt;/h2&gt;

&lt;p&gt;In this blog post, we will be constructing a process that makes our applications &lt;strong&gt;“secure-by-design”&lt;/strong&gt;. This means that our software development lifecycle (SDLC) includes security as &lt;em&gt;part of the development process&lt;/em&gt;, which guarantees a minimum level of security for every software product it produces.&lt;/p&gt;

&lt;p&gt;Through this strategy, our digital products will have gone through rigorous security testing by the time they are published, and we will have caught many vulnerabilities before anything is made available to customers.&lt;/p&gt;

&lt;p&gt;In DevSecOps, there are 2 key components in our software development pipeline that support our secure-by-design strategy: Security Gates and Automation. These 2 components work together to enforce a security baseline while preserving efficiency. Just like last time, we will be building a diagram to visualize how this process works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Software development pipeline
&lt;/h2&gt;

&lt;p&gt;In DevSecOps, we build our security practices on top of our existing software development practices. For the purposes of this blog post, we will say that our example organization produces container-based apps deployed through Kubernetes. These are the high-level artifacts or steps in our example pipeline:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jiNhN-GA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps-2-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jiNhN-GA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps-2-1.png" alt="Example pipeline" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your development process may look different, but as we go, you’ll find that many of the concepts will be transferable to whatever you’re working with. Let’s break each stage down briefly before moving on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Uncommitted Code
&lt;/h3&gt;

&lt;p&gt;The software development pipeline begins with the software engineer drafting &lt;strong&gt;new code&lt;/strong&gt; or modifying the application. This typically happens on the developer’s local workstation. From there, the code is added to the git history using the “&lt;strong&gt;git commit&lt;/strong&gt;” command.&lt;/p&gt;

&lt;h3&gt;
  
  
  Committed Code
&lt;/h3&gt;

&lt;p&gt;Once the code has been committed to git, it now exists in our repository’s history forever. We can make additional changes, but the old commits are still able to track how our code changed over time. This becomes important later. At some point, we will “&lt;strong&gt;git push&lt;/strong&gt;” our code to our git hosting provider. In this case, that’s GitHub.&lt;/p&gt;

&lt;h3&gt;
  
  
  GitHub Dev Branch
&lt;/h3&gt;

&lt;p&gt;It’s not good practice to make changes directly on your production (prod) branch, so we have a different development (dev) branch to push our code to first. Once our code is ready to be published, we will open a &lt;strong&gt;Pull Request&lt;/strong&gt; to review and merge the changes from the dev branch into our prod branch.&lt;/p&gt;

&lt;h3&gt;
  
  
  GitHub Prod Branch
&lt;/h3&gt;

&lt;p&gt;If the code passes review in the Pull Request from the dev branch, it is ready to be published as a container. We will &lt;strong&gt;build a container image&lt;/strong&gt; with our code and publish the image to our container registry.&lt;/p&gt;

&lt;h3&gt;
  
  
  Container Registry
&lt;/h3&gt;

&lt;p&gt;In the container registry, our software sits frozen as an image waiting to be deployed. Our example organization uses Kubernetes for orchestration to &lt;strong&gt;deploy the container(s)&lt;/strong&gt; to run our app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment
&lt;/h3&gt;

&lt;p&gt;Once we’ve deployed our app, it is running and exposed to the internet. Years ago, this was where most organizations would start doing vulnerability assessments of their applications. This means any major security issue would require that we start all the way back from the beginning and go through the entire process again.&lt;/p&gt;

&lt;p&gt;That’s obviously not very efficient, so over time, new tools were created to help developers shift security “left” in the pipeline and catch vulnerabilities earlier. Unfortunately, these tools have only been marginally effective, and vulnerable software is still extremely common. If we have the tools to tell us what is vulnerable and things still aren’t getting better, what are we doing wrong?&lt;/p&gt;

&lt;p&gt;I theorize that our problem with secure software development lies with our requirements. &lt;strong&gt;The ONLY requirement for software development has traditionally been that the app meets our functionality needs&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To make software that is secure-by-design, &lt;strong&gt;we need to redefine what “production-ready” means for our digital products&lt;/strong&gt;. We must agree upon some minimum level of security and guarantee that we are meeting those standards through &lt;strong&gt;Security Gates&lt;/strong&gt; that prevent us from moving on until we have met our security requirements. This leads us to the first key component of our DevSecOps pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Security gates
&lt;/h2&gt;

&lt;p&gt;To guarantee security in our software development pipeline, we will be adding scans or checks to each step of the process. Each of these scans will be automated to make sure that they can’t be forgotten.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scanner Types
&lt;/h3&gt;

&lt;p&gt;In the &lt;a href="https://blog.gitguardian.com/vulnerability-management-lifecycle-in-devsecops/"&gt;&lt;u&gt;last blog post&lt;/u&gt;&lt;/a&gt;, we covered many types of vulnerability scanners in the “Identification” stage of our process diagram. The same types of scanners will be used in the security gates we are about to cover, though we use them differently here.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;vulnerability management lifecycle&lt;/strong&gt; from last time, our security scanners were cataloging &lt;em&gt;historical, previously introduced vulnerabilities&lt;/em&gt; in our software. In our &lt;strong&gt;security gates&lt;/strong&gt;, we are mostly concerned with preventing the introduction of &lt;em&gt;new vulnerabilities&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;There’s one more distinction in how we are implementing the scanners here that I talked about briefly in the last post. Rather than making our software engineers context-switch and look at some web dashboards to see their vulnerabilities, we will be integrating our security scanners with the tools they already use. By doing this, we are showing them vulnerabilities &lt;em&gt;where they’re relevant&lt;/em&gt;, and &lt;em&gt;when they’re relevant&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;With that out of the way, let’s jump into the different types of security gates that we can set up in our pipeline. Below is the next part of our diagram which shows the interactions between our traditional pipeline and our security gates.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q40iU_RL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps-1-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q40iU_RL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps-1-1.png" alt="Security gates along the development pipeline&amp;lt;br&amp;gt;
" width="800" height="1215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, rather than moving directly from one stage of our pipeline to the next, our software now has to pass an automated security check before it can progress. We can set whatever we want as our threshold for failure, but ultimately, a failure will require us to fix vulnerabilities before we can move on.&lt;/p&gt;

&lt;p&gt;Now, let’s go into detail on what each type of security gate looks like. We’re going to start slightly out of order, but it will be clear why in a moment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pull Request checks
&lt;/h3&gt;

&lt;p&gt;Pull Request (PR) checks are one of the most critical pieces in our secure-by-design SDLC because &lt;strong&gt;PRs are the first place in our pipeline where we can truly guarantee that security checks are happening&lt;/strong&gt;. Prior to the code being in GitHub, everything is happening on our local workstations. We trust our software engineers, but we can never be 100% sure that they aren’t disabling security checks or using personal devices to write code. We &lt;em&gt;do&lt;/em&gt; know that we have full control of the GitHub repository, though.&lt;/p&gt;

&lt;p&gt;By configuring &lt;a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/managing-a-branch-protection-rule?ref=blog.gitguardian.com"&gt;&lt;u&gt;branch protection rules&lt;/u&gt;&lt;/a&gt;, we can force all code to go through a Pull Request before transitioning from our “development” branch to our “production” branch. In DevSecOps, we use PRs as an opportunity to run various security checks and require them to pass before the code can be merged.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pre-commit and pre-push hooks
&lt;/h3&gt;

&lt;p&gt;Even though the Pull Request is the first enforceable security gate, we should still try to help our developers out by shifting checks further “left” to catch things even earlier in the process. Pre-commit and pre-push hooks are automated actions that run when we execute a “git commit” or “git push” command.&lt;/p&gt;

&lt;p&gt;As a security gate on our software engineer’s workstations, we can configure pre-commit &lt;em&gt;or&lt;/em&gt; pre-push hooks. I emphasize the word “or” because the two hook types are redundant if all we want to accomplish is passing security checks before pushing our code to GitHub.&lt;/p&gt;

&lt;p&gt;There are reasons to use one or the other depending on what type of scan we’re talking about. For example, we can &lt;a href="https://blog.gitguardian.com/setting-up-a-pre-commit-git-hook-with-gitguardian-shield-to-scan-for-secrets/"&gt;set up a hook for discovering leaked secrets&lt;/a&gt;. A &lt;em&gt;pre-push&lt;/em&gt; hook won’t detect a leaked secret until it has already been committed to the git history. At that point, it might be difficult to undo our commits and we may have to revoke and rotate the secret.&lt;/p&gt;

&lt;p&gt;We can save ourselves from all that extra work by configuring our secret scanner as a &lt;em&gt;pre-commit&lt;/em&gt; hook, which prevents our code from entering the git history until it is free from secrets. This is a great example of &lt;strong&gt;why we need security gates at multiple steps of the software development pipeline&lt;/strong&gt;. We can’t guarantee or perform some scans until later, but it saves us time to catch things as early as possible.&lt;/p&gt;

&lt;p&gt;On the other hand, pre-push hooks might make more sense for SAST or SCA scanners. One of the software engineers I work with once gave me feedback that overdoing pre-commit hooks can cause you to be unable to commit the code you are working on. Especially when you are trying to commit a lot of new code all at once. By using pre-push hooks instead of pre-commit, we are allowed to commit code with vulnerabilities and still use the version control functionality of git. Then, we just fix any issues before pushing to GitHub.&lt;/p&gt;

&lt;p&gt;The debate of pre-commit versus pre-push hooks is arguable other than secret scans. My recommendation is to have security and software engineering teams collaborate and agree on what makes the most sense. The key thing to remember is that &lt;strong&gt;performing the same scan at different stages of the SDLC is helpful&lt;/strong&gt;, not unnecessary.&lt;/p&gt;

&lt;h3&gt;
  
  
  Container image scans
&lt;/h3&gt;

&lt;p&gt;Now let’s get back on track in our software development pipeline. We’ve merged a Pull Request that passed the security gates in our PR checks. Now the code has been merged into our “prod” branch, and we are ready to build the container image that will run our application. If you have multiple environments, this same thing might occur in your “dev” branch. This security gate will look the same either way.&lt;/p&gt;

&lt;p&gt;In this example, we will build and publish our container image using an automated workflow. After the step of our workflow that builds the image, we can run a container scanner that will fail the build if it finds vulnerable dependencies in our image that exceed our severity threshold. If the scan passes, our workflow publishes the image to our container registry, where it waits to be deployed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Kubernetes admission controller
&lt;/h3&gt;

&lt;p&gt;The last security gate in our example pipeline is a &lt;a href="https://kubernetes.io/blog/2019/03/21/a-guide-to-kubernetes-admission-controllers/?ref=blog.gitguardian.com"&gt;&lt;u&gt;Kubernetes admission controller&lt;/u&gt;&lt;/a&gt;. Admission controllers are just plugins that validate or even modify the instructions given to our Kubernetes cluster. The capabilities of the admission controller depend on the plugins.&lt;/p&gt;

&lt;p&gt;In our example pipeline, our admission controller is scanning the container images being deployed for critical dependency vulnerabilities that may have been introduced since the container was built. We could also enforce configuration policies that prevent unsafe settings from our infrastructure-as-code (IaC).&lt;/p&gt;

&lt;p&gt;If our admission controller plugins pass all their validations, our application finally reaches deployment. Having gone through each of the security gates we covered along the way, we can now be confident that our application meets the minimum security level that we configured in our security gates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Assisting with automation
&lt;/h3&gt;

&lt;p&gt;At this point, you’re probably thinking, “This is adding a lot of hassle to getting to deployment.” You’re not wrong, but you should remember that we are redefining what “production-ready” means so we can improve the security of our apps. Luckily for us, this isn’t the end of the post. Now comes the part where we look at the other key component of our DevSecOps pipeline that aims to assist developers and protect our velocity: &lt;strong&gt;Continuous Automation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Our goal for Continuous Automation is to provide software engineers with assistive technology that produces automated feedback and security fixes. This will &lt;strong&gt;reduce the time and cognitive load&lt;/strong&gt; needed to meet our new security requirements. Just like our security gates, we want to utilize technologies that operate where work is already being done to reduce context-switching. Below is our final process diagram, to which we have added the Continuous Automation column:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ueQPLKL9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps--3-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ueQPLKL9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps--3-.png" alt="Continuous automation added" width="800" height="1215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  IDE Plugins
&lt;/h3&gt;

&lt;p&gt;The IDE is as far “left” as we can get when providing vulnerability feedback – it’s where our software engineers are writing the code! By using security scanners as IDE plugins, we can get instant feedback in the linter and see issues in the code we are already working on. We can have all sorts of security scans take place in our IDEs: SAST, SCA, Secrets, IaC, etc… Also, these plugins will work the same whether the code has been committed or not.&lt;/p&gt;

&lt;h3&gt;
  
  
  Local container image scan
&lt;/h3&gt;

&lt;p&gt;Because container images aren’t built until the later stages of our software development pipeline, they don’t get stopped by a security gate until quite far into the process. The further “right” we are when an issue is discovered, the more time-consuming it is for us to fix it.&lt;/p&gt;

&lt;p&gt;To reduce the number of times we get stopped by a container image scan late in our security gates, we need to give our software engineers the ability to run the &lt;em&gt;same&lt;/em&gt; container image scans locally on their workstations in the earliest stages of development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Automated Dependency Updates
&lt;/h3&gt;

&lt;p&gt;Out of everything in our DevSecOps pipeline, one of the most challenging things we have to deal with is the constant discovery of vulnerabilities in our dependencies. Our software can pass through all our security gates and reach deployment, only to have a critical vulnerability discovered in some component that our app uses the very next day. While our software engineers can prevent the introduction of many types of vulnerabilities, this will always be something that they have to deal with. This problem can be helped by using &lt;a href="https://www.chainguard.dev/unchained/minimal-container-images-towards-a-more-secure-future?ref=blog.gitguardian.com"&gt;&lt;u&gt;minimal container base images&lt;/u&gt;&lt;/a&gt; that have fewer packages, but we will always have some dependencies.&lt;/p&gt;

&lt;p&gt;To make this ongoing challenge easier and less time consuming, we must use tools that automate dependency updates for us. We can use SCA and Container Image scanners to identify vulnerable dependencies in our runtimes, container registries, and/or git branches. Robust dependency scanners will have the option to automatically create Pull Requests that update the vulnerable packages to a fixed version. Then, all we need to do is accept the fix and merge the PR.&lt;/p&gt;

&lt;h3&gt;
  
  
  Others
&lt;/h3&gt;

&lt;p&gt;As technology evolves, there may be new ways to automate security fixes. For example, security researcher &lt;a href="https://github.com/JLLeitschuh?ref=blog.gitguardian.com"&gt;&lt;u&gt;Jonathan Leitschuh&lt;/u&gt;&lt;/a&gt; has used &lt;a href="https://codeql.github.com/?ref=blog.gitguardian.com"&gt;&lt;u&gt;CodeQL&lt;/u&gt;&lt;/a&gt; and &lt;a href="https://github.com/openrewrite/rewrite?ref=blog.gitguardian.com"&gt;&lt;u&gt;OpenRewrite&lt;/u&gt;&lt;/a&gt; to automate vulnerability discovery and patches across many open-source repositories. There is also a chance that we can use future AI models to find and/or fix vulnerabilities in our code for us. Ultimately, our goal is to help developers work less while maintaining security. Any chance we get to do that will be a huge win for DevSecOps and the security of our software.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reducing friction
&lt;/h2&gt;

&lt;p&gt;Now, we’ve covered the entire process of creating a secure-by-design software development pipeline. Before wrapping up, I’d like to provide some final advice from my experiences in implementing this architecture at my own company.&lt;/p&gt;

&lt;h3&gt;
  
  
  Importance of consistency
&lt;/h3&gt;

&lt;p&gt;Throughout this blog post and the last one, I’ve mentioned the importance of reducing context switching. Application security is a complex problem, even for those of us who dedicate our entire career to it. To simplify things for our non-security collaborators, &lt;strong&gt;the implementation of our DevSecOps architecture needs to be as consistent as possible&lt;/strong&gt;. There are two main ways to accomplish this.&lt;/p&gt;

&lt;p&gt;The first way to provide a consistent security experience for our software engineers is to &lt;strong&gt;ensure that our scan results are the same at every stage of the SDLC&lt;/strong&gt;. If we use a specific container image scanner in our Kubernetes admission controller, we need to make sure that our software engineers have access to the &lt;em&gt;same scan&lt;/em&gt; on their local workstation and build workflow. They need to be getting the &lt;em&gt;same information&lt;/em&gt; in the &lt;em&gt;same format&lt;/em&gt; so there are no surprises in the later stages of our software development pipeline.&lt;/p&gt;

&lt;p&gt;The other way to drive consistency in our DevSecOps implementation is to &lt;strong&gt;consolidate scanning tools where possible&lt;/strong&gt;. In our last blog post, we discussed how no one tool is the best at scanning for every type of vulnerability. But if we have the option of using the same provider for a few of our scans (e.g., SAST, SCA, and Container) rather than having a different tool for each one, it will reduce management overhead and provide a more consistent experience for our software engineers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Order of operations
&lt;/h3&gt;

&lt;p&gt;Lastly, I wanted to provide some generalized guidance on what order we should go about implementing the various components in our process diagram. The first thing you should do is help your software engineers get familiar with the security tooling and vulnerability scans. Take the time to help them get their IDE plugins set up, show them how to address false positive findings, set expectations and timelines, configure automated dependency fixes, and &lt;strong&gt;gather feedback&lt;/strong&gt; about all the tools.&lt;/p&gt;

&lt;p&gt;Once your software engineers are familiar with the tools and findings, start implementing warnings in your security gates. Don’t go blocking things right away, just display warnings for the things that would cause blocks in the future. &lt;strong&gt;Gather feedback&lt;/strong&gt; about the warnings.&lt;/p&gt;

&lt;p&gt;Finally, meet with leaders on the software engineering side and agree upon severity thresholds that will be blocking based on the feedback from the warnings and the perceived workload increase. Maybe start with PR checks and work from there on the rest.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There are a lot of technologies involved in the implementation of our secure-by-design SDLC. As we evaluate new code security tools, we should be trying to answer these questions to find the right fit for our DevSecOps architecture:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  How and where can we use this tool as a required security gate?&lt;/li&gt;
&lt;li&gt;  How can we automate fixes or feedback with this tool to protect our velocity while meeting security requirements?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the answer to either of these questions suggests that the tool won’t work well with our goals, it may be worth checking out alternatives to see if any can do these things.&lt;/p&gt;

&lt;p&gt;Implementing a secure-by-design SDLC is a complex challenge. But by leveraging technology and automation, we can guarantee that our digital products meet a minimum level of security without much drag on our ability to deliver. Here is &lt;a href="https://lucid.app/documents/view/429eb71f-a389-4a11-a545-b46f3ac5f2b5?ref=blog.gitguardian.com"&gt;&lt;u&gt;the template for the process diagram&lt;/u&gt;&lt;/a&gt; from this post, so you can use it to track your own progress.&lt;/p&gt;

&lt;p&gt;This concludes the second entry in this series on DevSecOps architecture. The next post will be the final entry, where we will be exploring how to protect the security and integrity of the systems involved in our SDLC.&lt;/p&gt;

</description>
      <category>devsecops</category>
      <category>security</category>
      <category>cybersecurity</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Vulnerability Management Lifecycle in DevSecOps</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Thu, 25 Apr 2024 09:45:28 +0000</pubDate>
      <link>https://dev.to/gitguardian/vulnerability-management-lifecycle-in-devsecops-3opi</link>
      <guid>https://dev.to/gitguardian/vulnerability-management-lifecycle-in-devsecops-3opi</guid>
      <description>&lt;p&gt;This is the first blog post in a series that will take a deep dive into DevSecOps program architecture. The goal of this series is to provide a holistic overview of DevSecOps as a collection of technology-driven, automated processes. What are the tools and technologies that play a role in DevSecOps? How can we use technology to set software engineering teams up for success? How do we align roles and responsibilities to ensure cohesion, safety, and velocity? These are some of the questions that will be answered as we progress through the series.&lt;/p&gt;

&lt;p&gt;I’ve spent the last 3 years in my professional role building the DevSecOps program at my company from the ground up. There will be parts of this series that may not apply directly to your company, but the themes and overall approach may still be valuable to you. The following mission statement summarizes my approach to DevSecOps:&lt;/p&gt;

&lt;p&gt;“My job is to implement a secure-by-design software development process that empowers engineering teams to own the security for their own digital products. We will ensure success through controls and training, and we will reduce friction and maintain velocity through a technology-driven, automated DevSecOps architecture.”&lt;/p&gt;

&lt;h2&gt;
  
  
  Vulnerability management overview
&lt;/h2&gt;

&lt;p&gt;In this post, we will be examining how technology can support the “people and processes” side of DevSecOps. Controls and automation will increasingly play a role in this series, but we need to start by defining the roles and responsibilities of the humans involved.&lt;/p&gt;

&lt;p&gt;At its core, DevSecOps is about managing vulnerabilities within software products. Some of these vulnerabilities are introduced by the software engineers creating the product, and others come from third-party dependencies that teams have little control over. The work needed to remediate these vulnerabilities must compete with other work like new features and bug fixes. In this blog post, we will look at a technology-driven vulnerability management lifecycle that allows informed decisions to be made about work selection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stages of vulnerability management
&lt;/h2&gt;

&lt;p&gt;The vulnerability management process can be broken down into 3 stages: Identification, Observability, and Management. Each stage is critical for the success of the next one. Below is a simplified diagram that we will add to as we go through this article. Technology plays a central role in each stage, but humans are an important part of this process as well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps-4.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.gitguardian.com%2Fcontent%2Fimages%2F2024%2F04%2FVulnerability-Management-Lifecycle-in-DevSecOps-4.png" alt="Stages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The 3 stages of the vulnerability management process&lt;/p&gt;

&lt;h2&gt;
  
  
  Identification
&lt;/h2&gt;

&lt;p&gt;This probably goes without saying, but you can’t fix vulnerabilities that you aren’t aware of. Identifying vulnerabilities is a complex challenge, though. It’s not just a matter of scanning source code; there are many artifacts in the layers of a software product that require their own type of vulnerability scanner.&lt;/p&gt;

&lt;p&gt;The first stage of our diagram is a list of places in the software development lifecycle (SDLC) where vulnerabilities or misconfigurations can arise, as well as the types of vulnerability scanning tools that can identify security issues in these areas. Here’s a quick rundown of each area:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps-1.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.gitguardian.com%2Fcontent%2Fimages%2F2024%2F04%2FVulnerability-Management-Lifecycle-in-DevSecOps-1.png" alt="Identification"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Version Control System
&lt;/h4&gt;

&lt;p&gt;GitHub is an example of a VCS, and it is often overlooked as an area that can create security risks. Things like &lt;a href="https://blog.gitguardian.com/github-actions-security-cheat-sheet/" rel="noopener noreferrer"&gt;&lt;u&gt;misconfigured actions&lt;/u&gt;&lt;/a&gt; and poor access control can allow attackers to gain read access to internal code or even the ability to inject malicious code.&lt;/p&gt;

&lt;h4&gt;
  
  
  Code
&lt;/h4&gt;

&lt;p&gt;In this context, “Code” refers to the custom code that was written by the software engineers at your own company. Vulnerability scanners such as SAST and DAST (Static/Dynamic Application Security Testing) can identify various vulnerabilities that were accidentally created in the code. But &lt;a href="https://blog.gitguardian.com/why-sast-dast-cant-be-enough/" rel="noopener noreferrer"&gt;&lt;u&gt;they can’t catch everything&lt;/u&gt;&lt;/a&gt;, which is why we have other specialized tools for vulnerability identification.&lt;/p&gt;

&lt;h4&gt;
  
  
  Secrets
&lt;/h4&gt;

&lt;p&gt;Finding and preventing leaked secrets is what GitGuardian is all about. Hackers and red teamers regularly find secrets in plain text that allow them to elevate their access. Identifying leaks and prioritizing their cleanup is a critical piece of DevSecOps.&lt;/p&gt;

&lt;h4&gt;
  
  
  Dependencies/SBOM
&lt;/h4&gt;

&lt;p&gt;SBOM stands for Software Bill of Materials, and it refers to a document containing all the third-party dependencies in your code. Why would you want to track software dependencies? New vulnerabilities emerge every day in open-source code. If your software uses a vulnerable dependency, it may also be exploitable. Software Composition Analysis (SCA) tools identify vulnerabilities in the dependencies you use.&lt;/p&gt;

&lt;h4&gt;
  
  
  IaC
&lt;/h4&gt;

&lt;p&gt;Infrastructure-as-Code (IaC) refers to deployment code such as Terraform or Kubernetes that declaratively defines how your deployment will be configured. IaC scanners identify security misconfigurations and unsafe exposure in your planned deployments.&lt;/p&gt;

&lt;h4&gt;
  
  
  Containers
&lt;/h4&gt;

&lt;p&gt;Containers add another layer of dependencies to your software, because they provide all the operating system programs that your code needs to run. These added dependencies can also introduce security issues into the runtime of your application. Container image scanners help you identify these kinds of issues.&lt;/p&gt;

&lt;h4&gt;
  
  
  Deployment
&lt;/h4&gt;

&lt;p&gt;Application deployments are the final area that we will cover. If you run your app in the cloud, you can use Cloud-Native Application Protection Platform (CNAPP) or Cloud Security Posture Management (CSPM) tools to identify misconfigurations and known vulnerabilities in your deployed application. Pentesting your live applications is another way to find previously undiscovered vulnerabilities. Human-operated security testing is the only way to find some kinds of vulnerabilities, such as business logic flaws.&lt;/p&gt;

&lt;p&gt;This list may not be exhaustive, and new threats and tools are emerging all the time. But this highlights the plethora of vulnerability types that we’re dealing with. The complexity of security scanners is the &lt;strong&gt;first major challenge of vulnerability management&lt;/strong&gt;. There are many things that need to be evaluated for security issues, and no single tool can do it all. If you have coverage in all these areas, you will likely end up with a mix of sources that identify vulnerabilities. This can get messy, which is what leads us to the next stage of our process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Observability
&lt;/h2&gt;

&lt;p&gt;Once we have identified vulnerabilities, we need to make sense of the noise. The observability stage is where the magic happens in our process diagram. In this stage, we are translating the technical security issues into higher-level metrics and scores to inform our decision-makers who are not security experts.&lt;/p&gt;

&lt;p&gt;Before we get into the diagram, I want to take a moment to rant about my biggest pet peeve in security. “Critical” has lost all meaning thanks to poor moderation by vendors of security tools. Security scanners aren’t perfect, and there will always be some number of “false positive” findings because of the wide net that they cast. But I think the word “critical” is used so often that we no longer have a term that invokes a swift response without interpretation and guidance from a security professional. If we did have a more urgent term than “critical” it would probably become useless to us too.&lt;/p&gt;

&lt;p&gt;This leads us to the &lt;strong&gt;second major challenge of vulnerability management&lt;/strong&gt;: translating risk for non-security professionals and prioritizing vulnerability findings. The observability stage of our vulnerability management process is where we attempt to do that translation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps-2.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.gitguardian.com%2Fcontent%2Fimages%2F2024%2F04%2FVulnerability-Management-Lifecycle-in-DevSecOps-2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Observability stage&lt;/p&gt;

&lt;p&gt;On the right side of our diagram, we see that observability mainly happens in the places where our software engineers do their work. By taking advantage of features like Pull Request checks and IDE plugins, we are making vulnerabilities relevant &lt;em&gt;where&lt;/em&gt; they are relevant. &lt;strong&gt;Minimizing context switching&lt;/strong&gt; is a key focus in DevSecOps architecture that aims to reduce friction for those involved.&lt;/p&gt;

&lt;p&gt;On the management-focused side, there is a bit more going on. The Product Owners (POs) or Managers are the ones that make the decisions about what gets worked on. For these people to make informed decisions, we need to present existing vulnerabilities in a way that is digestible for someone who is not a security expert.&lt;/p&gt;

&lt;p&gt;Informing POs and managers about vulnerabilities can be as simple as granting them access to the dashboards of our vulnerability scanning tools. All security scanners have their own severity scoring system that attempts to rank the findings, but some tools are better than others. GitGuardian allows you to tune the severities yourself, which is a great feature.&lt;/p&gt;

&lt;p&gt;Using individual tools to inform our less technical decision-makers isn’t ideal, though. Decision-makers don’t want to go to a bunch of different dashboards and learn how each tool works. They want a single place they can go to get a clear view of the security risk in the digital products they are responsible for.&lt;/p&gt;

&lt;p&gt;To set our decision-makers up for success, we need to distill the multitude of vulnerabilities into a prioritized list that is &lt;em&gt;relevant to our business&lt;/em&gt;. A tool category that aims to do this is Application Security Posture Management (ASPM).&lt;/p&gt;

&lt;p&gt;The term “ASPM” is relatively new. &lt;a href="https://www.gartner.com/en/documents/4326999?ref=blog.gitguardian.com" rel="noopener noreferrer"&gt;&lt;u&gt;Garter defined in it May 2023&lt;/u&gt;&lt;/a&gt; as a solution that “continuously manages application risk through collection, analysis, and prioritization of security issues across the software life cycle.” The main idea is that you ingest the findings from your vulnerability scanning tools into an ASPM, and it does the prioritization and metrics for you. If you want to read more about ASPM, check out &lt;a href="https://blog.gitguardian.com/good-application-security-posture-requires-good-data/" rel="noopener noreferrer"&gt;&lt;u&gt;this article&lt;/u&gt;&lt;/a&gt; from GitGuardian.&lt;/p&gt;

&lt;p&gt;I’m not saying you &lt;em&gt;need&lt;/em&gt; an ASPM for success, but you will need many of the capabilities that an ASPM provides. For the sake of our process diagram, “ASPM” can refer to a process or solution that provides the following benefits for the observability of security issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  “Single pane of glass” overview of your risk across multiple types of vulnerabilities&lt;/li&gt;
&lt;li&gt;  Hierarchical grouping of projects, teams, product groups, etc.&lt;/li&gt;
&lt;li&gt;  Context-based prioritization based on public exposure, known exploitation, business criticality, commit frequency, etc.&lt;/li&gt;
&lt;li&gt;  Deduplication of vulnerabilities across multiple tools&lt;/li&gt;
&lt;li&gt;  Generation of SLIs such as time-to-remediation, risk scores, etc.&lt;/li&gt;
&lt;li&gt;  Team or developer-based metrics to identify training needs&lt;/li&gt;
&lt;li&gt;  Corporate memory (who has fixed similar vulnerabilities that can help)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may be able to build your own solution for some of these features, or your existing tools might get you close enough. You could also hire someone whose job it is to organize and track vulnerability findings. In the end, the &lt;strong&gt;most important outcomes&lt;/strong&gt; of the observability stage are the &lt;strong&gt;metrics&lt;/strong&gt; and &lt;strong&gt;prioritization&lt;/strong&gt; of your open vulnerability findings. If your vulnerability management program feels like a mess of findings, you’re probably lacking some of the organizational capabilities listed above.&lt;/p&gt;

&lt;p&gt;Lastly, as you tune the prioritization or scoring for your observability layer, remember the key warning from this section: &lt;strong&gt;if everything is critical, nothing is&lt;/strong&gt;. Do your best to present the risk in a way that accurately reflects the likelihood and business impact of the vulnerabilities. In the next section, we will cover what it looks like for your product owners or business leaders to make decisions about vulnerability risk and remediation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Management
&lt;/h2&gt;

&lt;p&gt;Once the team leaders have access to high-fidelity data on their team’s security risk, they can make informed decisions about work selection, risk management, and training opportunities. Below is the last stage of our process diagram.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps-3-1.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.gitguardian.com%2Fcontent%2Fimages%2F2024%2F04%2FVulnerability-Management-Lifecycle-in-DevSecOps-3-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Management stage&lt;/p&gt;

&lt;p&gt;Most use Jira or another ticketing system to plan and track work. Product owners or managers can use these systems to create issues for vulnerabilities that need to be remediated. If the observability stage has been successful in prioritizing risks, team leaders should be equipped to make informed decisions about this work themselves.&lt;/p&gt;

&lt;p&gt;If more guidance is desired, Service Level Objectives (SLOs) are another way to think about work selection. Examples of SLOs could be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Introducing no more than 1 preventable vulnerability per sprint cycle&lt;/li&gt;
&lt;li&gt;  Remediating critical vulnerabilities within 7 days&lt;/li&gt;
&lt;li&gt;  Remediating high vulnerabilities within 4 sprint cycles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are just made-up examples. Security, product teams, and decision-makers should collaborate on the creation of SLOs to find a balance that works best for the business. Additionally, the security team will continue to play an important role in auditing open vulnerabilities for imminent threats.&lt;/p&gt;

&lt;p&gt;There may be times when an SLO is not able to be met. In those cases, the security risk needs to be escalated to higher-level decision-makers along with the current workload of the product team. Security issues must fight for developer time with new features, bug fixes, and tech debt. Sometimes, business leaders may decide to accept the risk of a security issue or delay the fix because they believe it’s in &lt;strong&gt;the best interest of the company&lt;/strong&gt;. Other times, a critical security issue may need to delay the launch of a new feature, and timelines need to be shifted.&lt;/p&gt;

&lt;p&gt;The last piece of vulnerability management is an often-overlooked area: security training for non-security personnel. Insights from our observability stage can highlight which types of vulnerabilities a developer or team is struggling with. These insights help security teams and leaders identify training needs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The most important part of security training is to create a positive learning culture&lt;/strong&gt;. Security training shouldn’t feel like a punishment. If it does, then the implementation needs some work. A great example of security training is to have a regular security segment in a meeting dedicated to sharing and learning. The security topics covered should prioritize the needs of the audience and be presented in a way that is positive, not pointing fingers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final process diagram
&lt;/h2&gt;

&lt;p&gt;Now that we’ve covered each stage of vulnerability management, this is the final process diagram. Here’s a link to a &lt;a href="https://lucid.app/documents/view/cd7405fe-6fb2-4990-93ef-1b6eb59d95d4?ref=blog.gitguardian.com" rel="noopener noreferrer"&gt;&lt;u&gt;copyable version on Lucidchart&lt;/u&gt;&lt;/a&gt; that you can use to track your progress. You can color-code areas to mark them as having full, partial, or no coverage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2024/04/Vulnerability-Management-Lifecycle-in-DevSecOps--1-.png" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.gitguardian.com%2Fcontent%2Fimages%2F2024%2F04%2FVulnerability-Management-Lifecycle-in-DevSecOps--1-.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Final process diagram&lt;/p&gt;

&lt;h2&gt;
  
  
  Roles and responsibilities
&lt;/h2&gt;

&lt;p&gt;We’ve covered the whole process diagram, but we still need to define roles and responsibilities. The following section is my suggested role structure to support the success of the vulnerability management process that I’ve laid out in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Software Engineers and Product Owners
&lt;/h2&gt;

&lt;p&gt;Product teams own the security work for the business’s software products. They are responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Being aware of the existing vulnerabilities in their team's projects&lt;/li&gt;
&lt;li&gt;  Managing and performing the work related to resolving vulnerabilities&lt;/li&gt;
&lt;li&gt;  Adhering to security-related SLOs, if any&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Managers, Directors, Tech Executives
&lt;/h2&gt;

&lt;p&gt;The higher-level decision makers own or escalate the security risk for the business’s software products. They are responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Being aware of critical severity vulnerabilities in the business’s digital products&lt;/li&gt;
&lt;li&gt;  Accepting or escalating risk when prioritizing other work over vulnerability remediation&lt;/li&gt;
&lt;li&gt;  Working with the business when prioritizing vulnerability remediation over other types of work&lt;/li&gt;
&lt;li&gt;  Auditing security-related SLOs, if any&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Security Team
&lt;/h2&gt;

&lt;p&gt;The software security team owns the work that supports the success of the vulnerability management process. They are responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Managing technical tools for vulnerability identification and prevention&lt;/li&gt;
&lt;li&gt;  Providing conceptual and tool-based training for software engineers&lt;/li&gt;
&lt;li&gt;  Managing technical tools for vulnerability observability&lt;/li&gt;
&lt;li&gt;  Auditing open vulnerabilities for imminent threats&lt;/li&gt;
&lt;li&gt;  Consulting for individual vulnerabilities as needed&lt;/li&gt;
&lt;li&gt;  Human-operated penetration testing for additional vulnerability identification&lt;/li&gt;
&lt;li&gt;  Working with other roles to establish security-related SLOs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We’ve covered a lot in this blog post, so let’s do a quick recap. This blog post showed how technology can support the “people and processes” side of the vulnerability management lifecycle. In the context of DevSecOps, our vulnerability management process includes 3 major stages: identification, observability, and management. In each stage, a considerate implementation of the technologies we covered is critical for setting ourselves up for success. In the end, our goal is to empower digital product teams to make informed decisions about how much work needs to be dedicated to remediating security risks.&lt;/p&gt;

&lt;p&gt;After reading this blog post, I hope you’ve got a solid idea of how to approach DevSecOps from the vulnerability management side of software development. The next blog post in this series will cover the software engineering side of things, where we will look at the implementation of controls and automation to create a secure-by-design software development pipeline.&lt;/p&gt;

</description>
      <category>devsecops</category>
      <category>security</category>
      <category>cybersecurity</category>
      <category>tooling</category>
    </item>
    <item>
      <title>The Open-Source Backdoor That Almost Compromised SSH</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Wed, 24 Apr 2024 15:45:38 +0000</pubDate>
      <link>https://dev.to/gitguardian/the-open-source-backdoor-that-almost-compromised-ssh-2lcg</link>
      <guid>https://dev.to/gitguardian/the-open-source-backdoor-that-almost-compromised-ssh-2lcg</guid>
      <description>&lt;p&gt;Researchers discovered a backdoor in the compression tools &lt;code&gt;xz Utils&lt;/code&gt; versions 5.6.0 and 5.6.1, targeting SSH authentication in several Linux distributions. Although not affecting production releases,the early detection prevented a potential catastrophe, underscoring the importance of vigilant open-source software monitoring.&lt;/p&gt;

&lt;p&gt;Here is a technical overview of the supply chain attack attempt by Thomas Roccia:&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1774342248437813525-527" src="https://platform.twitter.com/embed/Tweet.html?id=1774342248437813525"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1774342248437813525-527');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1774342248437813525&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;h2&gt;
  
  
  Incident Recap
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; A malicious backdoor was found in &lt;code&gt;xz utils&lt;/code&gt; versions 5.6.0 and 5.6.1.&lt;/li&gt;
&lt;li&gt; The backdoor was designed to interfere with SSH public key verification, potentially allowing remote code execution.&lt;/li&gt;
&lt;li&gt; This vulnerability targeted SSH connections in Linux distributions such as Red Hat, Debian, and Arch Linux.&lt;/li&gt;
&lt;li&gt; Homebrew, a package manager for macOS, also incorporated the compromised version but has since reverted to an unaffected version.&lt;/li&gt;
&lt;li&gt; Early detection prevented the backdoored versions from being widely deployed, averting widespread impact.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Long Story
&lt;/h2&gt;

&lt;p&gt;In a frankly alarming discovery, researchers have uncovered a malicious backdoor deeply embedded within &lt;code&gt;xz Utils&lt;/code&gt;, a widely utilized Linux compression tool. The discovery was particularly concerning given the broad usage of &lt;code&gt;xz Utils&lt;/code&gt; across multiple Linux distributions, including heavyweights like Red Hat and Debian. Even more distressing was the fact that these compromised versions had made their way into beta releases of these distributions, specifically targeting software that manages SSH connections – a backbone of secure remote access.&lt;/p&gt;

&lt;p&gt;This backdoor was ingeniously masked and went unnoticed for over a month, posing a critical risk to SSH's encrypted authentication process. &lt;strong&gt;Had a vigilant developer not discovered it early, the ramifications could have been dire, potentially allowing unauthorized access or remote code execution to countless systems worldwide&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The malicious code was sneakily introduced through updates under the guise of standard improvements. It was later revealed that these changes aimed at tampering with SSH functions, thereby jeopardizing secure remote access. The perpetrator behind these changes was a prominent developer within the project, raising questions about security and trust within the open-source community. This chain of events underscores not just the ever-present risks in software development and distribution but also the importance of early detection and rigorous vetting in the open-source ecosystem.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"As systems grow more interconnected, the impact of a single compromised tool can be exponential. The xz Utils case highlights the importance of scrutinizing even seemingly benign updates for potential security implications." said Mackenzie Jackson, Security Advocate.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thankfully, the quick response from various stakeholders, including the immediate rollback of vulnerable versions and rigorous patching efforts, helped mitigate the potential damage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson Learned
&lt;/h2&gt;

&lt;p&gt;This incident vividly highlights the critical need for vigilant monitoring of software dependencies. While invaluable, open-source software can also serve as a conduit for significant security threats when not properly scrutinized. In this case, the backdoor targeted SSH, a cornerstone of secure system management and operations.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Early detection and constant vigilance are the cornerstones of modern cybersecurity. This incident is a testament to that principle. Trust but verify should be the mantra in open-source software development." said Eric Fourrier, GitGuardian co-founder and CEO.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;GitGuardian's Software Composition Analysis (SCA) tool exemplifies how advanced monitoring and early detection can serve as a critical defense against such threats. By scanning dependencies for vulnerabilities and offering actionable remediation guidance, GitGuardian SCA enables a proactive approach to software security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recommendations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Regularly update and patch software from trusted sources.&lt;/li&gt;
&lt;li&gt;  Employ continuous monitoring solutions to detect and address vulnerabilities promptly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Supply Chain Attacks: 6 Steps to protect your software supply chain&lt;/p&gt;

&lt;p&gt;This article looks at software supply chain attacks, exactly what they are and 6 steps you can follow to protect your software supply chain and limit the impact of a supply chain attack.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/supply-chain-attack-6-steps-to-harden-your-supply-chain/"&gt;Supply Chain Attacks: 6 Steps to protect your software supply chain&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Review and vet contributions to critical software components, especially those with extensive access or privileges.&lt;/li&gt;
&lt;li&gt;  Integrate security early in the software development lifecycle to detect and mitigate threats preemptively.&lt;/li&gt;
&lt;li&gt;  Foster a culture of openness and prompt communication within development communities.&lt;/li&gt;
&lt;li&gt;  Prioritize security when selecting and updating software dependencies.&lt;/li&gt;
&lt;li&gt;  Engage with the open-source community for collective defense against emerging threats and vulnerabilities.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>security</category>
      <category>infosec</category>
      <category>opensource</category>
      <category>github</category>
    </item>
    <item>
      <title>The State of Secrets Sprawl 2024</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Wed, 10 Apr 2024 13:47:28 +0000</pubDate>
      <link>https://dev.to/gitguardian/the-state-of-secrets-sprawl-2024-bc2</link>
      <guid>https://dev.to/gitguardian/the-state-of-secrets-sprawl-2024-bc2</guid>
      <description>&lt;p&gt;We're excited to share the State of Secrets Sprawl 2024 report, GitGuardian's annual deep dive into the secrets exposed on public GitHub repositories. This year's findings issue a stark reminder of the escalating challenge we face, with a staggering 12.8 million new secrets leaked in 2023—a 28% increase from the previous year.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gitguardian.com/files/the-state-of-secrets-sprawl-report-2024"&gt;Read the full report&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2_48YBuM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/03/image-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2_48YBuM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/03/image-1.png" alt="New secrets detected per year on GitHub" width="800" height="551"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Secrets Sprawl on GitHub
&lt;/h2&gt;

&lt;p&gt;Our research, now more comprehensive than ever, shows the rapid growth of exposed secrets since our first report in 2021, quadrupling in number. With GitHub's repository count growing by 50 million in just the last year, the risk of both accidental and deliberate secret exposures skyrockets.&lt;/p&gt;

&lt;p&gt;In 2023 alone, GitGuardian's vigilance over 1.1 billion new commits revealed that secret sprawl is not just widespread but deepening, affecting a vast range of industries from IT to Education, Retail, and Finance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;7 commits out of 1,000 exposed at least one secret;&lt;/li&gt;
&lt;li&gt;4.6% of active repositories leaked a secret;&lt;/li&gt;
&lt;li&gt;11.7% of authors who contributed leaked a secret.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  GenAI Secrets Leaks
&lt;/h2&gt;

&lt;p&gt;A particularly alarming trend is the 1212x surge in OpenAI API key leaks, spotlighting the growing allure of AI services among developers—and the risks that accompany their popularity.&lt;/p&gt;

&lt;p&gt;Looking at other AI services, another trend emerged: the slow but steady rise of open-source AI:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BoP9YgZV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/03/image-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BoP9YgZV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/03/image-2.png" alt="The slow but steady rise of open-source AI" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A Hidden Threat: Zombie Leaks
&lt;/h2&gt;

&lt;p&gt;An alarming revelation from our report is the persistence of "zombie leaks," with over 90% of exposed secrets remaining active five days post-leakage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ftrWsVrb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/03/image-3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ftrWsVrb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/03/image-3.png" alt="Validity rate over time" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This negligence, often resulting from deleting leaky commits or privatizing repositories without revoking the exposed secrets, creates a gaping security vulnerability.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Developers erasing leaky commits or repositories instead of revoking are creating a major security risk for companies, which will remain vulnerable to threat actors mirroring public GitHub activity for as long as the credential remains valid. These zombie leaks are the worst,” said Eric Fourrier, CEO and Founder of GitGuardian.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  And More...
&lt;/h2&gt;

&lt;p&gt;Our investigation also delves into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The most sensitive file types on GitHub&lt;/li&gt;
&lt;li&gt;The fastest-remediated secrets&lt;/li&gt;
&lt;li&gt;The use of DMCA notices to stop leaks&lt;/li&gt;
&lt;li&gt;The potential of Large Language Models (LLMs) in secret detection&lt;/li&gt;
&lt;li&gt;The intersection of private and public secret leaks&lt;/li&gt;
&lt;li&gt;Secrets exposure within Python's official package management system, PyPI&lt;/li&gt;
&lt;li&gt;Strategies to combat secrets sprawl&lt;/li&gt;
&lt;li&gt;Read the Press Release&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.gitguardian.com/files/the-state-of-secrets-sprawl-report-2024"&gt;Read the full report&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates from GitGuardian as we continue to monitor the ever-changing threat landscape and provide the latest insights and recommendations to help you stay ahead of the curve.&lt;/p&gt;

</description>
      <category>github</category>
      <category>security</category>
      <category>devops</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Understanding the Risks of Long-Lived Kubernetes Service Account Tokens</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Mon, 29 Jan 2024 09:20:54 +0000</pubDate>
      <link>https://dev.to/gitguardian/understanding-the-risks-of-long-lived-kubernetes-service-account-tokens-dok</link>
      <guid>https://dev.to/gitguardian/understanding-the-risks-of-long-lived-kubernetes-service-account-tokens-dok</guid>
      <description>&lt;p&gt;The popularity of Kubernetes (K8s) as the defacto orchestration platform for the cloud is not showing any sign of pause. This graph, taken from the 2023 Kubernetes Security Report by the security company Wiz, clearly illustrates the trend:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2024/01/kubernetes-adoption-continues-to-soar.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CvUEZJ0j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/01/kubernetes-adoption-continues-to-soar.png" alt="Public K8s API server endpoints worldwide" width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As adoption continues to soar, so do the security risks and, most importantly, the attacks threatening K8s clusters. One such threat comes in the form of long-lived service account tokens. In this blog, we are going to dive deep into what these tokens are, their uses, the risks they pose, and how they can be exploited. We will also advocate for the use of short-lived tokens for a better security posture.&lt;/p&gt;

&lt;p&gt;Service account tokens are &lt;strong&gt;bearer tokens&lt;/strong&gt; (a type of token mostly used for authentication in web applications and APIs) used by service accounts to authenticate to the Kubernetes API. Service accounts provide an identity for processes (applications) that run in a Pod, enabling them to interact with the Kubernetes API securely. &lt;/p&gt;

&lt;p&gt;Crucially, these tokens are &lt;strong&gt;long-lived&lt;/strong&gt;: when a service account is created, Kubernetes automatically generates a token and stores it indefinitely as a Secret, which can be mounted into pods and used by applications to authenticate API requests.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: in more recent versions, including Kubernetes v1.29, API credentials are obtained directly by using the &lt;a href="https://kubernetes.io/docs/reference/kubernetes-api/authentication-resources/token-request-v1/?ref=blog.gitguardian.com"&gt;TokenRequest&lt;/a&gt; API, and are mounted into Pods using a &lt;a href="https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/?ref=blog.gitguardian.com#bound-service-account-token-volume"&gt;projected volume&lt;/a&gt;. The tokens obtained using this method have bounded lifetimes, and are automatically invalidated when the Pod they are mounted into is deleted.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As a reminder, the &lt;strong&gt;Kubelet&lt;/strong&gt; on each node is responsible for mounting service account tokens into pods, so they can be used by applications within those pods to authenticate to the Kubernetes API when needed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2024/01/21W27-Blog-Illu-DevSecOps-SDLC-image4--1-.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HPzJHX44--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2024/01/21W27-Blog-Illu-DevSecOps-SDLC-image4--1-.png" alt="Topography of a K8s cluster" width="800" height="468"&gt;&lt;/a&gt;&lt;br&gt;
If you need a refresher on K8s components, look &lt;a href="https://blog.gitguardian.com/hardening-your-k8-pt-1/#:~:text=right%20into%20it.-,1.%20Kubernetes%20Components,-First%2C%20let%27s%20do"&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;The Utility of Service Account Tokens&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Service account tokens are essential for enabling applications running on Kubernetes to interact with the Kubernetes API. They are used to deploy applications, manage workloads, and perform administrative tasks programmatically. For instance, a Continuous Integration/Continuous Deployment (CI/CD) tool like Jenkins would use a service account token to deploy new versions of an application or roll back a release.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;The Risks of Longevity&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;While service account tokens are indispensable for automation within Kubernetes, their longevity can be a significant risk factor. Long-lived tokens, if compromised, give attackers ample time to explore and exploit a cluster. Once in the hands of an attacker, these tokens can be used to gain unauthorized access, elevate privileges, exfiltrate data, or even disrupt the entire cluster's operations.&lt;/p&gt;

&lt;p&gt;Here are a few leak scenarios that could lead to some serious damage:&lt;/p&gt;

&lt;p&gt;- &lt;strong&gt;Misconfigured Access Rights&lt;/strong&gt;: A pod or container may be misconfigured to have broader file system access than necessary. If a token is stored on a shared volume, other containers or malicious pods that have been compromised could potentially access it.&lt;/p&gt;

&lt;p&gt;- &lt;strong&gt;Insecure Transmission&lt;/strong&gt;: If the token is transmitted over the network without proper encryption (like sending it over HTTP instead of HTTPS), it could be intercepted by network sniffing tools.&lt;/p&gt;

&lt;p&gt;- &lt;strong&gt;Code Repositories&lt;/strong&gt;: Developers might inadvertently commit a token to a public or private source code repository. If the repository is public or becomes exposed, the token is readily available to anyone who accesses it.&lt;/p&gt;

&lt;p&gt;- &lt;strong&gt;Logging and Monitoring Systems&lt;/strong&gt;: Tokens might get logged by applications or monitoring systems and could be exposed if logs are not properly secured or if verbose logging is accidentally enabled.&lt;/p&gt;

&lt;p&gt;- &lt;strong&gt;Insider Threat&lt;/strong&gt;: A malicious insider with access to the Kubernetes environment could extract the token and use it or leak it intentionally.&lt;/p&gt;

&lt;p&gt;- &lt;strong&gt;Application Vulnerabilities&lt;/strong&gt;: If an application running within the cluster has vulnerabilities (e.g., a Remote Code Execution flaw), an attacker could exploit this to gain access to the pod and extract the token.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;How Could an Attacker Exploit Long-Lived Tokens?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Attackers can collect long-lived tokens through network eavesdropping, exploiting vulnerable applications, or leveraging social engineering tactics. With these tokens, they can manipulate Kubernetes resources at their will. Here is a non-exhaustive list of potential abuses:&lt;/p&gt;

&lt;p&gt;- Abuse the cluster's (often barely limited) infra resources for &lt;strong&gt;cryptocurrency mining&lt;/strong&gt; or as part of a botnet.&lt;/p&gt;

&lt;p&gt;- With API access, attackers could &lt;strong&gt;deploy malicious containers&lt;/strong&gt;, alter running workloads, exfiltrate sensitive data, or even take down the entire cluster.&lt;/p&gt;

&lt;p&gt;- If the token has broad permissions, it can be used to modify roles and bindings to &lt;strong&gt;elevate privileges&lt;/strong&gt; within the cluster.&lt;/p&gt;

&lt;p&gt;- The attacker could create additional resources that provide them with persistent access (&lt;strong&gt;backdoor&lt;/strong&gt;) to the cluster, making it harder to remove their presence.&lt;/p&gt;

&lt;p&gt;- Access to sensitive data stored in the cluster or accessible through it could lead to &lt;strong&gt;data theft or leakage&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Why Aren’t Service Account Tokens Short-Lived by Default?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/a-maturity-model-for-secrets-management/"&gt;&lt;u&gt;Short-lived tokens are a security best practice in general&lt;/u&gt;&lt;/a&gt;, particularly for managing access to very sensitive resources like the Kubernetes API. They reduce the window of opportunity for attackers to exploit a token and facilitate better management of permissions as application access requirements change. Automating token rotation limits the impact of a potential compromise and aligns with the principle of least privilege—granting only the access necessary for a service to operate.&lt;/p&gt;

&lt;p&gt;The problem is that implementing short-lived tokens comes with some overhead.&lt;/p&gt;

&lt;p&gt;First, implementing short-lived tokens typically requires a &lt;strong&gt;more complex setup&lt;/strong&gt;. You need an automated process to handle token renewal before it expires. This may involve additional scripts or Kubernetes operators that watch for token expiration and request new tokens as necessary.&lt;/p&gt;

&lt;p&gt;This often means integrating a &lt;strong&gt;secret management system&lt;/strong&gt; that can securely store and automatically rotate the tokens. This adds a new dependency for system configuration and maintenance.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: it goes without saying that using a secrets manager with Kubernetes is highly recommended, even for non-production workloads. But the overhead cannot be understated.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Second, software teams running their CI/CD workers on top of the cluster will need adjustments to support dynamic retrieval and injection of these tokens into the deployment process. This could require changes in the pipeline configuration and additional error handling to manage potential token expiration during a pipeline run, which can be a true headache.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And secrets management is just the tip of the iceberg.&lt;/strong&gt; You will also need monitoring and alerts if you want to troubleshoot renewal failures. Fine-tuning token expiry time could break the deployment process, requiring immediate attention to prevent downtime or deployment failures.&lt;/p&gt;

&lt;p&gt;Finally, there could also be performance considerations, as many more API calls are needed to retrieve new tokens and update the relevant Secrets.&lt;/p&gt;

&lt;p&gt;By default, Kubernetes opts for a straightforward setup by issuing service account tokens without a built-in expiration. This approach simplifies initial configuration but lacks the security benefits of token rotation. It is the Kubernetes admin’s responsibility to configure more secure practices by implementing short-lived tokens and the necessary infrastructure for their rotation, thereby enhancing the cluster's security posture.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Mitigation Best Practices&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;For many organizations, the additional overhead is justified by the security improvements. Tools like service mesh implementations (e.g., &lt;a href="https://istio.io/latest/about/service-mesh/?ref=blog.gitguardian.com"&gt;Istio&lt;/a&gt;), secret managers (e.g., &lt;a href="https://docs.cyberark.com/conjur-enterprise/latest/en/Content/Integrations/k8s-ocp/k8s-architecture.htm?ref=blog.gitguardian.com"&gt;CyberArk Conjur&lt;/a&gt;), or cloud provider services can manage the lifecycle of short-lived certificates and tokens, helping to reduce the overhead.&lt;/p&gt;

&lt;p&gt;Additionally, recent versions of Kubernetes offer features like the &lt;a href="https://kubernetes.io/docs/reference/kubernetes-api/authentication-resources/token-request-v1/?ref=blog.gitguardian.com"&gt;TokenRequest&lt;/a&gt; API, which can automatically rotate tokens and project them into the running pods.&lt;/p&gt;

&lt;p&gt;Even without any additional tool, you can mitigate the risks by limiting the Service Account auto-mount feature. To do so, you can opt out of the default API credential automounting with a single flag in the service account or pod configuration. Here are two examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  For a Service Account:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ServiceAccount&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
 &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;build-robot&lt;/span&gt;
&lt;span class="na"&gt;automountServiceAccountToken&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="nn"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;  And for a specific Pod:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
 &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-pod&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
 &lt;span class="na"&gt;serviceAccountName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;build-robot&lt;/span&gt;
 &lt;span class="na"&gt;automountServiceAccountToken&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
 &lt;span class="s"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The bottom line is that &lt;strong&gt;if an application does not need to access the K8s API, it should not have a token mounted.&lt;/strong&gt; This also limits the number of service account tokens an attacker can access if the attacker manages to compromise any of the Kubernetes hosts.&lt;/p&gt;

&lt;p&gt;Okay, you might say, but how do we enforce this policy everywhere? Enter Kyverno, a policy engine designed for K8s.&lt;/p&gt;
&lt;h3&gt;
  
  
  Enforcement with Kyverno
&lt;/h3&gt;

&lt;p&gt;Kyverno allows cluster administrators to manage, validate, mutate, and generate Kubernetes resources based on custom policies. To prevent the creation of long-lived service account tokens, one can define the following Kyverno policy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kyverno.io/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ClusterPolicy&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;deny-secret-service-account-token&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;validationFailureAction&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Enforce&lt;/span&gt;
  &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;check-service-account-token&lt;/span&gt;
    &lt;span class="na"&gt;match&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;any&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;kinds&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;Secret&lt;/span&gt;
    &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;cel&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;expressions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Long&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;lived&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;API&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;tokens&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;are&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;not&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;allowed"&lt;/span&gt;
          &lt;span class="na"&gt;expression&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="s"&gt;object.type != "kubernetes.io/service-account-token"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This policy ensures that only Secrets that are not of type &lt;code&gt;kubernetes.io/service-account-token&lt;/code&gt; can be created, effectively blocking the creation of long-lived service account tokens!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Applying the Kyverno Policy&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To apply this policy, you need to have Kyverno installed on your Kubernetes cluster (&lt;a href="https://kyverno.io/docs/installation/methods/?ref=blog.gitguardian.com"&gt;&lt;u&gt;tutorial&lt;/u&gt;&lt;/a&gt;). Once Kyverno is running, you can apply the policy by saving the above YAML to a file and using &lt;code&gt;kubectl&lt;/code&gt; to apply it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; deny-secret-service-account-token.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After applying this policy, any attempt to create a Secret that is a service account token of the prohibited type will be denied, enforcing a safer token lifecycle management practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Wrap up&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In Kubernetes, managing the lifecycle and access of service account tokens is a critical aspect of cluster security. By preferring short-lived tokens over long-lived ones and enforcing policies with tools like Kyverno, organizations can significantly reduce the risk of token-based security incidents. Stay vigilant, automate security practices, and ensure your Kubernetes environment remains robust against threats.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>cloud</category>
      <category>security</category>
      <category>learning</category>
    </item>
    <item>
      <title>How to Secure Your Secrets Manager with GitGuardian Honeytoken</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Fri, 08 Dec 2023 14:59:40 +0000</pubDate>
      <link>https://dev.to/gitguardian/how-to-secure-your-secrets-manager-with-gitguardian-honeytoken-52m7</link>
      <guid>https://dev.to/gitguardian/how-to-secure-your-secrets-manager-with-gitguardian-honeytoken-52m7</guid>
      <description>&lt;p&gt;Protecting sensitive data is a crucial responsibility for modern businesses. To ensure the security of critical information, organizations utilize various tools and strategies.&lt;/p&gt;

&lt;p&gt;One such tool is a secrets manager, which securely stores and manages sensitive data like passwords, API keys, and encryption keys. Secrets managers offer a centralized and encrypted repository, providing a secure alternative to storing secrets in configuration files or source code. Popular secrets managers include &lt;a href="https://developer.hashicorp.com/vault/tutorials/getting-started/getting-started-install?ref=blog.gitguardian.com"&gt;Hashicorp Vault&lt;/a&gt;, &lt;a href="https://aws.amazon.com/fr/secrets-manager/?ref=blog.gitguardian.com"&gt;AWS Secrets Manager&lt;/a&gt;, &lt;a href="https://www.doppler.com/?ref=blog.gitguardian.com"&gt;Doppler&lt;/a&gt; and &lt;a href="https://www.cyberark.com/products/secrets-management/?ref=blog.gitguardian.com"&gt;CyberArk&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this blog, we will explore how GitGuardian Honeytoken can enhance the security of secrets managers by enabling easy and scalable breach detection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Honeytokens
&lt;/h2&gt;

&lt;p&gt;Honeytokens are digital baits designed to lure attackers into a trap. They have no permissions attached and serve as alerts when unauthorized users attempt to use them.&lt;/p&gt;

&lt;p&gt;When a honeytoken is triggered, it alerts you of the intrusion and provides crucial information about the attacker, such as their IP address and user agent. By storing honeytokens in a secure environment like a secrets manager, you can effectively detect and respond to unauthorized access attempts.&lt;/p&gt;

&lt;p&gt;In the upcoming section, we will guide you on how to place a honeytoken in your &lt;strong&gt;Hashicorp Vault&lt;/strong&gt; instance, but these guidelines are applicable to any other secrets manager.&lt;/p&gt;

&lt;p&gt;➡️ Before we begin, follow the step-by-step instructions below to create your first honeytoken! 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/how-to-create-and-use-honeytokens-step-by-step/"&gt;How to Create and Use Honeytokens: Step-by-Step Instructions&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Enhancing Secrets Manager Security with Honeytokens
&lt;/h2&gt;

&lt;p&gt;Hashicorp Vault is a popular secrets manager that securely stores and controls access to sensitive elements in a DevOps environment. While Vault provides advanced security features, the possibility of an instance compromise cannot be completely eliminated.&lt;/p&gt;

&lt;p&gt;Attackers understand the value of compromising a secrets manager, as it can provide them with access to sensitive information and facilitate lateral movement within your system. Integrating GitGuardian Honeytoken with Vault adds an additional layer of security, alerting you to any unauthorized attempts to access your secrets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrating GitGuardian Honeytoken with Vault (or any Secrets Manager)
&lt;/h2&gt;

&lt;p&gt;Before integrating GitGuardian Honeytoken, ensure that Vault is installed and running in your environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing Vault:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Download the latest version of Vault from the &lt;a href="https://developer.hashicorp.com/vault/tutorials/getting-started/getting-started-install?ref=blog.gitguardian.com"&gt;official website&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  Extract the downloaded file in a directory of your choice.&lt;/li&gt;
&lt;li&gt;  Add the Vault binary to your system &lt;code&gt;PATH&lt;/code&gt; for easy access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Configuring Vault:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Initiate the Vault server with the appropriate configurations for your organization.&lt;/li&gt;
&lt;li&gt;  Initialize Vault to create initial tokens and unseal keys that are critical for Vault's operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Using GitGuardian Honeytoken:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Sign in to your GitGuardian account and navigate to the &lt;a href="https://dashboard.gitguardian.com/workspace/honeytokens?ref=blog.gitguardian.com"&gt;Honeytoken section&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  Create new honeytokens with a descriptive name and description&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2023/10/image-2.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cdJPeIiX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/10/image-2.png" alt="" width="800" height="772"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Note down the keys (AWS Access and Secret Keys), as these will be used later in Vault.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2023/10/image-4.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MbeEless--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/10/image-4.png" alt="" width="800" height="599"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Honeytoken details&lt;/p&gt;

&lt;h3&gt;
  
  
  Integration Procedure: Step-by-Step Guide
&lt;/h3&gt;

&lt;p&gt;Vault supports multiple secret engines, and for simplicity, we will consider the key value (KV) secret engine. This engine is a generic Key-Value store used to store arbitrary secrets within Vault.&lt;/p&gt;

&lt;p&gt;💡A set of permissions policies will be needed to list, write, and manage secrets through the KV engine. &lt;a href="https://developer.hashicorp.com/vault/tutorials/policies/policies?ref=blog.gitguardian.com"&gt;Read more here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, ensure that your Vault cluster is reachable by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vault status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you get an error message, follow Vault's &lt;a href="https://developer.hashicorp.com/vault/tutorials/secrets-management/static-secrets?ref=blog.gitguardian.com"&gt;Lab Setup instructions here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Next, verify that the KV secrets engine is enabled and set to version 2 at the &lt;code&gt;secret/&lt;/code&gt; path. This should be the default configuration if you started a &lt;code&gt;dev&lt;/code&gt; server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vault secrets list &lt;span class="nt"&gt;-detailed&lt;/span&gt;

Path          Type         Accessor           ...   Options           Description
&lt;span class="nt"&gt;----&lt;/span&gt;          &lt;span class="nt"&gt;----&lt;/span&gt;         &lt;span class="nt"&gt;--------&lt;/span&gt;                 &lt;span class="nt"&gt;-------&lt;/span&gt;           &lt;span class="nt"&gt;-----------&lt;/span&gt;
cubbyhole/    cubbyhole    cubbyhole_9d52aeac ...   map[]             per-token private secret storage
identity/     identity     identity_acea5ba9  ...   map[]             identity store
secret/       kv           kv_2226b7d3        ...   map[version:2]    key/value secret storage
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, write the previously generated AWS secret values at the path of your choice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vault kv put secret/aws aws_access_key_id &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"AKIA..."&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
        aws_secret_access_key &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"QzfQeV..."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything went well, you should see this output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;======&lt;/span&gt; Secret Path &lt;span class="o"&gt;======&lt;/span&gt;
secret/aws

&lt;span class="o"&gt;=======&lt;/span&gt; Metadata &lt;span class="o"&gt;=======&lt;/span&gt;
Key                Value
&lt;span class="nt"&gt;---&lt;/span&gt;                &lt;span class="nt"&gt;-----&lt;/span&gt;
created_time       &amp;lt;CREATION_TIME&amp;gt;
custom_metadata    &amp;lt;nil&amp;gt;
deletion_time      n/a
destroyed          &lt;span class="nb"&gt;false
&lt;/span&gt;version            1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This confirms that your bait credentials have been set. If you receive an email alert about this honeytoken being triggered, you can assume that your secrets manager is compromised.&lt;/p&gt;

&lt;p&gt;💡 Currently, GitGuardian Honeytoken only supports one type of secret: &lt;strong&gt;AWS key.&lt;/strong&gt; In the future, more types of secrets will be available, allowing to place them in other Vault engines, like, for example, the SSH or the database secret engine&lt;/p&gt;

&lt;p&gt;You can further &lt;a href="https://docs.gitguardian.com/honeytoken/configure-alerts?ref=blog.gitguardian.com"&gt;&lt;strong&gt;configure&lt;/strong&gt;&lt;/a&gt; &lt;a href="https://docs.gitguardian.com/honeytoken/configure-alerts?ref=blog.gitguardian.com"&gt;&lt;strong&gt;your alerts&lt;/strong&gt;&lt;/a&gt; to receive instant notifications through custom webhooks, allowing you to customize your alerting workflow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of protecting your Secrets Manager with Honeytokens
&lt;/h3&gt;

&lt;p&gt;Taking proactive measures to secure sensitive information is both prudent and essential. There are a number of security benefits of integrating GitGuardian Honeytoken with Vault:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Proactive Breach Detection&lt;/strong&gt;: By integrating GitGuardian Honeytoken with Vault, you can proactively detect and respond to potential breaches. Honeytokens act as a silent alarm, alerting you when unauthorized users attempt to use them. This allows you to take immediate action and strengthen your system's security.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Enhanced Threat Intelligence&lt;/strong&gt;: Honeytokens provide valuable information about the actions taken by intruders, such as their IP address and user agent. This information helps you analyze and understand the threat, enabling you to further secure your system and track down the attackers.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Scalable Solution&lt;/strong&gt;: GitGuardian Honeytoken offers a scalable solution for breach detection. You can create and deploy multiple honeytokens, strategically placing them in your secrets manager to effectively deceive attackers. This scalability ensures comprehensive coverage and protection for your critical assets.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Customizable Alerting Workflow&lt;/strong&gt;: GitGuardian Honeytoken allows you to configure custom alerts through webhooks. This flexibility enables you to tailor your alerting workflow according to your specific requirements, ensuring that you receive instant notifications when a breach is detected.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By securing your secrets manager with GitGuardian Honeytoken, you can significantly enhance the security of your sensitive information. The proactive breach detection, enhanced threat intelligence, easy integration, scalability, and customizable alerting workflow provided by honeytokens make them a valuable addition to your security arsenal. Follow the step-by-step instructions in this blog to get started and protect your critical assets effectively.&lt;/p&gt;

</description>
      <category>vault</category>
      <category>secrets</category>
      <category>security</category>
      <category>devsecops</category>
    </item>
    <item>
      <title>HasMySecretLeaked - Building a Trustless and Secure Protocol</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Wed, 15 Nov 2023 15:27:52 +0000</pubDate>
      <link>https://dev.to/gitguardian/hasmysecretleaked-building-a-trustless-and-secure-protocol-3ife</link>
      <guid>https://dev.to/gitguardian/hasmysecretleaked-building-a-trustless-and-secure-protocol-3ife</guid>
      <description>&lt;p&gt;&lt;a href="https://blog.gitguardian.com/announcing-has-my-secret-leaked/"&gt;&lt;strong&gt;HasMySecretLeaked&lt;/strong&gt;&lt;/a&gt; is the first free service that allows security practitioners to proactively verify if their secrets have leaked on &lt;a href="https://blog.gitguardian.com/announcing-has-my-secret-leaked/"&gt;GitHub.com&lt;/a&gt;. With access to GitGuardian's extensive database of over 20 million records of detected leaked secrets, including their locations on GitHub, users can easily query and protect their sensitive information. This database is compiled from scanning billions of code files, commits, GitHub gists, and issues since 2017.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;By opening this project to everyone, we strive to enhance secrets protection at scale while acknowledging the responsibility and security challenges involved.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At GitGuardian, we believe in transparent, accessible and understandable security. This is why we aim to uphold complete transparency regarding the protocols behind HasMySecretLeaked. Our goal is to ensure the service remains resilient against malicious misuse while also fostering a trustless environment: &lt;strong&gt;with HasMySecretLeaked, you can rest assured that your secrets are secure - at no point do we have access to them, so you don’t even need to trust us!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To support these claims, this blog post dives into the technical choices that went into creating a safe yet pragmatic and easy-to-use protocol. Without further ado, let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  How We Built the Protocol
&lt;/h2&gt;

&lt;p&gt;HasMySecretLeaked is a highly efficient REST API designed to take a string of characters as input. Its key function is to answer with 100% assurance the critical question - 'Has my secret leaked?'&lt;/p&gt;

&lt;p&gt;Here is an example request for the &lt;code&gt;fffff&lt;/code&gt; input to show you what a typical response looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl https://api.hasmysecretleaked.com/v1/prefix/fffff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this input, the HasMySecretLeaked API response's payload is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"matches": [
    {
      "hint": "0ea3b034632487a17ba18e7086156c14cc8eb9993e33aec8e348183044b299b1",
      "payload": "adO72+jWqHstJso2DacOj..."
    },
    {
      "hint": "ddf4ef722ca2ec541074811692eff789bf48d963fa28e42d5542edc8e887239c",
      "payload": "sHrlooMIShmf+Oh0yqcYm..."
    },
    ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can notice, there is more going on under the hood. To understand how the client uses this information and the API design decisions involved, let's start from scratch with a naive, insecure, protocol implementation and iterate from there.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Naive approach
&lt;/h2&gt;

&lt;p&gt;In the most straightforward approach, the user would send their secret directly to the API. Problem: the service, aka GitGuardian, would "see" the users' secrets in cleartext, which is unacceptable.&lt;/p&gt;

&lt;p&gt;So, &lt;em&gt;how can a user know whether their secret is in our database of leaked credentials without sharing their secret with us?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Response: using a hashed version of the secret.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Hash-based approach
&lt;/h2&gt;

&lt;p&gt;Now, let’s imagine the user sends a hashed version of their secret to the API. This is definitely an improvement, as the secret is obfuscated, and the service cannot reverse the hash. There is still a privacy problem, though: by definition, if the hashed secret is present in our database, it implies that its cleartext version was once publicly accessible, indicating that GitGuardian has or had knowledge of it. In other words, the user would be leaking their secret to us. And that’s not acceptable either.&lt;/p&gt;

&lt;p&gt;So, &lt;em&gt;how can we prove GitGuardian has zero-knowledge about the requested secret?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Response: by responding with multiple possibilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Bucket-based approach
&lt;/h2&gt;

&lt;p&gt;In this approach, the user only sends a fragment of their secret's hash - specifically, the initial 5 characters. The service then retrieves all secrets it holds that align with these five characters. By ensuring the response 'bucket' is sufficiently large, we effectively veil the original secret request from the service, maintaining the user's privacy.&lt;/p&gt;

&lt;p&gt;💡The bucket's size is intrinsically linked to the hash chunk's length: a longer string yields a smaller bucket. Through hands-on experimentation, we've found that a five-character size currently delivers optimal results. However, this is not set in stone and may be fine-tuned in the future.&lt;/p&gt;

&lt;p&gt;👍 A hearty acknowledgment to Troy Hunt's &lt;a href="https://haveibeenpwned.com/?ref=blog.gitguardian.com"&gt;HaveIBeenPwned&lt;/a&gt;, which significantly inspired this design!&lt;/p&gt;

&lt;p&gt;Now, we have a secure service, yet it's missing a crucial feature. For the service to prove its claim that the secret has been leaked, it must provide the URL location of that leak. Without this feature, the service's usefulness would be almost null.&lt;/p&gt;

&lt;p&gt;So, &lt;em&gt;how can we share the URL of the leak while maintaining the confidentiality of the remaining URLs in the bucket?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Response: by encrypting this information so only the secret's owner can retrieve it.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Adding encryption
&lt;/h2&gt;

&lt;p&gt;The idea is simple: each element in the response bucket is now encrypted (using AES-GCM) with the (full-length) hash of the secret as the key. This way, we can guarantee only a user knowing the hash (and therefore the secret) will be able to decrypt the payload and retrieve the URL location.&lt;/p&gt;

&lt;p&gt;This additional layer of encryption significantly reduces the risk of an enumeration attack. Without it, a cybercriminal could potentially attempt every five-character combination, thereby harvesting our entire database of hashed secrets. However, there remains another potential attack scenario that we'll be addressing shortly.&lt;/p&gt;

&lt;p&gt;We are now faced with a usability issue: the client must painstakingly decipher each item individually to potentially locate the one they possess the key for. There is no way to quickly get an answer to the crucial question: has my secret leaked?&lt;/p&gt;

&lt;p&gt;So, &lt;em&gt;how can we allow the client to get an answer quicker?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Response: by providing an easy-to-check hint for each match.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Providing a hint
&lt;/h2&gt;

&lt;p&gt;The API now provides encrypted responses, coupled with a unique feature - a hint, essentially a hash of the hash. This allows the client to swiftly calculate the hint and determine if a match exists within the response. Put simply, they can rapidly confirm if the hash of their secret is present in the database. To dig deeper, they only need to decrypt the specific item using the original hash of their secret.&lt;/p&gt;

&lt;p&gt;We’ve now built a robust service, which corresponds to the example structure presented at the beginning of this article. Let's address the attack scenario mentioned before.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Preventing other risk scenarios
&lt;/h2&gt;

&lt;h3&gt;
  
  
  a. An attacker compromises a similar database
&lt;/h3&gt;

&lt;p&gt;This scenario implies that an attacker manages to compromise a database of hashed secrets using the same hash function as the one used by our service. In that very special case, they could use our service to reverse the hashes, collect all the locations, and uncover the cleartext secrets.&lt;/p&gt;

&lt;p&gt;To mitigate the above threat, we added a pepper to our hashing function.&lt;/p&gt;

&lt;p&gt;A "pepper" is an additional string added into the hashing process to further increase security. Unlike a "salt", which is unique for each item, a "pepper" is global.&lt;/p&gt;

&lt;p&gt;Adding a pepper makes our hashing function unique and mitigates the possibility of an attacker reversing our hashes with a dumped database.&lt;/p&gt;

&lt;h3&gt;
  
  
  b. An attacker uses a "rainbow table"
&lt;/h3&gt;

&lt;p&gt;What happens if someone attempts to guess the secrets? Similar to passwords, many secrets are not randomly generated but hastily created. This makes them vulnerable to attackers who may use a "rainbow table" - a precomputed table for reversing cryptographic hash functions - to probe our service with a list of common combinations in an attempt to uncover any leaks.&lt;/p&gt;

&lt;p&gt;To mitigate this risk, we've implemented two safeguards:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The service only discloses the first location where a secret is found. This strategy restricts the amount of information that can be misused without hindering legitimate usage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unauthenticated users are limited to five service queries per day. This IP-based rate limit creates a barrier for anyone hoping to strike it lucky with random attempts (we also rate limit authenticated users, but it is less stringent).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  7. Wrapping up: final design implementation
&lt;/h2&gt;

&lt;p&gt;Here is the final interaction diagram to summarize what happens client-side and server-side:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ek5SbcGJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/10/image--13-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ek5SbcGJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/10/image--13-.png" alt="" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HasMySecretLeaked protocol&lt;/p&gt;

&lt;p&gt;Two interfaces implement the client-side protocol we described here to interact with the service API:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;the Javascript code your browser downloads when visiting &lt;a href="https://www.gitguardian.com/hasmysecretleaked?ref=blog.gitguardian.com"&gt;HasMySecretLeaked&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the &lt;a href="https://github.com/GitGuardian/ggshield?ref=blog.gitguardian.com"&gt;GitGuardian CLI &lt;code&gt;ggshield&lt;/code&gt;&lt;/a&gt;, with the new option &lt;code&gt;ggshield hmsl&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the end of our journey! To wrap up, here are the key takeaways you need to remember about HasMySecretLeaked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;At no point does GitGuardian have access to your secret.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We fully recognize the immense responsibility associated with managing sensitive data, and we take the security challenges seriously.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your secret is obfuscated client-side and cannot be reversed by our services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your secret request remains private because you only send the initial five characters of the hash.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If we find a hit, only you, as the owner of the secret, can decrypt the payload and retrieve the URL location.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We have ensured that checking if your secret is included in the response is quick and simple without compromising privacy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To reduce potential risks, we have added extra security measures to our system, such as making our hashing function more complex and restricting the number of service queries allowed per day.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We hope you are now ready to take &lt;a href="https://www.gitguardian.com/hasmysecretleaked?ref=blog.gitguardian.com"&gt;HasMySecretLeaked&lt;/a&gt; for a spin with the peace of mind knowing your secrets are safe!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get started with HasMySecretLeaked&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Addendum: Deep dive into technical choices&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Prefix size
&lt;/h3&gt;

&lt;p&gt;As said earlier, it is important that users share only the prefix of their hashed secret with us, and it is as important for GitGuardian to design the service so that buckets are big enough. This approach ensures that GitGuardian retains minimal, if any, knowledge of the user’s secret.&lt;/p&gt;

&lt;p&gt;The challenge here lies in striking a balance: if the buckets are too small, GitGuardian inadvertently gains excessive insight into the user’s secret. Conversely, overly large buckets can burden the API with hefty payloads. To determine the ideal prefix size, we need to estimate the potential number of secrets in our database.&lt;/p&gt;

&lt;p&gt;Currently, our HMSL database houses approximately 22 million unique secrets. We've selected a prefix composed of 5 hexadecimal characters, yielding roughly 1 million buckets and an average of about 22 secrets per bucket. Assuming that the hash distribution is random and follows a normal distribution, we've ensured no bucket contains fewer than 8 secrets, which aligns with our protocol.&lt;/p&gt;

&lt;p&gt;It's important to note that as more secrets are leaked over time, the buckets will gradually fill up. If they become too cumbersome for our API, we can simply extend the prefix length by one, effectively reducing the average bucket size by a factor of 16.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hashing function
&lt;/h3&gt;

&lt;p&gt;Our chosen hashing function must adhere to the canonical properties of a hashing function, primarily to deter users from reversing a hash and, consequently, extracting passwords from our database. However, there's an additional complexity to consider. Passwords don't follow a random distribution; in fact, they're quite predictable. Passwords can be systematically enumerated, beginning with the most common ones.&lt;/p&gt;

&lt;p&gt;If an individual knows the prefix of a user's hash, they could swiftly compute hashes from a standard list of passwords and compare them to the prefix. If they stumble upon a match, they can reasonably conclude that they've cracked the user's password.&lt;/p&gt;

&lt;p&gt;To counter this, we need to select a hashing method that strikes a balance between speed and complexity. It must be quick enough to ensure a smooth user experience yet intricate enough to thwart attackers from rapidly generating a vast list of hashes. This led us to select &lt;a href="https://en.wikipedia.org/wiki/Scrypt?ref=blog.gitguardian.com"&gt;scrypt&lt;/a&gt; as our preferred hashing method.&lt;/p&gt;

</description>
      <category>security</category>
      <category>github</category>
      <category>secrets</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Yes, GitHub's Copilot can Leak (Real) Secrets</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Wed, 08 Nov 2023 16:18:46 +0000</pubDate>
      <link>https://dev.to/gitguardian/yes-githubs-copilot-can-leak-real-secrets-3jld</link>
      <guid>https://dev.to/gitguardian/yes-githubs-copilot-can-leak-real-secrets-3jld</guid>
      <description>&lt;p&gt;There has been a growing focus on the ethical and privacy concerns surrounding advanced language models like ChatGPT and OpenAI GPT technology. These concerns have raised important questions about the potential risks of using such models. However, it is not only these general-purpose language models that warrant attention; specialized tools like code completion assistants also come with their own set of concerns.&lt;/p&gt;

&lt;p&gt;Read: &lt;a href="https://blog.gitguardian.com/chatgpt-security-concern/" rel="noopener noreferrer"&gt;Why ChatGPT is a security concern for your organization (even if you don't use it)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A year into its launch, GitHub’s code-generation tool Copilot has been used by a million developers, adopted by more than 20,000 organizations, and generated more than three billion lines of code, GitHub said in a blog &lt;a href="https://github.blog/2023-06-27-the-economic-impact-of-the-ai-powered-developer-lifecycle-and-lessons-from-github-copilot/?ref=blog.gitguardian.com" rel="noopener noreferrer"&gt;post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, since its inception, security concerns have been raised by many about the associated legal risks associated with copyright issues, privacy concerns, and, of course, insecure code suggestions, of which examples abound, &lt;a href="https://vlad-rad.medium.com/github-copilot-security-conserns-d4209f0d5c28?ref=blog.gitguardian.com" rel="noopener noreferrer"&gt;including dangerous suggestions to hard-code secrets in code.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Extensive security research is currently being conducted to accurately assess the potential risks associated with these newly advertised productivity-enhancing tools.&lt;/p&gt;

&lt;p&gt;This blog post delves into &lt;a href="https://blog.gitguardian.com/yes-github-copilot-can-leak-secrets/Neural%20Code%20Completion%20Tools%20Can%20Memorize%20Hard-coded%20Credentials" rel="noopener noreferrer"&gt;recent research&lt;/a&gt; by Hong Kong University to test the possibility of abusing GitHub’s Copilot and Amazon’s CodeWhisperer to collect secrets that were exposed during the models' training.&lt;/p&gt;

&lt;p&gt;As highlighted by &lt;a href="https://www.gitguardian.com/files/the-state-of-secrets-sprawl-report-2023?ref=blog.gitguardian.com" rel="noopener noreferrer"&gt;GitGuardian's 2023 State of Secrets Spraw&lt;/a&gt;l, hard-coded secrets are highly pervasive on GitHub, with 10 million new secrets detected in 2022, up 67% from 6 million one year earlier. &lt;/p&gt;

&lt;p&gt;Given that Copilot is trained on GitHub data, it is concerning that coding assistants can potentially be exploited by malicious actors to reveal real secrets in their code suggestions.&lt;/p&gt;

&lt;p&gt;To test this hypothesis, the researchers conducted an experiment to build a prompt-building algorithm trying to extract credentials from the LLMs. &lt;/p&gt;

&lt;p&gt;The conclusion is unambiguous: by constructing 900 prompts from GitHub code snippets, they managed to successfully collect 2,702 hard-coded credentials from Copilot and 129 secrets from CodeWhisper (false positives were filtered out with a special methodology described below). &lt;/p&gt;

&lt;p&gt;Impressively, among those, &lt;strong&gt;at least 200, or 7.4% (respectively 18 and 14%), were real hard-coded secrets they could identify on GitHub&lt;/strong&gt;. While the researchers refrained from confirming whether these credentials were still active, it suggests that these models could potentially be exploited as an avenue for attack. This would enable the extraction and likely compromise of leaked credentials with a high degree of predictability.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Design of a Prompt Engineering Machine
&lt;/h2&gt;

&lt;p&gt;The idea of the study is to see if an attacker could extract secrets by crafting appropriate prompts. To test the odds, the researchers built a prompt testing machine, dubbed the Hard-coded Credential Revealer (HCR). &lt;/p&gt;

&lt;p&gt;The machine has been designed to maximize the chances of triggering a memorized secret. To do so, it needs to build a strong prompt that will "force" the model to emit the secret. The way to build this prompt is to first look on GitHub for files containing hard-coded secrets using regex patterns. Then, the original hard-coded secret is redacted, and the machine asks the model for code suggestions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://lh4.googleusercontent.com/Y-md-b4KyuFazSfBgwgAvPs43Z6Eet1lgGTwb1HZzC5JeU3ldanxwmsQMuDu7AWebH8dVj7vD6QyOk1ZsjTCpDbRwck_n7FOhASoW9uYGC_AU6UFA_fJ21gNjuJZC2hS76gCehiMKyy9w3dn0-xOXqo" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flh4.googleusercontent.com%2FY-md-b4KyuFazSfBgwgAvPs43Z6Eet1lgGTwb1HZzC5JeU3ldanxwmsQMuDu7AWebH8dVj7vD6QyOk1ZsjTCpDbRwck_n7FOhASoW9uYGC_AU6UFA_fJ21gNjuJZC2hS76gCehiMKyy9w3dn0-xOXqo" alt="the Hard-coded Credential Revealer (HCR)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, the model will need to be requested many times to have a slight chance of extracting valid credentials, because it often outputs "imaginary" credentials. &lt;/p&gt;

&lt;p&gt;They also need to test many prompts before finding an operational credential, allowing them to log into a system. &lt;/p&gt;

&lt;p&gt;In this study, 18 patterns are used to identify code snippets on GitHub, corresponding to 18 different types of secrets (AWS Access Keys, Google OAuth Access Token, GitHub OAuth Access Token, etc.).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;💡Although 18 secrets types is far from exhaustive (the GitGuardian secrets scanner is able to detect 350+ types of secrets), they are still representative of services widely used by software developers and are easily identifiable.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then, the secrets are removed from the original file, and the code assistant is used to suggest new strings of characters. Those suggestions are then passed through four filters to eliminate a maximum number of false positives&lt;/p&gt;

&lt;p&gt;Secrets are discarded if they:&lt;/p&gt;

&lt;p&gt;- don't match the regex pattern&lt;/p&gt;

&lt;p&gt;- don't show enough entropy (not random enough, ex: &lt;code&gt;AKIAXXXXXXXXXXXXXXXX&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;- have a recognizable pattern (ex: &lt;code&gt;AKIA3A3A3A3A3A3A3A3A&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;- include common words (ex: &lt;code&gt;AKIAIOSFODNN7EXAMPLE&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;A secret that passes all these tests is considered &lt;em&gt;valid&lt;/em&gt;, which means it could realistically be a true secret (hard-coded somewhere else in the training data).&lt;/p&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;Among 8,127 suggestions of Copilot, 2,702 valid secrets were successfully extracted. Therefore, the overall valid rate is 2702/8127 = 33.2%, meaning that &lt;strong&gt;Copilot generates 2702/900 = 3.0 valid secrets for one prompt on average.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CodeWhisperer suggests 736 code snippets in total, among which we identify 129 valid secrets. The valid rate is thus 129/736 = 17.5%.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;💡Keep in mind that in this study, a valid secret doesn't mean the secret is real. It means that it successfully passed the filters and, therefore has the properties corresponding to a real secret.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, how can we know if these secrets are genuine operational credentials?&lt;/strong&gt; The authors explained that they only tried a subset of the valid credentials (test keys like Stripe Test Keys designed for developers to test their programs) for ethical considerations. &lt;/p&gt;

&lt;p&gt;Instead, the authors are looking for another way to validate the authenticity of the valid credentials collected. They want to assess the memorization, or where the secret appeared on GitHub.&lt;/p&gt;

&lt;p&gt;The rest of the research focuses on the characteristics of the valid secrets. They look for the secret using GitHub Code Search and differentiate &lt;em&gt;strongly&lt;/em&gt; memorized secrets, which are identical to the secret removed in the first place, and &lt;em&gt;weakly&lt;/em&gt; memorized secrets, which came from one or multiple other repositories. Finally, there are secrets that could not be located on GitHub and which might come from other sources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consequences
&lt;/h2&gt;

&lt;p&gt;The research paper uncovers a significant privacy risk posed by code completion tools like GitHub Copilot and Amazon CodeWhisperer. The findings indicate that these models not only leak the original secrets present in their training data but also suggest other secrets that were encountered elsewhere in their training corpus. This exposes sensitive information and raises serious privacy concerns.&lt;/p&gt;

&lt;p&gt;For instance, even if a hard-coded secret was removed from the git history after being leaked by a developer, an attacker can still extract it using the prompting techniques described in the study. The research demonstrates that these models can suggest valid and operational secrets found in their training data.&lt;/p&gt;

&lt;p&gt;These findings are supported by another recent study conducted by a researcher from Wuhan University, titled &lt;a href="https://arxiv.org/pdf/2310.02059.pdf?ref=blog.gitguardian.com" rel="noopener noreferrer"&gt;Security Weaknesses of Copilot Generated Code in GitHub&lt;/a&gt;. The study analyzed 435 code snippets generated by Copilot from GitHub projects and used multiple security scanners to identify vulnerabilities.&lt;/p&gt;

&lt;p&gt;According to the study, 35.8% of the Copilot-generated code snippets exhibited security weaknesses, regardless of the programming language used. By classifying the identified security issues using Common Weakness Enumerations (CWEs), the researchers found that "Hard-coded credentials" (CWE-798) were present in 1.15% of the code snippets, accounting for 1.5% of the 600 CWEs identified.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mitigations
&lt;/h2&gt;

&lt;p&gt;Addressing the privacy attack on LLMs requires mitigation efforts from both programmers and machine learning engineers.&lt;/p&gt;

&lt;p&gt;To reduce the occurrence of hard-coded credentials, the authors recommend using centralized credential management tools and code scanning to prevent the inclusion of code with hard-coded credentials.&lt;/p&gt;

&lt;p&gt;During the various stages of code completion model development, different approaches can be adopted:&lt;/p&gt;

&lt;p&gt;- Before pre-training, hard-coded credentials can be excluded from the training data by cleaning it.&lt;/p&gt;

&lt;p&gt;- During training or fine-tuning, algorithmic defenses such as Differential Privacy (DP) can be employed to ensure privacy preservation. DP provides strong guarantees of model privacy.&lt;/p&gt;

&lt;p&gt;- During inference, the model output can be post-processed to filter out secrets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This study exposes a significant risk associated with code completion tools like GitHub Copilot and Amazon CodeWhisperer. By crafting prompts and analyzing publicly available code on GitHub, the researchers successfully extracted numerous valid hard-coded secrets from these models. &lt;/p&gt;

&lt;p&gt;To mitigate this threat, programmers should use centralized credential management tools and code scanning to prevent the inclusion of hard-coded credentials. Machine learning engineers can implement measures such as excluding these credentials from training data, applying privacy preservation techniques like Differential Privacy, and filtering out secrets in the model output during inference.&lt;/p&gt;

&lt;p&gt;These findings extend beyond Copilot and CodeWhisperer, emphasizing the need for security measures in all neural code completion tools. Developers must take proactive steps to address this issue before releasing their tools.&lt;/p&gt;

&lt;p&gt;In conclusion, addressing the privacy risks and protecting sensitive information associated with large language models and code completion tools requires collaborative efforts between programmers, machine learning engineers, and tool developers. By implementing the recommended mitigations, such as centralized credential management, code scanning, and exclusion of hard-coded credentials from training data, the privacy risks can be effectively mitigated. It is crucial for all stakeholders to work together to ensure the security and privacy of these tools and the data they handle.&lt;/p&gt;

</description>
      <category>github</category>
      <category>githubcopilot</category>
      <category>security</category>
      <category>llm</category>
    </item>
    <item>
      <title>From Code to Cloud: Security for Developers [cheat sheet included]</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Sun, 15 Oct 2023 22:00:00 +0000</pubDate>
      <link>https://dev.to/gitguardian/from-code-to-cloud-security-for-developers-cheat-sheet-included-3mbo</link>
      <guid>https://dev.to/gitguardian/from-code-to-cloud-security-for-developers-cheat-sheet-included-3mbo</guid>
      <description>&lt;p&gt;From code development and approval to continuous integration and deployment, each stage presents unique challenges and opportunities to enhance the security of your applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2023/08/Snyk-x-GG-cheat-sheet-2.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HlbDfYjo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/08/Snyk-x-GG-cheat-sheet-2.png" alt="5 tips to Supercharge App Security from Code to Cloud" width="800" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gitguardian.com/files/snyk-gitguardian-cheatsheet"&gt;Download the cheat sheet ⬇️⬇️&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By following the recommendations in this cheat sheet, you will be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Identify and fix vulnerabilities&lt;/strong&gt; in your code early using the Snyk CLI and Snyk IDE plugins.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Prevent secrets from being committed&lt;/strong&gt; to your repository with GitGuardian's ggshield.&lt;/li&gt;
&lt;li&gt;  Safely &lt;strong&gt;store and share secrets&lt;/strong&gt; using encryption or secrets managers.&lt;/li&gt;
&lt;li&gt;  Protect your source code from compromise using &lt;strong&gt;&lt;a href="https://www.gitguardian.com/honeytoken?ref=blog.gitguardian.com"&gt;honeytokens&lt;/a&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;  Conduct &lt;strong&gt;code reviews&lt;/strong&gt; and address security weaknesses during the code approval stage.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Analyze infrastructure code&lt;/strong&gt; for misconfigurations using Snyk Infrastructure as CodeI.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Scan your code and artifacts for vulnerabilities&lt;/strong&gt; during the continuous integration and deployment process.&lt;/li&gt;
&lt;li&gt;  Ensure that &lt;strong&gt;no secrets are leaked&lt;/strong&gt; in the final artifact with GitGuardian integration.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Be alerted&lt;/strong&gt; if your CI/CD service gets compromised using Honeytokens.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Scan container images&lt;/strong&gt; for vulnerabilities and leaked secrets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With these security measures in place, you can have confidence in the integrity and security of your code as it moves from development to deployment in the cloud.&lt;/p&gt;

&lt;p&gt;Let's dive into each stage and explore the tools and practices that will help you build secure and robust applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stage 1: Code Development
&lt;/h2&gt;

&lt;p&gt;At this stage, you are crafting your code, adding dependencies, preparing your app to interface with external systems (backends, SaaS, databases, etc.), and hopefully writing tests!&lt;/p&gt;

&lt;p&gt;The main threats here are committing a secret, misconfiguration, coding a vulnerability, or adding a malicious dependency. To prevent these outcomes, there is a lot that you can set up to detect and fix issues early on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Get security feedback right into your IDE&lt;/strong&gt; with the &lt;a href="https://snyk.co/ufRCQ?ref=blog.gitguardian.com"&gt;Snyk IDE&lt;/a&gt; plugin. This plugin provides real-time security feedback as you code, helping you identify and fix vulnerabilities and issues directly within your development environment.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Detect and fix vulnerabilities with the Snyk CLI&lt;/strong&gt;. Install the &lt;a href="https://snyk.co/ufRCP?ref=blog.gitguardian.com"&gt;Snyk CLI&lt;/a&gt; globally by running &lt;code&gt;npm install snyk-g&lt;/code&gt;. This allows you to run various commands such as &lt;code&gt;snyk test&lt;/code&gt;, &lt;code&gt;snyk code test&lt;/code&gt;, &lt;code&gt;snyk container test&lt;/code&gt;, and &lt;code&gt;snyk iac test&lt;/code&gt; to scan your code, dependencies, containers, and infrastructure-as-code for vulnerabilities and misconfiguration. &lt;strong&gt;Never commit a secret again&lt;/strong&gt; &lt;strong&gt;with GitGuardian&lt;/strong&gt; ggshield. Install GitGuardian by running the following command (on macOS):&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then automatically get a token for scanning with:&lt;code&gt;gghsield auth login&lt;/code&gt;&lt;br&gt;&lt;br&gt;
To prevent committing secrets, add the ggshield secret scan pre-commit hook to your local .git/hooks folder by using the command: &lt;code&gt;gghsield install --mode local --hook-type pre-commit -a&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also scan your local repository immediately to identify hard-coded secrets by running &lt;code&gt;gghsield secret scan repo&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Store and share secrets safely&lt;/strong&gt;: To securely store and share secrets, you can either encrypt your secrets in your repository using tools like &lt;a href="https://blog.gitguardian.com/a-comprehensive-guide-to-sops/"&gt;SOPS&lt;/a&gt; or call a secrets manager from your code using clients such as &lt;a href="https://github.com/hvac/hvac?ref=blog.gitguardian.com"&gt;hvac&lt;/a&gt; (for Hashicorp’s Vault) or &lt;a href="https://github.com/boto/boto3?ref=blog.gitguardian.com"&gt;boto3&lt;/a&gt; (for AWS Secrets Manager). Check out examples of how to handle secrets in Python &lt;a href="https://blog.gitguardian.com/how-to-handle-secrets-in-python/"&gt;here&lt;/a&gt;. &lt;strong&gt;Protect against code compromise&lt;/strong&gt;: Malicious actors actively seek source code to compromise organizations of all scales. Fortunately, you can protect your source code by using honeytokens. Use the &lt;code&gt;gghsield honeytoken create&lt;/code&gt; command to create honeytokens if enabled in your workspace. Honeytokens can help detect if an unauthorized actor accessed your source code or if it was publicly exposed on GitHub. Learn how to secure your SCM repositories with GitGuardian honeytokens &lt;a href="https://blog.gitguardian.com/how-to-secure-your-scm-repositories-with-gitguardian-honeytokens/"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Stage 2: Code Approval
&lt;/h2&gt;

&lt;p&gt;Whether you are working alongside dozens of fellow coders or contributing to an open-source project, the next step is to push your work to a central repository. This is the occasion for your changes to get reviewed by peers. The goal is to keep code quality consistent, get feedback, and fix security vulnerabilities and license issues.&lt;/p&gt;

&lt;p&gt;To ensure the security of your code during the code approval stage, consider the following guidelines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Get feedback&lt;/strong&gt;: When working in a team, it's essential to have at least one pair of eyes review the code for quality, security, and adherence to coding standards. Code reviews can help identify potential security vulnerabilities and provide valuable feedback.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Check for security failures&lt;/strong&gt;: Use &lt;a href="https://snyk.co/ufRCR?ref=blog.gitguardian.com"&gt;Snyk Open Source&lt;/a&gt; to assess the reliability of the added dependencies. Additionally, it can help identify if a license is compliant with your organization's policy. This ensures that the dependencies you are using are secure and meet the necessary licensing requirements.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Check for common security weaknesses&lt;/strong&gt;: Leverage &lt;a href="https://snyk.co/ufRCS?ref=blog.gitguardian.com"&gt;Snyk Code&lt;/a&gt;, a real-time static analysis tool, to identify common security weaknesses in your code. It can provide alerts and recommendations to help you address these weaknesses and improve the overall security of your codebase. &lt;strong&gt;Enforce no secrets get leaked&lt;/strong&gt;: Implement a check for leaked secrets in the main repository. This can be done by integrating GitGuardian into your code approval process. By scanning for hard-coded secrets during the code approval stage, you can ensure that no secrets are leaked and avoid the need for a secret rotation procedure.&lt;/li&gt;
&lt;li&gt;  *&lt;em&gt;**Analyze Infrastructure code (IaC) for misconfigurations&lt;/em&gt;&lt;em&gt;:&lt;/em&gt;* Use &lt;a href="https://snyk.co/ufRCT?ref=blog.gitguardian.com"&gt;Snyk Infrastructure as Code&lt;/a&gt; (IaC) to analyze your IaC  templates and configurations for misconfigurations and vulnerabilities. This helps ensure that your infrastructure is properly configured and secure before deployment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Stage 3: Continuous Integration and Deployment
&lt;/h2&gt;

&lt;p&gt;After being approved, your changes finally get merged into the main branch (or the appropriate trunk) of your project. The code is now ready to be built, tested, and eventually deployed. However, before that can happen, multiple checks are needed. Welcome to the automated test kingdom, where the inner workings of the code are scrutinized to ensure quality and security requirements are met.&lt;/p&gt;

&lt;p&gt;During the Continuous Integration and Deployment (CI/CD) pipeline, consider implementing the following steps to ensure the security of your code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Scan the source code for vulnerabilities&lt;/strong&gt;: Integrate Snyk with your CI/CD pipelines to scan for vulnerabilities during the build process. This ensures that any vulnerabilities in your code are identified and can be addressed before deployment.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Ensure no secrets are found in the final artifact&lt;/strong&gt;: Integrate GitGuardian into your CI/CD pipeline to detect any hard-coded secrets during the pipeline execution. This helps prevent secrets from being included in the final artifact and ensures that sensitive information is not exposed.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Detect intrusions in  your CI/CD pipelines&lt;/strong&gt;: Enhance the security of your build process by using Honeytokens. Place Honeytokens in the secure store of your CI/CD provider (as secrets, or environment variables) to ensure that you receive alerts if your builds are compromised. This helps detect any unauthorized access to pipelines and allows you to take appropriate actions. Learn more &lt;a href="https://blog.gitguardian.com/how-to-add-gitguardian-honeytokens-in-ci-cd-pipelines/"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Scan artifacts&lt;/strong&gt;: Even if your source code passes all security checks, it's important to scan the final artifact for vulnerabilities. Use tools like Snyk Container and ggshield secret scan docker to scan container images and ensure that the end product is clean and free from vulnerabilities and leaked secrets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By following these steps in the CI/CD pipeline, you can ensure that your code is secure and meets the necessary quality and security requirements before deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stage 4: Deploy
&lt;/h2&gt;

&lt;p&gt;Once your code has been approved and tested, it's time to deploy it to a cloud environment or infrastructure. However, before doing so, it's important to ensure the security of your deployment process. Here are some steps you can take:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Secure your deployment pipeline&lt;/strong&gt;: Implement secure deployment practices such as using secure connections (HTTPS), verifying the integrity of your deployment artifacts, and using secure authentication methods.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Scan your deployment configuration&lt;/strong&gt;: Use Snyk IaC to scan your infrastructure-as-code (IaC) templates and configurations for misconfigurations and vulnerabilities. This will help you identify any security issues before deploying your code.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Monitor your deployment&lt;/strong&gt;: Implement monitoring and logging solutions to track the performance and security of your deployment. This will help you identify any anomalies or potential security threats. &lt;strong&gt;Implement security best practices&lt;/strong&gt;: Follow security best practices for cloud deployments, such as using strong access controls, regularly updating your software and dependencies, and encrypting sensitive data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Stage 5: Cloud&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once your code is deployed to a cloud environment, it's important to continuously monitor the security of your cloud infrastructure and applications. Here are some steps you can take to ensure the security of your cloud environment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Implement logging and monitoring&lt;/strong&gt;: Set up logging and monitoring solutions to track and analyze the activity in your cloud environment. This will help you detect any security vulnerabilities or threats.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Implement threat detection&lt;/strong&gt;: Use threat detection tools and services to identify and respond to potential security threats in real-time. This can include detecting unauthorized access attempts, unusual network traffic, or suspicious behavior.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Regularly update and patch&lt;/strong&gt;: Keep your cloud infrastructure and applications up to date by regularly applying security patches and updates. This will help protect against known vulnerabilities and exploits.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Implement access controls&lt;/strong&gt;: Use strong access controls and authentication mechanisms to ensure that only authorized users and services can access your cloud resources. This can include implementing multi-factor authentication, role-based access controls, and least privilege principles. Get the &lt;a href="https://blog.gitguardian.com/understanding-identity-and-access-management-best-practices-cheat-sheet-included/"&gt;IAM cheat sheet here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Regularly review and audit&lt;/strong&gt;: Conduct regular security reviews and audits of your cloud environment to identify any potential security weaknesses or misconfigurations. This can help you proactively address any security issues before they are exploited.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By following these steps and utilizing tools like Snyk and GitGuardian, developers can ensure the security of their code throughout the entire development and deployment process.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>security</category>
      <category>programming</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Microsoft AI involuntarily exposed a secret giving access to 38TB of confidential data for 3 years</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Tue, 10 Oct 2023 13:29:59 +0000</pubDate>
      <link>https://dev.to/gitguardian/microsoft-ai-involuntarily-exposed-a-secret-giving-access-to-38tb-of-confidential-data-for-3-years-372j</link>
      <guid>https://dev.to/gitguardian/microsoft-ai-involuntarily-exposed-a-secret-giving-access-to-38tb-of-confidential-data-for-3-years-372j</guid>
      <description>&lt;p&gt;The WIZ Research team &lt;a href="https://www.wiz.io/blog/38-terabytes-of-private-data-accidentally-exposed-by-microsoft-ai-researchers?ref=blog.gitguardian.com"&gt;recently discovered&lt;/a&gt; that an overprovisioned SAS token had been lying exposed on GitHub for nearly three years. This token granted access to a massive 38-terabyte trove of private data. This Azure storage contained additional secrets, such as private SSH keys, hidden within the disk backups of two Microsoft employees. This revelation underscores the importance of robust data security measures.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://lh5.googleusercontent.com/ZnQJ4P9Bfg9RdOk1JVAsVUxXVdYEEplUooiCJk02G2-1kxQ5NVlPNQgu9ctJMKOtMZWHFEqrJltSnHtsg0_Q1bF8jZDeSO0ZTEe8vGU95TEl05LazW1Mv0wLvyL8Y79aE8D8HPhhkC_0M5008kR6H3s"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8ey3W19V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh5.googleusercontent.com/ZnQJ4P9Bfg9RdOk1JVAsVUxXVdYEEplUooiCJk02G2-1kxQ5NVlPNQgu9ctJMKOtMZWHFEqrJltSnHtsg0_Q1bF8jZDeSO0ZTEe8vGU95TEl05LazW1Mv0wLvyL8Y79aE8D8HPhhkC_0M5008kR6H3s" alt="Microsoft AI" width="728" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What happened?
&lt;/h2&gt;

&lt;p&gt;WIZ Research recently disclosed a data exposure incident found on Microsoft’s AI GitHub repository on June 23, 2023.&lt;/p&gt;

&lt;p&gt;The researchers managing the GitHub used an Azure Storage sharing feature through a SAS token to give access to a bucket of open-source AI training data.&lt;/p&gt;

&lt;p&gt;This token was misconfigured, giving access to the account's entire cloud storage rather than the intended bucket.&lt;/p&gt;

&lt;p&gt;This storage comprised 38TB of data, including a disk backup of two employees’ workstations with secrets, private keys, passwords, and more than 30,000 internal Microsoft Teams messages.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;SAS (Shared Access Signatures)&lt;/strong&gt; are signed URLs for sharing Azure Storage resources. They are configured with fine-grained controls over how a client can access the data: what resources are exposed (full account, container, or selection of files), with what permissions, and for how long. See &lt;a href="https://learn.microsoft.com/en-us/azure/storage/common/storage-sas-overview?ref=blog.gitguardian.com"&gt;Azure Storage documentation&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After disclosing the incident to Microsoft, the SAS token was invalidated. From its first commit to GitHub (July 20, 2020) to its revoking, &lt;strong&gt;nearly three years elapsed&lt;/strong&gt;. See the timeline presented by the Wiz Research team:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://lh5.googleusercontent.com/cKXTq7_8XSwl-MeJMQ6FOvNpsByk365bxgDZKHfnipBf1d0ou793OW88RD8EyjocC2d40xaWKaoOyp2l5_4nxeoV89TmLTtzek75zm4GFX0a9-C4w5lwkNlipSojgW8I0oWXu4y3h8NpL7Q5NMFmXBY"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oGelPzv8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh5.googleusercontent.com/cKXTq7_8XSwl-MeJMQ6FOvNpsByk365bxgDZKHfnipBf1d0ou793OW88RD8EyjocC2d40xaWKaoOyp2l5_4nxeoV89TmLTtzek75zm4GFX0a9-C4w5lwkNlipSojgW8I0oWXu4y3h8NpL7Q5NMFmXBY" alt="" width="677" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why did the token have such an extended lifespan? If you take a look at the timeline, you'll see that the token's expiration date was extended by an additional 30 &lt;em&gt;years&lt;/em&gt; post-expiration. This longevity isn't surprising when you consider that the token was intentionally engineered to be shared and grant access to training data.&lt;/p&gt;

&lt;p&gt;Yet, as emphasized by the WIZ Research team, &lt;strong&gt;there was a misconfiguration with the Shared Access Signature (SAS).&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Exposure
&lt;/h2&gt;

&lt;p&gt;The token was allowing anyone to access an additional 38TB of data, including sensitive data such as secret keys, personal passwords, and over 30,000 internal Microsoft Teams messages from hundreds of Microsoft employees.&lt;/p&gt;

&lt;p&gt;Here is an excerpt from some of the most sensitive data recovered by the Wiz team:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://lh4.googleusercontent.com/MCljgPSAna_g8PKXRwMGge4ej3rIddZA9nYCwasv3qDvt-1anWVHy2B84dgRzQTv_MY-IcjWb8SbFyvPvWsXIzHHkO06zJxhN8PaGFvNGRrMf--n93wXJfx32BeEVj9Y18xNq6PQpBSLTMn_mvxGB7o"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zoDoX-gE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh4.googleusercontent.com/MCljgPSAna_g8PKXRwMGge4ej3rIddZA9nYCwasv3qDvt-1anWVHy2B84dgRzQTv_MY-IcjWb8SbFyvPvWsXIzHHkO06zJxhN8PaGFvNGRrMf--n93wXJfx32BeEVj9Y18xNq6PQpBSLTMn_mvxGB7o" alt="1695041318-03-files.jpg" width="800" height="579"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not only was the access scope excessively permissive, but the token was also misconfigured to grant "full control" permissions instead of read-only. This means that an attacker not only had the ability to view all the files in the storage account but could also delete and overwrite existing files.&lt;/p&gt;

&lt;p&gt;As highlighted by the researchers, this could have allowed an attacker to inject malicious code into the storage blob that could then automatically execute with every download by a user (presumably an AI researcher) trusting in Microsoft's reputation, which could have led to a &lt;strong&gt;supply chain attack&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Also read&lt;/em&gt; &lt;a href="https://www.gitguardian.com/learning-center/software-supply-chain-security?ref=blog.gitguardian.com"&gt;&lt;em&gt;Examples of software supply chain attacks&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Security Risks
&lt;/h2&gt;

&lt;p&gt;According to the researchers, Account SAS tokens such as the one presented in their research present a high-security risk. This is because these tokens are highly permissive, long-lived tokens that escape the monitoring perimeter of administrators.&lt;/p&gt;

&lt;p&gt;When a user generates a new token, it is signed by the browser and doesn't trigger any Azure event. To revoke a token, an administrator needs to rotate the signing account key, therefore revoking all the other tokens at once.&lt;/p&gt;

&lt;p&gt;Ironically, the security risk of a Microsoft product feature (Azure SAS tokens) caused an incident for a Microsoft research team, a risk recently referenced by the second version of the Microsoft threat matrix for storage services:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://lh4.googleusercontent.com/PDWyEgvTaoye_ZZ7gLGO__EeWIULPLwuO3A7t36zNXcqjF8bs_ZQobcuZijV_c9UttP49AspRAkepjqNJYmHW7Nk4Hhok8_BdX2SiyqLZD63gRZZ6EIl_0le8Lqg_JfRaHoxI357MDSLTWbELcqbFDU"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D_j67t_5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh4.googleusercontent.com/PDWyEgvTaoye_ZZ7gLGO__EeWIULPLwuO3A7t36zNXcqjF8bs_ZQobcuZijV_c9UttP49AspRAkepjqNJYmHW7Nk4Hhok8_BdX2SiyqLZD63gRZZ6EIl_0le8Lqg_JfRaHoxI357MDSLTWbELcqbFDU" alt="" width="626" height="283"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Secrets Sprawl
&lt;/h2&gt;

&lt;p&gt;This example perfectly underscores the pervasive issue of &lt;strong&gt;secrets sprawl&lt;/strong&gt; within organizations, even those with advanced security measures. Intriguingly, it highlights how an AI research team, or any data team, can independently create tokens that could potentially jeopardize the organization. These tokens can cleverly sidestep the security safeguards designed to shield the environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gitguardian.com/files/the-state-of-secrets-sprawl-report-2023?ref=blog.gitguardian.com"&gt;&lt;em&gt;Read the State of Secrets Sprawl 2023&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mitigation strategies
&lt;/h2&gt;

&lt;h3&gt;
  
  
  For Azure Storage users:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1 - avoid Account SAS tokens
&lt;/h4&gt;

&lt;p&gt;The lack of monitoring makes this feature a security hole in your perimeter. A better way to share data externally is using a Service SAS with a &lt;a href="https://learn.microsoft.com/en-us/rest/api/storageservices/define-stored-access-policy?ref=blog.gitguardian.com"&gt;Stored Access Policy&lt;/a&gt;. This feature binds a SAS token to a policy, providing the ability to centrally manage token policies.&lt;/p&gt;

&lt;p&gt;Better though, if you don't need to use this Azure Storage sharing feature, is to simply disable SAS access for each account you own.&lt;/p&gt;

&lt;h4&gt;
  
  
  2 - enable Azure Storage analytics
&lt;/h4&gt;

&lt;p&gt;Active SAS tokens usage can be monitored through the &lt;a href="https://learn.microsoft.com/en-us/azure/storage/common/manage-storage-analytics-logs?ref=blog.gitguardian.com"&gt;Storage Analytics logs&lt;/a&gt; for each of your storage accounts. &lt;a href="https://learn.microsoft.com/en-us/azure/storage/blobs/blob-storage-monitoring-scenarios?ref=blog.gitguardian.com"&gt;Azure Metrics&lt;/a&gt; allows the monitoring of SAS-authenticated requests and identifies storage accounts that have been accessed through SAS tokens, for up to 93 days.&lt;/p&gt;

&lt;h3&gt;
  
  
  For all:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1 -  Audit your GitHub perimeter for sensitive secrets
&lt;/h4&gt;

&lt;p&gt;With around 90 million developer accounts, 300 million hosted repositories, and 4 million active organizations, including 90% of Fortune 100 companies, GitHub holds a much larger attack surface than meets the eye.&lt;/p&gt;

&lt;p&gt;Last year, GitGuardian uncovered 10 million leaked secrets on public repositories, up 67% from the previous year.&lt;/p&gt;

&lt;p&gt;GitHub must be actively monitored as part of any organization's security perimeter. Incidents involving leaked credentials on the platform continue to cause massive breaches for large companies, and this security hole in Microsoft's protective shell wasn't without reminding us of the &lt;a href="https://blog.gitguardian.com/toyota-accidently-exposed-a-secret-key-publicly-on-github-for-five-years/"&gt;Toyota data breach from a year ago&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;On October 7, 2022 Toyota, the Japanese-based automotive manufacturer, revealed they had accidentally exposed a credential allowing access to customer data in a public GitHub repo for nearly 5 years. The code was made public from December 2017 through September 2022. While Toyota says they have invalidated the key, any exposure this long could mean multiple malicious actors had already acquired access.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Being able to detect exposed sensitive tokens on GitHub is a unique feature of &lt;a href="https://www.gitguardian.com/monitor-public-github-for-secrets?ref=blog.gitguardian.com"&gt;GitGuardian's Public Monitoring&lt;/a&gt; system. It allows security analysts to quickly inspect an organization's footprint on the platform, identify valid secrets, and assess the severity of incidents. What is more, the engine is able to include developers’ personal public repositories —  where 80% of corporate credentials are leaked —  to an organization's perimeter.&lt;/p&gt;

&lt;p&gt;If your company has development teams, it is very likely that some of your company's secrets (API keys, tokens, password) end up on public GitHub, so you should evaluate your GitHub attack surface by &lt;a href="https://www.gitguardian.com/complimentary-audit-secrets-leaks-public-github?ref=blog.gitguardian.com"&gt;requesting a complimentary audit&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2 - Lay out traps in the form of honeytokens
&lt;/h3&gt;

&lt;p&gt;Do you need time to restructure governance around cloud storage access, yet need to be alerted if highly sensitive parts get scanned by a malicious actor?&lt;/p&gt;

&lt;p&gt;Your best allies are &lt;a href="https://www.gitguardian.com/honeytoken?ref=blog.gitguardian.com"&gt;honeytokens&lt;/a&gt;. These tokens are decoy AWS secrets you can deploy strategically across your software assets to regain observability in the grey areas of your IT infrastructure. Getting the attackers' IP addresses, user agent, what actions they were attempting, and the timestamps of each attempt will help you thwart attempts before they can inflict damage on your software supply chain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final words
&lt;/h2&gt;

&lt;p&gt;Every organization, regardless of size, needs to be prepared to tackle a wide range of emerging risks. These risks often stem from insufficient monitoring of extensive software operations within today's modern enterprises. In this case, an AI research team inadvertently created and exposed a misconfigured cloud storage sharing link, bypassing security guardrails. But how many other departments - support, sales, operations, or marketing - could find themselves in a similar situation? The increasing dependence on software, data, and digital services amplifies cyber risks on a global scale.&lt;/p&gt;

&lt;p&gt;Combatting the spread of confidential information and its associated risks necessitates reevaluating security teams' oversight and governance capabilities. It also requires the provision of appropriate tools to identify and counteract emerging threat categories. While human errors are an inevitable part of the process, GitGuardian is here to guide you along your security journey.&lt;/p&gt;

&lt;p&gt;Read also:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/findings-from-the-sophos-2023-active-adversary-report/"&gt;Compromised Credentials Leading Cause Of Initial Attack Access And Faster Attacks: Findings from the Sophos 2023 Active Adversary Report&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/a-maturity-model-for-secrets-management/"&gt;When it Comes to Secrets, How Mature is Your Organization?&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Securing your CI/CD: an OIDC Tutorial</title>
      <dc:creator>Thomas Segura</dc:creator>
      <pubDate>Wed, 04 Oct 2023 13:00:00 +0000</pubDate>
      <link>https://dev.to/gitguardian/securing-your-cicd-an-oidc-tutorial-57k6</link>
      <guid>https://dev.to/gitguardian/securing-your-cicd-an-oidc-tutorial-57k6</guid>
      <description>&lt;p&gt;Let's start with a story: have you heard the news about &lt;a href="https://techcrunch.com/2023/01/05/circleci-breach/?ref=blog.gitguardian.com"&gt;CircleCI's breach&lt;/a&gt;? No, not the one where they accidentally leaked some customer credentials a few years back. This time, it's a bit more serious:&lt;/p&gt;

&lt;p&gt;It seems that some unauthorized individuals were able to gain access to CircleCI's systems, compromising the secrets stored in CircleCI. CircleCI advised users to rotate "any and all secrets" stored in CircleCI, including those stored in project environment variables or contexts.&lt;/p&gt;

&lt;p&gt;The CircleCI breach serves as a stark reminder of the risks associated with storing sensitive information in CI/CD systems. Next, let's talk about CI/CD security a bit more.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. CI/CD Security
&lt;/h2&gt;

&lt;p&gt;CI/CD systems, like CircleCI, are platforms used by developers to automate build/deploy processes, which, by definition, means that they need to access other systems to deploy software or use some services, like cloud services.&lt;/p&gt;

&lt;p&gt;For example, after building some artifacts, you probably need to push those artifacts to some repositories; for another, when deploying your cloud infrastructure using code, you need to access public cloud providers to create stuff.&lt;/p&gt;

&lt;p&gt;As we can imagine, this means that a lot of sensitive information gets passed through the CI/CD platforms daily, because for CI/CD to interact with other systems, some type of authentication and authorization is required, and in most cases, passwords are used for this.&lt;/p&gt;

&lt;p&gt;So, needless to say, the security of the CI/CD systems themselves is critical. Unfortunately, although CI/CD systems are designed to automate software development processes, they might not necessarily be built with security in mind and they are not 100% secure (well, nothing is).&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Best Practices to secure CI/CD systems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Best Practice #1: No Long-Lived Credentials
&lt;/h3&gt;

&lt;p&gt;One of the best practices, of course, is not to use long-lived credentials at all.&lt;/p&gt;

&lt;p&gt;For example, when you access AWS, always use temporary security credentials (IAM roles) instead of long-term access keys. Now, when you try to create an access key, AWS even reminds you to not do this, but recommends SSO/other methods.&lt;/p&gt;

&lt;p&gt;In fact, in many scenarios, you don't need long-term access keys that never expire; instead, you can create IAM roles and generate temporary security credentials. Temporary security credentials consist of an access key ID and a secret access key, but they also include a security token that indicates when the credentials expire.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.2 Best Practice #2: Don't Store Secrets in CI/CD Systems
&lt;/h3&gt;

&lt;p&gt;By storing secrets in CI systems, we are essentially placing our trust in a third-party service to keep sensitive information safe. However, if that service is ever compromised, as was the case with CircleCI, then all of the secrets stored within it are suddenly at risk, which can result in serious consequences.&lt;/p&gt;

&lt;p&gt;What we can do is to use some secrets manager to store secrets, and use a secure way in our CI/CD systems to retrieve those secrets. If you are not familiar with data security or secrets managers, maybe give &lt;a href="https://blog.gitguardian.com/talking-about-data-security-an-introduction-to-aws-kms-and-hashicorp-vault/"&gt;this blog&lt;/a&gt; a quick read.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.3 Best Practice #3: Rotate/Refresh Your Passwords
&lt;/h3&gt;

&lt;p&gt;Not all systems you are trying to access from your CI/CD systems support some kind of short-lived credentials like AWS does. There are certain cases where you would have to use long-lived passwords, and in those cases, you need to make sure you rotate and refresh the token as it periodically expires.&lt;/p&gt;

&lt;p&gt;Certain secret managers even can rotate secrets for you, reducing operational overhead. For example, HashiCorp's Vault supports multiple "engines" (components that store, generate, or encrypt data), and most of the engines for Databases support root password rotation, where Vault manages the rotation automatically for you:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0ZAhfQnP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://developer.hashicorp.com/_next/image%3Furl%3Dhttps%253A%252F%252Fcontent.hashicorp.com%252Fapi%252Fassets%253Fproduct%253Dtutorials%2526version%253Dmain%2526asset%253Dpublic%25252Fimg%25252Fvault%25252Fui-vault-database-rotate-root.png%2526width%253D963%2526height%253D376%26w%3D2048%26q%3D75" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0ZAhfQnP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://developer.hashicorp.com/_next/image%3Furl%3Dhttps%253A%252F%252Fcontent.hashicorp.com%252Fapi%252Fassets%253Fproduct%253Dtutorials%2526version%253Dmain%2526asset%253Dpublic%25252Fimg%25252Fvault%25252Fui-vault-database-rotate-root.png%2526width%253D963%2526height%253D376%26w%3D2048%26q%3D75" alt="" width="800" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are interested in more best practices, there is a blog on &lt;a href="https://blog.gitguardian.com/how-to-secure-your-ci-cd-pipeline/"&gt;how to secure your CI/CD pipeline&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. How OIDC (OpenID Connect) Works
&lt;/h2&gt;

&lt;p&gt;Following these best practices, let's dive deep into two hands-on tutorials to harden your CI/CD security. Before that, let's do a very short introduction to the technology that enables us to do so: OpenID Connect (OIDC).&lt;/p&gt;

&lt;p&gt;If you are not bothered to read the official definition of OIDC from the &lt;a href="https://openid.net/?ref=blog.gitguardian.com"&gt;official website&lt;/a&gt;, here's the TL;DR version: OIDC allows us to use short-lived tokens instead of long-lived passwords, following our best practice #1 mentioned earlier.&lt;/p&gt;

&lt;p&gt;If integrated with CI, we can configure our CI to request short-lived access tokens and use that to access other systems (of course, other systems need to support OIDC on their end).&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Tutorial: GitHub Actions OIDC with AWS
&lt;/h2&gt;

&lt;p&gt;To use OIDC in GitHub Actions workflows, first, we need to configure AWS.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.1 Create an OIDC provider in AWS
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/content/images/2023/07/1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--on2BJ5Aa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/07/1.png" alt="" width="800" height="687"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  For Configure provider, choose OpenID Connect.&lt;/li&gt;
&lt;li&gt;  For the provider URL: Use &lt;a href="https://token.actions.githubusercontent.com/?ref=blog.gitguardian.com"&gt;https://token.actions.githubusercontent.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Choose "Get thumbprint" to verify the server certificate of your IdP.&lt;/li&gt;
&lt;li&gt;  For the "Audience": Use sts.amazonaws.com.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After creation, copy the provider ARN, which will be used next.&lt;/p&gt;

&lt;p&gt;To learn more about this step, see &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html?ref=blog.gitguardian.com#manage-oidc-provider-console"&gt;the official document here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.2 Create a Role with Assume Role Policy
&lt;/h3&gt;

&lt;p&gt;Next, let's configure the role and trust in IAM.&lt;/p&gt;

&lt;p&gt;Here, I created a role named "gha-oidc-role" and attached the AWS-managed policy "AmazonS3ReadOnlyAccess" (ARN: &lt;code&gt;arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Then, the tricky part is the trust relationships, and here's an example of the value I used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The Principal is the OIDC provider's ARN we copied from the previous step.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;token.actions.githubusercontent.com:sub&lt;/code&gt; in the condition defines which org/repo can assume this role; here I used &lt;code&gt;IronCore864/vault-oidc-test&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After creation, copy the IAM role ARN, which will be used next.&lt;/p&gt;

&lt;p&gt;To learn more about creating roles for OIDC, see &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-idp_oidc.html?ref=blog.gitguardian.com"&gt;the official document here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.3 Test AWS Access in GitHub Action Using OIDC
&lt;/h3&gt;

&lt;p&gt;Let's create a simple test workflow:&lt;/p&gt;

&lt;p&gt;This workflow named "AWS" is triggered manually, tries to assume the role we created in the previous step, and runs some simple AWS commands to test we get the access.&lt;/p&gt;

&lt;p&gt;The job or workflow run requires a permission setting with &lt;code&gt;id-token: write&lt;/code&gt;. You won't be able to request the OIDC JWT ID token if the permissions setting for id-token is set to read or none.&lt;/p&gt;

&lt;p&gt;For your convenience, I put the workflow YAML file &lt;a href="https://github.com/IronCore864/vault-oidc-test/blob/main/.github/workflows/aws.yaml?ref=blog.gitguardian.com"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After triggering the workflow, everything works with no access keys or secrets needed whatsoever:&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9K1l2KHD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/07/2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9K1l2KHD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/07/2.png" alt="2" width="800" height="980"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/github-actions-security-cheat-sheet/"&gt;GitHub Actions Security Best Practices [cheat sheet included]&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Tutorial: GitHub Actions OIDC with HashiCorp Vault
&lt;/h2&gt;

&lt;p&gt;Unfortunately, not all systems that you are trying to access from your CI/CD workflows support OIDC, and sometimes you would still need to use passwords.&lt;/p&gt;

&lt;p&gt;However, using hardcoded passwords means we need to duplicate and store them in GitHub as secrets, and this violates our aforementioned best practice.&lt;/p&gt;

&lt;p&gt;A better approach is to use a secrets manager to store secrets and set up OIDC between your CI and your secrets manager to retrieve secrets from your secrets manager, with no password used in the process.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.1 Install HashiCorp Vault
&lt;/h3&gt;

&lt;p&gt;In this tutorial, we will do a local dev server (DO NOT DO THIS IN PRODUCTION) and expose it to the public internet so that GitHub Actions can reach it.&lt;/p&gt;

&lt;p&gt;The quickest way to install Vault on Mac probably is using &lt;code&gt;brew&lt;/code&gt;. First, install the HashiCorp tap, a repository of all our Homebrew packages: &lt;code&gt;brew tap hashicorp/tap&lt;/code&gt;. Then, install Vault: &lt;code&gt;brew install hashicorp/tap/vault&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For other systems, refer to &lt;a href="https://developer.hashicorp.com/vault/docs/install?ref=blog.gitguardian.com"&gt;the official doc here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After installation, we can quickly start a local dev server by running:&lt;/p&gt;

&lt;p&gt;However, this is only running locally on our laptop, not accessible from the public internet. To expose it to the internet so that GitHub Actions can reach it, we use &lt;a href="https://ngrok.com/?ref=blog.gitguardian.com"&gt;grok&lt;/a&gt;, the fastest way to put your app on the internet. For detailed installation and usage, see the official doc. After installation, we can simply run &lt;code&gt;ngrok http 8200&lt;/code&gt; to expose the Vault port. Take note of the public URL to your local Vault.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.2 Enable JWT Auth
&lt;/h3&gt;

&lt;p&gt;Execute the following to enable JWT auth in Vault:&lt;/p&gt;

&lt;p&gt;Apply the configuration for GitHub Actions:&lt;/p&gt;

&lt;p&gt;Create a policy that grants access to the specified paths:&lt;/p&gt;

&lt;p&gt;Create a role to use the policy:&lt;/p&gt;

&lt;p&gt;When creating the role, ensure that the &lt;code&gt;bound_claims&lt;/code&gt; parameter is defined for your security requirements, and has at least one condition. To check arbitrary claims in the received JWT payload, the bound_claims parameter contains a set of claims and their required values. In the above example, the role will accept any incoming authentication requests from any repo owned by the user (or org) IronCore864.&lt;/p&gt;

&lt;p&gt;To see all the available claims supported by GitHub's OIDC provider, see &lt;a href="https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect?ref=blog.gitguardian.com#configuring-the-oidc-trust-with-the-cloud"&gt;"About security hardening with OpenID Connect"&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.3 Create a Secret in Vault
&lt;/h3&gt;

&lt;p&gt;Next, let's create a secret in Vault for testing purposes, and we will try to use GitHub Actions to retrieve this secret using OIDC.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d19SbBna--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/07/3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d19SbBna--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/07/3.png" alt="3" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we created a secret named "aws" under "secret", and there is a key named "accessKey" in the secret with some random testing value.&lt;/p&gt;

&lt;p&gt;To verify, we can run:&lt;/p&gt;

&lt;p&gt;Note that the "Secret Path" is actually &lt;code&gt;secret/data/aws&lt;/code&gt;, rather than &lt;code&gt;secret/aws&lt;/code&gt;. This is because of the &lt;a href="https://developer.hashicorp.com/vault/docs/secrets/kv/kv-v2?ref=blog.gitguardian.com"&gt;kv engine v2&lt;/a&gt;, the &lt;a href="https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2?ref=blog.gitguardian.com"&gt;API path&lt;/a&gt; has the added "data" part.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.4 Retrieve Secret from Vault in GitHub Actions Using OIDC
&lt;/h3&gt;

&lt;p&gt;Let's create another simple test workflow:&lt;/p&gt;

&lt;p&gt;This workflow named "Vault" is triggered manually, tries to assume the role we created in the previous steps, and receives the secret we just created.&lt;/p&gt;

&lt;p&gt;To use the secret, we can either use "env" or step outputs, as shown in the example above.&lt;/p&gt;

&lt;p&gt;Similarly to the previous AWS job, it requires a permission setting with &lt;code&gt;id-token: write&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For your convenience, I put the workflow YAML file &lt;a href="https://github.com/IronCore864/vault-oidc-test/blob/main/.github/workflows/vault.yaml?ref=blog.gitguardian.com"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After triggering the workflow, everything works with no secrets used to access our Vault:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VrmwmaGF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/07/4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VrmwmaGF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://blog.gitguardian.com/content/images/2023/07/4.png" alt="4" width="650" height="858"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this blog, we started with the infamous CircleCI breach, went on to talk about security in CI/CD systems with some best practices, did a quick introduction to OIDC, and did two hands-on tutorials on how to use it with your CI. After this tutorial, you should be able to configure secure access between GitHub Actions and your cloud providers and retrieve secrets securely using OIDC.&lt;/p&gt;

&lt;p&gt;If you enjoyed this article, please like, comment, and subscribe. See you in the next one!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>tutorial</category>
      <category>github</category>
      <category>cicd</category>
    </item>
  </channel>
</rss>
