<?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: Keshav Malik</title>
    <description>The latest articles on DEV Community by Keshav Malik (@theinfosecguy).</description>
    <link>https://dev.to/theinfosecguy</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%2F389239%2F1fcccfb2-435c-41d5-85d5-9bb1557a22d8.png</url>
      <title>DEV Community: Keshav Malik</title>
      <link>https://dev.to/theinfosecguy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theinfosecguy"/>
    <language>en</language>
    <item>
      <title>How to set up Django with Postgres from Neon</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Sat, 10 Feb 2024 07:22:23 +0000</pubDate>
      <link>https://dev.to/theinfosecguy/how-to-set-up-django-with-postgres-from-neon-2n6h</link>
      <guid>https://dev.to/theinfosecguy/how-to-set-up-django-with-postgres-from-neon-2n6h</guid>
      <description>&lt;p&gt;In this blog post, you’ll learn how to connect Django to Neon Serverless Postgres. We’ll start with a simple Django CRUD app as our example and demonstrate how to integrate Neon as the backing database.&lt;/p&gt;

&lt;p&gt;If you’re unfamiliar with Neon, consider it an open-source, standard Postgres version of AWS Aurora. It is PostgreSQL delivered as a cloud service, but it goes a step further than other managed Postgres services. Under the hood, Neon has separated the compute and storage layers of the database so that, as users, we simply get a URL to our database, and Neon handles the rest. When we’re not using the DB, Neon scales compute to zero, and we pay nothing; when usage goes up, Neon scales up to handle the load. You can sign up for their free &lt;a href="https://neon.tech?refcode=keshav" rel="noopener noreferrer"&gt;tier&lt;/a&gt; here to follow along.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites 🤔
&lt;/h2&gt;

&lt;p&gt;Before getting started with this tutorial, you’ll need:&lt;br&gt;
Git installed on your local machine - to install it, follow this &lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git" rel="noopener noreferrer"&gt;guide&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.* Installed - follow this &lt;a href="https://realpython.com/installing-python/" rel="noopener noreferrer"&gt;guide&lt;/a&gt; if you don't have it already&lt;/li&gt;
&lt;li&gt;Pip - Python package manager&lt;/li&gt;
&lt;li&gt;Django 5.0 - follow this guide to &lt;a href="https://docs.djangoproject.com/en/5.0/intro/install/" rel="noopener noreferrer"&gt;install Django&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Basic knowledge of Python and Django concepts and conventions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting Started with Django Setup 💡
&lt;/h2&gt;

&lt;p&gt;Let’s start by setting up a CRUD application using &lt;a href="https://www.djangoproject.com/start/" rel="noopener noreferrer"&gt;Django&lt;/a&gt; before we dive into the Neon part. If you already know Django, you can proceed to the next section. Here, we will create a basic Django project, set up an app, define our model, and perform our first migration.&lt;/p&gt;

&lt;p&gt;Our CRUD app is a note-taking application with creation, reading, updating, and deleting capabilities. Please find the source code for the Django project available &lt;a href="https://github.com/theinfosecguy/neon-django-api" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To follow along with the tutorial, clone the project by running:&lt;/p&gt;

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

git clone https://github.com/theinfosecguy/neon-django-api.git


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

&lt;/div&gt;

&lt;p&gt;From your terminal, open up the project in your IDE of choice. We’ll first set up a virtual environment with pipenv. Install it with the pip install pipenv command.&lt;/p&gt;

&lt;p&gt;Create a new virtual environment using the pipenv shell command. Now that our virtual environment is created let’s install Django using the &lt;code&gt;pipenv install django&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Lastly, install Django REST Framework using &lt;code&gt;pipenv install django_rest_framework&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;We’re done with initial dependencies we’ll require. To test your progress so far, run:&lt;/p&gt;

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

python3 manage.py runserver


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

&lt;/div&gt;

&lt;p&gt;You’ll see an error saying &lt;code&gt;Error loading psycopg2 or psycopg module&lt;/code&gt; which means you’re all set to follow along. We’ll resolve this further in the article.&lt;/p&gt;

&lt;p&gt;Another problem is that Django uses &lt;code&gt;sqlite&lt;/code&gt; database by default. We’ll switch to Postgres after integrating Neon in the upcoming sections.&lt;/p&gt;

&lt;h2&gt;
  
  
  Neon Setup and Integration ⚡
&lt;/h2&gt;

&lt;p&gt;Let’s walk you through the process of configuration of Neon with Django. This is how we’ll hook Neon up to our Django project, set up the initial database and tables, and map our Django models into Neon’s schema. &lt;/p&gt;

&lt;p&gt;Firstly, you need to have a Neon account. Sign up at &lt;a href="https://neon.tech/?refcode=keshav" rel="noopener noreferrer"&gt;neon.tech&lt;/a&gt; and create a Neon Project. Each Project is its own Postgres Cluster. &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%2F3yy3ykq7eg2el5eqwlhu.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%2F3yy3ykq7eg2el5eqwlhu.png" alt="Neon"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once done, it will open up a prompt with the connection details for your newly created project. Select Django from the dropdown and copy the database configuration to your clipboard. &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%2Fl4k5v82gk3p0uozopxbi.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%2Fl4k5v82gk3p0uozopxbi.png" alt="Neon Config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, head to the project directory, open the file &lt;code&gt;neon_project\settings.py&lt;/code&gt;, and find the variable &lt;code&gt;DATABASES&lt;/code&gt;. It’ll look somewhat like this as per typical Django boilerplate code where, by default, it uses a SQLite database under the hood.&lt;/p&gt;

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


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

&lt;/div&gt;

&lt;p&gt;Replace the value of this with the new configuration.&lt;/p&gt;

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

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': 'neon_example_db',
    'USER': 'your-username-here',
    'PASSWORD': 'your-password-here',
    'HOST': 'ep-steep-recipe-44764255.us-east-2.aws.neon.tech',
    'PORT': '5432',
    'OPTIONS': {'sslmode': 'require'},
  }
}


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

&lt;/div&gt;

&lt;p&gt;Follow through the rest of the article however we strongly advise that you revisit this after local testing. Switch to either &lt;a href="https://www.freecodecamp.org/news/python-env-vars-how-to-get-an-environment-variable-in-python/" rel="noopener noreferrer"&gt;environment variables&lt;/a&gt; or adopt a secret management service such as &lt;a href="https://www.vaultproject.io/" rel="noopener noreferrer"&gt;Hashicorp Vault&lt;/a&gt; or &lt;a href="https://aws.amazon.com/kms/" rel="noopener noreferrer"&gt;AWS KMS&lt;/a&gt; to store these secrets. Here’s an example of an environment variable-based approach with Python.&lt;/p&gt;

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

DATABASES = {
  'default': {
    'ENGINE': os.environ.get('db_engine', 'django.db.backends.postgresql'),
    'NAME': os.environ.get('db_name'),
    'USER': os.environ.get('db_user'),
    'PASSWORD': os.environ.get('db_password'),
    'HOST': os.environ.get('db_host'),
    'PORT': os.environ.get('db_port', '5432'),
    'OPTIONS': {'sslmode': 'require'},
  }
}


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

&lt;/div&gt;

&lt;p&gt;For instance, the &lt;code&gt;.env&lt;/code&gt; file could look like the below example.&lt;/p&gt;

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

db_engine=django.db.backends.postgresql
db_name=neon_example_db
db_user= # your-username-here
db_password= # your-password-here
db_host=ep-steep-recipe-44764255.us-east-2.aws.neon.tech
db_port=5432


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

&lt;/div&gt;

&lt;p&gt;Lastly, we need a Postgres database driver for Django. We’ll install &lt;code&gt;[psycopg](https://pypi.org/project/psycopg2/)&lt;/code&gt;, which should serve the purpose of this tutorial. This will resolve the “Error loading psycopg2 or psycopg module” error we faced while setting up the project initially.&lt;/p&gt;

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

pipenv install psycopg2-binary


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

&lt;/div&gt;

&lt;p&gt;Once installed, run the following command so that Django can read the new settings. Django will automatically make the necessary migrations to initialize our Neon database.&lt;/p&gt;

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

python3 manage.py migrate


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

&lt;/div&gt;

&lt;p&gt;Now that our database is ready, run the following command to run the development server.&lt;/p&gt;

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

python3 manage.py runserver


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

&lt;/div&gt;

&lt;p&gt;Django provides a built-in admin panel that we can use for read and write API operations. Head to &lt;code&gt;http://127.0.0.1:8000/notes/api/&lt;/code&gt; and create a new note entry.&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%2F7yhu6adc1a3ucu361rn1.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%2F7yhu6adc1a3ucu361rn1.png" alt="Python API using Neon"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the new note entry is created, refresh the page. You’ll see that the new record is created and is being fetched with the GET All Notes API call on the top.&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%2F6k0ccawhjsdyfm1l8eyy.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%2F6k0ccawhjsdyfm1l8eyy.png" alt="Python API using Neon"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we can verify the same from the Neon interface. Head to &lt;code&gt;https://console.neon.tech/app/projects/{{your_project_id_here}}/tables&lt;/code&gt; and scroll down in the tables section to our notes table. You can see that the records are visible in the interface, too.&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%2Fz9vtwq7ta9or6jdumwq4.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%2Fz9vtwq7ta9or6jdumwq4.png" alt="Neon Dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have now successfully integrated NeonDB with our Django app 🔥. NeonDB is incredibly easy to integrate into a Django project, providing smooth access to perform database tasks.&lt;/p&gt;

&lt;p&gt;For instance, in this tutorial, we've strategically switched from our ordinary SQLite database to a Postgres one to perfectly match the features NeonDB offers. This transition also highlights the adaptability and integration that NeonDB provides for Django development. Stay tuned for part two of this tutorial where we demonstrate some of the unique branching features of Neon with our CRUD app.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>django</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Secure Your CI/CD Pipelines with GitGuardian Honeytokens</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Mon, 10 Jul 2023 06:56:11 +0000</pubDate>
      <link>https://dev.to/gitguardian/how-to-secure-your-cicd-pipelines-with-gitguardian-honeytokens-2g9k</link>
      <guid>https://dev.to/gitguardian/how-to-secure-your-cicd-pipelines-with-gitguardian-honeytokens-2g9k</guid>
      <description>&lt;p&gt;In the realm of software development, Continuous Integration and Continuous Deployment (CI/CD) pipelines have become integral. They streamline the development process, automate repetitive tasks, and enable teams to release software quickly and reliably. But while CI/CD pipelines are a marvel of modern development practices, they also present potential security vulnerabilities.&lt;/p&gt;

&lt;p&gt;With the integration of various tools, systems, and environments, CI/CD pipelines often deal with sensitive information, making them a potential target for cyber attacks. Consequently, it's crucial to weave in robust security measures to protect these pipelines and maintain the integrity of your development process.&lt;/p&gt;

&lt;p&gt;One such proactive measure is the deployment of honeytokens. Created within &lt;a href="https://blog.gitguardian.com/gitguardian-honeytoken/"&gt;GitGuardian's Honeytoken&lt;/a&gt; module, honeytokens are essentially digital baits designed to attract and detect unauthorized access or activity within your systems. By adding honeytokens to your pipelines, you can add an extra layer of defense against potential intruders.&lt;/p&gt;

&lt;p&gt;In the following sections, we will delve into what honeytokens are, how they work to detect intrusions, and how you can effectively implement them in your CI/CD pipelines to enhance security. Stay tuned to uncover how you can leverage the power of Honeytokens to protect your digital assets better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decoding Honeytokens: An Extra Layer of Defense
&lt;/h2&gt;

&lt;p&gt;A honeytoken is a deceptive instrument, a digital decoy strategically positioned to attract potential intruders.&lt;/p&gt;

&lt;p&gt;These tokens have no legitimate operational value. Their sole purpose is to serve as bait and alert you if someone tries to use them. When an unauthorized user attempts to use a honeytoken, it triggers an alert, letting you know of the intrusion. It's like having a silent alarm in your house that triggers when a burglar tries to unlock the safe.&lt;/p&gt;

&lt;p&gt;Not only does a honeytoken alert you of the intrusion, but it also provides crucial information about the attacker. You get details like the IP address and the user agent of the intruder, helping you in further securing your system and even tracking down the threat.&lt;/p&gt;

&lt;p&gt;Introducing honeytokens to your CI/CD pipelines, especially within your platform's environment variables, echoes the essence of a diligent watchman, standing guard around the clock. This ever-alert sentinel stands its ground, much like during the infamous CircleCI security incident in early 2023 (the detailed account can be read here).&lt;/p&gt;

&lt;p&gt;Imagine if an intruder had an audacious scheme to exploit these 'secret' variables, say your AWS Keys. The very moment they attempted, your trusty honeytoken watchman would sound the alarm. The alert would reach you in a flash, giving you ample opportunity to intervene, halt the dubious activity, and glean crucial lessons to fortify your digital infrastructure.&lt;/p&gt;

&lt;p&gt;In the upcoming sections, we will guide you on how to implement honeytokens in various CI/CD pipelines, including Jenkins, CircleCI, Travis CI, GitLab CI/CD, Azure DevOps Pipelines, and AWS CodePipeline.&lt;/p&gt;

&lt;p&gt;➡️ Before getting started, follow the step-by-step instructions below to get started creating 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;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Boosting Travis CI Security using Honeytokens
&lt;/h2&gt;

&lt;p&gt;If you're involved in software development, you're likely familiar with Travis CI. As a popular Continuous Integration (CI) service, Travis CI is used to build and test software projects hosted on GitHub and Bitbucket. While Travis CI already has its own measures to ensure the security of your software projects, honeytokens can provide an extra layer of defense to help identify and respond to potential threats.&lt;/p&gt;

&lt;p&gt;To enhance your Travis CI security, you can strategically place honeytokens in your build scripts or configuration files. Files like .travis.yml, environment variables, or even in your test scripts are some of the places you can consider. Remember, a honeytoken's value lies in its ability to deceive potential intruders, so placing them where sensitive data might usually reside can increase your chances of detecting a breach.&lt;/p&gt;

&lt;p&gt;Here's how you can start boosting your Travis CI security with honeytokens:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Begin by creating a honeytoken using GitGuardian's Honeytoken module. Keep it handy for the upcoming steps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to your Travis CI configuration file (.travis.yml or similar) or any script files where you wish to place your honeytoken.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Place the honeytoken in the selected location, treating it as you would any sensitive data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save the changes and ensure the updated files are pushed to your SCM repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Travis CI also uses environment variables to store secrets. You can add your honeytoken to your repository settings under the "Environment Variables" section. If someone tries to misuse these variables, the honeytoken will serve as an alarm bell.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Securing CircleCI Pipelines with Honeytokens
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://circleci.com/?ref=blog.gitguardian.com"&gt;CircleCI&lt;/a&gt; is a widely adopted Continuous Integration and Delivery (CI/CD) platform. It simplifies the automation of your software development process, from building and testing to deploying your applications. Despite CircleCI's built-in security measures, enhancing it with honeytokens can further protect your CI/CD pipeline from malicious intrusions.&lt;/p&gt;

&lt;p&gt;A honeytoken can be strategically added to several parts of your CircleCI pipeline. Some common locations include configuration files like config.yml, shell scripts, or even within environment variables. Similar to a secret key, an attacker accessing and using a honeytoken will trigger an alert, providing you with an early warning of a potential security breach.&lt;/p&gt;

&lt;p&gt;Here's how you can integrate honeytokens into your CircleCI pipeline:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First, create a honeytoken in the GitGuardian Honeytoken module. Remember to note down the generated token for later use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to your project repository and find the CircleCI configuration file, typically named config.yml and located in the .circleci directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Embed the honeytoken in this file. Once the honeytoken is in place, save your changes and push the updated file to your repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;CircleCI uses environment variables as secure storage for secrets. Go to your project settings, find the "Environment Variables" section, and add your honeytoken there. If someone unauthorized gets ahold of these environment variables, your honeytoken will alert you right away.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Beefing up Jenkins Security with Honeytokens
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.jenkins.io/?ref=blog.gitguardian.com"&gt;Jenkins&lt;/a&gt; is an open-source automation server that allows developers to build, test, and deploy their applications. It's a popular choice for implementing Continuous Integration and Continuous Deployment (CI/CD) pipelines.&lt;/p&gt;

&lt;p&gt;Honeytokens can be added to your Jenkins configuration files, script files, or even injected into your pipeline as a fake environment variable.&lt;/p&gt;

&lt;p&gt;Here's a simple guide to integrating honeytokens into your Jenkins setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Start by creating a honeytoken in the GitGuardian Honeytoken module. Remember to take note of the generated token.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to your Jenkins pipeline script, typically a Jenkinsfile found in your project repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the honeytoken into the script. It could be disguised as a decoy API key, a dummy password, or another type of attractive bait for an attacker.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once you've positioned your honeytoken, save the changes and commit the updated script to your repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Should an attacker stumble upon and use this honeytoken, an alert will be triggered. The alert includes crucial information about the attempted security breach, enabling you to quickly address the threat.&lt;/p&gt;

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

&lt;p&gt;Jenkins offers a plugin called "Credentials" that's perfect for storing sensitive data. It's an ideal place to add your honeytoken as it's designed to keep secrets, well, secret! By doing this, should an attacker ever gain unauthorized access to Jenkins and attempt to exploit these credentials, you'll be instantly alerted.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Also read&lt;/strong&gt;: &lt;a href="https://blog.gitguardian.com/how-to-handle-secrets-with-jenkins/"&gt;How to Handle Secrets in Jenkins&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Upping GitLab CI/CD Security Ante with Honeytokens
&lt;/h2&gt;

&lt;p&gt;GitLab is a powerful DevOps tool that provides a unified platform for source code management, CI/CD, and much more. GitLab CI/CD is a part of GitLab that provides the tools necessary for software development and deployment.&lt;/p&gt;

&lt;p&gt;As with any CI/CD platform, securing your GitLab pipelines is crucial. One method of enhancing your security measures is by utilizing honeytokens. These tokens can be placed in configuration files, like &lt;code&gt;.gitlab-ci.yml&lt;/code&gt;, or even within your pipeline scripts as faux environment variables.&lt;/p&gt;

&lt;p&gt;Here's how to integrate honeytokens into your GitLab CI/CD pipeline:&lt;/p&gt;

&lt;p&gt;Create a honeytoken through the GitGuardian Honeytoken module. Ensure to note down the token that is generated.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Navigate to your &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file or any other configuration files within your project repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Place the honeytoken in the chosen location. It can masquerade as a decoy API key, a dummy password, or another tempting bait for an intruder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save the changes and commit the updated file to your repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In GitLab, you can store your honeytoken in CI/CD variables. Navigate to your project settings, find the "CI/CD" section, and under "Variables," add your honeytoken. Should anyone infiltrate these variables, the honeytoken will let you know.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Empowering Azure Repos Security with Honeytokens
&lt;/h2&gt;

&lt;p&gt;Azure DevOps Pipelines, a cloud service from Microsoft, is used for automatically building, testing, and deploying applications to any platform. Despite the powerful security features, it provides, including access controls and protection against DDoS attacks, integrating honeytokens into your Azure DevOps Pipelines can fortify your line of defense.&lt;/p&gt;

&lt;p&gt;Honeytokens can be added to Azure DevOps Pipelines within several files, such as pipeline configuration files (azure-pipelines.yml), or environment variables.&lt;/p&gt;

&lt;p&gt;Below are steps to add a honeytoken to your Azure DevOps Pipelines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Kickstart the process by generating a honeytoken on the GitGuardian dashboard. Ensure you record the generated token safely.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to your pipeline configuration file (e.g., azure-pipelines.yml) or any other relevant file within your Azure DevOps Pipelines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the honeytoken to a location within the selected file, where it can convincingly act as a fake credential or sensitive data. This could be within a section of the file specifying environment variables.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Azure DevOps keeps secrets safe through "Secret Variables." You can add your honeytoken here to monitor for any unauthorized access. Open your pipeline, go to "Variables," and choose to create a new "Secret Variable."&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Strengthening AWS CodePipeline with Honeytokens
&lt;/h2&gt;

&lt;p&gt;AWS CodePipeline is a fully managed continuous delivery service that helps you automate your release pipelines. As secure as AWS services are, the addition of honeytokens can boost your security strategy.&lt;/p&gt;

&lt;p&gt;Adding honeytokens to your buildspec.yml or other AWS CodePipeline configuration files can provide early intrusion detection.&lt;/p&gt;

&lt;p&gt;Here's how to deploy a honeytoken in your AWS CodePipeline:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a honeytoken in the GitGuardian Honeytoken module. Remember to record the generated token.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to your buildspec.yml or another configuration file within your project repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Insert the honeytoken in the chosen location, appearing as an attractive piece of data for potential attackers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save the changes and commit the updated file to your repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;AWS CodePipeline offers two options for storing secrets: AWS Secrets Manager or the Parameter Store. You can add your honeytoken to either of these services. This way, if either service is compromised, you'll receive a prompt notification.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Optimizing Honeytoken Usage: Best Practices
&lt;/h2&gt;

&lt;p&gt;While honeytokens are a potent weapon in your cybersecurity arsenal, their effectiveness significantly depends on how you deploy and manage them. Here are a few best practices to help you maximize the benefits of using honeytokens in your CI/CD pipelines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Placement is Key: Place honeytokens in locations where they mimic sensitive data. This increases the chances that an intruder might use them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Variety in Deployment: Use honeytokens across various files and stages of your CI/CD pipeline. Diversifying the honeytoken deployment can cast a wider net for detecting intrusions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uniqueness for Each Pipeline: Use unique honeytokens for each pipeline and repository. This can help pinpoint the exact location of an intrusion when a honeytoken is triggered.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Routine Checks: Regularly verify that your honeytokens are in place and functioning as expected. This ensures that they are always ready to detect any suspicious activities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Immediate Action: As soon as a honeytoken is triggered, take immediate action. Investigate the incident, identify the scope of the potential breach, and strengthen your defenses accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replacements after Trigger: Once a honeytoken has been triggered, replace it with a new one. A triggered honeytoken can lose its effectiveness if not replaced promptly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remember, the goal of a honeytoken isn't just to catch a potential intruder but to learn from the incident and fortify your defenses. Hence, a well-planned and executed deployment of honeytokens can not only detect intrusions but also provide valuable insights to enhance your overall security strategy.&lt;/p&gt;

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

&lt;p&gt;In the vast digital ocean where malicious entities lurk, the right defenses are critical for a secure voyage. And the innovative Honeytokens by GitGuardian provides just that - an extra layer of security that not only detects intrusions but also aids in understanding potential breach points.&lt;/p&gt;

&lt;p&gt;By placing these deceptive honeytokens in your CI/CD pipelines, you create a security net that actively monitors and notifies you of any unauthorized activity. From Travis CI to AWS CodePipeline, these tokens seamlessly integrate into various environments, enhancing the security posture of your development processes.&lt;/p&gt;

&lt;p&gt;So, why wait? Begin your journey towards a more secure development process today. &lt;a href="https://dashboard.gitguardian.com/?ref=blog.gitguardian.com"&gt;Sign up for GitGuardian&lt;/a&gt; and start deploying Honeytokens in your CI/CD pipelines. Secure your digital assets, gain peace of mind, and focus on what truly matters - creating excellent software.&lt;/p&gt;

&lt;p&gt;Remember, in cybersecurity, it's always better to be proactive than reactive, and with GitGuardian Honeytokens, you're already one step ahead.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>devops</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Handle Secrets in Terraform</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Wed, 31 May 2023 14:46:16 +0000</pubDate>
      <link>https://dev.to/gitguardian/how-to-handle-secrets-in-terraform-5en2</link>
      <guid>https://dev.to/gitguardian/how-to-handle-secrets-in-terraform-5en2</guid>
      <description>&lt;p&gt;In today's fast-paced world of cloud computing and &lt;a href="https://blog.gitguardian.com/infrastructure-as-code-everything-you-need-to-know/"&gt;infrastructure as code&lt;/a&gt; (IaC), efficiently managing your resources and keeping them secure has become crucial. Terraform, an open-source infrastructure as a code tool, is widely used by DevOps teams to provision and manage cloud infrastructure. While Terraform provides a powerful, flexible, and easy-to-use platform, it also poses certain challenges when it comes to managing sensitive information, such as API keys, passwords, and other secrets.&lt;/p&gt;

&lt;p&gt;Proper management of secrets is essential to maintaining the security and integrity of your infrastructure. Inadequate handling of secrets can lead to disastrous consequences, including unauthorized access, data breaches, and regulatory non-compliance.&lt;/p&gt;

&lt;p&gt;This blog post aims to provide a comprehensive guide on secrets management in Terraform, offering insights into best practices, tools, and techniques to help you protect your infrastructure and keep your secrets safe.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before diving into the depths of secrets management in &lt;a href="https://www.terraform.io/?ref=blog.gitguardian.com"&gt;Terraform&lt;/a&gt;, it's important to ensure that you have the necessary foundation to build upon. The following prerequisites will help you get the most out of this guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Basic understanding of Terraform&lt;/strong&gt;: Having a fundamental knowledge of Terraform and its core concepts, such as providers, resources, and modules. You can start here: &lt;a href="https://blog.gitguardian.com/content/images/2022/04/22W14-blog-9TerraformBestPractices.jpg"&gt;9 Extraordinary Terraform Best Practices That Will Rock Your Infrastructure&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Installed Terraform&lt;/strong&gt;: To follow along with this guide and try out the examples provided, make sure you have Terraform &lt;a href="https://developer.hashicorp.com/terraform/downloads?product_intent=terraform&amp;amp;ref=blog.gitguardian.com"&gt;installed&lt;/a&gt; on your local machine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Access to a cloud provider account&lt;/strong&gt;: Having access to a cloud provider's account, such as AWS, Azure, or Google Cloud Platform, will enable you to put the concepts and strategies discussed in this guide into practice.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Familiarity with basic security concepts&lt;/strong&gt;: Understanding the fundamentals of information security, such as encryption, access control, and authentication. Here is an introduction to &lt;a href="https://blog.gitguardian.com/understanding-identity-and-access-management-best-practices-cheat-sheet-included/"&gt;Identity and Access Management&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Understanding Secrets Management&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Secrets refer to sensitive information such as API keys, passwords, access tokens, and encryption keys, which require restricted access to maintain the security and integrity of your infrastructure. Properly managing secrets is crucial to prevent unauthorized access and minimize potential security risks.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Types of Secrets in Terraform&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In the context of Terraform, secrets can be classified into various types, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;API keys&lt;/strong&gt; used for authentication with cloud providers and other services&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Database credentials&lt;/strong&gt; like usernames and passwords&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;SSH keys&lt;/strong&gt; for secure server access&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Risks of not managing secrets properly&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Inadequate secrets management can lead to several potential risks, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Compliance violations&lt;/strong&gt;: Many industries are subject to strict regulations regarding the handling of sensitive information, and failing to manage secrets properly can lead to hefty fines and reputational damage.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Unauthorized access&lt;/strong&gt;: Improperly managed secrets can allow unauthorized individuals to access sensitive resources, resulting in data leakage and potential security violations.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Security breaches&lt;/strong&gt;: Exposed secrets can be exploited by attackers to steal or tamper with data or even to completely compromise entire systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding these risks underscores the importance of implementing effective secrets management practices in your Terraform deployments.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Also Read&lt;/strong&gt;:&lt;/em&gt; &lt;a href="https://blog.gitguardian.com/security-in-infrastructure-as-code-with-terraform/"&gt;&lt;em&gt;Security in Infrastructure as Code with Terraform&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Best Practices for Managing Secrets in Terraform&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Managing secrets securely in Terraform is crucial to protect sensitive information and prevent unauthorized access. In this section, we will discuss several best practices for handling secrets in Terraform, including using environment variables, storing secrets in secure external storage, and encrypting sensitive data.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Use environment variables&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Storing secrets as environment variables keeps them out of your Terraform code and version control systems. Environment variables can be easily accessed in Terraform using the var keyword. For example, to set up an AWS provider using an API key stored as an environment variable:  &lt;/p&gt;

&lt;p&gt;To set the environment variable, use the export command in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;export TF_VAR_aws_access_key=&amp;lt;your_access_key&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Store Secrets in a Secure External Storage&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Instead of storing secrets directly in your Terraform code or environment variables, consider using a secure external storage service designed for secrets management, such as &lt;strong&gt;HashiCorp Vault&lt;/strong&gt; or &lt;strong&gt;AWS Secrets Manager&lt;/strong&gt;. These services provide advanced features like access control, auditing, and automatic rotation of secrets. In the following sections, we will discuss integrating Terraform with Vault and AWS Secrets Manager in more detail.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Encrypt sensitive data&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When storing secrets in remote backends or transferring them over the network, ensure they are encrypted. Many cloud providers offer Key Management Services (KMS) to encrypt and decrypt data. For instance, with AWS KMS, you can encrypt sensitive data using the &lt;code&gt;aws_kms_secrets&lt;/code&gt; data source:&lt;/p&gt;

&lt;p&gt;Secret management tools can significantly enhance the security of your Terraform deployments by providing centralized, secure storage for sensitive information. Here we will discuss various secret management tools and provide step-by-step instructions for integrating them with Terraform.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Overview of secrets management tools&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There are several secrets management tools available, each offering different features and levels of integration with Terraform. Some popular options include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;HashiCorp Vault&lt;/strong&gt;: A comprehensive secrets management solution designed to handle a wide range of secret types, with tight integration with Terraform.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;AWS Secrets Manager&lt;/strong&gt;: A managed service provided by AWS that offers seamless integration with other AWS services and Terraform.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Integrating Terraform with Vault&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;HashiCorp Vault is a widely-used secret management solution that allows you to store, manage, and access secrets securely. To integrate Terraform with Vault, follow these steps:&lt;/p&gt;

&lt;p&gt;1. &lt;strong&gt;Install and configure Vault&lt;/strong&gt;: Follow the official &lt;a href="https://developer.hashicorp.com/vault/docs?ref=blog.gitguardian.com"&gt;Vault documentation&lt;/a&gt; to install and set up Vault on your local machine or a dedicated server.&lt;/p&gt;

&lt;p&gt;2. &lt;strong&gt;Enable the &lt;code&gt;kv secrets engine&lt;/code&gt; in Vault&lt;/strong&gt;: Run the following command which allows you to store key-value pairs:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vault secrets enable -path=my-secrets kv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3. &lt;strong&gt;Write secrets to Vault&lt;/strong&gt;: Store your secrets in Vault using the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vault kv put my-secrets/aws aws_access_key_id=&amp;lt;your_access_key&amp;gt; aws_secret_access_key=&amp;lt;your_secret_key&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;4. &lt;strong&gt;Configure the Terraform Vault provider&lt;/strong&gt;: In your Terraform configuration, set up the Vault provider and authenticate using a token or other supported authentication methods:&lt;/p&gt;

&lt;p&gt;5. &lt;strong&gt;Access secrets from Vault in Terraform&lt;/strong&gt;: Use the &lt;code&gt;vault_generic_secret&lt;/code&gt;data source to read secrets from Vault:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Integrating Terraform with AWS Secrets Manager&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;AWS Secrets Manager is a managed service that helps you protect access to your applications, services, and IT resources. To integrate Terraform with AWS Secrets Manager, follow these steps:&lt;/p&gt;

&lt;p&gt;1. &lt;strong&gt;Store secrets in AWS Secrets Manager&lt;/strong&gt;: Log in to the AWS Management Console, navigate to Secrets Manager, and create a new secret containing your sensitive data (e.g., API keys and database credentials).&lt;/p&gt;

&lt;p&gt;2. &lt;strong&gt;Configure the Terraform AWS provider&lt;/strong&gt;: In your Terraform configuration, set up the AWS provider with the appropriate credentials:  &lt;/p&gt;

&lt;p&gt;3. Access secrets from AWS Secrets Manager in Terraform: Use the &lt;code&gt;aws_secretsmanager_secret_version&lt;/code&gt; data source to read secrets:&lt;/p&gt;

&lt;p&gt;You can now use the &lt;code&gt;local.example_secret&lt;/code&gt; variable to access the stored secret as a JSON object. For example, if your secret contains a database username and password, you can reference them like this:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Implementing Role-Based Access Control (RBAC) in Terraform&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Role-Based Access Control (RBAC) is an effective approach to managing access to sensitive information in your Terraform deployments, allowing you to grant permissions based on roles and responsibilities. In this section, we will discuss the fundamentals of RBAC and provide guidance on configuring RBAC in Terraform.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Understanding RBAC&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;RBAC is a security model that assigns permissions to users based on their roles within an organization instead of assigning permissions directly to individual users. This approach simplifies access management and improves security by ensuring that users only have the permissions they need to perform their job functions. The main components of RBAC are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Roles&lt;/strong&gt;: Collections of permissions that define what actions users can perform on specific resources.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Users&lt;/strong&gt;: Individuals or entities that interact with the system and are assigned roles based on their responsibilities.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Permissions&lt;/strong&gt;: Access rights that determine what actions can be performed on specific resources.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you guessed, implementing RBAC in Terraform involves defining roles, assigning them to users, and managing permissions for accessing sensitive data, such as secrets.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Configuring RBAC in Terraform&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To configure RBAC in Terraform, you can leverage features provided by your cloud provider, secret management tool, or Terraform Enterprise. The following example demonstrates how to configure RBAC using HashiCorp Vault:&lt;/p&gt;

&lt;p&gt;1. &lt;strong&gt;Create policies in Vault&lt;/strong&gt;: Define Vault policies that outline the permissions for each role. For example, you can create a policy that allows read access to a specific path within Vault:&lt;/p&gt;

&lt;p&gt;To write the policy to Vault, use the vault &lt;code&gt;policy write&lt;/code&gt; command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vault policy write read-only read-only-policy.hcl&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2. &lt;strong&gt;Assign policies to users&lt;/strong&gt;: After creating the necessary policies, assign them to users by attaching the policy to an authentication method or a specific user:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vault write auth/userpass/users/john password="johnspassword" policies="read-only"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3. &lt;strong&gt;Access secrets in Terraform based on RBAC&lt;/strong&gt;: Users can now access secrets in Terraform according to their assigned policies. For example, a user with the "read-only" policy can read secrets from the "my-secrets" path:&lt;/p&gt;

&lt;p&gt;By implementing RBAC in Terraform, you can ensure that users only have access to the secrets they need, minimizing the risk of unauthorized access and improving overall security.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Continuous Monitoring and Auditing&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Continuous monitoring and auditing play a crucial role in secrets management, as they help identify potential security vulnerabilities, unauthorized access, and policy violations. In this section, we will introduce some tools that can assist in tracking Terraform secrets.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Tools for Monitoring and Auditing Terraform Secrets&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There are several tools available that can help you monitor and audit Terraform secrets, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Cloud provider tools&lt;/strong&gt;: Many cloud providers offer monitoring and auditing services, such as AWS CloudTrail, Azure Monitor, and Google Cloud's Stackdriver. These tools can track changes in your cloud resources and provide logs for analysis.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;HashiCorp Vault&lt;/strong&gt;: Vault includes built-in auditing capabilities, allowing you to track and log all access and modifications to secrets stored in Vault.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;GitGuardian&lt;/strong&gt;: GitGuardian is a powerful secrets detection tool that can automatically scan your code repositories for exposed secrets, including those in Terraform configurations. By integrating GitGuardian into your development workflow, you can identify and remediate exposed secrets early in the development process.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By implementing continuous monitoring and auditing in your Terraform deployments, you can enhance the security of your secrets management strategy and reduce the likelihood of unauthorized access or data breaches.&lt;/p&gt;

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

&lt;p&gt;Managing secrets in Terraform is a critical aspect of ensuring the security and integrity of your infrastructure deployments. By following best practices such as using environment variables, storing secrets in secure external storage, and implementing Role-Based Access Control (RBAC), you can significantly reduce the risks associated with handling sensitive information.&lt;/p&gt;

&lt;p&gt;Additionally, leveraging secret management tools like HashiCorp Vault and AWS Secrets Manager can provide advanced features that further enhance security.&lt;/p&gt;

&lt;p&gt;Continuous monitoring and auditing, using tools like GitGuardian and its CLI tool &lt;a href="https://blog.gitguardian.com/introducing-infrastructure-as-code-security/"&gt;ggshield&lt;/a&gt;, are essential in maintaining a secure environment and identifying potential vulnerabilities. The &lt;a href="https://github.com/GitGuardian/ggshield?ref=blog.gitguardian.com"&gt;ggshield&lt;/a&gt; CLI allows developers, Site Reliability Engineers, and DevOps Engineers to scan Infrastructure as Code (IaC) configurations from the command line, helping to prevent misconfigurations from being deployed.&lt;/p&gt;

&lt;p&gt;By adopting these practices and tools, &lt;strong&gt;especially integrating ggshield as a pre-commit check&lt;/strong&gt; or CI pipeline integration, you can establish a robust secrets management strategy in Terraform, protecting your sensitive data and ensuring the security of your infrastructure deployments.&lt;/p&gt;

&lt;p&gt;Learn how to use ggshield as a git hook with these resources:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.gitguardian.com/setting-up-a-pre-commit-git-hook-with-gitguardian-shield-to-scan-for-secrets/"&gt;Creating a pre-commit git hook to detect secrets&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/embed/ObksvAZyWdo?feature=oembed"&gt;https://www.youtube.com/embed/ObksvAZyWdo?feature=oembed&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Handle Secrets in Kubernetes</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Thu, 18 May 2023 11:21:20 +0000</pubDate>
      <link>https://dev.to/gitguardian/how-to-handle-secrets-in-kubernetes-2epe</link>
      <guid>https://dev.to/gitguardian/how-to-handle-secrets-in-kubernetes-2epe</guid>
      <description>&lt;p&gt;Kubernetes has become the de facto standard for container orchestration, enabling organizations to build, deploy, and scale modern applications with efficiency and agility. As more organizations adopt Kubernetes, the need for proper security and management of sensitive data within these environments becomes paramount. One crucial aspect of ensuring a secure Kubernetes infrastructure is the effective management of secrets, such as API keys, passwords, and tokens.&lt;/p&gt;

&lt;p&gt;In this blog post, we will delve into the world of secret management in Kubernetes, exploring various approaches and best practices to keep your sensitive data safe and accessible only to authorized components.&lt;/p&gt;

&lt;p&gt;We will discuss how to create, store, and use secrets in Kubernetes, along with the importance of encryption, role-based access control, and auditing. By understanding and implementing these practices, you can significantly enhance the security and reliability of your Kubernetes cluster, safeguarding your applications and data from unauthorized access and potential breaches.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Secrets in Kubernetes (K8s)?
&lt;/h2&gt;

&lt;p&gt;In the context of K8s, secrets are objects that store sensitive information, such as passwords, API keys, OAuth tokens, and Secure Shell (SSH) keys. These secrets are crucial for the proper functioning of applications and services within a Kubernetes cluster, as they often grant access to essential resources and authentication mechanisms.&lt;/p&gt;

&lt;p&gt;Understanding and managing secrets is vital for maintaining the security and integrity of your Kubernetes environment. Inadequate management of secrets can lead to unauthorized access, data breaches, and compromised infrastructure. Therefore, it is essential to ensure that secrets are stored, transmitted, and utilized securely within your cluster.&lt;/p&gt;

&lt;h1&gt;
  
  
  Different Ways to Manage Secrets in K8s
&lt;/h1&gt;

&lt;p&gt;A variety of methods are available to manage secrets in Kubernetes. In this section, we will focus on Kubernetes Secrets, a native solution for storing and managing sensitive data within your cluster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Kubernetes Secrets
&lt;/h2&gt;

&lt;p&gt;Kubernetes Secrets are built-in objects that enable you to store and manage sensitive information securely. They provide a convenient way to distribute confidential data to containers and maintain the separation of concerns between the application and its credentials.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Kubernetes Secrets
&lt;/h2&gt;

&lt;p&gt;There are several ways to create Kubernetes Secrets:&lt;/p&gt;

&lt;h3&gt;
  
  
  Using kubectl
&lt;/h3&gt;

&lt;p&gt;You can create a secret using the kubectl command-line tool by providing the required data as key-value pairs. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create secret generic my-secret --from-literal=username=myuser --from-literal=password=mypassword
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a secret named &lt;code&gt;my-secret&lt;/code&gt; containing two key-value pairs for the username and password.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using a configuration file
&lt;/h3&gt;

&lt;p&gt;Another way to create a Kubernetes Secret is through a YAML configuration file. First, encode your sensitive data in base64 format, then create a YAML file with the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: Secret
metadata:
  name: my-secret
data:
  username: bXl1c2Vy
  password: bXlwYXNzd29yZA==
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the YAML file using &lt;code&gt;kubectl apply -f my-secret.yaml&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Using the Kustomize tool
&lt;/h3&gt;

&lt;p&gt;Kustomize is a standalone tool for customizing Kubernetes objects through a &lt;code&gt;kustomization.yaml&lt;/code&gt; file. You can create a secret generator with it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

generators:
- secret.yaml

secretGenerator:
- name: my-secret
  literals:
  - username=admin
  - password=secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then to generate the secret run: &lt;code&gt;kubectl apply -k&lt;/code&gt; .&lt;/p&gt;

&lt;h2&gt;
  
  
  Ways to employ secrets within Pods
&lt;/h2&gt;

&lt;p&gt;Secrets can be used within Pods in the following ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mounting secrets as files in a volume for containers&lt;/strong&gt;: You can mount a secret as a volume inside a container. Each key-value pair in secret will be presented as a separate file within the mounted volume.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Setting secrets as container environment variables&lt;/strong&gt;: Secrets can be exposed as environment variables in containers. This approach allows your application to read the secret value without changing the code, making it more secure and manageable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Leveraging kubelet for image pulling with secrets&lt;/strong&gt;: Kubelet can use secrets to pull container images from private registries. By specifying the secret in the Pod's imagePullSecrets field, Kubernetes will authenticate to the registry using the provided credentials.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Also read&lt;/strong&gt;: &lt;a href="https://blog.gitguardian.com/kubernetes-tutorial-part-1-pods/"&gt;Kubernetes Hardening Tutorial Part 1: Pods&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessing secrets in containers
&lt;/h3&gt;

&lt;p&gt;Once a secret is mounted as a file or exposed as an environment variable, the application running in the container can access the secret data. If an attacker gains access to the container, they may be able to view the secret data and potentially use it to compromise other parts of the system. Therefore, it is important to ensure that only authorized containers and users can access these secrets.&lt;/p&gt;

&lt;p&gt;This can be achieved in several ways, such as using RBAC (Role-Based Access Control) to restrict access to the secrets or encrypting the secrets at rest and in transit.&lt;/p&gt;

&lt;p&gt;Also read: &lt;a href="https://blog.gitguardian.com/kubernetes-tutorial-part-3-authn-authz/"&gt;Kubernetes Hardening Tutorial Part 3: Authn, Authz, Logging &amp;amp; Auditing&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Updating and rotating secrets
&lt;/h3&gt;

&lt;p&gt;Regularly updating and rotating secrets is a crucial security practice. While you can update a secret using &lt;code&gt;kubectl edit&lt;/code&gt;, this approach is not recommended because it can be error-prone and can potentially lead to unintended consequences.&lt;/p&gt;

&lt;p&gt;When you edit a secret with &lt;code&gt;kubectl edit&lt;/code&gt;, you are modifying the existing secret in place. This means that any existing references to the secret (such as environment variables or volume mounts) will continue to use the old secret data until the application is restarted or the pod is deleted and recreated.&lt;/p&gt;

&lt;p&gt;If you need to rotate a secret, you would have to update any references to the old secret to use the new secret instead!&lt;/p&gt;

&lt;p&gt;That's why past a certain size, it becomes more interesting to either implement app-specific mechanisms that reload configuration at runtime or deploy a sidecar container that monitors for changes and restarts the main container when necessary.&lt;/p&gt;

&lt;h3&gt;
  
  
  Limitations of Kubernetes Secrets
&lt;/h3&gt;

&lt;p&gt;While Kubernetes Secrets provide a convenient way to manage sensitive data, they have some limitations:&lt;/p&gt;

&lt;p&gt;Limited encryption: by default, secrets are stored unencrypted in etcd. K8s does support encryption, but the encrypting key needs separate management.&lt;/p&gt;

&lt;p&gt;Limited rotation: K8s secrets are designed to be immutable, which means that they cannot be modified or versioned once they are created. This, as we have seen, makes it difficult to rotate secrets. They can't be audited either.&lt;/p&gt;

&lt;p&gt;Limited access control: While Kubernetes provides RBAC (Role-Based Access Control) to control access to secrets, it is still possible for unauthorized users to gain access to secrets if they are able to compromise the cluster or the underlying infrastructure.&lt;/p&gt;

&lt;p&gt;They may not be suitable for large-scale or highly regulated environments, where more advanced secret management solutions might be necessary.&lt;/p&gt;

&lt;p&gt;Despite these limitations, Kubernetes Secrets remain a handy tool for managing secrets when you don't need to scale immediately your cluster.&lt;/p&gt;

&lt;h3&gt;
  
  
  Kubernetes External Secrets
&lt;/h3&gt;

&lt;p&gt;Kubernetes External Secrets offer an alternative approach to managing secrets in Kubernetes by integrating with external secret management solutions. This allows you to maintain sensitive data outside of your Kubernetes cluster while still providing seamless access to applications running within the cluster.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does it work?
&lt;/h3&gt;

&lt;p&gt;Kubernetes External Secrets are custom resources that act as a bridge between your Kubernetes cluster and external secret management systems.&lt;/p&gt;

&lt;p&gt;Instead of storing secrets directly in Kubernetes, External Secrets fetch and synchronize secrets from external systems, making them available as native Kubernetes Secrets. This ensures that your applications can access sensitive data without any code changes while benefiting from the security features provided by external secret management solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrating with external secret management solutions
&lt;/h2&gt;

&lt;p&gt;Kubernetes External Secrets can integrate with a variety of external secret management solutions, such as HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, and Google Cloud Secret Manager.&lt;/p&gt;

&lt;p&gt;To integrate External Secrets with your chosen secret management system, you need to deploy the corresponding External Secrets controller in your cluster and configure it to communicate with the external system.&lt;/p&gt;

&lt;p&gt;For example, to integrate with HashiCorp Vault, you would deploy the Kubernetes External Secrets controller for Vault and configure it with the necessary Vault authentication and connection details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating and using External Secrets in Kubernetes
&lt;/h2&gt;

&lt;p&gt;To create an External Secret, you need to define a custom resource in a YAML file, specifying the reference to the secret stored in the external system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: external-secrets.io/v1alpha1
kind: ExternalSecret
metadata:
  name: my-external-secret
spec:
  backendType: vault
  data:
    - secretKey: username
      remoteRef:
        key: secret/data/my-secret
        property: username
    - secretKey: password
      remoteRef:
        key: secret/data/my-secret
        property: password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the YAML file using &lt;code&gt;kubectl apply -f my-external-secret.yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The External Secrets controller will fetch the secret data from the external system and create a native Kubernetes Secret with the same name. This generated secret can be used by your applications in the same way as regular Kubernetes Secrets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Kubernetes External Secrets
&lt;/h2&gt;

&lt;p&gt;Using Kubernetes External Secrets offers several benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Enhanced security by leveraging the features of external secret management solutions, such as encryption, access control, and auditing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduced risk of exposing sensitive data within the Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simplified secret management for organizations already using external secret management systems.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Centralized secret management across multiple Kubernetes clusters and other platforms.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By integrating Kubernetes External Secrets with your chosen secret management solution, you can achieve a higher level of security and control over your sensitive data while maintaining compatibility with your existing Kubernetes applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best practices for managing secrets in Kubernetes
&lt;/h2&gt;

&lt;p&gt;To ensure the security and integrity of your sensitive data, it is crucial to follow best practices for secret management in Kubernetes. In this section, we will discuss some of the most important practices to keep your secrets secure and maintain a robust Kubernetes environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Role-based access control (RBAC)
&lt;/h3&gt;

&lt;p&gt;RBAC is essential for managing secrets securely, as it enables you to control which users and components can create, read, update, or delete secrets. By implementing fine-grained access control, you can minimize the risk of unauthorized access and potential data breaches.&lt;/p&gt;

&lt;p&gt;To implement RBAC for secrets management, you should create roles and role bindings that define the allowed actions on secrets for each user or group. For example, you can create a role that allows read-only access to secrets within a specific namespace and bind it to a specific user or group:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: my-namespace
  name: secret-reader
rules:
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["get", "watch", "list"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Encrypting secrets at rest and in transit
&lt;/h3&gt;

&lt;p&gt;Encrypting secrets is crucial for protecting sensitive data from unauthorized access, both when stored in &lt;code&gt;etcd&lt;/code&gt; (at rest) and when transmitted within the cluster (in transit).&lt;/p&gt;

&lt;p&gt;Kubernetes provides native encryption options, such as enabling &lt;code&gt;etcd&lt;/code&gt; encryption to protect secrets at rest and using TLS for securing communications within the cluster. Ensure these options are configured and enabled to maintain the confidentiality of your secrets.&lt;/p&gt;

&lt;p&gt;In addition to Kubernetes native encryption options, you can also integrate third-party encryption solutions, such as HashiCorp Vault or cloud-based key management services, to further enhance the security of your secrets.&lt;/p&gt;

&lt;h3&gt;
  
  
  Secret rotation and expiration
&lt;/h3&gt;

&lt;p&gt;Regularly rotating secrets is an essential security practice that minimizes the risk of unauthorized access and potential data breaches.&lt;/p&gt;

&lt;p&gt;Strategies for secret rotation include manual updates using &lt;code&gt;kubectl&lt;/code&gt; or automated rotation using custom controllers or third-party secret management solutions.&lt;/p&gt;

&lt;p&gt;Automating secret rotation can be achieved using Kubernetes operators, external secret management systems, or custom scripts that periodically update secrets based on a predefined schedule or events.&lt;/p&gt;

&lt;h3&gt;
  
  
  Auditing and monitoring
&lt;/h3&gt;

&lt;p&gt;Auditing and monitoring are crucial for maintaining the security and integrity of your secrets, as they enable you to track and analyze secret access, usage, and modifications and detect potential security incidents.&lt;/p&gt;

&lt;p&gt;Several tools can be used for &lt;a href="https://blog.gitguardian.com/kubernetes-tutorial-part-3-authn-authz/"&gt;auditing&lt;/a&gt; and monitoring secrets, such as Kubernetes audit logs, Prometheus, Grafana, and complimentary solutions such as &lt;a href="https://www.gitguardian.com/?ref=blog.gitguardian.com"&gt;GitGuardian&lt;/a&gt; that provide detection against hard-coded secrets.&lt;/p&gt;

&lt;p&gt;Configure alerts and notifications to proactively notify administrators of potential security incidents or irregular secret access patterns, enabling timely investigation and response to potential threats.&lt;/p&gt;

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

&lt;p&gt;In this blog post, we have discussed the importance of secrets management in Kubernetes and explored various methods and best practices for securely managing sensitive data in your applications. Kubernetes Secrets, Kubernetes External Secrets, and GitOps workflows provide powerful tools and methodologies for managing secrets effectively, ensuring the security and integrity of your sensitive information.&lt;/p&gt;

&lt;p&gt;We encourage you to follow the best practices outlined in this post, such as implementing RBAC, encrypting secrets at rest and in transit, rotating secrets regularly, and auditing and monitoring your secrets. Continuously exploring additional resources and tools can further enhance your secret management processes.&lt;/p&gt;

&lt;p&gt;One such tool is GitGuardian, which helps you protect your sensitive data by monitoring your Git repositories for leaked secrets and credentials. GitGuardian can be integrated with your GitOps workflows to ensure that secrets are not accidentally exposed in your repositories, providing an additional layer of security for your Kubernetes environment.&lt;/p&gt;

&lt;p&gt;In conclusion, managing secrets securely in Kubernetes is critical for maintaining the confidentiality and integrity of your sensitive data. By following best practices and utilizing the right tools and methodologies, you can create a robust and secure Kubernetes environment, safeguarding your applications and data from potential threats.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>kubernetes</category>
      <category>security</category>
    </item>
    <item>
      <title>Introducing DependAware: Automating Dependency Updates for NPM Repositories 🚀</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Sat, 13 May 2023 14:14:08 +0000</pubDate>
      <link>https://dev.to/theinfosecguy/introducing-dependaware-automating-dependency-updates-for-npm-repositories-4p15</link>
      <guid>https://dev.to/theinfosecguy/introducing-dependaware-automating-dependency-updates-for-npm-repositories-4p15</guid>
      <description>&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;Introducing DependAware, an automated dependency update tool for NPM repositories that keeps your projects up-to-date and secure by creating pull requests for updating package dependencies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Category Submission:
&lt;/h3&gt;

&lt;p&gt;Wacky Wildcards&lt;/p&gt;

&lt;h3&gt;
  
  
  App Link
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/theinfosecguy/dependaware"&gt;DependAware on GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Screenshots
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Image: Branches created by DependAware&lt;/em&gt; 👇&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_veTMUy1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vod681ndcb2qy0pr2ha8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_veTMUy1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vod681ndcb2qy0pr2ha8.png" alt="Branches created by DependAware" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image: Pull Requests Tab running test cases&lt;/em&gt; 👇&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s71_WMse--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cq5dddha7oepg20t321.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s71_WMse--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cq5dddha7oepg20t321.png" alt="Pull Requests Tab running test cases" width="800" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image: Pull Requests Description updated after running tests&lt;/em&gt; 👇&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pRTiYf0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/giotg2myhiejq9efh624.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pRTiYf0y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/giotg2myhiejq9efh624.png" alt="Pull Requests Description updated after running tests" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image: Pull Requests created by DependAware&lt;/em&gt; 👇&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9Ncn3rrL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/inakxyitw8qr2gxjbn1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9Ncn3rrL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/inakxyitw8qr2gxjbn1w.png" alt="Pull Requests created by DependAware" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image: GitHub Actions Tab&lt;/em&gt; 👇&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J-g0VYv1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rrqyx7suho5rmhrne3qw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J-g0VYv1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rrqyx7suho5rmhrne3qw.png" alt="GitHub Actions Tab" width="800" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Description
&lt;/h3&gt;

&lt;p&gt;DependAware is designed to help developers maintain the health of their NPM projects by automatically scanning, detecting, and updating outdated or vulnerable package dependencies. With DependAware, you can easily integrate it into your GitHub Actions and keep your repositories up-to-date with the latest dependency versions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Link to Source Code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/theinfosecguy/dependaware"&gt;DependAware Repository&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Permissive License
&lt;/h3&gt;

&lt;p&gt;MIT License&lt;/p&gt;

&lt;h2&gt;
  
  
  Background (What made you decide to build this particular app? What inspired you?)
&lt;/h2&gt;

&lt;p&gt;In today's fast-paced software development world, managing dependencies can be a daunting task. Outdated or vulnerable dependencies can lead to security risks, performance issues, and general instability. I was inspired by the need for a seamless, automated solution that can help developers stay on top of their dependencies while maintaining focus on building amazing products.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I built it (How did you utilize GitHub Actions or GitHub Codespaces? Did you learn something new along the way? Pick up a new skill?)
&lt;/h3&gt;

&lt;p&gt;I built DependAware using GitHub Actions to automatically scan NPM repositories for outdated dependencies, create branches for each update, and then generate pull requests with detailed titles, descriptions, and the "dependencies" label. &lt;/p&gt;

&lt;p&gt;I also learned how to integrate DependAware with various GitHub workflows, such as running tests and updating PR descriptions with the test results.&lt;/p&gt;

&lt;p&gt;Throughout the development process, I picked up new skills in GitHub Actions and deepened our understanding of dependency management in NPM projects. I also explored the importance of communication between different workflows and ensuring smooth integration of DependAware into existing CI/CD pipelines.&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Resources/Info
&lt;/h3&gt;

&lt;p&gt;For more information on how to set up and use DependAware, check out the &lt;a href="https://github.com/theinfosecguy/dependaware"&gt;DependAware GitHub Repository&lt;/a&gt;. I encourage you to contribute, provide feedback, and help us improve this invaluable tool for developers. Together, we can make software development more secure and efficient! 🚀&lt;/p&gt;

</description>
      <category>githubhack23</category>
      <category>github</category>
      <category>githubactions</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Handle Secrets in Jenkins</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Tue, 18 Apr 2023 18:30:33 +0000</pubDate>
      <link>https://dev.to/gitguardian/how-to-handle-secrets-in-jenkins-56b3</link>
      <guid>https://dev.to/gitguardian/how-to-handle-secrets-in-jenkins-56b3</guid>
      <description>&lt;p&gt;Jenkins is a popular open-source automation server that is widely used for building, testing, and deploying software. It allows developers to automate many aspects of their software development process, including continuous integration and continuous deployment.&lt;/p&gt;

&lt;p&gt;As with any continuous integration software, managing secrets in Jenkins is crucial to ensure the security and integrity of the applications being built and deployed. In this blog post, we will be discussing the best practices for managing secrets in Jenkins, including configuring and managing secrets and how to handle potential security breaches.&lt;/p&gt;

&lt;p&gt;The blog post also covers storing secrets with Hashicorp Vault and integrating it with Jenkins.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before diving into the specifics of this tutorial, managing secrets in Jenkins, it’s important to have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Familiarity with Jenkins and its basic concepts, including how to create jobs and build pipelines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access to an already set up Jenkins instance and a &lt;a href="https://developer.hashicorp.com/vault/tutorials/getting-started/getting-started-install?ref=blog.gitguardian.com"&gt;Hashicorp Vault&lt;/a&gt; for testing and implementation, which will allow you to follow along with the tutorial.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Installed plugins in your Jenkins instance: &lt;a href="https://plugins.jenkins.io/credentials?ref=blog.gitguardian.com"&gt;Credentials | Jenkins plugin&lt;/a&gt;, &lt;a href="https://plugins.jenkins.io/credentials-binding?ref=blog.gitguardian.com"&gt;Credentials Binding | Jenkins plugin&lt;/a&gt;, and &lt;a href="https://plugins.jenkins.io/hashicorp-vault-plugin/?ref=blog.gitguardian.com"&gt;HashiCorp Vault | Jenkins plugin&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Additionally, you can have an application codebase ready to test the secrets management flow in your workflow. We will take as an example a NodeJS application that has Mocha tests and a Docker build setup.&lt;/p&gt;

&lt;p&gt;Next, we have a continuous integration (CI) job that is triggered when commits are pushed to the stage branch. The code is then tested and merged into the main branch. After that, a continuous deployment (CD) job is triggered and builds a Docker image before publishing it to DockerHub.&lt;/p&gt;

&lt;p&gt;Please note that this blog post is not contingent on this CI/CD workflow: although the presented flow can look pretty basic, you can follow along without any issues, no matter how complex or simple your workflow is!&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Jenkins Secrets
&lt;/h3&gt;

&lt;p&gt;Jenkins secrets, also known as credentials, are used for various authentication and authorization purposes and can include things like passwords, API keys, and private SSH keys.&lt;/p&gt;

&lt;p&gt;When it comes to managing these secrets, it’s important to understand there are two scopes in Jenkins: system-wide and job-specific. System-wide secrets are available to all jobs and projects within a Jenkins instance, such as credentials for a shared database or Git repository. Job-specific secrets are only available to a specific job or project and are typically used for specific tasks, like deploying to a particular environment.&lt;/p&gt;

&lt;p&gt;It is important to follow best practices when managing secrets in Jenkins. This includes using different secrets for different purposes, restricting their access, and regularly rotating and updating them to minimize the impact of a potential breach.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring Jenkins Secrets
&lt;/h3&gt;

&lt;p&gt;Now that we understand the basics of Jenkins secrets, let’s take a look at how to set up and configure them. The process of configuring secrets in Jenkins will vary depending on the type of secret and the specific use case.&lt;/p&gt;

&lt;p&gt;One way to configure Jenkins secrets is through the Jenkins web interface. To do this, navigate to the “Credentials” page in the Jenkins settings.&lt;/p&gt;

&lt;p&gt;This is Jenkins’ official credential management tool. You can add, modify, and delete secrets as needed. You can also specify which jobs or projects a secret is available for, and assign permissions to specific users or groups. There are multiple ways to store secrets using the Credentials Plugin.&lt;/p&gt;

&lt;p&gt;One good practice when configuring a secret is to give it a descriptive and unique name that clearly indicates what the secret is used for. Avoid using generic or ambiguous names that could cause confusion or make it difficult to identify the correct secret.&lt;/p&gt;

&lt;p&gt;Also, it is important to scope credentials appropriately based on the intended usage. For example, if a credential is only needed for a specific job or pipeline, it should be scoped to that job or pipeline rather than being made available globally. This helps to minimize the potential for unauthorized access or misuse of the credential.&lt;/p&gt;

&lt;p&gt;Here we have stored DockerHub username and password with a global scope:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VqVccSdv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csctslsn50b6zhj4b8uz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VqVccSdv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csctslsn50b6zhj4b8uz.png" alt="DockerHub Jenkins" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is an example of storing SSH keys (GitHub credentials in this case):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9dmVb7Yo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9l49vi6lml56u8zlxd1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9dmVb7Yo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9l49vi6lml56u8zlxd1.png" alt="SSH Keys Secret in Jenkins" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also store a text-based secret like an OAuth client secret for example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zgLkLtl8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e6xrzgf2e6412qw7fyi4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zgLkLtl8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e6xrzgf2e6412qw7fyi4.png" alt="OAuth Client Secret" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have an &lt;code&gt;.env&lt;/code&gt; holding environment variables needed in multiple steps in the build pipeline:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T4rJHokt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfu9dn8rour1u28eateb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T4rJHokt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfu9dn8rour1u28eateb.png" alt="New Credentials" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is where the “Credentials Binding” plugin comes into play. This plugin allows you to bind secrets to environment variables, making them available to your build scripts. It gives you an easy way to package up all a job’s secret files and passwords and access them using a single environment variable during the build.&lt;/p&gt;

&lt;p&gt;To use this plugin, you’ll need to specify the ID of the secret you want to use, as well as the environment variable it should be bound to. The following example is for a freestyle project in Jenkins.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u2-OcP9T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dg2138ngxnd6bwo7wy34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u2-OcP9T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dg2138ngxnd6bwo7wy34.png" alt="Freestyle Jenkins" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And below is an example for injecting the credentials &lt;code&gt;PORT&lt;/code&gt; into a pipeline project in Jenkins. (&lt;a href="https://github.com/theinfosecguy/nodejs-jenkins-app/blob/main/jenkinsfile-native?ref=blog.gitguardian.com"&gt;full config here&lt;/a&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pipeline &lt;span class="o"&gt;{&lt;/span&gt;
  …
  stages&lt;span class="o"&gt;{&lt;/span&gt;
    …
    stage&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Building Docker Image'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      steps &lt;span class="o"&gt;{&lt;/span&gt;
        script &lt;span class="o"&gt;{&lt;/span&gt;
          withCredentials&lt;span class="o"&gt;([&lt;/span&gt;string&lt;span class="o"&gt;(&lt;/span&gt;credentialsId: &lt;span class="s1"&gt;'PORT'&lt;/span&gt;, variable: &lt;span class="s1"&gt;'PORT'&lt;/span&gt;&lt;span class="o"&gt;)])&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            dockerImage &lt;span class="o"&gt;=&lt;/span&gt; docker.build&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$registry&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$BUILD_NUMBER&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;, &lt;span class="s2"&gt;"--build-arg PORT=&lt;/span&gt;&lt;span class="nv"&gt;$PORT&lt;/span&gt;&lt;span class="s2"&gt; ."&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
  …
  &lt;span class="o"&gt;}&lt;/span&gt;
  …
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to Use Vault Secrets in Jenkins
&lt;/h3&gt;

&lt;p&gt;In addition to the built-in Jenkins Secrets manager, it is also possible to integrate with third-party secret management tools such as Hashicorp Vault, AWS KMS, etc. This can be particularly useful if you are already using Vault to manage secrets for other applications or services.&lt;/p&gt;

&lt;p&gt;In this section, we will walk through the process of configuring Jenkins to retrieve secrets from Vault and use them in your pipeline.&lt;/p&gt;

&lt;p&gt;Run your Vault with the following command and leave this terminal session open as dev servers run in-memory, i.e., shutting them off would wipe the slate clean.&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="c"&gt;# we are running the vault inside an ec2 machine thus the private ip&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;vault server &lt;span class="nt"&gt;-dev&lt;/span&gt; &lt;span class="nt"&gt;-dev-listen-address&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;”&amp;lt;private ip of ec2&amp;gt;:8082”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, run the following commands in a separate terminal session:&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="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;VAULT_ADDR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'http://&amp;lt;private ip of ec2&amp;gt;:8082'&lt;/span&gt;
&lt;span class="c"&gt;# check the status just to be sure&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;vault status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should print information similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aonO1l3X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cq21fh6ovh8dqfqnbdjy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aonO1l3X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cq21fh6ovh8dqfqnbdjy.png" alt="Terminal OPT" width="577" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, our Jenkins instance needs to communicate with the Vault. The following commands will take care of the auth-related formalities. Jenkins will later use this role to talk to the Vault.&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="c"&gt;# firstly enable the vault approle authentication method&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;vault auth &lt;span class="nb"&gt;enable &lt;/span&gt;approle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# ensure a v2 kv secrets engine is in use&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;vault secrets &lt;span class="nb"&gt;enable &lt;/span&gt;kv-v2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# create a local file “jenkins-policy.hcl” that houses a policy allowing “read” access to the path “secret/data/jenkins” under which we’ll store our secret&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;tee &lt;/span&gt;jenkins-policy.hcl &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;"
  path "secret/data/jenkins/*" {
    capabilities = [ "read" ]
  }
&lt;/span&gt;&lt;span class="no"&gt;  EOF
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# create a vault policy "jenkins" from the local policy file "jenkins-policy.hcl"&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;vault policy write jenkins jenkins-policy.hcl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# create a vault approle “jenkins” and associate the vault policy “jenkins” with it&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;vault write auth/approle/role/jenkins &lt;span class="nv"&gt;token_policies&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;”jenkins” &lt;span class="nv"&gt;token_ttl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1h &lt;span class="nv"&gt;token_max_ttl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4h

&lt;span class="c"&gt;# Next, we need the strings roleId and secretId with &lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;vault &lt;span class="nb"&gt;read &lt;/span&gt;auth/approle/role/jenkins/role-id
&lt;span class="nv"&gt;$ &lt;/span&gt;vault write &lt;span class="nt"&gt;-f&lt;/span&gt; auth/approle/role/jenkins/secret-id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands will ensure that apps and/or services like Jenkins can connect with the Vault. The access policy we’ve defined allows the path &lt;code&gt;secret/data/jenkins/*&lt;/code&gt; to be accessed by the policyholder. Then, this policy is registered with the Vault and a role is attached to this policy.&lt;/p&gt;

&lt;p&gt;Copy the &lt;code&gt;role_id&lt;/code&gt; and &lt;code&gt;secret_id&lt;/code&gt; for later use. These are what Jenkins will use to identify itself while communicating with the Vault, and to access secrets in the path &lt;code&gt;secret/data/jenkins/*&lt;/code&gt;. We’ll store these as a credential in Jenkins.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hU-AxK9p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mx5mc2v9l09vmvm70xio.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hU-AxK9p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mx5mc2v9l09vmvm70xio.png" alt="Terminal" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, on Vault’s end, we need to store the secret. There are multiple ways to achieve this, but we’ll store it as a secret text here. The following command is used to store a secret identified as &lt;code&gt;my-secret&lt;/code&gt; in the &lt;code&gt;kv&lt;/code&gt; secret engine in the path we earlier declared in the &lt;code&gt;approle&lt;/code&gt; policy.&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="nv"&gt;$ &lt;/span&gt;vault kv put secret/data/jenkins/my-secret &lt;span class="nv"&gt;PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EZIJ3LPf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxwyseyozym1vd0igw1y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EZIJ3LPf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxwyseyozym1vd0igw1y.png" alt="Output" width="800" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then create credentials in Jenkins via the Jenkins web interface. To do this, navigate to the “Credentials” page in the Jenkins settings. Add a new credential under Global credentials. Select the “Kind” as “Vault App Role Credential”. And paste in the IDs role and secret we copied from the terminal. The form should look like the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VS6_CA7k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n5g3c38jb7rw4lkw8lip.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VS6_CA7k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n5g3c38jb7rw4lkw8lip.png" alt="Jenkins Dashboard" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the credentials are added, copy the credential’s ID for later reference in the Jenkins pipeline.&lt;/p&gt;

&lt;p&gt;Lastly, the following example is for a pipeline project in Jenkins. (&lt;a href="https://github.com/theinfosecguy/nodejs-jenkins-app/blob/main/jenkinsfile-vault?ref=blog.gitguardian.com"&gt;full config here&lt;/a&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;def secrets &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt;
    path: &lt;span class="s1"&gt;'secret/data/jenkins/my-secret'&lt;/span&gt;,
    engineVersion: 2,
    secretValues: &lt;span class="o"&gt;[&lt;/span&gt;
      &lt;span class="o"&gt;[&lt;/span&gt;envVar: &lt;span class="s1"&gt;'PORT'&lt;/span&gt;, vaultKey: &lt;span class="s1"&gt;'PORT'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
    &lt;span class="o"&gt;]&lt;/span&gt;
  &lt;span class="o"&gt;]&lt;/span&gt;,
&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;def configuration &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
  vaultUrl: &lt;span class="s1"&gt;'http://172.31.36.198:8082'&lt;/span&gt;,
  vaultCredentialId: &lt;span class="s1"&gt;'ccc2cf0c-1b1a-40a1-a7bd-81ef1dc764f1'&lt;/span&gt;,
  engineVersion: 2
&lt;span class="o"&gt;]&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pipeline &lt;span class="o"&gt;{&lt;/span&gt;
  …
  stages&lt;span class="o"&gt;{&lt;/span&gt;
    …
    stage&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Building Docker Image'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      steps &lt;span class="o"&gt;{&lt;/span&gt;
        script &lt;span class="o"&gt;{&lt;/span&gt;
          withVault&lt;span class="o"&gt;([&lt;/span&gt;configuration: configuration, vaultSecrets: secrets]&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            dockerImage &lt;span class="o"&gt;=&lt;/span&gt; docker.build&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$registry&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;$BUILD_NUMBER&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;, &lt;span class="s2"&gt;"--build-arg PORT=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.PORT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; ."&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
  …
  &lt;span class="o"&gt;}&lt;/span&gt;
  …
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this section, we have demonstrated how to integrate Jenkins with Hashicorp Vault to securely manage your secrets. By leveraging the power of Vault’s secret management capabilities and Jenkins’ flexible pipeline configuration, you can ensure that your sensitive information remains protected throughout your CI/CD process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Managing Secrets in Jenkins
&lt;/h3&gt;

&lt;p&gt;Managing secrets in Jenkins is crucial for maintaining the security of your applications. To ensure this, it is important to follow best practices such as &lt;strong&gt;rotating secrets regularly, using strong passwords, and avoiding storing plaintext secrets in Jenkins or in version control.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In addition, regular auditing and monitoring of secrets are also important. This involves keeping track of access to secrets, and their usage, and updating them as necessary. Alerts should also be set up to notify of potential breaches, such as unauthorized access to secrets or failed login attempts.&lt;/p&gt;

&lt;p&gt;In case of a security breach or secrets leakage, having a plan in place for revoking access to the compromised secrets, rotating all secrets, and conducting a thorough investigation to prevent similar incidents in the future is crucial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;As we have seen, Jenkins secrets are used to store sensitive information such as passwords, tokens, and keys that are needed by your applications to function properly. However, if not managed properly, these secrets can become a security risk.&lt;/p&gt;

&lt;p&gt;Throughout this blog post, we have discussed the importance of managing secrets in Jenkins, the types of secrets that can be managed, and best practices for securing and managing these secrets. We also provided step-by-step instructions for setting up and configuring secrets in Jenkins natively or with an external secrets management solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is important to remember that hard-coding secrets or storing them in plaintext can lead to security breaches.&lt;/strong&gt; Therefore, it is crucial to follow &lt;a href="https://blog.gitguardian.com/secrets-api-management/"&gt;best practices for secret management&lt;/a&gt; and to have a plan in place for handling potential breaches.&lt;/p&gt;

&lt;p&gt;We hope this blog post has provided you with a better understanding of how to manage secrets in Jenkins and keep your applications secure.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>cloud</category>
    </item>
    <item>
      <title>How to Handle AWS Secrets</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Fri, 07 Apr 2023 15:07:48 +0000</pubDate>
      <link>https://dev.to/gitguardian/how-to-handle-aws-secrets-2ba1</link>
      <guid>https://dev.to/gitguardian/how-to-handle-aws-secrets-2ba1</guid>
      <description>&lt;p&gt;Secure management of AWS secrets is essential for protecting sensitive data and preventing unauthorized access to critical systems and applications. In today’s rapidly escalating threat landscape, organizations must ensure their secrets are appropriately managed and safeguarded.&lt;/p&gt;

&lt;p&gt;The AWS SDK also referred to as the AWS Software Development Kit, is a set of software development tools and libraries created to make it easier for developers to utilize AWS services in their applications. It provides an accessible interface for accessing resources like EC2, S3, and DynamoDB on AWS with ease.&lt;/p&gt;

&lt;p&gt;However, when using AWS SDK to interact with AWS services, it’s essential that secrets used for authentication and authorization are managed appropriately. In this blog post, we’ll cover some best practices for managing AWS secrets when using the AWS SDK in Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before using the AWS SDK for Python to securely manage your AWS secrets, ensure that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic understanding &amp;amp; knowledge of Python and the ability to install packages using pip&lt;/li&gt;
&lt;li&gt;An AWS account with appropriate permissions to access AWS services&lt;/li&gt;
&lt;li&gt;An IAM user or role with necessary access rights&lt;/li&gt;
&lt;li&gt;Boto3, the AWS SDK for Python, should also be installed on your system using pip.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Problem with Long-Lived Access Keys and Secret Keys in Code
&lt;/h2&gt;

&lt;p&gt;When using AWS SDK with Python, hard-coding long-lived access keys and secret keys is not recommended. These credentials are used for authentication to AWS resources, and these keys pose a security risk since they aren’t automatically rotated.&lt;/p&gt;

&lt;p&gt;Here are some potential risks of hard-coding long-lived access keys and secret keys into your code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Code sharing increases the risk of accidental exposure of sensitive information to those with access to it, whether through public sharing or accidental committing to a public repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It can be challenging to rotate access keys and secret keys, which could lead to version control issues and the need to update all instances of those keys within a codebase.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the following section, we’ll see how you can overcome this problem by using temporary keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Temporary Access Keys Instead
&lt;/h2&gt;

&lt;p&gt;For better security when using AWS SDK with Python, temporary access keys are the better solution. Temporary keys are short-lived credentials that allow secure access to AWS resources.&lt;/p&gt;

&lt;p&gt;Here are some advantages of using temporary access keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;They expire after a specified period (e.g., one month or one week), decreasing the risk of unauthorized access and making it easier to manage resource access.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Temporary access credentials can be generated on demand, making it simpler &amp;amp; easier to provide end users with access to AWS resources without defining an AWS identity for each user.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note&lt;/strong&gt;: The AWS Security Token Service (STS) is a utility that generates temporary access keys.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using AWS CLI to Manage AWS Secrets
&lt;/h2&gt;

&lt;p&gt;AWS CLI is a command-line tool that enables engineers to interact with AWS services by using CLI commands. Also, AWS CLI can be utilized for managing AWS secrets.&lt;/p&gt;

&lt;p&gt;One of the advantages of using AWS CLI is that it automatically fetches AWS credentials (access &amp;amp; secret keys) from a credentials file created by AWS CLI, so there’s no need to manually supply access keys and secret keys when creating an AWS client.&lt;/p&gt;

&lt;p&gt;Here’s an example of creating an AWS client without specifying access keys and secret keys when using AWS CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import boto3
client = boto3.client('s3')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;boto3.client()&lt;/code&gt; function is called with the s3 argument to create a client for Amazon S3. Since access keys and secret keys are not specified, the AWS SDK will automatically retrieve them from the credentials file created by AWS CLI.&lt;/p&gt;

&lt;p&gt;To create the credentials file, run the following command in the terminal:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This command will prompt you to enter your access key, secret key, default region, and output format. Once executed, a credentials file will be created on your machine which the AWS SDK can automatically search for and retrieve when creating an AWS client.&lt;/p&gt;

&lt;h2&gt;
  
  
  Manual Way to Configure AWS Secrets
&lt;/h2&gt;

&lt;p&gt;Another way to create a credentials file is to do it manually. The default location for the file is &lt;code&gt;~/.aws/credentials&lt;/code&gt;. The credentials file should have, at minimum, the access key and secret access key specified.&lt;/p&gt;

&lt;p&gt;In the sample file provided below, the access key and secret key for the account are specified in the default profile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you use the aws configure command, the configuration options that are not sensitive (such as region &amp;amp; output format) are saved in a file named &lt;code&gt;config&lt;/code&gt;. This file is also stored in the &lt;code&gt;.aws&lt;/code&gt; folder in your home directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[default]
region=us-west-2
output=json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating Multiple Named Profiles
&lt;/h2&gt;

&lt;p&gt;Developers can create &amp;amp; configure additional profiles to manage different sets of AWS credentials by using the aws configure command with the &lt;code&gt;--profile&lt;/code&gt; option. Alternatively, you can manually add entries to the config and credentials files. These files store configurations and access keys for each profile.&lt;/p&gt;

&lt;p&gt;To add new profiles, you can create separate named profiles in the config and credentials files.&lt;/p&gt;

&lt;p&gt;Here's an example of the credentials file with two profiles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY 
[user1]
aws_access_key_id=AKIAI44QH8DHBEXAMPLE
aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the default profile ([default]) is used when the AWS CLI command is used without specifying a profile. The second profile (&lt;code&gt;[user1]&lt;/code&gt;) is used when you run a command with the --profile user1 parameter. The file can be found in &lt;code&gt;~/.aws/credentials&lt;/code&gt; on Linux and Mac systems.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note&lt;/strong&gt;: Credentials location for a Windows system is &lt;code&gt;%USER%\.aws\credentials&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Managing AWS CLI Configuration Settings
&lt;/h2&gt;

&lt;p&gt;AWS CLI provides several commands to manage the configuration settings. You can use the aws configure set command to modify or set the configuration settings, and the aws configure get command to retrieve the configuration settings. Here's how you can use them:&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Configuration Settings
&lt;/h3&gt;

&lt;p&gt;To set any configuration settings, you can use the aws configure set command. Specify the profile you want to modify using the &lt;code&gt;--profile&lt;/code&gt; option. For example, to set the region for the USER profile, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws configure set region me-south-1 --profile USER
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can remove a configuration setting by using an empty string as the value or deleting the setting manually from the config and credentials files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Retrieving Configuration Settings
&lt;/h3&gt;

&lt;p&gt;You can retrieve the configuration settings that you've set using the aws configure get command. To retrieve the region setting for the USER profile, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws configure get region --profile USER
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Importing CSV Credentials
&lt;/h3&gt;

&lt;p&gt;You can import the CSV credentials generated from the AWS web console using the aws configure import command. The CSV file must contain the following headers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User Name&lt;/li&gt;
&lt;li&gt;Access key ID&lt;/li&gt;
&lt;li&gt;Secret access key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To import the credentials from the &lt;code&gt;credentials.csv&lt;/code&gt; file, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws configure import --csv file://credentials.csv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Listing Profiles
&lt;/h3&gt;

&lt;p&gt;You can list all your profile names using the aws configure &lt;code&gt;list-profiles&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws configure list-profiles --region &amp;lt;&amp;lt;YOUR_REGION&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Best Practices for Secure Credential Management in AWS
&lt;/h2&gt;

&lt;p&gt;When working with AWS, it's essential to adhere to best practices for credential management in order to protect your resources. Here are six top tips for AWS SDK credential management:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use the AWS CLI to Configure AWS Keys&lt;/strong&gt;: Avoid hardcoding AWS access keys and secret keys into your code. Instead, utilize the AWS CLI to configure your keys and store them securely.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Limit access to secrets with IAM policies and roles&lt;/strong&gt;: Use AWS Identity and Access Management (IAM) policies and roles to limit access to your secrets only to the users and services that require them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Regularly rotate secrets to minimize impact&lt;/strong&gt;: Regularly rotate your access keys, passwords, and other secrets to minimize the impact of potential exposure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Parameter Store to store secrets&lt;/strong&gt;: Parameter Store is a secure and scalable AWS service that allows you to store and manage secrets securely.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use AWS Secrets Manager for more advanced management&lt;/strong&gt;: AWS Secrets Manager provides advanced secret management features, such as automatic rotation and integration with Amazon RDS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use tools like GitGuardian to detect leaked secrets&lt;/strong&gt;: Leaked secrets can put your AWS resources at risk. Use tools like GitGuardian to detect and prevent leaks of your secrets in code repositories and other sources.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Properly managing AWS credentials is crucial to maintaining the security of your AWS resources. By using AWS's configuration and credential files, you can keep your AWS access and secret keys secure and separate from your code. Additionally, following best practices such as limiting access to secrets with IAM policies and roles, and regularly rotating secrets can further enhance your AWS credential management.&lt;/p&gt;

&lt;p&gt;As always, it's essential to stay vigilant against potential security breaches. That's where GitGuardian comes in. GitGuardian is a tool that can scan your GitHub repositories for exposed secrets, such as AWS keys, and alert you when it finds them. By using GitGuardian in conjunction with proper AWS credential management practices, you can ensure that your AWS resources remain secure.&lt;/p&gt;

&lt;p&gt;So, whether you're new to AWS or a seasoned pro, remember the importance of proper AWS credential management and take steps to keep your AWS resources secure. And don't forget to give GitGuardian a try for an extra layer of security.&lt;/p&gt;

&lt;p&gt;If you are interested in learning more about AWS IAM security best practices check this &lt;a href="https://blog.gitguardian.com/how-to-handle-secrets-with-jenkins/"&gt;post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We hope this blog post has provided you with a better understanding of how to manage AWS secrets and keep your applications secure.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>aws</category>
      <category>security</category>
    </item>
    <item>
      <title>How to Handle Secrets in Docker</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Thu, 16 Feb 2023 07:51:38 +0000</pubDate>
      <link>https://dev.to/gitguardian/how-to-handle-secrets-in-docker-3plm</link>
      <guid>https://dev.to/gitguardian/how-to-handle-secrets-in-docker-3plm</guid>
      <description>&lt;p&gt;Secrets management in Docker is a critical security concern for any business. When using Docker containers, it is essential to keep sensitive data such as passwords, API keys, and other credentials secure.&lt;/p&gt;

&lt;p&gt;This blog post will discuss some best practices for managing secrets in Docker, including how to store them securely and minimize their exposure. We will explore multiple solutions: using Docker Secrets with Docker Swarm, Docker Compose, or Mozilla SOPS. Feel free to choose what’s more appropriate to your use case. But most importantly is to remember to never hard-code your Docker secrets in plaintext in your Dockerfile!&lt;/p&gt;

&lt;p&gt;Following these guidelines ensures that your organization's sensitive information remains safe even when running containerized services.&lt;/p&gt;

&lt;h1&gt;
  
  
  4 Ways to Store &amp;amp; Manage Secrets in Docker
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Using Docker Secrets &amp;amp; Docker Swarm
&lt;/h2&gt;

&lt;p&gt;Docker Secrets and Docker Swarm are two official and complimentary tools allowing to securely manage secrets when running containerized services.&lt;/p&gt;

&lt;p&gt;Docker Secrets provides a secure mechanism for storing and retrieving secrets from the system without exposing them in plaintext. It enables users to keep their credentials safe by encrypting the data with a unique key before passing it to the system.&lt;/p&gt;

&lt;p&gt;Docker Swarm is a powerful tool for managing clusters of nodes for distributed applications. It provides an effective means of deploying containerized applications at scale. With this tool, you can easily manage multiple nodes within a cluster and automatically distribute workloads among them. This helps ensure that your application has enough resources available at all times, even during peak usage periods or unexpected traffic spikes.&lt;/p&gt;

&lt;p&gt;Together, these two tools provide an effective way to ensure that your organization's sensitive information remains safe despite ever-evolving security needs.&lt;/p&gt;

&lt;p&gt;Let’s see how create and manage an example secret.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a Secret
&lt;/h3&gt;

&lt;p&gt;To create a secret, we need to first initialize Docker Swarm. You can do so using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker swarm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the service is initialized, we can use the docker secret create command to create the secret:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t rsa -b 4096 -N "" -f mykey
docker secret create my_key mykey
rm mykey
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In these commands, we first create an SSH key using the ssh-keygen command and write it to mykey. Then, we use the docker secret command to generate the secret. Ensure that you delete the mykey file to avoid any security risks.&lt;/p&gt;

&lt;p&gt;You can use the following command to confirm that the secret is created successfully:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker secret ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now use this secret in our Docker containers. One way is to pass this secret with &lt;code&gt;–secret&lt;/code&gt; flag when creating a service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker service  create --name mongodb --secret my_mongodb_secret redis:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also pass this secret to &lt;code&gt;docker-compose.yml&lt;/code&gt; file. Let’s take a look at an example file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.7'
services:
  myapp:
    image: mydummyapp:latest
    secrets:
      - my_secret
    volumes:
      - type: bind
        source: my_secret_key
        target: /run/secrets/my_secret
        read_only: true
secrets:
  my_secret:
    external: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example compose file, the secrets section defines a secret named &lt;code&gt;my_secret_key&lt;/code&gt; (discussed earlier). The &lt;code&gt;myapp&lt;/code&gt; service definition specifies that it requires &lt;code&gt;my_secret_key&lt;/code&gt; , and mounts it as a file at &lt;code&gt;/run/secrets/my_secret&lt;/code&gt; in the container.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Docker Compose
&lt;/h2&gt;

&lt;p&gt;Docker Compose is a powerful tool for defining and running multi-container applications with Docker. A stack is defined by a docker-compose file allowing you to define and configure the services that make up your application, including their environment variables, networks, ports, and volumes. &lt;/p&gt;

&lt;p&gt;With Docker Compose, it is easy to set up an application in a single configuration file and deploy it quickly and consistently across multiple environments.&lt;/p&gt;

&lt;p&gt;Docker Compose provides an effective solution for managing secrets for organizations handling sensitive data such as passwords or API keys. You can read your secrets from an external file (like a TXT file). But be careful not to commit this file with your code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.7'
services:
  myapp:
    image: myapp:latest
    secrets:
      - my_secret
secrets:
  my_secret:
    file: ./my_secret.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using a Sidecar Container
&lt;/h2&gt;

&lt;p&gt;A typical strategy for maintaining and storing secrets in a Docker environment is to use sidecar containers. Secrets can be sent to the main application container via the sidecar container, which can also operate a secrets manager or another secure service.&lt;/p&gt;

&lt;p&gt;Let’s understand this using a Hashicorp Vault sidecar for a MongoDB container:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, create a Docker Compose (docker-compose.yml) file with two services: mongo and secrets.&lt;/li&gt;
&lt;li&gt;In the secrets service, use an image containing your chosen secret management tool, such as a vault.&lt;/li&gt;
&lt;li&gt;Mount a volume from the secrets container to the mongo container so the mongo container can access the secrets stored in the secrets container.&lt;/li&gt;
&lt;li&gt;In the &lt;code&gt;mongo&lt;/code&gt; service, use environment variables to set the credentials for the MongoDB database, and reference the secrets stored in the mounted volume.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the example compose file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.7'

services:
  mongo:
    image: mongo
    volumes:
      - secrets:/run/secrets
    environment:
      MONGO_INITDB_ROOT_USERNAME_FILE: /run/secrets/mongo-root-username
      MONGO_INITDB_ROOT_PASSWORD_FILE: /run/secrets/mongo-root-password
  secrets:
    image: vault
    volumes:
      - ./secrets:/secrets
    command: ["vault", "server", "-dev", "-dev-root-token-id=myroot"]
    ports:
      - "8200:8200"

volumes:
  secrets:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Mozilla SOPS
&lt;/h2&gt;

&lt;p&gt;Mozilla SOPS (Secrets Ops) is an open-source platform that provides organizations with a secure and automated way to manage encrypted secrets in files. &lt;/p&gt;

&lt;p&gt;It offers a range of features designed to help teams share secrets in code in a safe and practical way. The following assumes you are already familiar with SOPS, if that's not the case, &lt;a href="https://blog.gitguardian.com/a-comprehensive-guide-to-sops/"&gt;start here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use SOPS with &lt;code&gt;docker-compose.yml&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.7'

services:
  myapp:
    image: myapp:latest
    environment:
      API_KEY: ${API_KEY}
    secrets:
      - mysecrets

  sops:
    image: mozilla/sops:latest
    command: ["sops", "--config", "/secrets/sops.yaml", "--decrypt", "/secrets/mysecrets.enc.yaml"]
    volumes:
      - ./secrets:/secrets
    environment:
      # Optional: specify the path to your PGP private key if you encrypted the file with PGP
      SOPS_PGP_PRIVATE_KEY: /secrets/myprivatekey.asc

secrets:
  mysecrets:
    external: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above, the myapp service requires a secret called &lt;code&gt;API_KEY&lt;/code&gt;. The secrets section uses a secret called &lt;code&gt;mysecrets&lt;/code&gt;, which is expected to be stored in an external key/value store, such as Docker Swarm secrets or HashiCorp Vault.&lt;/p&gt;

&lt;p&gt;The sops service uses the official SOPS Docker image to decrypt the &lt;code&gt;mysecrets.enc.yaml&lt;/code&gt; file, which is stored in the local &lt;code&gt;./secrets&lt;/code&gt; directory. The decrypted secrets are mounted to the &lt;code&gt;myapp&lt;/code&gt; service as environment variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Make sure to create the secrets directory and add the encrypted &lt;code&gt;mysecrets.enc.yaml&lt;/code&gt; file and the &lt;code&gt;sops.yaml&lt;/code&gt; configuration file (with SOPS configuration) in that directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scan for secrets in your Docker images
&lt;/h2&gt;

&lt;p&gt;Hard coding secrets in Docker is a significant security risk, making them vulnerable to attackers. We have seen different best practices to avoid hard-coding secrets in plaintext in your Docker images, but security doesn't stop there.&lt;/p&gt;

&lt;p&gt;You should also scan your images for secrets.&lt;/p&gt;

&lt;p&gt;All Dockerfiles start with a &lt;code&gt;FROM&lt;/code&gt; directive that defines the base image. It's important to understand that when you use a base image, especially from a public registry like Docker Hub, you are pulling external code that may contain hardcoded secrets. &lt;/p&gt;

&lt;p&gt;More information is exposed than visible in your single Dockerfile. Indeed, it's possible to retrieve a plaintext secret hard-coded in a previous layer starting from your image.&lt;/p&gt;

&lt;p&gt;In fact, many public Docker images are concerned: in 2021, we estimated that &lt;strong&gt;7% of the &lt;a href="https://blog.gitguardian.com/hunting-for-secrets-in-docker-hub/"&gt;Docker Hub images&lt;/a&gt; contained at least one secret&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Fortunately, you can easily detect them with &lt;code&gt;ggshield&lt;/code&gt; (GitGuardian CLI). For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ggshield secret scan docker ubuntu:22.04
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;To sum up, managing secrets in Docker is a crucial part of preserving the security of your containerized apps. Docker includes several built-in tools for maintaining secrets, such as Docker Secrets and Docker Compose files.&lt;/p&gt;

&lt;p&gt;Additionally, organizations can use third-party solutions like HashiCorp Vault and Mozilla SOPS to manage secrets in Docker. These technologies offer extra capabilities like access control, encryption, and audit logging to strengthen the security of your secret management.&lt;/p&gt;

&lt;p&gt;Finally, finding and limiting accidental or unintended exposure of sensitive information is crucial to handling secrets in Docker. Companies are invited to use secret scanning tools such as GitGuardian to scan the Docker images built in their CI/CD pipelines as mitigation to prevent &lt;a href="https://blog.gitguardian.com/codecov-supply-chain-breach/"&gt;supply-chain attacks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you want to know more about Docker security, we also summarized some of the best practices in a &lt;a href="https://blog.gitguardian.com/how-to-improve-your-docker-containers-security-cheat-sheet/"&gt;cheat sheet&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Time Management Techniques for Developers to Boost Productivity⏳</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Fri, 10 Feb 2023 07:56:07 +0000</pubDate>
      <link>https://dev.to/theinfosecguy/time-management-techniques-for-developers-to-boost-productivity-34ck</link>
      <guid>https://dev.to/theinfosecguy/time-management-techniques-for-developers-to-boost-productivity-34ck</guid>
      <description>&lt;p&gt;Developers are often tasked with managing their time effectively to ensure the successful completion of projects. However, good time management isn't just about setting deadlines; it involves discipline and organization to manage workloads efficiently.&lt;/p&gt;

&lt;p&gt;By implementing specific techniques related to planning, tracking progress, and following through on tasks, developers can boost their productivity and stay organized throughout their workday. &lt;/p&gt;

&lt;p&gt;In this blog post, we'll discuss various strategies for effective time management that will help developers stay on top of their workloads while ensuring quality work is produced in a timely manner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Importance of Time Management 💡
&lt;/h2&gt;

&lt;p&gt;Time management is an essential skill for any successful developer, as it allows them to stay organized and use their time better. Good time management helps developers produce work that meets deadlines without sacrificing quality due to being overwhelmed with too many tasks or having insufficient organizational skills.&lt;/p&gt;

&lt;p&gt;By implementing specific techniques related to planning, &lt;a href="https://www.timedoctor.com/blog/what-is-employee-monitoring/" rel="noopener noreferrer"&gt;tracking progress&lt;/a&gt;, and following through on tasks, developers can boost their productivity and stay organized throughout their workday. This leads to higher-quality output in less time and increases overall job satisfaction by reducing stress levels associated with tight deadlines.&lt;/p&gt;

&lt;p&gt;Effective time management allows developers to stay organized, make better use of their time, and ensure that they produce high-quality work efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  5 Ways to Manage Time as a Developer 👨‍💻
&lt;/h2&gt;

&lt;p&gt;Time management is an essential skill for any successful developer. Without proper planning, tracking progress, and following through on tasks, developers can quickly become overwhelmed and struggle to complete their work in a timely manner. &lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Goals and Prioritizing Tasks
&lt;/h3&gt;

&lt;p&gt;Planning ahead and setting specific goals with deadlines is essential for successful time management. It is vital to break down big projects into smaller tasks and prioritize them to ensure that the most critical tasks are done first. This will help developers stay organized, focused, and motivated throughout their workday.&lt;/p&gt;

&lt;p&gt;Additionally, creating a timeline or checklist of tasks can help keep the developer on track and ensure that the tasks are completed on time without sacrificing quality.&lt;/p&gt;

&lt;h3&gt;
  
  
  Staying Focused and Avoiding Distractions 🎯
&lt;/h3&gt;

&lt;p&gt;Being mindful of how one spends time is essential for effective time management. For example, limiting distractions such as checking emails too often or spending too much time on social media can help create an environment where productivity is maximized.&lt;/p&gt;

&lt;p&gt;Additionally, developing strategies for staying focused, such as taking regular breaks or setting aside specific times during the day for tasks, can help keep motivation high while ensuring that all work assignments are completed on schedule.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3kyewowcwbbkn71omr01.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3kyewowcwbbkn71omr01.jpg" alt="Image by Cheezburger" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Managing Email and Communication 📧
&lt;/h3&gt;

&lt;p&gt;Managing emails and communication is a critical time management technique for developers to boost productivity. Emails contain valuable information that can be used to plan tasks, track progress, and make sure deadlines are met without sacrificing quality.&lt;/p&gt;

&lt;p&gt;By filtering out unnecessary emails or setting up automatic replies, developers can save themselves valuable time each day while also staying organized with their workloads.&lt;/p&gt;

&lt;p&gt;Additionally, effective communication helps create clear expectations between the developer and their team members or clients regarding when certain tasks should be completed. With proper email management strategies, developers can maximize efficiency throughout their workday while ensuring all assignments are finished on schedule.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Visual Timelines 📈
&lt;/h3&gt;

&lt;p&gt;Having a visual timeline of when specific tasks need to be completed can also be beneficial to staying organized. This timeline should encompass everything from long-term projects to small daily tasks so that developers can effectively gauge their progress and stay on track throughout their workday.&lt;/p&gt;

&lt;p&gt;Additionally, setting realistic timelines for projects will ensure that the developer does not overextend themselves by giving an unrealistic deadline for completing each task or project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Taking Care of Your Physical and Mental Health 😷
&lt;/h3&gt;

&lt;p&gt;The importance of taking care of one's physical and mental health when managing time as a developer cannot be overstated. Not only is it important to stay focused and organized while working, but prioritizing self-care is also essential for boosting productivity in the long run.&lt;/p&gt;

&lt;p&gt;When it comes to time management, ensuring enough sleep, exercising regularly, eating healthy meals, and taking regular breaks throughout the day are all key strategies for staying productive and energized. &lt;/p&gt;

&lt;p&gt;Additionally, taking the time to practice mindfulness or setting aside some time each day for activities that bring joy can help reduce stress levels while allowing developers to stay focused during their workday.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fjktdxh08cnc3ezjlf7ld.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjktdxh08cnc3ezjlf7ld.jpg" alt="Developers in Gym" width="594" height="579"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Time management is essential for any successful developer, and one can employ many strategies to help manage time effectively. Setting goals and prioritizing tasks, staying focused and avoiding distractions, managing emails and communication wisely, creating visual timelines of when certain tasks should be completed, and taking care of one's physical and mental health all boost productivity.&lt;/p&gt;

&lt;p&gt;By following these simple steps daily, developers can ensure they stay organized while completing their work assignments within the desired timeframe.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>productivity</category>
      <category>programming</category>
      <category>motivation</category>
    </item>
    <item>
      <title>How to Handle Secrets in Python</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Thu, 26 Jan 2023 06:11:15 +0000</pubDate>
      <link>https://dev.to/gitguardian/how-to-handle-secrets-in-python-c0n</link>
      <guid>https://dev.to/gitguardian/how-to-handle-secrets-in-python-c0n</guid>
      <description>&lt;p&gt;We live in a world where applications are used to do everything, be it stock trading or booking a salon, but behind the scenes, the connectivity is done using secrets. Secrets such as database passwords, API keys, tokens, etc., must be managed appropriately to avoid any breach.&lt;/p&gt;

&lt;p&gt;The need for &lt;a href="https://blog.gitguardian.com/a-maturity-model-for-secrets-management/" rel="noopener noreferrer"&gt;managing secrets&lt;/a&gt; is critical for any organization. Secrets can be leaked in many ways, including through version control systems (never hardcode any secrets in your code!), private messages, email and other communication channels. If secrets are leaked, it can lead to a loss of trust, credibility, and even business (you can learn why &lt;a href="https://blog.gitguardian.com/secret-sprawl/" rel="noopener noreferrer"&gt;here&lt;/a&gt;). In some cases, leaked secrets can also lead to legal action. That's why it's so important to have a plan for managing secrets.&lt;/p&gt;

&lt;p&gt;In this post, we will discuss 4 different ways to manage secrets in Python efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;p&gt;Before getting started, below are a few things to keep in mind to avoid any issues later.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python &amp;amp; pip installed on your machine&lt;/li&gt;
&lt;li&gt;Understanding of Python &amp;amp; CLI&lt;/li&gt;
&lt;li&gt;Python IDE such as PyCharm or VS Code&lt;/li&gt;
&lt;li&gt;Basic understanding of Cloud&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 We will be using MacOS for this device. Please use the commands as per your OS.&lt;/p&gt;

&lt;h2&gt;
  
  
  4 Ways to Manage Secrets in Python
&lt;/h2&gt;

&lt;p&gt;In this section, we will discuss 4 different ways to manage your secrets in Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. From a file
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using an .env file
&lt;/h4&gt;

&lt;p&gt;The .env file is a file used to store environment variables in Python. Environment variables are variables set outside of the Python code and are used to configure the Python code. The .env file is typically used to store secret keys and passwords.&lt;/p&gt;

&lt;p&gt;We will use the python-dotenv package for accessing the content of the .env file. To get started, first install the package using the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install python-dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file for testing purposes and paste the following secrets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API_KEY=test-key
API_SECRET=test-secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, this file should not be committed to your git repo! Otherwise, it would be versioned and readable even after you delete it.&lt;/p&gt;

&lt;p&gt;Add this line to your &lt;code&gt;.gitignore&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Already committed the file? No worries, follow the instructions &lt;a href="https://blog.gitguardian.com/rewriting-git-history-cheatsheet/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Exposing secrets in a git repository is bad but mistakes happen. This is a complete guide and cheatsheet to rewrite and remove files from git history&lt;/p&gt;

&lt;p&gt;Once done, create a &lt;code&gt;main.py&lt;/code&gt; file and paste the below-mentioned code snippet. In this code, we are using the &lt;code&gt;load_dotenv()&lt;/code&gt; function to load content from the &lt;code&gt;.env&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dotenv&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_dotenv&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;

&lt;span class="nf"&gt;load_dotenv&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;api_secret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;API_SECRET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;API_KEY: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;API_SECRET: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;api_secret&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also use &lt;code&gt;dotenv_values()&lt;/code&gt; function, which converts the secrets into a dictionary. Secrets can be accessed by using the following code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dotenv&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dotenv_values&lt;/span&gt;

&lt;span class="n"&gt;secrets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dotenv_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.env&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secrets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secrets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;API_SECRET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When working on a large project, you may find that you need multiple &lt;code&gt;.env&lt;/code&gt; files. For example, you may have a &lt;code&gt;.env&lt;/code&gt; file for your local development environment and a &lt;code&gt;.env.dev&lt;/code&gt; file for your cloud development production environment. The following code snippet can be helpful if you have multiple env files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dotenv&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dotenv_values&lt;/span&gt;

&lt;span class="n"&gt;secrets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dotenv_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.env&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;local_secrets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dotenv_values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.env.dev&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secrets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;local_secrets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;API_SECRET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using a JSON file
&lt;/h4&gt;

&lt;p&gt;To keep the secrets more organized, you can also use a JSON file. Let's create a &lt;code&gt;secrets.json&lt;/code&gt; file and paste the following secrets into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="nl"&gt;"db"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"localhost"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"port"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;27017&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"test"&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="nl"&gt;"server"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"localhost"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"port"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;💡 The same as above applies, do not commit this file!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now that we have the JSON file ready, let’s write a function to access secrets from the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# main.py
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_value_from_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sub_key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
   &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
           &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;sub_key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;get_value_from_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;secrets.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;db&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;host&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# prints localhost
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Using Environment Variables
&lt;/h3&gt;

&lt;p&gt;Environment variables are variables that are set by the operating system or a specific user and are used by programs to determine various settings. &lt;/p&gt;

&lt;p&gt;We can use these variables to store our secrets and then access them in our program. You can use the following syntax to create an environment variable in macOS or a Linux machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ export variable_name=value
$ export API_KEY_TEST=dummykey
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a Windows machine, you use GUI to add environment variables or use the following command to add a variable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ setx [variable_name] “[value]”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can use the os package to access the os environment variable. Below mentioned is the sample code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;

&lt;span class="c1"&gt;# Get the secret key from the environment
&lt;/span&gt;&lt;span class="n"&gt;secret_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;api_key_test&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret_key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;prints&lt;/span&gt; &lt;span class="n"&gt;dummykey&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Secrets at the command line should be handled with special care too! Have a look at the &lt;a href="https://blog.gitguardian.com/secrets-at-the-command-line/" rel="noopener noreferrer"&gt;best practices&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Secrets at the Command Line [cheat sheet included]&lt;br&gt;
Developers need to prevent credentials from being exposed while working on the command line. Learn how you might be at risk and what tools and methods to help you work more safely.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Use a Cloud Secrets Manager
&lt;/h3&gt;

&lt;p&gt;Most cloud service providers offer an inbuilt secrets manager that can be used to create and use secrets across cloud infrastructure. Following the secret managers offered by cloud providers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/secrets-manager/" rel="noopener noreferrer"&gt;AWS Secrets Manager&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cloud.google.com/secret-manager" rel="noopener noreferrer"&gt;Secret Manager&lt;/a&gt; (By Google Cloud)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://azure.microsoft.com/en-us/products/key-vault/" rel="noopener noreferrer"&gt;Azure Key Vault&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AWS Secrets Manager is widely used across the industry. Let’s write a function to create and access a secret in AWS using &lt;a href="https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html" rel="noopener noreferrer"&gt;Boto3&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fetch_secret_from_aws&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret_name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
   &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="n"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
       &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;service_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;secretsmanager&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;region_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;us-east-1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="n"&gt;get_secret_value_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_secret_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SecretId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;secret_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;get_secret_value_response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;SecretString&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_secret_in_aws&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;secret_value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
   &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="n"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
       &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;service_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;secretsmanager&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;region_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;us-east-1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_secret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;secret_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;SecretString&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;secret_value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
   &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Using a KMS
&lt;/h3&gt;

&lt;p&gt;A KMS is a key management system that is used to manage cryptographic keys. It is typically used in organizations in order to centrally manage and secure keys. A KMS can be used to generate, store, and distribute keys. It can also be used to revoke keys and to monitor key usage.&lt;/p&gt;

&lt;p&gt;KMS is a convenient way to centrally manage the keys used by your applications and services and helps to ensure that only authorized users have access to them.&lt;/p&gt;

&lt;p&gt;Hashicorp Vault is one of the best open-source KMS available in the market that offers a number of features and benefits, including the ability to manage secrets and keys across multiple environments, strong security controls, and good scalability.&lt;/p&gt;

&lt;p&gt;Let’s write a function to read and write secrets to a specific path in the vault.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;💡 Note: Please ensure you have &lt;a href="https://pypi.org/project/hvac/" rel="noopener noreferrer"&gt;hvac&lt;/a&gt; (Python client for Vault) installed and have a Hashicorp Vault setup.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;hvac&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_secret_from_vault&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;secret_name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
   &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hvac&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
           &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://localhost:8200&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="n"&gt;read_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;secrets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_secret_version&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;secret_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;read_response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;secret_name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
   &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;write_secret_to_vault&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;secret_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;secret_value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
   &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hvac&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
           &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://localhost:8200&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="n"&gt;create_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;secrets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_or_update_secret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
           &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;secret_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="n"&gt;secret&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;secret_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;secret_value&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;create_response&lt;/span&gt;
   &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
       &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrapping it up
&lt;/h2&gt;

&lt;p&gt;Managing secrets is an essential part of application development. When developers hardcode secrets in cleartext into their applications, it creates a potential security breach. An attacker can use those secrets to access sensitive data if those secrets are discovered.&lt;/p&gt;

&lt;p&gt;Another alternative to the proposed methods here is to check secrets into source code and share them with your team encrypted. This can be a very flexible solution if you learn how to leverage a tool such as Mozilla SOPS. To learn more about SOPS and get started using it, read this &lt;a href="https://blog.gitguardian.com/a-comprehensive-guide-to-sops/" rel="noopener noreferrer"&gt;tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Did you know that GitGuardian detects more than 16000 secrets hardcoded into GitHub commits daily? When a secret is detected, GitGuardian notifies the repository owner so they can take action to protect their data.&lt;/p&gt;

&lt;p&gt;If you want a better view of how many secrets could be hidden inside your repositories, &lt;a href="https://dashboard.gitguardian.com/" rel="noopener noreferrer"&gt;sign up&lt;/a&gt; (for free) or &lt;a href="https://www.gitguardian.com/book-a-demo" rel="noopener noreferrer"&gt;book a demo&lt;/a&gt; to the GitGuardian Platform to scan every single commit and take preventive action now!&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>productivity</category>
      <category>tooling</category>
      <category>playwright</category>
    </item>
    <item>
      <title>9 Things to Consider When Choosing an SCA Tool</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Wed, 07 Dec 2022 06:02:36 +0000</pubDate>
      <link>https://dev.to/gitguardian/9-things-to-consider-when-choosing-an-sca-tool-2h4n</link>
      <guid>https://dev.to/gitguardian/9-things-to-consider-when-choosing-an-sca-tool-2h4n</guid>
      <description>&lt;p&gt;In the past, the development of software was something that required a lot of effort and resources. Basically, every piece of code was developed in-house, and code reuse was quite limited. The situation is now the opposite. Open-source packages are so widely used that they make up the bulk of the total amount of software produced by passionate hobbyists and virtually all the software professionals in tech companies. The convenience of reusing and fine-tuning components made open-source is just too strong for most software engineers to ignore it and keep "reinventing the wheel".&lt;/p&gt;

&lt;p&gt;To get a better idea of how big open source has become, we have some recent insights: according to a &lt;a href="https://www.gartner.com/en/documents/3971011"&gt;survey&lt;/a&gt; from Gartner, over 90% of the respondents stated that they rely on open source components. In another &lt;a href="https://www.synopsys.com/content/dam/synopsys/sig-assets/reports/rep-ossra-2021.pdf"&gt;report&lt;/a&gt; from Synopsis, 98% of the audited codebases contained at least one open-source component, and 75% of the source code came from open-source. The report also noted that 85% of the audited codebases contained components "more than four years out of date".&lt;/p&gt;

&lt;p&gt;This last data reveals the growing concern about the reliability and security of all this open-source material found in private code bases. Packages that are not maintained anymore cannot be patched for recently discovered vulnerabilities. Therefore it's become critical for organizations to be able to inventory open-source components and assess their vulnerabilities, making the use of software composition analysis mandatory. But not all SCA tools are created equal.&lt;/p&gt;

&lt;p&gt;This blog post will provide eight factors to consider when choosing an SCA tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is SCA (Software Composition Analysis)?
&lt;/h2&gt;

&lt;p&gt;SCA is the process of analyzing an application's dependencies to determine if it is affected by known security vulnerabilities. Organizations can more effectively manage security risks by understanding the dependencies between components.&lt;/p&gt;

&lt;p&gt;SCA can be performed either manually or using automated tools. Manual SCA is not scalable as the engineers must constantly check a vulnerability database such as &lt;a href="https://nvd.nist.gov/"&gt;NVD&lt;/a&gt; (National Vulnerability Database, maintained by NIST) and then compare the vulnerable versions with their existing dependencies. Much more efficient is to use automated SCA scanning tools, which can be triggered manually or integrated into the CI/CD pipeline for continuous checks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Importance of Software Composition Analysis
&lt;/h2&gt;

&lt;p&gt;SCA is integral to application security, as it helps identify and mitigate risks associated with using third-party components. SCA can help identify vulnerabilities in third-party components that attackers could exploit. It can also help track the versions of third-party components and ensure that they are up to date. By keeping track of the components used in an application, SCA can also help ensure compliance with license and security policies.&lt;/p&gt;

&lt;p&gt;In short, SCA is an essential part of the code security toolkit, focused on third-party components.&lt;/p&gt;

&lt;h2&gt;
  
  
  How is SCA different from SAST?
&lt;/h2&gt;

&lt;p&gt;SAST is a software testing technique that involves analyzing the source code of a software application to identify potential security vulnerabilities such as injection attacks, cross-site scripting (XSS), improper error handling, and insecure use of cryptographic functions.&lt;/p&gt;

&lt;p&gt;SAST aims to identify security vulnerabilities early in the software development cycle to mitigate them before the application is compiled and deployed.&lt;/p&gt;

&lt;p&gt;While SAST is an analysis technique used to check for known vulnerabilities in source code, SCA is used to scan dependencies for security vulnerabilities and license issues.&lt;/p&gt;

&lt;p&gt;Both are usually performed pre-build (against source code), or post-build (against binaries), as they don't require an application's execution to identify potential vulnerabilities. Both are equally important in ensuring the security of a software application.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to Choose an SCA tool?
&lt;/h1&gt;

&lt;p&gt;The many SCA tools on the market today can make it hard to decide which is the right one for your needs. To help you select the right one, we have curated a list of 9 things you should look out for in an SCA tool:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Language Support
&lt;/h2&gt;

&lt;p&gt;When opting for an SCA tool, it's vital to check what all languages are supported by the tool. Software composition analysis is language, end even ecosystem-dependent (package managers, build system, etc.): for instance, most SCA tools rely on lock files such as &lt;code&gt;package-lock.json&lt;/code&gt; or &lt;code&gt;Pipfile.lock&lt;/code&gt; to find dependencies and their respective versions. So you need to be careful here.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Accessible to Use/Developer Friendliness
&lt;/h2&gt;

&lt;p&gt;The SCA tool you choose should make your life easier, not harder. It should be intuitive and easy to use so that you can focus on your work, not on learning the tool. It should also be developer friendly so that you can easily integrate it into your existing development process. Also, it should be scalable to grow with your organization.&lt;/p&gt;

&lt;p&gt;The vendor should also have proper technical documentation available for the developers and having technical support for the tool is always a plus.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Support for Binary scanning
&lt;/h2&gt;

&lt;p&gt;When looking for a Software Composition Analysis (SCA) tool, choosing one that supports the scanning of binary files is essential. Many SCA tools don't support this type of scanning, which can leave vulnerabilities in the binaries used by the developers unchecked.&lt;/p&gt;

&lt;p&gt;Scanning binary files such as wheel files(.whl) are essential because it can find vulnerabilities that would otherwise be missed by scanning the dependencies. If you are not doing binary scanning used by your developers, you are not getting the complete picture of your code's security.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Direct vs. Transitive Dependencies
&lt;/h2&gt;

&lt;p&gt;There are two types of dependencies in software development: direct and transitive. &lt;/p&gt;

&lt;p&gt;A direct dependency is when one piece of software directly depends on another piece of software. For example, if software A directly uses software B, then A has a direct dependency on B. Conversely if software A uses software B, and software B uses software C, then A has a transitive dependency on C.&lt;/p&gt;

&lt;p&gt;The SCA tool should be able to provide you with the information if the vulnerability is in the direct dependency or transitive dependency. This is important because both types of dependencies can pose a security threat to a software project.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. False positives / False negatives
&lt;/h2&gt;

&lt;p&gt;If you are not familiar with the concept of false positives and false negatives, you should read this article about &lt;a href="https://blog.gitguardian.com/secrets-detection-accuracy-precision-recall-explained/"&gt;accuracy, precision, and recall&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;In a nutshell, false positives are vulnerabilities wrongly flagged as such by the tool, and false negatives are genuine vulnerabilities that the detection tool silently skipped. This is an important factor to consider when choosing a software composition analysis tool because false positives can lead to wasted time and resources. &lt;/p&gt;

&lt;p&gt;Developers may spend a significant amount of time manually reviewing and investigating these results, even though most are not security threats. This (also known as "alert fatigue") can be frustrating for developers and decrease their trust in the tool, potentially leading them to ignore or not use the tool as frequently as they otherwise would.&lt;/p&gt;

&lt;p&gt;The numbers reported by vendors can be challenging to verify. The best way to ensure that an SCA tool can accurately identify security threats while minimizing the number of false positives is to test it (for free, when possible).&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Webhooks &amp;amp; API Support
&lt;/h2&gt;

&lt;p&gt;When looking for an SCA tool, it's essential to check if the tool has proper API and webhook support so that you can easily integrate it into your CI/CD pipeline.&lt;/p&gt;

&lt;p&gt;Having proper API and webhook support will allow you to automate SCA scanning as part of your CI/CD process, which will help ensure that your applications are always up-to-date and compliant with security standards. Without proper API and webhook support, you may have to manually trigger SCA scans, which can lead to delays in your pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Rich Vulnerability Database
&lt;/h2&gt;

&lt;p&gt;A good SCA vendor should have a rich vulnerability database to detect vulnerabilities in your open-source packages. Such a database would enable the SCA vendor to provide you with customized alerts and recommendations on the best way to fix the identified vulnerabilities.&lt;/p&gt;

&lt;p&gt;In addition, the SCA vendor should have a team of expert analysts who can help you understand the nature of the vulnerabilities and their potential impact on your organization in case you need any support.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Time to Onboard New CVEs
&lt;/h2&gt;

&lt;p&gt;SCA tools are used by many organizations to keep track of vulnerabilities and potential security risks. It's essential to check how much time the SCA tool takes to onboard new CVEs on their platform from the vulnerability database. This allows organizations to plan for and respond to new security risks promptly. Additionally, it helps to ensure that SCA tools are up-to-date and provide accurate information about the latest security threats.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Detailed Reporting/Remediation
&lt;/h2&gt;

&lt;p&gt;The scanning should provide detailed reporting that helps the security team understand the scan results of the open-source packages. The report should include a list of all the packages that were scanned, as well as the results of the scan, including&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vulnerability description&lt;/li&gt;
&lt;li&gt;CVSS score&lt;/li&gt;
&lt;li&gt;CVSSv3 score&lt;/li&gt;
&lt;li&gt;Version impacted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The SCA tool should also provide proper remediation steps so that the developers can fix the issues.&lt;/p&gt;

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

&lt;p&gt;Open source has become the norm in the software development world, with nearly 80% of companies using open-source software in some form or another. For many companies, open source is the preferred choice for software development due to its flexibility, cost-effectiveness, and vast ecosystem of available tools and resources.&lt;/p&gt;

&lt;p&gt;However, with the increasing popularity of open source, there is also an increase in the number of vulnerabilities of open-source packages. This can create several risks and challenges for companies, including vulnerabilities in developed applications, licensing issues, and potential security breaches.&lt;/p&gt;

&lt;p&gt;Having SCA tools in your build and deployment pipeline can help you avoid security risks that might arise from any open-source dependency. You should now be more informed about the important factors to consider before selecting such as tool.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>security</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Best practices for managing developer teams in GitHub Orgs</title>
      <dc:creator>Keshav Malik</dc:creator>
      <pubDate>Wed, 02 Nov 2022 07:49:13 +0000</pubDate>
      <link>https://dev.to/gitguardian/best-practices-for-managing-developer-teams-in-github-orgs-1b23</link>
      <guid>https://dev.to/gitguardian/best-practices-for-managing-developer-teams-in-github-orgs-1b23</guid>
      <description>&lt;p&gt;Are you looking for ways to manage your developer team better? GitHub Orgs is a great way to keep track of repositories, branches, and collaborators all in one place. In this article, we'll share some best practices for managing developer teams in GitHub Orgs.&lt;/p&gt;

&lt;p&gt;There's a lot to love about GitHub, and the organizational structure it can give you is definitely one of them. When you share your code with other developers, make it public, or collaborate with a large team (or even a small one), the circle expands faster than you would imagine. Like it or not, a managed hierarchy of access and well-thought rules become imperative for the sustainability and security of your projects.&lt;/p&gt;

&lt;p&gt;What could go wrong if you do not manage access? It's a legitimate question considering you trust the people you collaborate with. Well, all it takes is an honest intern who rewrites the history in your master branch to wreak havoc. Let us say it is safe to have a managed organizational structure, and that's what we'll talk about.  &lt;/p&gt;

&lt;p&gt;In this blog, I will guide you through the best practices for managing developer teams in GitHub Orgs and provide recommendations to help you secure your GitHub organization.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an organization in GitHub?
&lt;/h2&gt;

&lt;p&gt;A GitHub organization is a shared platform where you can put one or more repositories and share controlled access with members and collaborators who can perform specific tasks. These organizations can be companies, non-profit organizations, some coalitions, or independent developers working together on a project for fun. An unlimited number of people can collaborate in an organization across multiple projects. &lt;/p&gt;

&lt;p&gt;Usually, an organization has five levels of role-based permissions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Owner: has complete control of the organization along with full administrative access. They can determine the team's access level to the project code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Billing manager: can manage payment settings for the organization. This includes setting up payment methods, managing subscriptions, and viewing invoices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Member:  is granted role-based access to control what they can see and do within the organization. Depending on their role, they may access the repositories or projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Moderator: have all the permissions granted to members by default. On top of that, they can block or unblock outside collaborators, set interaction limits, and hide comments on public repositories that belong to the organization.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Outside collaborator: a contractual member who's granted access to one or more repositories to perform specific tasks but doesn't have the full array of permissions granted to the members.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is a team in GitHub?
&lt;/h2&gt;

&lt;p&gt;Teams are groups of members that reflect the organization's structure. The teams are maintained by organization owners and team maintainers who can manage the level of access granted to a team and add or remove members. Teams have pages where you can see the members, child teams, the team profile picture, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Managing a team's access to repositories in GitHub
&lt;/h3&gt;

&lt;p&gt;The owners can give a team access to a repository, remove the access, or modify the permission level to a specific repository based on the need.&lt;br&gt;
If a team has direct access to a repository, the access can be simply removed. However, if a team has inherited access from a parent team, then the maintainers have to remove the access for the parent team to remove access for the child team.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---7wWXchG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.gitguardian.com/content/images/2022/10/Frame-67.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---7wWXchG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.gitguardian.com/content/images/2022/10/Frame-67.png" alt="GitHub Teams" width="864" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  8 Best Practices for Managing Teams in GitHub
&lt;/h2&gt;

&lt;p&gt;Now that we have somewhat established organizations and teams in GitHub let's jump right into the practices that make it easier to manage teams safely and sustainably.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure the Organization
&lt;/h3&gt;

&lt;p&gt;Creating an organization on GitHub is extremely simple; it takes just a few clicks. But you should take the time to configure the organization based on the group's specific needs. This could mean restricting access to certain repositories, setting up review cycles, or modifying other settings to strengthen the organization's security. This will help to keep things organized and make it easier for team members to find the information they need.&lt;/p&gt;

&lt;h3&gt;
  
  
  One Branch for Each Feature or Bug
&lt;/h3&gt;

&lt;p&gt;One of the key advantages of a GitHub organization is allowing an unlimited number of developers to work on different projects simultaneously. Having a branch for each bug or feature helps you make the most out of this advantage, allowing multiple people to work on various features without worrying about overwriting the code written by someone else. This also keeps things well organized.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Nested Teams
&lt;/h3&gt;

&lt;p&gt;As an organization owner, you can create child teams or nested teams that inherit the permissions from their parent teams. It simplifies access management, as adding or removing permissions for the parent teams automatically means doing the same for the child teams. &lt;/p&gt;

&lt;p&gt;When working with a large number of groups, having nested teams simplify communication.&lt;br&gt;
Nested teams can also be given different permissions than their parent teams so that you can tailor the team's access to your organization's needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Assign Code Owners
&lt;/h3&gt;

&lt;p&gt;The success of a project relies heavily on code reviews. Code owners are a special type of GitHub user responsible for reviewing and approving code changes in a repository. Code owners can be assigned to specific files or directories and will be notified whenever a change is made to those files. This makes pull requests safer, removes the confusion pertaining to ownership and reviews, and ensures the smooth functioning of a team.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rebasing the Feature Branches
&lt;/h3&gt;

&lt;p&gt;As we have discussed earlier, creating a branch for each feature or bug is a good practice. But if a team is working on a bunch of features simultaneously, it creates a complicated graph of branches that becomes very difficult to track. To avoid that, the ideal practice is to rebase the feature branches with the master branch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase"&gt;Rebasing&lt;/a&gt; can help resolve merge conflicts more efficiently and make it easier to track changes and keep your codebase up to date.&lt;/p&gt;

&lt;h3&gt;
  
  
  Squash Commits Before Merging
&lt;/h3&gt;

&lt;p&gt;Commits are like milestones in the journey of a Git project. Squashing commits is a way of rewriting the commit history before you share it with your team. It keeps the commit history clean and makes it easier to associate a bug with a specific commit when it comes to testing or debugging.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup Pre-Merge &amp;amp; Post-Merge Jobs with GitHub Repositories
&lt;/h3&gt;

&lt;p&gt;If you're using GitHub for your project development, you can easily set up pre-merge and post-merge jobs to run automatically on your repositories.&lt;/p&gt;

&lt;p&gt;This also helps to ensure that the code integrates properly and that any potential conflicts are resolved before they cause problems. Pre-merge jobs can be used to run tests and verify that the code compiles correctly. Post-merge jobs can be used to deploy the code to a staging environment for further testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Secret Scanning Tools
&lt;/h3&gt;

&lt;p&gt;Secret scanning tools like GitGuardian or &lt;a href="https://github.com/zricethezav/gitleaks"&gt;gitleaks&lt;/a&gt; can help you avoid accidentally leaking secrets like API keys and passwords through your GitHub repositories. These tools work by scanning your repositories and pull requests for potentially sensitive information and then alerting you so you can take action to remove or protect the information.&lt;br&gt;
You can install the GitGuardian App through the GitHub Marketplace for free on public repositories &lt;a href="https://github.com/marketplace/gitguardian"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Using a secret scanning tool is a good first step in preventing accidental leaks, but it's also important to be aware of the potential risks and to review your code regularly to ensure that no sensitive information is accidentally left exposed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Track Progress using GitHub Projects
&lt;/h3&gt;

&lt;p&gt;It is essential to keep track of team progress. This can be done by creating a &lt;a href="https://docs.github.com/en/issues/planning-and-tracking-with-projects/learning-about-projects/about-projects"&gt;GitHub project board&lt;/a&gt; and adding issues and milestones. This feature allows you to create Kanban-style boards for your repositories to see what's being worked on and what is still pending. You can also add notes and tags to your cards to keep all the relevant information in one place. Tracking progress using GitHub Projects is a great way to keep your project organized and on track.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best practices to secure your GitHub Organization at a glance
&lt;/h2&gt;

&lt;p&gt;To keep your GitHub Organization secure, it is essential to follow best practices. Some of these best practices include:&lt;/p&gt;

&lt;h3&gt;
  
  
  Backup &amp;amp; restore for your repos
&lt;/h3&gt;

&lt;p&gt;As a best practice, it is always recommended that you have a backup and recovery plan for critical repositories and ever-changing metadata. This will help ensure that you can recover your data in the event of a disaster and that your metadata is always up-to-date.&lt;/p&gt;

&lt;h3&gt;
  
  
  Supervise access controls
&lt;/h3&gt;

&lt;p&gt;One of the most crucial security steps is setting access controls on an as-needed basis. Make sure that no one has more permissions than they need to have. This will help to prevent unauthorized access to sensitive information. You should also have a process in place for revoking access when someone no longer needs it.&lt;/p&gt;

&lt;h3&gt;
  
  
  MFA for all
&lt;/h3&gt;

&lt;p&gt;Enforce multi-factor authentication for all members of the GitHub organization, moderators &amp;amp; billing managers. MFA (multi-factor authentication) adds an extra layer of security to your account by requiring you to enter a code from your mobile phone or another device in addition to your password. This makes it much harder for threat actors to gain access to your account, even if they have your password.&lt;/p&gt;

&lt;h3&gt;
  
  
  Security policies
&lt;/h3&gt;

&lt;p&gt;Organizations on GitHub have several different &lt;a href="https://docs.github.com/en/organizations/keeping-your-organization-secure/managing-security-settings-for-your-organization/managing-security-and-analysis-settings-for-your-organization"&gt;security settings&lt;/a&gt; that can be adjusted to fit the organization's needs. It is essential to review these settings regularly and audit your member's activity to ensure that your organization's data is safe.&lt;/p&gt;

&lt;h2&gt;
  
  
  To sum it up
&lt;/h2&gt;

&lt;p&gt;GitHub organizations are fantastic if you can maintain a few habits and imbibe some practices into the way your teams function. The responsibility is shared between the owners and the team members. As the owner, you can create nested teams, set security policies, and assign code owners to make things easier. Then if the team members can pull their share of the weight by being responsible for squashing the commits, rebasing the branches, and testing code, everything falls into place.&lt;/p&gt;

</description>
      <category>agile</category>
      <category>github</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
