<?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: Rajesh Kumar</title>
    <description>The latest articles on DEV Community by Rajesh Kumar (@rajesh_kumar_36a2b4761e0d).</description>
    <link>https://dev.to/rajesh_kumar_36a2b4761e0d</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%2F2780808%2F0ffb4005-a195-4e58-8406-e019a44d23b2.jpg</url>
      <title>DEV Community: Rajesh Kumar</title>
      <link>https://dev.to/rajesh_kumar_36a2b4761e0d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajesh_kumar_36a2b4761e0d"/>
    <language>en</language>
    <item>
      <title>How to Set Up HashiCorp Vault on Kubernetes</title>
      <dc:creator>Rajesh Kumar</dc:creator>
      <pubDate>Wed, 29 Jan 2025 04:04:20 +0000</pubDate>
      <link>https://dev.to/rajesh_kumar_36a2b4761e0d/how-to-set-up-hashicorp-vault-on-kubernetes-96d</link>
      <guid>https://dev.to/rajesh_kumar_36a2b4761e0d/how-to-set-up-hashicorp-vault-on-kubernetes-96d</guid>
      <description>&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%2F7ewqmv018mn49x1fkojy.png" 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%2F7ewqmv018mn49x1fkojy.png" alt="Image description" width="800" height="793"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vault by HashiCorp is a powerful tool for managing secrets securely. In this tutorial, we’ll walk through setting up Vault on Kubernetes and using it with External Secrets to securely manage secrets in your applications.&lt;/p&gt;

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

&lt;p&gt;Before we begin, ensure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A running Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;kubectl installed and configured.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Helm installed on your system.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Add the HashiCorp Helm Repository&lt;/strong&gt;&lt;br&gt;
HashiCorp provides a Helm chart for installing Vault. First, we need to add their repository to Helm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ helm repo add hashicorp https://helm.releases.hashicorp.com
$ helm repo update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command adds HashiCorp’s Helm repository and updates your local Helm chart index.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Install Vault Using Helm&lt;/strong&gt;&lt;br&gt;
Now, let’s deploy Vault into your Kubernetes cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ helm install vault hashicorp/vault -n vault --create-namespace

# vault: The name of the Helm release.
# hashicorp/vault: Specifies the Vault Helm chart from the HashiCorp repository.
# -n vault: Deploys Vault in the vault namespace.
# --create-namespace: Ensures the vault namespace is created if it doesn’t already exist.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once this command runs successfully, Vault will be deployed, but it won’t be ready to use until initialized and unsealed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Initialize Vault&lt;/strong&gt;&lt;br&gt;
Vault must be initialized before it can store and manage secrets. Use the following command:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;$ kubectl -n vault exec -it vault-0 -- vault operator init&lt;/strong&gt;&lt;br&gt;
This generates the unseal keys and an initial root token. Make sure to copy and securely store these tokens, as they are critical for accessing Vault.&lt;/p&gt;

&lt;p&gt;You’ll see output 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;Unseal Key 1: &amp;lt;key1&amp;gt;
Unseal Key 2: &amp;lt;key2&amp;gt;
Unseal Key 3: &amp;lt;key3&amp;gt;
Initial Root Token: &amp;lt;root-token&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4: Unseal Vault&lt;br&gt;
Vault operates in a “sealed” state by default. To make it operational, you need to “unseal” it using the keys generated earlier. Enter the Vault pod and unseal it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kubectl -n vault exec -it vault-0 -- sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the following commands to unseal Vault:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ vault operator unseal
&amp;lt;insert key1&amp;gt;
$ vault operator unseal
&amp;lt;insert key2&amp;gt;
$ vault operator unseal
&amp;lt;insert key3&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’ll paste each of the unseal keys when prompted. Once all keys are entered, the Vault becomes unsealed and operational.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Log in to Vault&lt;/strong&gt;&lt;br&gt;
Log in using the initial root token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ vault login &amp;lt;INITIAL_ROOT_TOKEN&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace  with the token you saved earlier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Enable a Secret Engine&lt;/strong&gt;&lt;br&gt;
Vault organizes secrets using engines. Here, we’ll enable the KV (Key-Value) engine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ vault secrets enable --version=2 --path=kv kv

# --version=2: Specifies that we’re using version 2 of the KV engine.
# --path=kv: Sets the mount path for the engine.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7: Add Secrets to Vault&lt;/strong&gt;&lt;br&gt;
Let’s add some secrets to Vault. 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;vault kv put -mount=kv dev-blog adminUser=test
vault kv put -mount=kv dev-blog adminPass='password'

Here:

# -mount=kv: Refers to the KV engine we enabled earlier.
# dev-blog: The path under which the secrets are stored.
# adminUser and adminPass: The key-value pairs representing your secrets.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can repeat this process for all the secrets your application needs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8: Install External Secrets&lt;/strong&gt;&lt;br&gt;
External Secrets bridges the gap between Kubernetes and external secret management systems like HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, and others. Its primary purpose is to sync secrets from these external systems into Kubernetes-native secrets so that your applications can access them seamlessly.&lt;/p&gt;

&lt;p&gt;In this setup, we’re using Vault as the secret management solution to securely store sensitive data. However, Kubernetes applications require secrets to be in the form of Kubernetes-native secrets. External Secrets acts as the intermediary that syncs secrets from Vault into Kubernetes.&lt;/p&gt;

&lt;p&gt;Deploying External Secrets at this stage ensures that we have the required infrastructure to make Vault secrets accessible to our Kubernetes workloads. Once External Secrets is installed and configured, it will continuously monitor Vault for updates and keep Kubernetes secrets in sync with the external secret store.&lt;/p&gt;

&lt;p&gt;This ensures that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Secrets are always up-to-date.&lt;/li&gt;
&lt;li&gt;Developers and applications don’t need to directly interact with Vault. &lt;/li&gt;
&lt;li&gt;The system remains secure, as Vault handles the secure storage and lifecycle of secrets, while Kubernetes secrets provide easy access for workloads.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ helm install external-secrets external-secrets/external-secrets -n external-secrets --create-namespace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This installs External Secrets in the external-secrets namespace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9: Create a Vault Token Secret in Kubernetes&lt;/strong&gt;&lt;br&gt;
External Secrets needs a Vault token to authenticate. Create a Kubernetes secret with the token:&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
data:
  token: &amp;lt;your-token-base64&amp;gt;
kind: Secret
metadata:
  name: vault-token
  namespace: external-secrets
type: Opaque
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace  with the Base64-encoded token (use echo -n "token" | base64 to generate it).&lt;/p&gt;

&lt;p&gt;Save this file as &lt;strong&gt;vaultTokenSecret.yaml&lt;/strong&gt; and apply it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kubectl -n external-secrets apply -f vaultTokenSecret.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Step 10: Configure External Secrets to Access Vault
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, create a ClusterSecretStore resource to configure External Secrets to communicate with Vault:&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/v1beta1
kind: ClusterSecretStore
metadata:
  name: vault-backend-access
spec:
  provider:
    vault:
      server: "https://vault.rajesh-kumar.in/"
      path: "kv"
      version: "v2"
      auth:
        tokenSecretRef:
          name: "vault-token"
          key: "token"
          namespace: external-secrets

# server: The Vault server URL.
# path: The KV engine path (kv in our setup).
# auth.tokenSecretRef: Points to the secret containing the Vault token.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save this as &lt;strong&gt;clusterSecretStore.yaml&lt;/strong&gt; and apply it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kubectl -n vault apply -f clusterSecretStore.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 11: Verify and Use Secrets&lt;/strong&gt;&lt;br&gt;
With everything configured, you can create ExternalSecret resources to sync Vault secrets into Kubernetes secrets. 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;apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
  name: dev-blog-secrets
  namespace: dev-blog-ns
spec:
  secretStoreRef:
    name: vault-backend-access
    kind: ClusterSecretStore
  target:
    name: dev-blog-k8s-secret
  data:
  - secretKey: ADMIN_USER
    remoteRef:
      key: kv/dev-blog
      property: adminUser
  - secretKey: ADMIN_PASS
    remoteRef:
      key: kv/dev-blog
      property: adminPass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply this file, and External Secrets will create an externalsecrets resource named dev-blog-secrets and a Kubernetes secret named dev-blog-k8s-secret in the dev-blog-ns namespace with the values pulled from Vault.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kubectl get externalsecret -n medium-blog-ns -o yaml
$ kubectl get secret -n medium-blog-ns -o yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Bonus: Expose Vault with Ingress Using Traefik&lt;/strong&gt;&lt;br&gt;
To make Vault accessible externally, we’ll expose it using an Ingress. This setup ensures that Vault is accessible through a friendly domain name (vault.rajesh-kumar.in) using HTTP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Ensure Traefik is Deployed&lt;/strong&gt;&lt;br&gt;
Traefik is a popular Kubernetes Ingress Controller that provides robust routing capabilities. If you don’t have Traefik installed, follow these steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add the Traefik Helm Repository:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ helm repo add traefik https://traefik.github.io/charts helm repo update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Install Traefik: Deploy Traefik to your cluster:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ helm install traefik traefik/traefik --namespace traefik --create-namespace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Verify Installation: Ensure that Traefik is running:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kubectl get pods -n traefik
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;You should see pods like traefik- running successfully.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Expose Traefik’s Dashboard (Optional): To access Traefik’s dashboard, configure an additional IngressRoute (optional but useful for debugging).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Expose Vault Using Ingress&lt;/strong&gt;&lt;br&gt;
Create a IngressRoute resource to expose Vault using Traefik. Save the following configuration as:vaultIngressRoute.yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: vault-ingressroute
  namespace: vault
spec:
  entryPoints:
    - web
  routes:
  - match: Host(`vault.rajesh-kumar.in`)
    kind: Rule
    services:
    - name: vault
      port: 8200
      scheme: http

Explanation:
entryPoints: web: Indicates that this route uses the HTTP entry point. You can modify this to websecure for HTTPS if TLS is configured.
Host(vault.rajesh-kumar.in): The domain that maps to the Vault service. Ensure this domain points to your Kubernetes cluster via DNS.
services: name: vault: Refers to the Vault service created by the Helm chart.
port: 8200: The default port Vault listens on.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Apply the IngressRoute&lt;/strong&gt;&lt;br&gt;
Apply the IngressRoute configuration to your cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kubectl apply -f vaultIngressRoute.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Update DNS or Hosts File&lt;/strong&gt;&lt;br&gt;
Point your domain (vault.rajesh-kumar.in) to the external IP of the Traefik LoadBalancer. If you’re testing locally, you can edit your /etc/hosts file to map the domain to the NODE IP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;NODE-IP&amp;gt; vault.rajesh-kumar.in
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Access Vault&lt;/strong&gt;&lt;br&gt;
Now you should be able to access Vault in your browser using &lt;a href="http://vault.rajesh-kumar.in" rel="noopener noreferrer"&gt;http://vault.rajesh-kumar.in&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optional: Secure with HTTPS&lt;/strong&gt;&lt;br&gt;
For production environments, it’s highly recommended to secure the Ingress with TLS. To enable HTTPS:&lt;/p&gt;

&lt;p&gt;Configure a certificate (e.g., via Let’s Encrypt or a self-signed certificate).&lt;br&gt;
Update the Traefik entry point to websecure.&lt;br&gt;
Modify the IngressRoute to include a tls section.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spec:
  entryPoints:
    - websecure
  tls:
    secretName: mysecret-cert
  routes:
  - match: Host(`vault.rajesh-kumar.in`)
    kind: Rule
    services:
    - name: vault
      port: 8200
      scheme: http
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures secure communication with Vault over HTTPS.&lt;/p&gt;

&lt;p&gt;By exposing Vault with Ingress, you now have an external, accessible endpoint for managing secrets securely. This configuration is flexible, allowing further customization like TLS and additional routing rules to suit your needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Congratulations! You’ve successfully set up HashiCorp Vault on Kubernetes, stored secrets, and integrated it with External Secrets for secure secret management in Kubernetes.&lt;/p&gt;

&lt;p&gt;This setup provides a robust foundation for securely managing application secrets, ensuring compliance, and enhancing security. Feel free to expand and customize this configuration for your specific use case!&lt;/p&gt;

&lt;p&gt;Happy learning!&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;br&gt;
Feel free to explore &lt;a href="https://blogs.learningdevops.com/" rel="noopener noreferrer"&gt;my articles&lt;/a&gt; for fascinating perspectives and useful suggestions. Let’s connect on &lt;a href="https://www.linkedin.com/in/techwith-rajesh/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;. I’m eager to hear your thoughts and delve deeper into any discussions!&lt;/p&gt;

</description>
      <category>hashicorp</category>
      <category>vault</category>
      <category>kubernetes</category>
      <category>traefik</category>
    </item>
    <item>
      <title>How to setup AWS IAM Roles Anywhere: A Step-by-Step Guide</title>
      <dc:creator>Rajesh Kumar</dc:creator>
      <pubDate>Wed, 29 Jan 2025 03:24:13 +0000</pubDate>
      <link>https://dev.to/rajesh_kumar_36a2b4761e0d/how-to-setup-aws-iam-roles-anywhere-a-step-by-step-guide-596e</link>
      <guid>https://dev.to/rajesh_kumar_36a2b4761e0d/how-to-setup-aws-iam-roles-anywhere-a-step-by-step-guide-596e</guid>
      <description>&lt;p&gt;Are you managing cloud infrastructure but need a secure way to access AWS resources from outside the AWS environment? AWS IAM Roles Anywhere has you covered! This feature enables you to assume IAM roles using X.509 certificates, eliminating the need for long-term AWS credentials. Let’s dive into how you can set this up, step by step.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is AWS IAM Roles Anywhere?
&lt;/h2&gt;

&lt;p&gt;Imagine you’re working with on-premises servers, CI/CD pipelines, or even IoT devices, and you need these to interact securely with AWS services. IAM Roles Anywhere allows these external systems to assume IAM roles without storing static access keys. It’s like giving your non-AWS workloads temporary AWS credentials but with extra layers of security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Create Your Own Certificate Authority (CA)?
&lt;/h2&gt;

&lt;p&gt;AWS provides services like Private Certificate Manager (ACM Private CA) to manage certificates, but these services can be expensive for smaller setups or learning environments. Creating your own CA gives you control over the certificate lifecycle without incurring additional AWS costs.&lt;/p&gt;

&lt;p&gt;A Certificate Authority (CA) is the foundation of trust in a secure system. It issues certificates that prove the identity of your workloads. By creating your own Root CA, you establish a trusted entity that AWS can verify.&lt;/p&gt;

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

&lt;p&gt;Before we start, ensure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;AWS CLI installed and configured.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;OpenSSL installed on your local machine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Proper IAM permissions to create roles and trust anchors in AWS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IAM role with the following permissions to manage Route 53:&lt;br&gt;
IAM Policy for Route 53&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "route53:GetChange",
            "Resource": "arn:aws:route53:::change/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "route53:ChangeResourceRecordSets",
                "route53:ListResourceRecordSets",
                "route53:ListHostedZones"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "route53:ListHostedZonesByName",
            "Resource": "*"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Trust Relationship for IAM Role&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "rolesanywhere.amazonaws.com"
            },
            "Action": [
                "sts:AssumeRole",
                "sts:SetSourceIdentity",
                "sts:TagSession"
            ]
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This IAM role is essential for enabling DNS management through Route 53 when creating a profile in AWS IAM Roles Anywhere.&lt;/p&gt;

&lt;p&gt;Let’s Build It Step-by-Step:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a Root Certificate Authority (CA)&lt;/strong&gt;&lt;br&gt;
The Root CA will be the anchor of trust for your setup. Here’s how to create it:&lt;/p&gt;

&lt;p&gt;Generate the private key for your CA:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ openssl genrsa -out privateRootCA.key 2048

# Explanation:

# genrsa: Generates an RSA private key.
# -out privateRootCA.key: Saves the private key to a file named privateRootCA.key.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a self-signed certificate for your Root CA:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ openssl req -x509 -new -nodes -key privateRootCA.key -sha256 -days 365 -out privateRootCA.pem \
-subj "/C=IN/O=Learning DevOps" \
-addext "basicConstraints=critical,CA:TRUE" \
-addext "keyUsage=critical,keyCertSign,cRLSign"

# Explanation:

# req: Generates a certificate signing request or self-signed certificate.
# -x509: Creates a self-signed certificate instead of a CSR.
# -key privateRootCA.key: Uses the private key you just generated.
# -days 365: Makes the certificate valid for 365 days.
# -subj: Provides the certificate's subject details (country, organization, etc.).
# -addext: Adds certificate extensions, marking it as a CA capable of signing certificates.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This step creates two files:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;privateRootCA.key&lt;/strong&gt;: The private key for your Root CA (keep this secure).&lt;br&gt;
&lt;strong&gt;privateRootCA.pem&lt;/strong&gt;: The self-signed certificate that AWS will trust.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Create a Trust Anchor in AWS&lt;/strong&gt;&lt;br&gt;
The trust anchor connects your Root CA with AWS IAM Roles Anywhere.&lt;/p&gt;

&lt;p&gt;Upload the Root CA certificate to AWS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws rolesanywhere create-trust-anchor \
--name "MyTrustAnchor" \
--source "sourceType=CERTIFICATE_BUNDLE,sourceData={x509CertificateData=\"$(cat privateRootCA.pem)\"}"

# Explanation:

# create-trust-anchor: Creates a trust anchor in AWS.
# --source: Specifies the source type and data (your Root CA certificate).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this command to verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws rolesanywhere list-trust-anchors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see your newly created trust anchor listed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Create a Client Certificate&lt;/strong&gt;&lt;br&gt;
Your external systems will use this certificate to authenticate.&lt;/p&gt;

&lt;p&gt;Generate the private key for the client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ openssl genrsa -out client.key 2048
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generate the certificate signing request (CSR):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ openssl req -new -key client.key -out client.csr -config &amp;lt;(\
  cat &amp;lt;&amp;lt;-EOF
  [req]
  default_bits = 2048
  prompt = no
  default_md = sha256
  distinguished_name = dn
  [dn]
  C = IN
  O = Learning DevOps
  CN = ClientCert
  [v3_ext]
  basicConstraints = CA:FALSE
  keyUsage = digitalSignature
  extendedKeyUsage = clientAuth
  EOF
)

# Explanation:

# -new: Creates a new CSR.
# -key client.key: Uses the client's private key.
# -config: Provides the certificate configuration inline.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sign the client certificate with the Root CA:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ openssl x509 -req -in client.csr -CA privateRootCA.pem -CAkey privateRootCA.key -CAcreateserial \
-out client.crt -days 365 -sha256 -extfile &amp;lt;(echo -e "basicConstraints = CA:FALSE\nkeyUsage = digitalSignature\nextendedKeyUsage = clientAuth")

# Explanation:

# x509: Creates an X.509 certificate.
# -CA privateRootCA.pem: Specifies the Root CA certificate.
# -CAkey privateRootCA.key: Specifies the Root CA private key.
# -CAcreateserial: Automatically generates a serial number for the client certificate.
# -out client.crt: Specifies the output client certificate file.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Create a Profile in AWS&lt;/strong&gt;&lt;br&gt;
Profiles define which IAM roles external systems can assume.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws rolesanywhere create-profile \
--name "TestProfile" \
--role-arns "arn:aws:iam::&amp;lt;AWS_ACCOUNT_ID&amp;gt;:role/&amp;lt;RoleName&amp;gt;" \
--trust-anchor-arn "arn:aws:rolesanywhere::&amp;lt;AWS_REGION&amp;gt;::trust-anchor/&amp;lt;TrustAnchorID&amp;gt;" \
--enabled

# Explanation:

# create-profile: Creates a profile in AWS.
# --role-arns: Arn of the role we created in the prerequisites section.
# --trust-anchor-arn: Links the profile to your trust anchor.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify your profiles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws rolesanywhere list-profiles
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Install AWS Signing Helper&lt;/strong&gt;&lt;br&gt;
The AWS Signing Helper simplifies signing API requests using your certificates.&lt;/p&gt;

&lt;p&gt;Download and install it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -O https://rolesanywhere.amazonaws.com/releases/1.4.0/X86_64/Linux/aws_signing_helper
$ chmod +x aws_signing_helper
$ sudo mv aws_signing_helper /usr/local/bin/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6: Assume a Role Using the Client Certificate&lt;/strong&gt;&lt;br&gt;
Run the signing helper to fetch temporary credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws_signing_helper credential-process \
--trust-anchor-arn arn:aws:roles anywhere:ap-south-1:&amp;lt;Account_ID&amp;gt;:trust-anchor/&amp;lt;TrustAnchorID&amp;gt; \
--role-arn arn:aws:iam::&amp;lt;Account_ID&amp;gt;:role/&amp;lt;RoleName&amp;gt; \
--profile-arn arn:aws:rolesanywhere:ap-south-1:&amp;lt;Account_ID&amp;gt;:profile/&amp;lt;ProfileID&amp;gt; \
--certificate client.crt \
--private-key client.key

# Explanation:

# credential-process: Fetches temporary credentials for AWS.
# --certificate: Specifies the client certificate.
# --private-key: Specifies the client’s private key.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Export the credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ export AWS_ACCESS_KEY_ID=&amp;lt;AccessKeyIdFromOutput&amp;gt;
$ export AWS_SECRET_ACCESS_KEY=&amp;lt;SecretAccessKeyFromOutput&amp;gt;
$ export AWS_SESSION_TOKEN=&amp;lt;SessionTokenFromOutput&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify access:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ aws route53 list-hosted-zones
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations! You’ve securely accessed AWS resources from outside the AWS environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;AWS IAM Roles Anywhere is a powerful tool for hybrid and on-premises setups. Securely linking your external workloads to AWS can eliminate static credentials and improve security.&lt;/p&gt;

&lt;p&gt;Happy learning!&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;br&gt;
Feel free to explore &lt;a href="https://blogs.learningdevops.com/" rel="noopener noreferrer"&gt;my articles&lt;/a&gt; for fascinating perspectives and useful suggestions. Let’s connect on &lt;a href="https://www.linkedin.com/in/techwith-rajesh/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;. I’m eager to hear your thoughts and delve deeper into any discussions!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>role</category>
      <category>iam</category>
      <category>roleanywhere</category>
    </item>
  </channel>
</rss>
