<?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: M Nitin Kumar</title>
    <description>The latest articles on DEV Community by M Nitin Kumar (@m_nitinkumar_12140be2dce).</description>
    <link>https://dev.to/m_nitinkumar_12140be2dce</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%2F1952915%2F8003a971-1e45-43ae-8be3-340ff98f9136.jpg</url>
      <title>DEV Community: M Nitin Kumar</title>
      <link>https://dev.to/m_nitinkumar_12140be2dce</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/m_nitinkumar_12140be2dce"/>
    <language>en</language>
    <item>
      <title>Storing Certificate Files in AWS Secrets Manager and Accessing Them in Kubernetes Secrets</title>
      <dc:creator>M Nitin Kumar</dc:creator>
      <pubDate>Sat, 09 Nov 2024 04:56:45 +0000</pubDate>
      <link>https://dev.to/m_nitinkumar_12140be2dce/storing-certificate-files-in-aws-secrets-manager-and-accessing-them-in-kubernetes-secrets-53ca</link>
      <guid>https://dev.to/m_nitinkumar_12140be2dce/storing-certificate-files-in-aws-secrets-manager-and-accessing-them-in-kubernetes-secrets-53ca</guid>
      <description>&lt;h1&gt;
  
  
  Storing Certificate Files in AWS Secrets Manager and Accessing Them in Kubernetes Secrets
&lt;/h1&gt;

&lt;p&gt;In modern cloud-native applications, managing sensitive information like TLS/SSL certificates securely is crucial. One reliable approach is to store certificates in &lt;strong&gt;AWS Secrets Manager&lt;/strong&gt; and retrieve them in &lt;strong&gt;Kubernetes Secrets&lt;/strong&gt;. This blog post explains how to configure this setup, ensuring your certificates remain secure and accessible to your Kubernetes workloads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use AWS Secrets Manager for Certificates?
&lt;/h2&gt;

&lt;p&gt;AWS Secrets Manager provides robust security features for managing sensitive information such as certificates. Key benefits include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Automatic rotation&lt;/strong&gt; of secrets for enhanced security.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fine-grained access control&lt;/strong&gt; using IAM policies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encryption&lt;/strong&gt; of sensitive data at rest and in transit.&lt;/li&gt;
&lt;li&gt;Centralized &lt;strong&gt;management of secrets&lt;/strong&gt; across environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While Kubernetes Secrets can also manage certificates, integrating AWS Secrets Manager enhances security by leveraging AWS’s built-in encryption and management capabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps to Store and Retrieve Certificates
&lt;/h2&gt;

&lt;p&gt;Let’s go through the process of storing certificates in AWS Secrets Manager and configuring Kubernetes to retrieve them.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Storing Certificates in AWS Secrets Manager
&lt;/h3&gt;

&lt;p&gt;To store your certificates:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;AWS Secrets Manager&lt;/strong&gt; and select &lt;strong&gt;Store a new secret&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Other type of secret&lt;/strong&gt; for custom data.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Under &lt;strong&gt;Key/value pairs&lt;/strong&gt;, add the certificate and private key. Ensure the private key follows this format:&lt;br&gt;
&lt;/p&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;"name_of_cert.crt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"-----BEGIN CERTIFICATE-----&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;MIID...base64content...&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;-----END CERTIFICATE-----"&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;p&gt;Each line within the certificate and key content must be separated by &lt;code&gt;\n&lt;/code&gt; for correct formatting.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Name the secret (e.g., &lt;code&gt;my-app-certificates&lt;/code&gt;) and add any required tags.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure access permissions using IAM policies to ensure only authorized services can access these secrets.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  2. Retrieving Certificates in Kubernetes
&lt;/h3&gt;

&lt;p&gt;Once stored, you can configure a Kubernetes Secret to retrieve and store the certificate data from AWS Secrets Manager. The following Helm chart snippet demonstrates how to create a Kubernetes Secret that dynamically pulls and base64-encodes the certificate data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Sample Kubernetes Secret Manifest
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Secret&lt;/span&gt;
&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Opaque&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;certs&lt;/span&gt;
&lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt;.Values.name_of_cert&lt;/span&gt;&lt;span class="pi"&gt;}}&lt;/span&gt;&lt;span class="na"&gt;.crt&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;path:{{.Values.secret_aws_arn_path}}#name_of_cert.crt | base64encode&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;.Values.name_of_cert is a Helm variable for dynamic certificate naming.&lt;/li&gt;
&lt;li&gt;{{.Values.secret_aws_arn_path}} references the AWS Secrets Manager ARN where the certificate is stored.&lt;/li&gt;
&lt;li&gt;base64encode ensures the certificate data meets Kubernetes Secret requirements.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Using AWS Secrets Manager to store certificates provides a secure, manageable, and compliant method for handling sensitive certificate data in Kubernetes. With AWS handling encryption and access management, and Kubernetes natively managing the secret retrieval, this setup optimally balances security and accessibility in cloud-native applications.&lt;/p&gt;

&lt;p&gt;With these steps, your certificates are securely stored in AWS Secrets Manager and can be accessed by Kubernetes workloads without compromising sensitive data. Always review and update IAM policies to enforce the principle of least privilege, and periodically rotate your certificates for optimal security.&lt;/p&gt;

&lt;p&gt;By following this guide, you’ll have a secure solution for managing certificates across Kubernetes and AWS environments.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>kubernetes</category>
      <category>secretmanager</category>
      <category>secret</category>
    </item>
  </channel>
</rss>
