<?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: Siranjeevi Dheenadhayalan</title>
    <description>The latest articles on DEV Community by Siranjeevi Dheenadhayalan (@security-and-technology).</description>
    <link>https://dev.to/security-and-technology</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%2F1406970%2Ffff18d0f-2169-4124-916b-244bebf5cc12.jpg</url>
      <title>DEV Community: Siranjeevi Dheenadhayalan</title>
      <link>https://dev.to/security-and-technology</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/security-and-technology"/>
    <language>en</language>
    <item>
      <title>Secure your enterprise critical assets from secret sprawl</title>
      <dc:creator>Siranjeevi Dheenadhayalan</dc:creator>
      <pubDate>Thu, 13 Jun 2024 22:02:23 +0000</pubDate>
      <link>https://dev.to/security-and-technology/secure-your-enterprise-critical-assets-from-secret-sprawl-4ajj</link>
      <guid>https://dev.to/security-and-technology/secure-your-enterprise-critical-assets-from-secret-sprawl-4ajj</guid>
      <description>&lt;p&gt;Understand the risks of secret sprawl, embracing shift-left and strategies to secure secret leaks in the modern software development lifecycle. &lt;/p&gt;




&lt;h2&gt;
  
  
  Secret sprawl:
&lt;/h2&gt;

&lt;p&gt;Enterprises often need help with the uncontrolled proliferation of secrets across their IT infrastructure. The unchecked proliferation is called a secret sprawl, and usually, secrets get scattered across server systems, repositories, configuration files, applications, and other storage locations. The risk from secret sprawl can compromise security and enable unauthorized access, thus making it essential for organizations to address the issue. &lt;/p&gt;

&lt;h3&gt;
  
  
  Risks:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;High Blast radius:&lt;/strong&gt; When sensitive secrets get dispersed across multiple locations, the attack surface for possible data breaches multiplies. When attackers gain access to the secret, it can lead to unauthorized access and breaches.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insider threat:&lt;/strong&gt; Even if the sprawled secret exists within the enterprise VPC, unauthorized employees can access sensitive assets violating least privilege access. This insider threat can lead to compromised security posture and the theft of sensitive data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Application downtime:&lt;/strong&gt; When a sprawled secret expires or reaches the end of life due to a set TTL, determining the side effects is often complex and time-consuming. The effort is high to estimate the number of applications using the hardcoded secret and the importance of those applications to business operations. Hence, rotation or expiration of such secrets without proper usage analysis can lead to application downtime, affecting users and other applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lack of visibility:&lt;/strong&gt; Since SecOps cannot monitor hardcoded secret usage, it isn't easy to track the entities accessing the secret - making audit and access control challenging.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compliance:&lt;/strong&gt; Regulatory compliance policies such as GDPR, PCI DSS, HIPAA, NIST, etc… require enterprises to safeguard secrets that can access sensitive user information. Exposure of these secrets internally within the organization or externally in public repositories can lead to hefty fines and distrust among users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prevent Secret Sprawl Proactively
&lt;/h2&gt;

&lt;p&gt;Enterprises often adopt the following best practices to prevent sprawl from happening and maintain governance:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Centralized secrets management:&lt;/strong&gt; As organizations adopt a multi-cloud approach, developers store secrets in native secret managers like AWS Secrets Manager, Azure Key Vault, GCP Secrets Manager, etc. While this is convenient for developers, it creates multiple secret store hotspots and complicates audit and visibility for security operations. Hence, a centralized secrets management experience is essential.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dynamic secrets:&lt;/strong&gt; When an application requests a secret, creating a just-in-time secret with role-based access policies can remove secrets with a long lifetime and thus prevent any sprawl. It is essential to understand the required secret TTL based on application needs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secret Scanners:&lt;/strong&gt; Secret scanners can scan to detect sprawled secrets from popular hotspots such as repositories, container images, applications, server system files, etc. While scanning leaked secrets seems essential, the secret scanners can also help prevent future secret sprawls by preemptively guiding developers and security teams in the right direction.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Education and Training:&lt;/strong&gt; Enterprises should train and create security awareness programs to educate developers and security operations about the importance of collaboration and the risks associated with sprawl. Educated users are more likely to adhere to best practices and contribute to preventing sprawl.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shift-Left in Security
&lt;/h2&gt;

&lt;p&gt;To proactively reduce secret sprawl, enterprises are moving from the operational utopia of siloed security and development teams to an integrated, developer-first security approach. The main reasons that drive the integrated approach are the following:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agility and faster time to market:&lt;/strong&gt; Enterprise products aim to stay relevant and competitive in a fast-paced software market. Thus, constant business requirement changes require rapid development and release processes often hindered by a siloed security team. Therefore, an integrated security team can aid rapid release without compromising security.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Early Issue Identification and Remediation:&lt;/strong&gt; Teams can identify and address issues sooner by shifting tasks such as testing, security reviews, and code analysis to earlier stages of the SDLC. Doing so reduces the cost and effort required to fix issues discovered later in the development process and minimizes the impact on project timelines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Risk Reduction:&lt;/strong&gt; Independent security and development teams may need to pay more attention to address security vulnerabilities promptly. The integrated team can proactively identify and address security threats on time. &lt;/p&gt;

&lt;p&gt;Embracing the trend emphasizes that security is no longer a dedicated security team's concern; instead, there is a shared responsibility with the development teams. The approach is often termed "shift-left," enterprises that adopt this paradigm constantly seek to integrate security practices early in the software development lifecycle (SDLC) to address vulnerabilities. &lt;/p&gt;

&lt;p&gt;With a shift-left paradigm, the developers refrain from embedding secrets such as API tokens, passwords, and encryption keys in their source code. While this is ideal in theory, the SDLC has multiple checkpoints; thus, more than developer education is needed to help maintain compliance. So, how can enterprises preserve developer productivity while ensuring security best practices in program files? This uncertainty has led to the production of security collaboration products that can centrally manage and provide visibility into secrets embedded in source code. &lt;/p&gt;

&lt;h2&gt;
  
  
  Attack Vectors
&lt;/h2&gt;

&lt;p&gt;As we discuss the importance of shit-left and security in source code, it is imperative to understand how modern development practices can introduce attack vectors that increase risk. Attack vectors refer to the various points within the development process where malicious actors can exploit vulnerabilities to gain unauthorized access. Here are some common attack vectors that attackers look for:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OSS/3rd party library usage:&lt;/strong&gt; To save time, developers often use OSS/3rd party libraries to extend the application's functionality. When such libraries have a security vulnerability, it is easier for attackers to target products that use it to exploit the vulnerability. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configuration files:&lt;/strong&gt; For modularity and portability, developers often use configuration files to store API endpoints and secrets. IaC tools like Terraform and containerization tools like docker also contain configuration files. Secrets in configuration files can lead to unauthorized access, service impacts, and many other possible threats.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log files:&lt;/strong&gt; While logging is helpful for debugging, developers may accidentally log sensitive information to logs/console outputs/ error messages, leading to unauthorized access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments:&lt;/strong&gt; Developers may inadvertently include secrets as comments during debugging or documentation. While comments are not executed, they are still visible in the source code.&lt;/p&gt;

&lt;p&gt;Developers manage their source code using version control software like GitHub, GitLab, and BitBucket. These repositories often become central repositories for sensitive information. Recognizing all potential attack vectors, evaluating each checkpoint in the Software Development Life Cycle (SDLC), and implementing strategies to ensure developers adhere to security best practices throughout the process are crucial.   &lt;/p&gt;

</description>
      <category>enterprise</category>
      <category>cybersecurity</category>
      <category>secrets</category>
      <category>shiftleft</category>
    </item>
    <item>
      <title>How to close attack vectors for exposed secrets in Docker</title>
      <dc:creator>Siranjeevi Dheenadhayalan</dc:creator>
      <pubDate>Thu, 04 Apr 2024 18:22:43 +0000</pubDate>
      <link>https://dev.to/security-and-technology/how-to-close-attack-vectors-for-exposed-secrets-in-docker-26c</link>
      <guid>https://dev.to/security-and-technology/how-to-close-attack-vectors-for-exposed-secrets-in-docker-26c</guid>
      <description>&lt;p&gt;&lt;a href="https://cybernews.com/security/docker-hub-images-contain-thousands-of-secrets/" rel="noopener noreferrer"&gt;Cybernews&lt;/a&gt; recently reported 5,500 out of 10,000 public docker images contained 48,000+ sensitive secrets - a combination of harmless and potentially vulnerable API keys. This report illustrates why it's imperative that security and platform teams know the most common attack vectors for their Docker containers and understand how to close them. &lt;/p&gt;

&lt;p&gt;This post will provide a brief checklist of the various attack vectors into your Docker containers specifically originating from exposed secrets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker and exposed secrets
&lt;/h2&gt;

&lt;p&gt;Let’s quickly examine the relationship between container runtime and registry. When we spin-up a container, an image is pulled from the registry via APIs and is deployed. This is visualized below:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcojyefuebjaksrvebc68.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcojyefuebjaksrvebc68.png" alt="Docker Runtime and Registry"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://community.sap.com/legacyfs/online/storage/blog_attachments/2022/09/1-83.png" rel="noopener noreferrer"&gt;Image Source&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The high number of secrets from the Cybernews report is attributed to developers re-using packages from a registry containing sensitive secrets. Secrets are commonly found in the container image metadata - the environment variables and filesystem. Also, source code leakage could allow attackers to generate newer valid tokens that could provide unauthorized system access. &lt;/p&gt;

&lt;h2&gt;
  
  
  Attack surface:
&lt;/h2&gt;

&lt;p&gt;An attack surface is a collection of all vulnerable points an attacker can use to enter the target system. Attackers skillfully exploit these vulnerable points in technology and human behavior to access sensitive assets. &lt;/p&gt;

&lt;p&gt;We need to understand two Docker concepts as we continue this discussion:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Filesystem:&lt;/strong&gt; In Docker, each layer can contain directory changes. The most commonly used filesystem, OverlayFS, enables Docker to overlay these layers to create a unified filesystem for a container. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layers:&lt;/strong&gt; Docker images are created in layers - i.e., each command on the DockerFile corresponds to a layer. &lt;/p&gt;

&lt;p&gt;With that context, let’s understand and analyze how exposed secrets can affect these Docker image attack vectors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker image layers
&lt;/h3&gt;

&lt;p&gt;Secrets explicitly declared in the Dockerfile or build arguments can easily be accessed via the Docker image history command.  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#terminal

docker image history &amp;lt;image&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This represents one of the simplest methods for an attacker to capitalize on a secret.&lt;/p&gt;

&lt;h3&gt;
  
  
  Filesystem
&lt;/h3&gt;

&lt;p&gt;This Dockerfile demonstrates a scenario where sensitive data like SSH private key and secrets.txt are added to the container's filesystem and later removed.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#Dockerfile
FROM nginx:latest

# Copy in SSH private key, then delete it; this is INSECURE,
# the secret will still be in the image.
COPY id_rsa .
RUN rm -r id_rsa

ARG DB_USERNAME
ENV DB_USERNAME =$DB_USERNAME
ARG DB_PASSWORD
ENV DB_PASSWORD =$DB_PASSWORD
ARG API_KEY
ENV API_KEY =$API_KEY

# Expose secrets via a publicly accessible endpoint (insecure practice)
RUN echo "DB_USERNAME=$DB_USERNAME" &amp;gt; /usr/share/nginx/html/secrets.txt
RUN echo "DB_PASSWORD=$DB_PASSWORD" &amp;gt;&amp;gt; /usr/share/nginx/html/secrets.txt
RUN echo "API_KEY=$API_KEY" &amp;gt;&amp;gt; /usr/share/nginx/html/secrets.txt
RUN rm /usr/share/nginx/html/secrets.txt

CMD ["nginx", "-g", "daemon off;"]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Docker uses layer caching - hence, the secret is still available in one of the layers. An internal attacker can also extract individual layers of a Docker image, stored as tar files in registries, which enables them to uncover hidden secrets.  &lt;/p&gt;

&lt;p&gt;After creating a Dockerfile, developers mistakenly use build arguments to create an image.  For the above dockerfile, the secrets are input as arguments.&lt;/p&gt;

&lt;h1&gt;
  
  
  terminal
&lt;/h1&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker build \
--build-arg DB_USERNAME=root \
--build-arg DB_PASSWORD=Xnkfnbgf \
--build-arg  API_KEY=PvL4FjrrSXyT7qr \
-t myapp:1.0 .


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;While convenient, it is not secure since the arguments also get embedded in the image. A simple docker history --no-trunc  can expose the secret values. Developers should either use multi-stage builds or secret managers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Environment variables
&lt;/h3&gt;

&lt;p&gt;Apart from Docker image access, unauthorized access to the source code of the docker image can provide additional attack vectors. The .env files are primarily used to store secrets such as API tokens, database credentials, and other forms of secrets that an application needs. When attackers have access to secrets in the .env, they can make unauthorized accesses that the secret allows. &lt;/p&gt;

&lt;h3&gt;
  
  
  Dockerfile
&lt;/h3&gt;

&lt;p&gt;DockerFile is a standard file that contains execution instructions to build an image while spinning up containers. Hard-coding secrets into DockerFile creates a significant attack surface. When attackers access the DockerFile, they can see hard-coded secrets, the base image, the list of dependencies, and critical file locations. Developers need to use appropriate secret managers to reference variables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker-compose.yml 
&lt;/h3&gt;

&lt;p&gt;Docker-compose defines networks, services, and storage volumes. When an attacker views the file, they can understand the application architecture and exploit or disrupt its operation. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#docker-compose.yml
services:
  web:
    image: my-web-app:latest
    ports:
      - "80:80"
    networks:
      - app-network
  db:
    image: postgres:latest
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: example_db_password
networks:
  app-network:
volumes:
  db-data:


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above docker-compose.yml, the postgres database password is hardcoded. The password can easily be accessed with the docker exec command as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#terminal
docker exec -it &amp;lt;container id or name&amp;gt; /bin/bash
env


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Apart from secrets, an attacker can also analyze the volume mappings and identify potential points of weakness. If they discover that the database volume (db-data) is also mounted to the host filesystem, they could exploit and perform a container breakout attack, gaining access to the underlying host system. &lt;/p&gt;

&lt;h3&gt;
  
  
  CI/CD config files
&lt;/h3&gt;

&lt;p&gt;CI/CD configuration files such as .gitlab-ci.yml, Azure-pipelines.yml , Jenkinsfile,  etc., contain instructions for building, testing, and deploying applications. The logs generated in CI/CD pipeline can contain debugging and logging information. If a developer includes a logging statement that inadvertently prints a sensitive secret, it can lead to unauthorized exposure and compromise. Such secret leaks need to be detected so that developers can fix their source code.&lt;/p&gt;

&lt;p&gt;Developers also tend to leave the registry login credentials in the CI CD configuration files. Consider the following gitlab-ci.yml. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# .gitlab-ci.yml

variables:
  DOCKER_IMAGE_TAG: latest
  DOCKER_REGISTRY_URL: registry.example.com
  DOCKER_IMAGE_NAME: my-docker-image
  DOCKER_REGISTRY_USER: adminuser &amp;lt;-- should use $CI_REGISTRY_USER  
  DOCKER_REGISTRY_PASSWORD: secretpassword &amp;lt;-- should use $CI_REGISTRY_PASSWORD 

# Jobs
build:
  stage: build
  image: image_name:stable
  script:
    - docker build -t $DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG .
    - docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PASSWORD $DOCKER_REGISTRY_URL
    - docker push $DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the configuration above, the developer makes a docker registry login using a hardcoded username and password, leading to unwarranted secret exposure. A good development practice is to integrate CI/CD environments with secret managers like Hashicorp Vault.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Detecting secrets
&lt;/h2&gt;

&lt;p&gt;Older or unused Docker images can contain unpatched vulnerabilities or outdated dependencies, posing security risks to the enterprise. Regularly scanning and removing unused images helps mitigate these risks by reducing the attack surface and ensuring that only secure images are deployed. &lt;/p&gt;

&lt;p&gt;Enterprises also need to be actively using &lt;a href="https://developer.hashicorp.com/hcp/docs/vault-radar" rel="noopener noreferrer"&gt;secret scanners&lt;/a&gt; to detect secrets in docker images, whether they’re stored in Docker Hub, JFrog Artifactory, AWS ECR, or any other repository. There are numerous secret scanning tools and &lt;a href="https://www.techtarget.com/searchsecurity/tip/IaC-security-scanning-tools-features-and-use-cases" rel="noopener noreferrer"&gt;infrastructure as code scanning tools&lt;/a&gt; as well as &lt;a href="https://radar.cncf.io/2021-02-secrets-management" rel="noopener noreferrer"&gt;secrets management platforms&lt;/a&gt; that provide a more high-scale, holistic answer to these secrets detection, management, encryption, and storage challenges. &lt;/p&gt;

&lt;p&gt;I recommend that enterprise users buy a mature platform with plenty of &lt;a href="https://www.hashicorp.com/resources?products=Vault&amp;amp;contentType=Case%20Study" rel="noopener noreferrer"&gt;successful case studies&lt;/a&gt;, rather than embark on an expensive, high-skill DIY project to detect and manage secrets. &lt;/p&gt;

</description>
      <category>containersecurity</category>
      <category>docker</category>
      <category>secrets</category>
    </item>
  </channel>
</rss>
