<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stéphane Este-Gracias on Medium]]></title>
        <description><![CDATA[Stories by Stéphane Este-Gracias on Medium]]></description>
        <link>https://medium.com/@sestegra?source=rss-a605ad9e51a6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WDuwH4pjE6IbZFAXrJtZxg.png</url>
            <title>Stories by Stéphane Este-Gracias on Medium</title>
            <link>https://medium.com/@sestegra?source=rss-a605ad9e51a6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:34:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sestegra/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using OCI Image Volume source in Kubernetes Pods]]></title>
            <link>https://sestegra.medium.com/using-oci-image-volume-source-in-kubernetes-pods-684069792b32?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/684069792b32</guid>
            <category><![CDATA[storage]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Sat, 17 May 2025 12:36:15 GMT</pubDate>
            <atom:updated>2025-05-21T11:00:18.251Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubernetes v1.33 promotes the <strong>OCI Image Volume Source</strong> feature to <strong>Beta</strong>, marking a major milestone in how you can mount container images directly as read-only volumes in your Pods. Previously introduced in alpha in v1.31, this capability now offers an approach to distributing static assets — such as AI/ML models or configuration patterns — across your clusters without building a custom delivery service.</p><p>By leveraging <a href="https://opencontainers.org/">OCI standards</a> for image format and distribution via any compliant registry, you can streamline the delivery of static data in your applications with minimal operational overhead.</p><p>In this hands-on guide, I’ll walk through how to enable and use the OCI Image Volume Source in its Beta form. Before diving into the hands-on section, let’s first explore how this feature originated and how it has been implemented.</p><h3>KEP — Kubernetes Enhancement Proposal</h3><p>The <strong>OCI Image Volume </strong>feature was proposed, discussed, and selected for implementation using a <strong>KEP</strong> (<strong>Kubernetes Enhancement Proposal</strong>), namely <a href="https://github.com/kubernetes/enhancements/issues/4639"><strong>KEP-4639</strong></a><strong> </strong>supported by the <a href="https://github.com/kubernetes/community/blob/master/sig-node/README.md">SIG Node</a> and the <a href="https://github.com/kubernetes/community/blob/master/sig-storage/README.md">SIG Storage</a>.</p><p>In Kubernetes, features follow a well-defined lifecycle — see <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/#feature-stages">Kubernetes — Features stages</a>. The feature often starts from an idea from a developer, initially taking shape through online discussions. This raw idea typically matures into a formal <strong>Kubernetes Enhancement Proposal (KEP)</strong>, which establishes the foundation for the feature’s development.</p><p>The KEP number corresponds to an issue number on a Kubernetes Git repository, namely<a href="https://github.com/kubernetes/enhancements">kubernetes/enhancements</a>, to track the lifecycle of this proposal, and the associated motivation is documented in the folder corresponding to the related responsible SIG on the same Git repository.</p><p>In a KEP, you have to define a summary that gives a brief overview of the enhancement, explaining its purpose. Then, the motivation section outlines why the feature is needed and its impact on Kubernetes. Goals define the intended outcomes, while non-goals clarify what the proposal won’t cover. Then, the proposal section provides a detailed technical description. It includes any API changes, design specifics, and user stories to illustrate use cases. Finally, it discusses potential risks and how they might be mitigated.</p><p>For instance, in this <a href="https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/4639-oci-volume-source">KEP document</a>, you can find the planned roadmap for this feature, namely, it has been released in alpha for Kubernetes 1.31 and in beta in version 1.33.</p><h3>OCI Image Volume Implementation</h3><p>The OCI Image Volume feature defines a new interface for the <a href="https://kubernetes.io/docs/concepts/architecture/cri/"><strong>Container Runtime Interface</strong></a><strong> (CRI)</strong> that container runtimes such as <a href="https://containerd.io/"><strong>containerd</strong></a> or <a href="https://cri-o.io/"><strong>CRI-O</strong></a> must implement.</p><p>The implementation on the Kubernetes side has been done and can be enabled using a feature flag, because it still in alpha mode, so it’s not enabled by default. To enable it, an option must be passed to the <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/">featureGates</a> parameter for the API server and for the Kubelet on each node.</p><p>After a POD is scheduled on a specific node, when starting a POD with an OCI Image Volume specified, the Kubelet informs the container runtime through the CRI API to pull the image from the registry and mount it to the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/0*YAD9POXB-xd24AYx.png" /><figcaption>Kubernetes Container Runtime Interface (CRI) and container image ecosystem</figcaption></figure><p>The container runtimes already implement the image pulling and its local storage on the node (used by the container image), so this functionality is already present on <strong>containerd</strong> and <strong>CRI-O</strong>. On the other hand, the new aspect of mounting the volume into a container needs to be implemented in the container runtime.</p><p>To implement this new feature, the container runtime projects (CRI-O and containerd) use both a respective PR in their respective Git repository to follow the implementation of this feature.</p><p>Each container runtime now includes OCI Image Volume feature support.</p><ul><li>CRI-O — Add OCI/Image Volume Source support<br>PR <a href="https://github.com/cri-o/cri-o/pull/8317">https://github.com/cri-o/cri-o/pull/8317</a><br>Feature available since <a href="https://github.com/cri-o/cri-o/releases/tag/v1.31.0">1.31.0 release</a></li><li>Containerd — Add OCI Volume Source support<br>PR <a href="https://github.com/containerd/containerd/issues/10496">https://github.com/containerd/containerd/issues/10496</a><br>Feature available since <a href="https://github.com/containerd/containerd/releases/tag/v2.1.0">2.1.0 release</a></li></ul><h3>Installation</h3><p>I’m used to using <a href="https://kind.sigs.k8s.io/"><strong>kind</strong></a> in my experiments, so I’ll use <strong>kind</strong> for this experiment</p><p>For information, <strong>kind</strong> is using <a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/"><strong>kubeadm</strong></a> to deploy Kubernetes components into Docker containers using <strong>containerd</strong> as container runtime. So, I can use <a href="https://github.com/kubernetes-sigs/kind/releases/tag/v0.29.0">kind v0.29.0 release</a> that bundles <strong>containerd 2.1.1</strong> and provides <strong>Kubernetes 1.33.1</strong> node image.</p><p>Here are the steps to follow:</p><ul><li>Install Kind</li></ul><pre>$ curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-amd64<br>$ chmod +x ./kind<br>$ sudo mv ./kind /usr/local/bin<br>$ kind version<br>kind v0.29.0 go1.24.2 linux/amd64</pre><ul><li>Create YAML file cluster.yaml to use Kubernetes 1.31 and enable the ImageVolume feature.</li></ul><pre>kind: Cluster<br>apiVersion: kind.x-k8s.io/v1alpha4<br>featureGates:<br>  ImageVolume: true<br>nodes:<br>  - role: control-plane<br>    image: kindest/node:v1.33.1@sha256:8d866994839cd096b3590681c55a6fa4a071fdaf33be7b9660e5697d2ed13002</pre><ul><li>Create the cluster</li></ul><pre>$ kind create cluster --config cluster.yaml</pre><ul><li>Verify the nodes and the containerd version</li></ul><pre>$ kubectl get nodes -o wide<br>NAME                 STATUS   ROLES           AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION       CONTAINER-RUNTIME<br>kind-control-plane   Ready    control-plane   13m   v1.33.1   172.25.0.2    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   5.15.0-140-generic   containerd://2.1.0</pre><ul><li>Verify the feature flag is set on Kube API server</li></ul><pre>$ kubectl -n kube-system describe pod kube-apiserver-kind-control-plane<br>...<br>   Command:<br>      kube-apiserver<br>      ...<br>      --feature-gates=ImageVolume=true<br>      ...<br>...</pre><ul><li>Verify the features flag is set on Kubelet</li></ul><pre>$ docker exec kind-control-plane cat /var/lib/kubelet/config.yaml<br>...<br>featureGates:<br>  ImageVolume: true<br>...</pre><p>So, the test cluster should be ready to test the OCI Image Volume feature.</p><h3>Create an image artifact</h3><p>As this writing, only OCI images are supported by <strong>containerd 2.1.0</strong>. So, the OCI artifacts aren’t supported.</p><ul><li>Create an OCI image containing an artifact using the following Dockerfile and push it to an OCI registry</li></ul><pre>FROM scratch<br>COPY artifact.txt /</pre><pre>$ echo &quot;Hello ImageVolume&quot; &gt; artifact.txt<br>$ IMAGE_NAME=$(uuidgen)<br>$ docker build -t ttl.sh/${IMAGE_NAME}:1h .<br>$ docker push ttl.sh/${IMAGE_NAME}:1h</pre><h3>Usage</h3><ul><li>Define a Pod that mounts an OCI image as a volume — see the <a href="https://kubernetes.io/docs/concepts/storage/volumes/#image">OCI Image Volume source documentation</a> for detailed instructions.</li></ul><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: pod-oci-volume-source<br>spec:<br>  containers:<br>    - name: test<br>      image: nginx<br>      volumeMounts:<br>        - name: volume<br>          mountPath: /volume<br>  volumes:<br>    - name: volume<br>      image:<br>        reference: ttl.sh/${IMAGE_NAME}:1h<br>        pullPolicy: Always</pre><ul><li>Check container image (nginx) and image artifact (ttl.sh/${IMAGE_NAME}:1h) have been pulled locally on the Kubernetes node by the container runtime using <strong>crictl</strong> command.</li></ul><pre>$ docker exec kind-control-plane crictl image<br>IMAGE                                           TAG                  IMAGE ID            SIZE<br>...<br>ttl.sh/853ab7a2-30f8-4cba-ada0-84ea2f399207     1h                   b113365d4c064       1.07kB<br>...</pre><ul><li>Check if the POD is running and explore /volume mount</li></ul><pre>$ kubectl get pods<br>NAME                    READY   STATUS             RESTARTS   AGE<br>pod-oci-volume-source   1/1     Running            0          2m22s<br><br>$ kubectl exec pod-oci-volume-source -- cat /volume/artifact.txt<br>Hello ImageVolume</pre><p>Great! OCI Image Volume feature functions exactly as intended!</p><h3>Conclusion</h3><p>The OCI Image Volume feature allows to mount container images directly as read-only volumes in Kubernetes Pods, simplifying how applications can access static data resources such AI/ML models or data patterns to share across you Kubernetes clusters.</p><p>To access this functionality on Kubernetes 1.33, it is necessary to <strong>enable the ImageVolume feature gate</strong>, as well as use a container runtime that <strong>implements the new CRI API required </strong>for this functionality to work.</p><p>This functionality is promising and will certainly simplify the needs for sharing static data such as AI/ML models or any other data patterns that need to be distributed across your different clusters.</p><h3>References</h3><ul><li>Kubernetes — Volumes Image<br><a href="https://kubernetes.io/docs/concepts/storage/volumes/#image">https://kubernetes.io/docs/concepts/storage/volumes/#image</a></li><li>OCI — Open Container Initiative<br><a href="https://opencontainers.org/">https://opencontainers.org/</a></li><li>Kubernetes — Features stages <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/#feature-stages">https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/#feature-stages</a></li><li>Kubernetes — List of Kubernetes enhancements (KEPs) <a href="https://www.kubernetes.dev/resources/keps/">https://www.kubernetes.dev/resources/keps/</a></li><li>KEP-4639 Issue — VolumeSource: OCI Artifact and/or Image <a href="https://github.com/kubernetes/enhancements/issues/4639">https://github.com/kubernetes/enhancements/issues/4639</a></li><li>KEP-4639 Document — OCI Image Volume<br><a href="https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/4639-oci-volume-source">https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/4639-oci-volume-source</a></li><li>Kubernetes — Features Gates <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/">https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/</a></li><li>Kubernetes — Container Runtime Interface (CRI) <a href="https://kubernetes.io/docs/concepts/architecture/cri/">https://kubernetes.io/docs/concepts/architecture/cri/</a></li><li>Containerd — Project Page<br><a href="https://containerd.io/">https://containerd.io/</a></li><li>CRI-O — Project Page<br><a href="https://cri-o.io/">https://cri-o.io/</a></li><li>Kind — Kubernetes IN Docker — local clusters for testing Kubernetes <a href="https://kind.sigs.k8s.io/">https://kind.sigs.k8s.io/</a></li><li>Kubeadm<br><a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/">https://kubernetes.io/docs/reference/setup-tools/kubeadm/</a></li><li>CRI-O — Add OCI/Image Volume Source support<br><a href="https://github.com/cri-o/cri-o/pull/8317">https://github.com/cri-o/cri-o/pull/8317</a></li><li>Containerd — Add OCI Volume Source support <a href="https://github.com/containerd/containerd/issues/10496">https://github.com/containerd/containerd/issues/10496</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=684069792b32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Podman: An Alternative to Docker]]></title>
            <link>https://sestegra.medium.com/podman-an-alternative-to-docker-388260d9176a?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/388260d9176a</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[podman]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Mon, 14 Apr 2025 09:54:14 GMT</pubDate>
            <atom:updated>2025-04-15T21:23:25.051Z</atom:updated>
            <content:encoded><![CDATA[<p>New CNCF sandbox project — Lightweight, secure, and versatile container engine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*ZAxXUsFewae_-MfJK0GD8w.png" /><figcaption>Podman logo</figcaption></figure><p>Podman is a lightweight, daemonless container engine that provides a secure and user-friendly alternative to Docker. It’s available on Linux, macOS, and Windows, making it easy to start containerizing your applications regardless of your operating system.</p><h3>Container Ecosystem</h3><p>Podman is a key player in a vibrant container ecosystem, that relies on OCI (Open Container Initiative) specifications and <strong>runc</strong> to interact with the Linux kernel.</p><p>The following diagram shows how various container tools (like Podman, Docker, CRI-O, containerd…) interact with the Linux kernel via the OCI specifications and <strong>runc</strong> (the low-level container runtime).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*FFFkcyAwX459wjYUbJC2QA.png" /><figcaption>Container Tools</figcaption></figure><p><strong>Container Tools and Kubernetes</strong></p><ul><li><strong>Kubernetes</strong> uses the Container Runtime Interface (CRI) to talk to compatible runtimes such as <strong>CRI-O</strong> or containerd (via cri-containerd).</li><li><strong>Docker</strong>, <strong>nerdctl</strong>, <strong>Podman</strong>, and other CLI tools also manage containers, but they can integrate with or bypass additional daemons in different ways.</li></ul><p><strong>Container Engine</strong></p><ul><li><strong>containerd</strong> is a daemon that handles container lifecycle management.</li><li><strong>CRI-O</strong> is another daemon that implements the CRI for Kubernetes.</li><li><strong>Docker Engine</strong> relies on containerd under the hood.</li></ul><p><strong>OCI Specifications</strong></p><ul><li>All these higher-level tools adhere to <strong>OCI specs</strong>, which define how container images and runtimes should behave.</li><li><strong>runc</strong> is the reference implementation of the OCI runtime specification. It’s the actual tool that sets up namespaces, cgroups, and other kernel-level features to run containers.</li></ul><p><strong>Linux Kernel and Containers</strong></p><ul><li>At the very bottom, you have the <strong>Linux kernel</strong>, which provides the core functionalities (namespaces, cgroups) that make containers possible.</li><li>Each running container is essentially a set of processes isolated by kernel features.</li></ul><h3>CNCF &amp; LF projects</h3><p>The container ecosystem is built on a strong foundation of CNCF and Linux Foundation projects, each playing a pivotal role in ensuring interoperability and standardization across container execution, management, and distribution.</p><ul><li><strong>Kubernetes, CRI-O, containerd</strong> are graduated CNCF projects</li><li><strong>kubectl</strong> is part of Kubernetes</li><li><strong>crictl</strong> is part of Kubernetes CRI Tools</li><li><strong>podman</strong> is now a CNCF sandbox project</li><li><strong>nerdctl</strong> lives in containerd’s GitHub organization, so it’s effectively within the CNCF scope.</li><li><strong>OCI Specifications</strong> (distribution, image and runtime) is LF project that provide standardized guidelines that ensure all container tools — whether CNCF projects or otherwise — can operate with a common set of rules for container execution, image format and distribution, leading to a more interoperable and robust container ecosystem.</li><li><strong>runc</strong> is an OCI project under the Linux Foundation, providing the common runtime layer that all these higher-level container tools rely on.</li></ul><p>This division of responsibilities — standards from the OCI, and higher-level projects from the CNCF — ensures a healthy, interoperable ecosystem for containers and Cloud-Native computing.</p><h3>Podman Architecture</h3><p>Podman integrates with <strong>systemd </strong>and <strong>Kubernetes </strong>not only for individual containers but also for pods — groups of containers that share network and storage resources.</p><ul><li><strong>Integration with systemd<br></strong>Podman can generate systemd unit files for both containers and pods. This allows you to manage containerized applications or entire pods as native systemd services, ensuring they start automatically at boot, benefit from process supervision, and integrate with other system services.</li><li><strong>Integration with Kubernetes<br></strong>Podman supports generating Kubernetes YAML manifests for both individual containers and pods. This feature converts your local Podman configurations into Kubernetes resource definitions, easing the transition from local development to production orchestration on a Kubernetes cluster.</li></ul><p>Together, these integrations make Podman a versatile tool for both development and production, enabling seamless management of individual containers and multi-container pods within systemd-based systems and Kubernetes clusters.</p><h3>Quick Start</h3><p>Here’s a concise guide to help you begin using Podman:</p><p><strong>Installation</strong></p><ul><li><strong>Linux users</strong> can install Podman directly via their package manager or use Podman Desktop for a graphical interface and easier container management.</li><li><strong>macOS and Windows users</strong> benefit from Podman Desktop, which abstracts the virtualization layer and provides an intuitive GUI for managing containers.</li></ul><p><strong>Podman Desktop</strong> is particularly appealing for beginners because it bundles all necessary components, automates setup, and provides a consistent, cross-platform experience that makes container management accessible without a steep learning curve.</p><p><strong>Running Containers</strong></p><p>After installation, verify your setup by running:</p><pre>podman run &lt;image-name&gt;</pre><p>This command pulls the image and runs it.</p><p><strong>Managing Containers and Pods</strong></p><ul><li><strong>Containers &amp; Pods:</strong> Podman lets you create both individual containers and pods (groups of containers that share resources).</li><li><strong>Systemd Integration:</strong> Configure quadlet files to generate systemd units to run your containers or pods as native system services.</li><li><strong>Kubernetes Integration:</strong> Easily transition to orchestration by using podman generate kube to produce Kubernetes YAML manifests from your local configurations.</li></ul><p>For more detailed instructions, check out the full documentation at <a href="https://podman.io/docs">podman.io/docs</a></p><h3>Podman’s Companions: Exploring the containers Ecosystem</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*_lXRrT6JtxtWYU8wnvq2bg.png" /><figcaption>Podman Container Tools</figcaption></figure><p>Podman is not alone — he has some “companions” in the container ecosystem, each focusing on a different aspect of container creation, management, and runtime. From build tools to alternative runtimes, here are the key projects illustrated above:</p><ul><li><strong>Podman Desktop:</strong> A cross-platform GUI solution that bundles everything you need to run Podman on macOS, Windows or Linux, while also offering a user-friendly interface for managing containers and pods.</li><li><strong>Buildah:</strong> A command-line tool dedicated to building container images without needing a daemon. It lets you create images from scratch or Dockerfiles and is well-suited for scripting and automation.</li><li><strong>Skopeo:</strong> A utility for transferring, inspecting, and managing container images across different registries. You can copy images between registries, verify signatures, and more — all from the command line.</li><li><strong>bootc:</strong> A project for managing and booting container-based systems (e.g., container-first operating system images), streamlining how systems are provisioned and updated.</li><li><strong>crun:</strong> A fast and lightweight container runtime written in C. It’s OCI-compliant, making it a drop-in replacement for runc in many scenarios.</li><li><strong>youki:</strong> A container runtime implemented in Rust, emphasizing performance and safety while remaining fully OCI-compliant.</li><li><strong>ramalama:</strong> It automates AI model management using OCI containers. It detects GPU support, pulls images via Podman/Docker, and launches AI models from registries in one command.</li></ul><p>Each of these tools contributes unique functionality and perspectives to the container ecosystem, giving developers.</p><h3>References</h3><ul><li>Podman — Web page<br><a href="https://podman.io/">https://podman.io/</a></li><li>Podman — Official Documentation<br><a href="https://podman.io/docs">https://podman.io/docs</a></li><li>Containerd — Web page<br><a href="https://containerd.io/">https://containerd.io/</a></li><li>Open Container Initiative — Web page<br><a href="https://opencontainers.org/">https://opencontainers.org/</a></li><li>Open Container Initiative — runc — GIthub project page<br><a href="https://github.com/opencontainers/runc">https://github.com/opencontainers/runc</a></li><li>Kubernetes — CRI Tools<br><a href="https://github.com/kubernetes-sigs/cri-tools">https://github.com/kubernetes-sigs/cri-tools</a></li><li>Cri-o — Web page<br><a href="https://cri-o.io/">https://cri-o.io/</a></li><li>Nerdctl — Github project page<br><a href="https://github.com/containerd/nerdctl">https://github.com/containerd/nerdctl</a></li><li>Containers — Github Organization<br><a href="https://github.com/containers">https://github.com/containers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=388260d9176a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using OCI Volume Source in Kubernetes Pods: Kubernetes 1.31 Alpha]]></title>
            <link>https://sestegra.medium.com/using-oci-volume-source-in-kubernetes-pods-06d62fb72086?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/06d62fb72086</guid>
            <category><![CDATA[storage]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Wed, 21 Aug 2024 14:41:54 GMT</pubDate>
            <atom:updated>2025-05-17T12:47:36.062Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>📌 Update (May 17, 2025)<br></strong>Kubernetes v1.33 has promoted the OCI Volume Source feature to <strong>Beta<br></strong>An updated walkthrough for OCI Volume Source in Kubernetes v1.33 Beta is now available.</blockquote><blockquote>Read it here<br><a href="https://medium.com/@sestegra/using-oci-volume-source-in-kubernetes-pods-kubernetes-1-33-beta-684069792b32">Using OCI Image Volume source in Kubernetes Pods</a></blockquote><p>Kubernetes 1.31 introduces an exciting new feature: the <strong>OCI Volume Source</strong>, currently in alpha. This feature allows mounting container images directly as read-only volumes in Kubernetes Pods, simplifying how applications can access static data resources such ML models or data patterns to share across your Kubernetes clusters.</p><p>This feature allows for easy static data distribution without having to develop a specific delivery service. <a href="https://opencontainers.org/">OCI standards</a> already specify everything for the image format and the use of an OCI registry for its distribution.</p><p>In this hands-on guide, we’ll explore how to set up and work with OCI Volume Source. Before diving into the hands-on section, let’s first explore how this feature originated and how it has been implemented.</p><h3>KEP — Kubernetes Enhancement Proposal</h3><p>The <strong>OCI Volume Source</strong> feature was proposed, discussed, and selected for implementation using a <strong>KEP</strong> (<strong>Kubernetes Enhancement Proposal</strong>), namely <a href="https://github.com/kubernetes/enhancements/issues/4639"><strong>KEP-4639</strong></a><strong> </strong>supported by the <a href="https://github.com/kubernetes/community/blob/master/sig-node/README.md">SIG Node</a> and the <a href="https://github.com/kubernetes/community/blob/master/sig-storage/README.md">SIG Storage</a>.</p><p>In Kubernetes, features follow a well-defined lifecycle — see <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/#feature-stages">Kubernetes — Features stages</a>. The feature often starts from an idea from a developer, initially taking shape through online discussions. This raw idea typically matures into a formal <strong>Kubernetes Enhancement Proposal (KEP)</strong>, which establishes the foundation for the feature’s development.</p><p>The KEP number corresponds to an issue number on a Kubernetes Git repository, namely<a href="https://github.com/kubernetes/enhancements">kubernetes/enhancements</a>, to track the lifecycle of this proposal, and the associated motivation is documented in the folder corresponding to the related responsible SIG on the same Git repository.</p><p>In a KEP, you have to define a summary that gives a brief overview of the enhancement, explaining its purpose. Then, the motivation section outlines why the feature is needed and its impact on Kubernetes. Goals define the intended outcomes, while non-goals clarify what the proposal won’t cover. Then, the proposal section provides a detailed technical description. It includes any API changes, design specifics, and user stories to illustrate use cases. Finally, it discusses potential risks and how they might be mitigated.</p><p>For instance, in this <a href="https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/4639-oci-volume-source">KEP document</a>, you can find the planned roadmap for this feature, namely, it has just been released in alpha for Kubernetes 1.31, is scheduled for beta in version 1.32, and for stable in version 1.33.</p><h3>OCI Volume Source Implementation</h3><p>The OCI Volume Source feature defines a new interface for the <a href="https://kubernetes.io/docs/concepts/architecture/cri/"><strong>Container Runtime Interface</strong></a><strong> (CRI)</strong> that container runtimes such as <a href="https://containerd.io/"><strong>containerd</strong></a> or <a href="https://cri-o.io/"><strong>CRI-O</strong></a> must implement.</p><p>The implementation on the Kubernetes side has been done and can be enabled using a feature flag, because it still in alpha mode, so it’s not enabled by default. To enable it, an option must be passed to the <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/">featureGates</a> parameter for the API server and for the Kubelet on each node.</p><p>After a POD is scheduled on a specific node, when starting a POD with an OCI Image Volume specified, the Kubelet informs the container runtime through the CRI API to pull the image from the registry and mount it to the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*7p9TqILb9gwJIPe6Nc-Q_w.png" /><figcaption>Kubernetes Container Runtime Interface (CRI) and container image ecosystem</figcaption></figure><p>The container runtimes already implement the image pulling and its local storage on the node (used by the container image), so this functionality is already present on <strong>containerd</strong> and <strong>CRI-O</strong>. On the other hand, the new aspect of mounting the volume into a container needs to be implemented in the container runtime.</p><h3>Installation</h3><p>I’m used to using <a href="https://kind.sigs.k8s.io/"><strong>kind</strong></a> in my experiments, so I’ll use <strong>kind</strong> for this experiment and I’ll use the <a href="https://oras.land/"><strong>ORAS</strong></a> tool to create an artifact image that should be mounted in the container.</p><p>For information, <strong>kind</strong> is using <strong>kubeadm</strong> to deploy Kubernetes components into Docker containers using <strong>containerd</strong> as container runtime.</p><p>Here are the steps to follow:</p><ul><li>Install Kind</li></ul><pre>$ curl -Lo ./kind &lt;https://kind.sigs.k8s.io/dl/v0.24.0/kind-linux-amd64&gt;<br>$ chmod +x ./kind<br>$ sudo mv ./kind /usr/local/bin<br>$ kind version<br>kind v0.24.0 go1.22.5 linux/amd64</pre><ul><li>Create YAML file cluster.yaml to use Kubernetes 1.31 and enable the ImageVolume feature.</li></ul><pre>kind: Cluster<br>apiVersion: kind.x-k8s.io/v1alpha4<br>featureGates:<br>  ImageVolume: true<br>nodes:<br>  - role: control-plane<br>    image: kindest/node:v1.31.0@sha256:53df588e04085fd41ae12de0c3fe4c72f7013bba32a20e7325357a1ac94ba865</pre><ul><li>Create the cluster</li></ul><pre>$ kind create cluster --config cluster.yaml</pre><ul><li>Verify the nodes and the containerd version, kind 0.24 is using containerd 1.7.18</li></ul><pre>NAME                 STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION       CONTAINER-RUNTIME<br>kind-control-plane   Ready    control-plane   7m18s   v1.31.0   172.25.0.8    &lt;none&gt;        Debian GNU/Linux 12 (bookworm)   5.15.0-117-generic   containerd://1.7.18</pre><ul><li>Verify the feature flag is set on Kube API server</li></ul><pre>$ kubectl -n kube-system describe pod kube-apiserver-kind-control-plane<br>...<br>   Command:<br>      kube-apiserver<br>      ...<br>      --feature-gates=ImageVolume=true<br>      ...<br>...</pre><ul><li>Verify the features flag is set on Kubelet</li></ul><pre>$ docker exec kind-control-plane cat /var/lib/kubelet/config.yaml<br>...<br>featureGates:<br>  ImageVolume: true<br>...</pre><p>So, the test cluster should be ready to test the OCI Volume Source feature.</p><ul><li>Create an image artifact using ORAS command and push it to an OCI registry</li></ul><pre>$ echo &quot;Hello ImageVolume&quot; &gt; artifact.txt<br>$ IMAGE_NAME=$(uuidgen)<br>$ oras push ttl.sh/${IMAGE_NAME}:1h \\<br>    --artifact-type application/vnd.acme.config \\<br>    artifact.txt:text/plain</pre><h3>Usage</h3><ul><li>Create a POD with a defined image volume</li></ul><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: pod-oci-volume-source<br>spec:<br>  containers:<br>    - name: test<br>      image: nginx<br>      volumeMounts:<br>        - name: volume<br>          mountPath: /mnt<br>  volumes:<br>    - name: volume<br>      image:<br>        reference: ttl.sh/${IMAGE_NAME}:1h<br>        pullPolicy: IfNotPresent</pre><ul><li>Check container image (nginx) and image artifact (ttl.sh/xxx:1h) have been pulled locally on the Kubernetes node by the container runtime using <strong>crictl</strong> command.</li></ul><pre>$ docker exec kind-control-plane crictl image<br>IMAGE                                           TAG                  IMAGE ID            SIZE<br>docker.io/kindest/kindnetd                      v20240813-c6f155d6   12968670680f4       36.8MB<br>docker.io/kindest/local-path-helper             v20230510-486859a6   be300acfc8622       3.05MB<br>docker.io/kindest/local-path-provisioner        v20240813-c6f155d6   3a195b56ff154       19.4MB<br>docker.io/library/nginx                         latest               5ef79149e0ec8       71MB<br>registry.k8s.io/coredns/coredns                 v1.11.1              cbb01a7bd410d       18.2MB<br>registry.k8s.io/etcd                            3.5.15-0             2e96e5913fc06       56.9MB<br>registry.k8s.io/kube-apiserver-amd64            v1.31.0              4f8c99889f8e4       95.2MB<br>registry.k8s.io/kube-apiserver                  v1.31.0              4f8c99889f8e4       95.2MB<br>registry.k8s.io/kube-controller-manager-amd64   v1.31.0              7e9a7dc204d9d       89.4MB<br>registry.k8s.io/kube-controller-manager         v1.31.0              7e9a7dc204d9d       89.4MB<br>registry.k8s.io/kube-proxy-amd64                v1.31.0              af3ec60a3d89b       92.7MB<br>registry.k8s.io/kube-proxy                      v1.31.0              af3ec60a3d89b       92.7MB<br>registry.k8s.io/kube-scheduler-amd64            v1.31.0              418e326664bd2       68.4MB<br>registry.k8s.io/kube-scheduler                  v1.31.0              418e326664bd2       68.4MB<br>registry.k8s.io/pause                           3.10                 873ed75102791       320kB<br>ttl.sh/fab04c8a-6d9d-4c9a-b2d6-568b0193dfe0     1h                   44136fa355b36       575B</pre><p>But, the POD is not running and we get some weird error on the events.</p><pre>$ kubectl get pods<br>NAME                    READY   STATUS             RESTARTS   AGE<br>pod-oci-volume-source   0/1     ImagePullBackOff   0          3m</pre><pre>Warning  Failed     3s    kubelet            Failed to pull image &quot;ttl.sh/fab04c8a-6d9d-4c9a-b2d6-568b0193dfe0:1h&quot;: failed to pull and unpack image &quot;ttl.sh/fab04c8a-6d9d-4c9a-b2d6-568b0193dfe0:1h&quot;: number of layers and diffIDs don&#39;t match: 1 != 0</pre><p>After asking to the community, I got more insights. Thanks of them. Because, containerd 1.7.18 doesn’t implement the new CRI API required for the Image Volume feature yet.</p><p>To implement this new feature, the container runtime projects (CRI-O and containerd) use both a respective PR in their respective Git repository to follow the implementation of this feature.</p><ul><li>CRI-O — Add OCI/Image Volume Source support<br><a href="https://github.com/cri-o/cri-o/pull/8317">https://github.com/cri-o/cri-o/pull/8317</a></li><li>Containerd — Add OCI Volume Source support <a href="https://github.com/containerd/containerd/issues/10496">https://github.com/containerd/containerd/issues/10496</a></li></ul><p>As this writing, none of them released an official version of the container runtime yet.</p><p>So, let’s wait for their implementation and I will update this article later.</p><h3>Conclusion</h3><p>The OCI Volume Source feature allows to mount container images directly as read-only volumes in Kubernetes Pods, simplifying how applications can access static data resources such ML models or data patterns to share across you Kubernetes clusters.</p><p>To access this functionality on Kubernetes 1.31, it is necessary to <strong>enable the ImageVolume feature gate</strong>, as well as use a container runtime that <strong>implements the new CRI API required </strong>for this functionality to work.</p><p>This functionality is promising and will certainly simplify the needs for sharing static data such as ML models or any other data patterns that need to be distributed across your different clusters.</p><p>To be continued…</p><h3>References</h3><ul><li>OCI — Open Container Initiative<br><a href="https://opencontainers.org/">https://opencontainers.org/</a></li><li>Kubernetes — Features stages <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/#feature-stages">https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/#feature-stages</a></li><li>Kubernetes — List of Kubernetes enhancements (KEPs) <a href="https://www.kubernetes.dev/resources/keps/">https://www.kubernetes.dev/resources/keps/</a></li><li>KEP-4639 Issue — VolumeSource: OCI Artifact and/or Image <a href="https://github.com/kubernetes/enhancements/issues/4639">https://github.com/kubernetes/enhancements/issues/4639</a></li><li>KEP-4639 Document — OCI VolumeSource <a href="https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/4639-oci-volume-source">https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/4639-oci-volume-source</a></li><li>Kubernetes — Features Gates <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/">https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/</a></li><li>Kubernetes — Container Runtime Interface (CRI) <a href="https://kubernetes.io/docs/concepts/architecture/cri/">https://kubernetes.io/docs/concepts/architecture/cri/</a></li><li>Containerd — Project Page<br><a href="https://containerd.io/">https://containerd.io/</a></li><li>CRI-O — Project Page<br><a href="https://cri-o.io/">https://cri-o.io/</a></li><li>Kind — Kubernetes IN Docker — local clusters for testing Kubernetes <a href="https://kind.sigs.k8s.io/">https://kind.sigs.k8s.io/</a></li><li>ORAS — Distribute Artifacts Across OCI Registries With Ease <a href="https://oras.land/">https://oras.land/</a></li><li>Kubeadm<br><a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/">https://kubernetes.io/docs/reference/setup-tools/kubeadm/</a></li><li>CRI-O — Add OCI/Image Volume Source support<br><a href="https://github.com/cri-o/cri-o/pull/8317">https://github.com/cri-o/cri-o/pull/8317</a></li><li>Containerd — Add OCI Volume Source support <a href="https://github.com/containerd/containerd/issues/10496">https://github.com/containerd/containerd/issues/10496</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06d62fb72086" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OCI Registry — Store more than Container Images]]></title>
            <link>https://sestegra.medium.com/oci-registry-store-more-than-container-images-08ca1ac74a01?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/08ca1ac74a01</guid>
            <category><![CDATA[artifact-registry]]></category>
            <category><![CDATA[container-registry]]></category>
            <category><![CDATA[open-container-initiative]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Fri, 26 Apr 2024 14:33:12 GMT</pubDate>
            <atom:updated>2024-04-26T14:33:12.365Z</atom:updated>
            <content:encoded><![CDATA[<h3>OCI Registry — Store more than Container Images</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLeTDE-iVdBA3lHdQzzLtQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@guibolduc?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Guillaume Bolduc</a> on <a href="https://unsplash.com/photos/stack-of-cargo-trailer-uBe2mknURG4?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><p>The swift progress of container technologies necessitates standardized practices, notably guided by the Open Container Initiative (OCI).</p><p>This article examines the new OCI specifications crucial for standardizing container images and artifacts’ operation, structure, and distribution. The practical application of these standards in a registry to store artifacts is presented.</p><h3>Introduction to OCI Specifications</h3><p>The <a href="https://opencontainers.org/">Open Container Initiative</a> (OCI) specifications are defined for standardizing container technologies. There are 3 specifications.</p><p>First, the <strong>Runtime Specification</strong> defines the environment where containers operate. Next, the <strong>Image Specification</strong> defines how container images are organized. Finally, the <strong>Distribution Specs</strong> defines how to serve these images.</p><blockquote><em>💡</em> <em>OCI Specifications</em><br><em>- </em><a href="https://github.com/opencontainers/runtime-spec"><strong><em>Runtime</em></strong><em> Specifications</em></a><em> — latest release v1.2.0 — Feb 13th, 2024<br>- </em><a href="https://github.com/opencontainers/image-spec"><strong><em>Image</em></strong><em> Specifications</em></a><em> — latest release v1.1.0 — Feb 15th, 2024<br>- </em><a href="https://github.com/opencontainers/distribution-spec"><strong><em>Distribution</em></strong><em> Specifications</em></a><em> — latest release v1.1.0 — Feb 15th, 2024</em></blockquote><p>Together, the <strong>Image and Distribution Specs</strong> have been updated to support more than container images. Before going to the new features, let’s focus first on image format and storage.</p><p>First, the <strong>registry</strong> is a service that implements the required HTTP API endpoints to push and pull images.</p><p>Then, a <strong>repository</strong> is a collection of related images, as different versions of the same application, stored within the registry. It represents a <strong>namespace </strong>for grouping images.</p><p>Then, the <strong>reference</strong> is a generic pointer to an image within a repository. It can be a <strong>tag</strong>, a human readable string, or a <strong>digest</strong> providing a unique hash for the image content, ensuring immutability and verification.</p><p>Usually, the registry clients support both references simultaneously: <strong>tag</strong> and <strong>digest</strong> for human readability and unicity, but, in that case, only the digest is sent to registry API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QMUFVX6JHZJ6qpfihlA9Vw.png" /><figcaption>Registry / Repository URL</figcaption></figure><p>The subsequent paragraphs provide explanations of the diagram presented below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kDasylE9H5qCkzXtxSdf-w.png" /><figcaption>OCI Registry components</figcaption></figure><h3>Tags Management</h3><p>The <strong>registry</strong> implements a <strong>tags</strong> list endpoint /v2/&lt;name&gt;/tags/list to retrieve the related <strong>tags</strong> from the &lt;name&gt; <strong>repository</strong>. The response returns the list of stored <strong>tags</strong> on this <strong>repository</strong> with the following format.</p><pre>$ curl https://registry.my.labs/v2/kube-apiserver-amd64/tags/list<br>{<br>  &quot;name&quot;: &quot;kube-apiserver-amd64&quot;,<br>  &quot;tags&quot;: [<br>    &quot;v1.28.0&quot;,<br>    &quot;v1.28.1&quot;,<br>    &quot;v1.28.2&quot;,<br>    &quot;v1.28.3&quot;,<br>    &quot;v1.28.4&quot;,<br>    &quot;v1.28.5&quot;,<br>    &quot;v1.28.6&quot;,<br>    &quot;v1.28.7&quot;,<br>    &quot;v1.29.1&quot;,<br>    &quot;v1.29.2&quot;<br>  ]<br>}</pre><p>So, the <strong>tags</strong> are named-pointers to a <strong>manifest</strong> in a repository. They are designed to be human-readable.</p><p>It’s possible to assign multiple <strong>tags</strong>, each pointing to distinct <strong>manifests</strong>, allowing the management of different image versions. Multiple <strong>tags</strong> can be assigned to the same <strong>manifest</strong>: for instance, the latest tag. And a <strong>tag</strong> can be reassigned to a different <strong>manifest</strong>.</p><h3>Manifests Management</h3><h3>Image Manifest</h3><p>To access the <strong>manifest</strong> pointed by a <strong>tag</strong>, the endpoint is the following for a given &lt;name&gt; <strong>repository</strong> and &lt;tag&gt;<strong> tag: </strong>/v2/&lt;name&gt;/manifests/&lt;tag&gt; .</p><p>A <strong>manifest</strong> is a JSON document that describes an object in the given repository.</p><pre>$ curl https://registry.my.labs/v2/kube-apiserver-amd64/manifests/v1.29.2<br>{<br>  &quot;schemaVersion&quot;: 2,<br>  &quot;mediaType&quot;: &quot;application/vnd.oci.image.manifest.v1+json&quot;,<br>  &quot;config&quot;: {<br>    &quot;mediaType&quot;: &quot;application/vnd.oci.image.config.v1+json&quot;,<br>    &quot;digest&quot;: &quot;sha26:786295faae…&quot;,<br>    &quot;size&quot;: 2564<br>  },<br>  &quot;layers&quot;: [<br>   {<br>      &quot;mediaType&quot;: &quot;application/vnd.oci.image.layer.v1.tar+gzip&quot;,<br>      &quot;digest&quot;: &quot;sha256:aba5379b9c…&quot;,<br>      &quot;size&quot;: 84572<br>   }, <br>	 …<br>  ]<br>}</pre><p>In this case, the manifest is an <strong>image manifest </strong>as described in <strong>mediaType</strong> key,</p><p>Then, the <strong>config</strong> part describes the image configuration. It references a <strong>blob</strong> by its <strong>digest</strong> within this <strong>repository</strong>.</p><p><strong>Blobs</strong> are the binary form of the content that is stored by a <strong>registry</strong>, addressable by its <strong>digest</strong>.</p><p>So, the <strong>config blob</strong> defines the image’s runtime configuration, including environment variables, default command to run, and other settings coming from the tool used to build the image.</p><p>The next part are the <strong>layers</strong> of the image. Each <strong>layer</strong> references a <strong>blob</strong> by its digest.</p><p>The <strong>layers blobs</strong> are the file system layers. Each <strong>layer</strong> is built upon the previous one, creating a full filesystem of the image when combined.</p><h3>Image Index</h3><pre>$ curl https://registry.my.labs/v2/opentelemetry-operator/manifests/latest<br>{<br>  &quot;schemaVersion&quot;: 2,<br>  &quot;mediaType&quot;: &quot;application/vnd.oci.image.index.v1+json&quot;,<br>  &quot;manifests&quot;: [<br>    {<br>      &quot;mediaType&quot;: &quot;application/vnd.oci.image.manifest.v1+json&quot;,<br>      &quot;digest&quot;: &quot;sha256:7db3ebbdd5480eb18035d1ef8f8dd5604923bc0796d6ff80ac6025365fed214e&quot;,<br>      &quot;size&quot;: 673,<br>      &quot;platform&quot;: {<br>        &quot;architecture&quot;: &quot;amd64&quot;,<br>        &quot;os&quot;: &quot;linux&quot;<br>      }<br>    },<br>    {<br>      &quot;mediaType&quot;: &quot;application/vnd.oci.image.manifest.v1+json&quot;,<br>      &quot;digest&quot;: &quot;sha256:97bcecfaefc88fa27b1a81f9ec3bc18ee2fd50bd7163bf8bb8448ba0f7e6f307&quot;,<br>      &quot;size&quot;: 673,<br>      &quot;platform&quot;: {<br>        &quot;architecture&quot;: &quot;arm64&quot;,<br>        &quot;os&quot;: &quot;linux&quot;<br>      }<br>    }<br>  ]<br>}</pre><p>Another type of manifest is <strong>image index </strong>that points to multiple <strong>image manifests </strong>as denoted by the <strong>mediaType</strong> key and the <strong>manifests</strong> list. Here, both <strong>manifests</strong> point to the same image version but with different architecture.</p><p>The pointed <strong>image manifests</strong> are the same as explained above, except that the <strong>image manifest</strong> is stored as a <strong>blob</strong>.</p><p>So, the usual use of OCI Registry is for image storage, let’s see now its expanded use to store artifacts.</p><h3>OCI Artifacts</h3><p>OCI <strong>artifacts</strong> storage uses the same principles explained before using an <strong>image manifest</strong> metadata to identify the <strong>artifacts</strong> and using the <strong>layers blobs </strong>to store their contents.</p><p>For several years, some projects have been coming up with different ways to specify <strong>artifacts</strong> in the registry.</p><p>First by storing content on the same <strong>repository</strong> as the image, such as signatures and software bill of materials. The usual implementation uses a well-known <strong>tag</strong> to identify the <strong>artifact</strong>.</p><p>Another method relied on using a dedicated repository to store content.<br>This is the method used by tools such as Helm, FluxCD, Open Policy Agent bundles…</p><p>In the new OCI release, the use of <strong>image manifest</strong> metadata and <strong>layers</strong> to store contents<br>has been finally codified as a valid way with some adjustments.</p><p>For new clients pushing <strong>artifacts</strong>, there is a new top-level key called <strong>artifactType </strong>which can be used to denote a custom <strong>artifact</strong>.</p><p>A new key called <strong>subject</strong> can now be included on <strong>manifests</strong> which points to another object in the <strong>registry</strong>. This feature can establish <strong>relationships</strong> for linking objects in the <strong>registry</strong> (image and/or artifacts). To discover these <strong>relationships</strong>, a new endpoint called <strong>referrers</strong> has been implemented.</p><p>ORAS implements these new specifications. ORAS means OCI Registry As Storage.</p><p>To demonstrate these changes, ORAS CLI tool is used in the following paragraphs to achieve the process represented in the following diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CQ1aQ_6yArvPr1I8k1ceWw.png" /><figcaption>Hierarchy of artifacts on OCI Registry</figcaption></figure><h3>Push Content</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IrxRxEB5eIVDOiPt6ac-CA.png" /><figcaption>Push Content</figcaption></figure><p>First, let’s create a resource file, basically, push a test namespace.</p><pre>$ cat namespace.yaml<br>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: test<br><br>$ oras push registry.my.labs/oras/test:v1 \<br>    --artifact-type application/vnd.example.manifests.v1 \<br>    namespace.yaml:application/yaml<br><br>Uploading d6f2a1f4c156 namespace.yaml<br>Uploaded  d6f2a1f4c156 namespace.yaml<br>Pushed [registry] registry.my.labs/oras/test:v1<br>Digest: sha256:ba4a52f4c16afeb6af9e5fa7c833ea4d9e806bf032e9f10e4ea337ca6809469e</pre><p>Let’s use oras push command to push this YAML resource to the local <strong>registry</strong>: oras/test:v1. Define the <strong>artifact</strong> type: example vendor of Kubernetes manifests. For each pushed file, define the filename with its type: namespace.yaml and application/yaml. After pushing the <strong>artifact</strong>, you get the <strong>digests</strong> of all uploaded files and the related <strong>image manifest</strong>.</p><p>Let’s see the created manifest.</p><pre>$ curl https://registry.my.labs/v2/oras/test/manifests/v1 | jq .<br>{<br>  &quot;schemaVersion&quot;: 2,<br>  &quot;mediaType&quot;: &quot;application/vnd.oci.image.manifest.v1+json&quot;,<br>  &quot;artifactType&quot;: &quot;application/vnd.example.manifests.v1&quot;,<br>  &quot;config&quot;: {<br>    &quot;mediaType&quot;: &quot;application/vnd.oci.empty.v1+json&quot;,<br>    &quot;digest&quot;: &quot;sha256:44136fa355b3…&quot;,<br>    &quot;size&quot;: 2<br>  },<br>  &quot;layers&quot;: [<br>    {<br>      &quot;mediaType&quot;: &quot;application/yaml&quot;,<br>      &quot;digest&quot;: &quot;sha256:d6f2a1f4c156…&quot;,<br>      &quot;size&quot;: 54,<br>      &quot;annotations&quot;: {<br>        &quot;org.opencontainers.image.title&quot;: &quot;namespace.yaml&quot;<br>      }<br>    }...</pre><p>It’s still a JSON file representing an <strong>image manifest</strong>:</p><ul><li>the same <strong>mediaType</strong> as for an image</li><li>the new <strong>artifactType</strong> and the referenced <strong>layer</strong> are those passed to the ORAS CLI just before</li></ul><p>To pull the YAML resource from the registry, use oras pull command using the same URL as the push command.</p><pre>$ oras pull registry.my.labs/oras/test:v1<br>Downloading d6f2a1f4c156 namespace.yaml<br>Downloaded  d6f2a1f4c156 namespace.yaml<br>Pulled [registry] registry.my.labs/oras/test:v1<br>Digest: sha256:ba4a52f4c16afeb6af9e5fa7c833ea4d9e806bf032e9f10e4ea337ca6809469e<br><br>$ cat namespace.yaml<br>apiVersion: v1<br>kind: Namespace<br>metadata:<br>  name: test</pre><p>So, ORAS download and extract the namespace.yaml file.</p><p>So, it’s straightforward to push and pull <strong>artifacts</strong> to the OCI <strong>registry</strong>.</p><h3>Sign Content</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lz3zWDp10sOelDDeQ9f8uA.png" /><figcaption>Sign Content</figcaption></figure><p>Now, let’s sign the just pushed resource and push &amp; attach the signature to the content.</p><pre>$ cat signature.json<br>{<br>  &quot;artifact&quot;: &quot;registry.my.labs/oras/test:v1@sha256:ba4a52f4c16a…&quot;,<br>  &quot;signature&quot;: &quot;sestegra&quot;<br>}<br><br>$ oras attach registry.my.labs/oras/test:v1 \<br>    --artifact-type=application/vnd.example.signature.v1+json \<br>    signature.json:application/json<br>Uploading 2dc8164f1420 signature.json<br>Uploaded  2dc8164f1420 signature.json<br>Attached to [registry] registry.my.labs/oras/test@sha256:ba4a52f4c16a…<br>Digest: sha256:73499a9600d96c6bc46671affd5b58559a1bb1b99644d8638fbb563bee7a3982</pre><p>Let’s assume the given JSON is a valid signature.</p><p>Use the oras attach command, to push the signature <strong>artifact</strong> to the same <strong>repository</strong> as the YAML resource and to <strong>attach</strong> the signature to the YAML resource</p><p>As before, define the <strong>artifact</strong> type pushed to the <strong>registry: </strong>example vendor of signature. And define the filename with its type: signature.json and application/json. After pushing and attached to the YAML resource, the <strong>digest</strong> of the related <strong>image manifest </strong>is returned.</p><p>Let’s see the created manifest.</p><pre>$ curl https://registry.my.labs/v2/oras/test/manifests/sha256:73499a9... | jq .<br>{<br>  &quot;schemaVersion&quot;: 2,<br>  &quot;mediaType&quot;: &quot;application/vnd.oci.image.manifest.v1+json&quot;,<br>  &quot;artifactType&quot;: &quot;application/vnd.example.signature.v1+json&quot;,<br>  &quot;config&quot;: {<br>    &quot;mediaType&quot;: &quot;application/vnd.oci.empty.v1+json&quot;,<br>    &quot;digest&quot;: &quot;sha256:44136fa355b3…&quot;,<br>    &quot;size&quot;: 2<br>  },<br>  &quot;layers&quot;: [<br>    {<br>      &quot;mediaType&quot;: &quot;application/json&quot;,<br>      &quot;digest&quot;: &quot;sha256:2dc8164f1420…&quot;,<br>      &quot;size&quot;: 153,<br>      &quot;annotations&quot;: {<br>        &quot;org.opencontainers.image.title&quot;: &quot;signature.json&quot;<br>      }<br>    }<br>  ],<br>  &quot;subject&quot;: {<br>    &quot;mediaType&quot;: &quot;application/vnd.oci.image.manifest.v1+json&quot;,<br>    &quot;digest&quot;: &quot;sha256:ba4a52f4c16a…&quot;,<br>    &quot;size&quot;: 572<br>  },<br>  &quot;annotations&quot;: {<br>    &quot;org.opencontainers.image.created&quot;: &quot;2024-03-17T08:42:37Z&quot;<br>  }<br>}</pre><p>It’s still a JSON file representing an <strong>image manifest</strong>:</p><ul><li>the same <strong>mediaType</strong> as for an image</li><li>the new <strong>artifactType</strong> and the referenced <strong>layer</strong> are those passed to the ORAS CLI just before</li></ul><p>Then, extra information for relationships are present. The <strong>subject</strong> field points to the <strong>image manifest</strong> of the YAML resource (see sha256:ba4a52f4c16a… when pushing this content to the local registry).</p><p>To discover all <strong>relationships</strong> of an <strong>artifact</strong>, the oras discover command can be used.</p><pre>$ oras discover registry.my.labs/oras/test:v1<br>Discovered 1 artifact referencing v1<br>Digest: sha256:ba4a52f4c16afeb6af9e5fa7c833ea4d9e806bf032e9f10e4ea337ca6809469e<br><br>Artifact Type                               Digest<br>application/vnd.example.signature.v1+json   sha256:73499a9600d9…<br><br>$ oras pull registry.my.labs/oras/test@sha256:73499a9600d9…<br>Downloading 2dc8164f1420 signature.json<br>Downloaded  2dc8164f1420 signature.json<br>Pulled [registry] registry.my.labs/oras/test:v1@sha256:73499a9600d9…<br>Digest: sha256:73499a9600d96c6bc46671affd5b58559a1bb1b99644d8638fbb563bee7a3982<br><br>$ cat signature.json<br>{<br>  &quot;artifact&quot;: &quot;registry.my.labs/oras/test:v1@sha256:ba4a52f4c16a…&quot;,<br>  &quot;signature&quot;: &quot;sestegra&quot;<br>}</pre><p>So, the list of attached <strong>artifacts</strong> is returned, here the signature (see attached digest sha256:73499a9600d9… when pushing the content’s signature to the local registry).</p><p>Now, let’s pull the signature from the registry with oras pull command as before using the returned digest.</p><p>So, ORAS download and extract the signature.</p><p>So, it’s straightforward to get the attached signature from the tag of the YAML resource.</p><h3>Create and Attach the SBOM</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxgFxWuAPDb5RoCDlf6jPA.png" /><figcaption>Create and Attach the SBOM</figcaption></figure><p>Let’s continue to push stuff on OCI registry, let’s create a software bill of materials and push and attach it the resource.</p><pre>$ cat sbom.json<br>{<br>  &quot;artifact&quot;: &quot;registry.my.labs/oras/test:v1@sha256:ba4a52f4c16a…&quot;,<br>  ”components&quot;: […]<br>}<br><br>$ oras attach registry.my.labs/oras/test:v1 \<br>    --artifact-type=application/vnd.example.sbom.v1+json \<br>    sbom.json:application/json<br>Uploading adebfc263c9c sbom.json<br>Uploaded  adebfc263c9c sbom.json<br>Attached to [registry] registry.my.labs/oras/test@sha256:ba4a52f4c16afeb... <br>Digest: sha256:e3ef102e5c87576a7cc66885bf6d50608c86469f42da10f877f75c71184ad008<br></pre><p>A SBOM consists of the list of the used components. Let’s assume the given JSON is a valid SBOM.</p><p>Use oras attach command to push the SBOM artifact to the same repository as the YAML resource and to attach the SBOM to the YAML resource.</p><p>As before, define the artifact type pushed to the registry: example vendor of SBOM. As before, define the filename with its type: sbom.json and application/json. After pushing, and attached to the artifact, the digest of the related image manifest is returned.</p><p>The content of the created image manifest is similar than before.</p><p>So, where we are in the global process?</p><ul><li>Create an artifact containing YAML resources</li><li>Sign and attach the signature to the YAML resources</li><li>Create SBOM and attach it to the YAML resources</li></ul><h3>Sign SBOM, Push &amp; Attach its Signature</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RrHNkSjeeIdP9KQOxo1zIw.png" /><figcaption>Sign SBOM, Push &amp; Attach its Signature</figcaption></figure><p>Now, let’s sign the SBOM, and attach the SBOM signature to the SBOM artifact.</p><pre>$ cat sbom-signature.json<br>{<br>  &quot;artifact&quot;: &quot;registry.my.labs/oras/test:v1@sha256:ba4a52f4c16a…&quot;,<br>  &quot;signature&quot;: &quot;sestegra&quot;<br>}<br><br>$ oras attach registry.my.labs/oras/test@sha256:e3ef102e5c87... \<br>    --artifact-type=application/vnd.example.signature.v1+json \<br>    sbom-signature.json:application/json<br>Uploading 1743cdc854d6 sbom-signature.json<br>Uploaded  1743cdc854d6 sbom-signature.json<br>Attached to [registry] registry.my.labs/oras/test@sha256:e3ef102e5c87576a...<br>Digest: sha256:bae78f64dc90d9e0d135342cd4ce938b746ca9d5e194a21640475fe7d492f1df</pre><p>As before, let’s assume this is a valid signature represented by a JSON file.</p><p>Use oras attach command to push the SBOM signature <strong>artifact</strong> to the same <strong>repository</strong> as the initial <strong>artifact, </strong>and to <strong>attach</strong> the SBOM signature to the SBOM.</p><p>As before, define the artifact type pushed to the registry: example vendor of signature As before, define the filename with its type: sbom-signature.json and application/json. After pushing, and attached to the SBOM artifact, the digest of the related image manifest is returned.</p><h3>Discover Referrers</h3><p>Now, to discover the relationships just created, use the oras discover command using the <strong>repository</strong> oras/test and v1 <strong>tag </strong>with the tree option to get the hierarchy of all pushed artifacts.</p><pre>$ oras discover -o tree registry.my.labs/oras/test:v1<br><br>registry.my.labs/oras/test@sha256:ba4a52f4c16afeb6af9e5fa7c83...<br>├── application/vnd.example.signature.v1+json<br>│   └── sha256:73499a9600d96c6bc46671affd5b58559a1bb1b99644d8638fbb563bee7a3982<br>└── application/vnd.example.sbom.v1+json<br>    └── sha256:e3ef102e5c87576a7cc66885bf6d50608c86469f42da10f877f75c71184ad008<br>        └── application/vnd.example.signature.v1+json<br>            └── sha256:bae78f64dc90d9e0d135342cd4ce938b746ca...</pre><p>The hierarchy is the expected as pushed artifacts.</p><ul><li>First the YAML resource on top</li><li>With the attached signature</li><li>With the attached SBOM</li><li>And the signature of the SBOM attached to the SBOM</li></ul><p>So, it’s straightforward to discover and pull all artifacts in these relationships by only knowing the initial pushed content.</p><h3>Conclusion</h3><p>The OCI specifications provide a consistent and reliable framework for containers images and artifacts across various environments. They standardize runtime, image, and distribution, ensuring predictable, secure container operations, irrespective of the infrastructure.</p><p>This standardization promotes innovation, collaboration, and scalability in container images and artifacts deployments.</p><h3>References</h3><ul><li>Open Container Initiative (OCI)<br><a href="https://opencontainers.org/">https://opencontainers.org/</a></li><li>OCI Runtime Specifications<br><a href="https://github.com/opencontainers/runtime-spec">https://github.com/opencontainers/runtime-spec</a></li><li>OCI Image Specifications<br><a href="https://github.com/opencontainers/image-spec">https://github.com/opencontainers/image-spec</a></li><li>OCI Distribution Specifications<br><a href="https://github.com/opencontainers/distribution-spec">https://github.com/opencontainers/distribution-spec</a></li><li>ORAS — OCI Registry As Storage<br><a href="https://oras.land/">https://oras.land/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=08ca1ac74a01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Codify Vault Internal PKI using Terraform]]></title>
            <link>https://sestegra.medium.com/codify-vault-internal-pki-using-terraform-c0f760323813?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0f760323813</guid>
            <category><![CDATA[hashicorp-terraform]]></category>
            <category><![CDATA[hashicorp-vault]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Sun, 16 Jul 2023 13:46:04 GMT</pubDate>
            <atom:updated>2023-07-16T13:56:59.976Z</atom:updated>
            <content:encoded><![CDATA[<p>Automate your Certificates Lifecycle with Vault — Part 5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UFFk_Ev2B4eVtKHlU6FhcA.jpeg" /></figure><blockquote>To make sure that you can automate things correctly using Vault’s Internal PKI, you need to know how to do some steps manually. You can learn about these important requirements by reading the detailed article <a href="https://sestegra.medium.com/build-an-internal-pki-with-vault-f7179306f18c">Build an Internal PKI with Vault</a>.</blockquote><p><em>This article is a part of a series about how to<br></em><a href="https://medium.com/@sestegra/automate-your-certificates-lifecycle-with-vault-bc7ffff2430c"><strong><em>Automate your Certificates Lifecycle with Vault</em></strong></a><em>.</em></p><ol><li><a href="https://medium.com/@sestegra/build-an-internal-pki-with-vault-f7179306f18c">Build an Internal PKI with Vault</a></li><li><a href="https://medium.com/@sestegra/issue-deploy-and-renew-your-private-certificates-with-vault-and-consul-template-1f5e4fe5f15c">Issue, Deploy and Renew your Private Certificates with Vault and Consul-Template</a></li><li><a href="https://medium.com/@sestegra/rotate-your-ca-seamlessly-using-a-vault-pki-9262228b4afb">Rotate your CA seamlessly using a Vault PKI</a></li><li><a href="https://medium.com/@sestegra/securely-store-public-certificates-in-vault-generated-by-acme-sh-2d6e98c9d308">Securely store Public Certificates in Vault, generated by acme.sh</a></li><li><a href="https://medium.com/@sestegra/codify-vault-internal-pki-using-terraform-c0f760323813"><strong>Codify Vault Internal PKI using Terraform</strong></a><strong> (this article)</strong></li></ol><h3>Introduction</h3><p>This article contains a walkthrough to codifying a branch of a three-tier PKI CA with Vault using an offline Root CA generated with certstrap.</p><h3>Three-Tier PKI CA Hierarchy</h3><p>In order to respect the IT security principle of Least Privilege And Separation Of Duties and to obtain flexibility of use, the Vault PKI built in this article is a branch of a three-tier PKI Certification Authority hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L7Iei6FPmBIROw25wN6gpg.png" /><figcaption>Three-Tier PKI Certification Authority Hierarchy</figcaption></figure><p>Usually, the root of trust is anchored within an existing company Root CA outside of Vault. So, the <strong>Root CA</strong> is stored offline, namely outside of Vault.</p><p>Then, the <strong>Intermediate CA</strong> and <strong>Issuing CA</strong> are stored inside of Vault using a dedicated <a href="https://developer.hashicorp.com/vault/docs/secrets/pki">PKI secret engine</a> for each. Moreover, a dedicated <strong>Role</strong> is required for issuing Leaf Certificates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*qmpnfYYbrSzUqcJWykEoyw.png" /><figcaption>PKI CA Hierarchy with Vault</figcaption></figure><h3>Pre-Requisites</h3><ul><li>Install <a href="https://developer.hashicorp.com/vault/docs/install"><strong>vault</strong></a> 1.14.0 or higher</li><li>Install <a href="https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli"><strong>terraform</strong></a> 1.15.3 or higher</li><li>Install <a href="https://github.com/square/certstrap"><strong>certstrap</strong></a> 1.3.0 or higher</li><li>Install <a href="https://stedolan.github.io/jq/"><strong>jq</strong></a> 1.6 or higher</li></ul><h3>Vault Server in Dev mode</h3><p>First, launch Vault Server in Dev mode using root as a root token id. The root token is used on purpose to focus only on the PKI secret engine features.</p><blockquote><strong><em>Disclaimer</em></strong><em>: On production<br>- Don’t use the root token<br>- Create auth methods, entities, groups and policies to grant or forbid access to PKI features</em></blockquote><pre>$ vault server -dev -dev-root-token-id=root</pre><p>In a second terminal, export Vault variables and check its status.</p><pre>$ export VAULT_ADDR=http://127.0.0.1:8200<br>$ export VAULT_TOKEN=root<br>$ vault status<br>Key             Value<br>---             -----<br>Seal Type       shamir<br>Initialized     true<br>Sealed          false<br>Total Shares    1<br>Threshold       1<br>Version         1.11.3<br>Build Date      2022-08-26T10:27:10Z<br>Storage Type    inmem<br>Cluster Name    vault-cluster-80f46c53<br>Cluster ID      075e1954-dd54-6614-f8a0-09351c840504<br>HA Enabled      false</pre><p>So, the Vault server is running now.</p><h3>Root CA</h3><p>Let’s start with the Root CA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*wPfloPwtQ9GFt4Em.png" /></figure><p>The offline Root CA is simulated using <a href="https://github.com/square/certstrap"><strong>certstrap</strong></a> open source tool from <a href="https://squareup.com/">Square</a>.</p><pre>$ certstrap --depot-path root init \<br>    --organization &quot;Example&quot; \<br>    --common-name &quot;Example Labs Root CA v1&quot; \<br>    --expires &quot;10 years&quot; \<br>    --curve P-256 \<br>    --path-length 2 \<br>    --passphrase &quot;secret&quot;<br>Created root/Example_Labs_Root_CA_v1.key (encrypted by passphrase)<br>Created root/Example_Labs_Root_CA_v1.crt<br>Created root/Example_Labs_Root_CA_v1.crl</pre><p>The private key and certificate are stored in root folder.</p><h3>Codify the PKI</h3><p>Execute Terraform on the running Vault server to codify the <strong>Intermediate CA, </strong>the <strong>Issuing CA </strong>and the<strong> role.</strong></p><p>First, you have to configure the Vault provider in providers.tf file. The provider uses VAULT_ADDR and VAULT_TOKEN environment variables to connect to the Vault server.</p><pre># providers.tf<br>terraform {<br>  required_version = &quot;&gt;= 1.5.3&quot;<br>  required_providers {<br>    vault = &quot;~&gt; 3.18.0&quot;<br>  }<br>}<br><br>provider &quot;vault&quot; {}</pre><p>Then, create both PKI secret engines using <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/mount">vault_mount</a> resource in main.tf file.</p><pre># main.tf<br>resource &quot;vault_mount&quot; &quot;pki_int&quot; {<br>  path                  = &quot;pki_int&quot;<br>  type                  = &quot;pki&quot;<br>  description           = &quot;PKI engine hosting intermediate CA&quot;<br>  max_lease_ttl_seconds = 157680000<br>}<br><br>resource &quot;vault_mount&quot; &quot;pki_iss&quot; {<br>  path                  = &quot;pki_iss&quot;<br>  type                  = &quot;pki&quot;<br>  description           = &quot;PKI engine hosting issuing CA&quot;<br>  max_lease_ttl_seconds = 31536000<br>}</pre><p>Initialise and download the Vault provider by initiating Terraform, and create both PKI secret engines.</p><pre>$ terraform init<br>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><h3>Issuer modules</h3><p>Since multiple issuers will be created to build the entire PKI CA hierarchy and during its lifetime when rotating a CA, using a module is appropriate to simplify the configuration.</p><p>Since the generation and signing of the certificate can be either external for the <strong>Intermediate CA</strong> or internal for the <strong>Issuing CA</strong>, it is preferable to have two separate modules: isser_external_ca and issuer_internal_ca.</p><h4>Issuer using external CA</h4><p>First, you have to define the issuervariable to collect the required issuer configuration. The attributes are self-explaining and certificate attribute will be used to pass the certificate generated and signed by the <strong>Root CA</strong></p><pre># modules/issuer_external_ca/variables.tf<br>variable &quot;issuer&quot; {<br>  type = object({<br>    name             = string<br>    backend          = string<br>    organization     = string<br>    certificate_name = string<br>    key_type         = string<br>    key_bits         = number<br>    certificate      = string<br>  })<br>  description = &quot;Issuer configuration&quot;<br>}</pre><p>Then, the required resources are the following:</p><ul><li>Create a <strong>Private key </strong>using the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_key">vault_pki_secret_backend_key</a> resource</li><li>Generate a <strong>CSR, </strong>used by <strong>Root CA</strong> to generate and sign the certificate, using the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_intermediate_cert_request">vault_pki_secret_backend_intermediate_cert_request</a> resource</li><li>Store the resulting <strong>Certificate </strong>using the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_intermediate_set_signed">vault_pki_secret_backend_intermediate_set_signed</a> resource</li><li>Name the new <strong>issuer </strong>using the <a href="http://vault_pki_secret_backend_issuer/">vault_pki_secret_backend_issuer</a> resource</li></ul><p>As the last two steps must be managed after the certificate generation, the related resources are conditional.</p><pre># modules/issuer_external_ca/main.tf<br># Generate a key<br>resource &quot;vault_pki_secret_backend_key&quot; &quot;this&quot; {<br>  backend  = var.issuer.backend<br>  type     = &quot;internal&quot;<br>  key_type = var.issuer.key_type<br>  key_bits = var.issuer.key_bits<br>  key_name = var.issuer.name<br>}<br><br># Generate a CSR<br>resource &quot;vault_pki_secret_backend_intermediate_cert_request&quot; &quot;this&quot; {<br>  backend      = var.issuer.backend<br>  type         = &quot;existing&quot;<br>  organization = var.issuer.organization<br>  common_name  = var.issuer.certificate_name<br>  key_ref      = vault_pki_secret_backend_key.this.key_id<br>}<br><br># Store the signed certificate<br>resource &quot;vault_pki_secret_backend_intermediate_set_signed&quot; &quot;this&quot; {<br>  count       = var.issuer.certificate != null ? 1 : 0<br>  backend     = var.issuer.backend<br>  certificate = var.issuer.certificate<br>}<br><br># Name the issuer<br>resource &quot;vault_pki_secret_backend_issuer&quot; &quot;this&quot; {<br>  count       = var.issuer.certificate != null ? 1 : 0<br>  backend     = var.issuer.backend<br>  issuer_ref  = vault_pki_secret_backend_intermediate_set_signed.this[0].imported_issuers[0]<br>  issuer_name = var.issuer.name<br>}</pre><p>Finally, the outputs are the following:</p><ul><li>the generated <strong>CSR</strong></li><li>the <strong>certificate</strong> and the <strong>issuer ID</strong></li></ul><pre># modules/issuer_external_ca/outputs.tf<br>output &quot;csr&quot; {<br>  description = &quot;PEM-encoded CSR&quot;<br>  value       = vault_pki_secret_backend_intermediate_cert_request.this.csr<br>}<br><br>output &quot;certificate&quot; {<br>  description = &quot;PEM-encoded certificate&quot;<br>  value       = length(vault_pki_secret_backend_intermediate_set_signed.this) &gt; 0 ? vault_pki_secret_backend_intermediate_set_signed.this[0].certificate : null<br>}<br><br>output &quot;issuer_id&quot; {<br>  description = &quot;ID of the issuer&quot;<br>  value       = length(vault_pki_secret_backend_intermediate_set_signed.this) &gt; 0 ? vault_pki_secret_backend_intermediate_set_signed.this[0].imported_issuers[0] : null<br>}</pre><h4>Issuer using internal CA</h4><p>This module is similar to the previous, except that the CSR can be used directly inside the Vault server that simplify the module.</p><p>First, you have to define the issuervariable to collect the required issuer configuration. The attributes are self-explaining and parent_backend attribute will be used to pass the <strong>Intermediate CA </strong>backend mount path.</p><pre># modules/issuer_external_ca/variables.tf<br>variable &quot;issuer&quot; {<br>  type = object({<br>    name             = string<br>    backend          = string<br>    organization     = string<br>    certificate_name = string<br>    key_type         = string<br>    key_bits         = number<br>    parent_backend   = string<br>  })<br>  description = &quot;Issuer configuration&quot;<br>}</pre><p>Then, the required resources are the following:</p><ul><li>Create a <strong>Private key </strong>using the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_key">vault_pki_secret_backend_key</a> resource</li><li>Generate a <strong>CSR </strong>using the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_intermediate_cert_request">vault_pki_secret_backend_intermediate_cert_request</a> resource</li><li>Generate and sign a certificate by <strong>Intermediate CA </strong>using the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_root_sign_intermediate">vault_pki_secret_backend_root_sign_intermediate</a> resource</li><li>Store the resulting <strong>Certificate </strong>using the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_intermediate_set_signed">vault_pki_secret_backend_intermediate_set_signed</a> resource</li><li>Name the new <strong>issuer </strong>using the <a href="http://vault_pki_secret_backend_issuer/">vault_pki_secret_backend_issuer</a> resource</li></ul><pre>va# Generate a key<br>resource &quot;vault_pki_secret_backend_key&quot; &quot;this&quot; {<br>  backend  = var.issuer.backend<br>  type     = &quot;internal&quot;<br>  key_type = var.issuer.key_type<br>  key_bits = var.issuer.key_bits<br>  key_name = var.issuer.name<br>}<br><br># Generate a CSR<br>resource &quot;vault_pki_secret_backend_intermediate_cert_request&quot; &quot;this&quot; {<br>  backend      = var.issuer.backend<br>  type         = &quot;existing&quot;<br>  organization = var.issuer.organization<br>  common_name  = var.issuer.certificate_name<br>  key_ref      = vault_pki_secret_backend_key.this.key_id<br>}<br><br># Sign the CSR using the parent CA<br>resource &quot;vault_pki_secret_backend_root_sign_intermediate&quot; &quot;this&quot; {<br>  backend      = var.issuer.parent_backend<br>  organization = var.issuer.organization<br>  common_name  = var.issuer.certificate_name<br>  csr          = vault_pki_secret_backend_intermediate_cert_request.this.csr<br>}<br><br># Store the signed certificate<br>resource &quot;vault_pki_secret_backend_intermediate_set_signed&quot; &quot;this&quot; {<br>  backend     = var.issuer.backend<br>  certificate = vault_pki_secret_backend_root_sign_intermediate.this.certificate_bundle<br>}<br><br># Name the issuer<br>resource &quot;vault_pki_secret_backend_issuer&quot; &quot;this&quot; {<br>  backend     = var.issuer.backend<br>  issuer_ref  = vault_pki_secret_backend_intermediate_set_signed.this.imported_issuers[0]<br>  issuer_name = var.issuer.name<br>}</pre><p>Finally, the outputs are the following:</p><ul><li>the generated <strong>CSR</strong></li><li>the <strong>certificate</strong> and the <strong>issuer ID</strong></li></ul><pre>output &quot;csr&quot; {<br>  description = &quot;PEM-encoded CSR&quot;<br>  value       = vault_pki_secret_backend_intermediate_cert_request.this.csr<br>}<br><br>output &quot;certificate&quot; {<br>  description = &quot;PEM-encoded certificate&quot;<br>  value       = vault_pki_secret_backend_intermediate_set_signed.this.certificate<br>}<br><br>output &quot;issuer_id&quot; {<br>  description = &quot;ID of the issuer&quot;<br>  value       = vault_pki_secret_backend_intermediate_set_signed.this.imported_issuers[0]<br>}</pre><h3>Intermediate CA</h3><p>Let’s use the issuer_external_ca module to build the <strong>Intermediate CA</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*9_-9Q3IJUzPXvnXi.png" /></figure><p>First, the certificate attribute must be nullas you need the CSR first to generate and sign the certificate using the <strong>Root CA</strong>.</p><pre># pki_int_v1.1.tf<br>module &quot;issuer_v1_1&quot; {<br>  source = &quot;./modules/issuer_external_ca&quot;<br>  issuer = {<br>    name             = &quot;v1.1&quot;<br>    backend          = &quot;pki_int&quot;<br>    organization     = &quot;Example&quot;<br>    certificate_name = &quot;Example Labs Intermediate CA v1.1&quot;<br>    key_type         = &quot;ec&quot;<br>    key_bits         = 256<br>    certificate      = null<br>  }<br>  depends_on = [vault_mount.pki_int]<br>}<br><br>output &quot;csr_v1_1&quot; {<br>  description = &quot;CSR for v1.1&quot;<br>  value       = module.issuer_v1_1.csr<br>  sensitive   = true<br>}<br><br>output &quot;certificate_v1_1&quot; {<br>  description = &quot;CRT for v1.1&quot;<br>  value       = module.issuer_v1_1.certificate<br>  sensitive   = true<br>}<br><br>output &quot;issuer_v1_1&quot; {<br>  description = &quot;v1.1 issuer ID&quot;<br>  value       = module.issuer_v1_1.issuer_id<br>}</pre><p>Initialise the new module, plan and apply the plan to generate the CSR.</p><pre>$ terraform init<br>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Extract the CSR from Terraform outputs, then generate and sign the certificate using the <strong>Root CA </strong>into pki_int_v1.1.crt file.</p><pre>$ terraform output -json &gt; pki_int_v1.1.json<br>$ jq -r .csr_v1_1.value pki_int_v1.1.json &gt; pki_int_v1.1.csr<br>$ certstrap --depot-path root sign \<br>  --CA &quot;Example Labs Root CA v1&quot; \<br>  --passphrase &quot;secret&quot; \<br>  --intermediate \<br>  --csr pki_int_v1.1.csr \<br>  --expires &quot;5 years&quot; \<br>  --path-length 1 \<br>  --cert pki_int_v1.1.crt \<br>  &quot;Example Labs Intermediate CA v1.1&quot;</pre><p>Use the generated certificate to update the pki_int_v1.1.tfconfiguration file by adding certificate = file(&quot;${path.root}/pki_int_v1.1.tf&quot;).</p><pre># pki_int_v1.1.tf<br>module &quot;issuer_v1_1&quot; {<br>    ...<br>    certificate      = file(&quot;${path.root}/pki_int_v1.1.tf&quot;)<br>    ...<br>}</pre><p>Then, plan and apply the plan to generate to store the resulting <strong>Certificate </strong>into the <strong>Intermediate CA </strong>backend.</p><pre>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Finally, verify the presence of the new issuer in the <strong>Intermedia CA</strong>.</p><pre>$ vault list -detailed pki_int/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>0e31e03b-2955-63b8-810c-1871b347ace7    true          v1.1           d15dfcee-bd40-335b-06fb-6487225aaacf    40:6e:7b:11:e2:02:7e:16:54:d4:31:89:3d:36:4f:dd</pre><p>The <strong>Intermediate CA</strong> is now configured, let’s move to the configuration of the <strong>Issuing CA</strong>.</p><h3>Issuing CA</h3><p>Let’s use the issuer_internal_ca module to build the <strong>Issuing CA</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*qRbm5cojQ6eTm9hQ.png" /></figure><p>First, the parent_backend attribute must be equal to <strong>Intermediate CA </strong>backend mount path.</p><pre># pki_iss_v1.1.1.tf<br>module &quot;issuer_v1_1_1&quot; {<br>  source = &quot;./modules/issuer_internal_ca&quot;<br>  issuer = {<br>    name             = &quot;v1.1.1&quot;<br>    backend          = &quot;pki_iss&quot;<br>    parent_backend   = &quot;pki_int&quot;<br>    organization     = &quot;Example&quot;<br>    certificate_name = &quot;Example Labs Issuing CA v1.1.1&quot;<br>    key_type         = &quot;ec&quot;<br>    key_bits         = 256<br>  }<br>  depends_on = [module.issuer_v1_1]<br>}<br><br>output &quot;certificate_v1_1_1&quot; {<br>  description = &quot;CRT for v1.1.1&quot;<br>  value       = module.issuer_v1_1_1.certificate<br>  sensitive   = true<br>}<br><br>output &quot;issuer_v1_1_1&quot; {<br>  description = &quot;Issuer ID for v1.1.1&quot;<br>  value       = module.issuer_v1_1_1.issuer_id<br>}</pre><p>Initialise the new module, plan and apply the plan to configure the <strong>Issuing CA </strong>backend.</p><pre>$ terraform init<br>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Finally, verify the presence of the new issuer in the <strong>Issuing CA</strong>.</p><pre>$ vault list -detailed pki_iss/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>36dd2a84-7aeb-89d1-b241-bbc3bfa9e25e    false         n/a            n/a                                     e2:dc:ad:0f:3d:ba:28:e8:f3:62:e9:cb:87:fd:4e:ab<br>b5d00900-dda8-94fa-0e1f-7a36dc5ff7b1    true          v1.1.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    34:9b:68:13:93:e8:f7:36:07:7e:e0:f5:2d:56:cc:19:ff:33:9a:4a</pre><h3>Role</h3><p>Finally, let’s create a role for <strong>Issuing CA</strong> secret engine to issue leaf certificates on the example.com domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*DmFy95wR1MbFjE3o.png" /></figure><p>Create an issuing role using the<a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_role">vault_pki_secret_backend_role</a> resource. Note that, the issuer_ref parameter is set to default.</p><pre>resource &quot;vault_pki_secret_backend_role&quot; &quot;example_com&quot; {<br>  backend                     = &quot;pki_iss&quot;<br>  name                        = &quot;example_com&quot;<br>  organization                = [&quot;Example&quot;]<br>  key_type                    = &quot;ec&quot;<br>  key_bits                    = 256<br>  max_ttl                     = 3600<br>  allowed_domains             = [&quot;example.com&quot;]<br>  allow_subdomains            = true<br>  allow_ip_sans               = true<br>  allow_wildcard_certificates = false<br>  issuer_ref                  = &quot;default&quot;<br>}</pre><p>Plan and apply the plan to configure the <strong>Role</strong>.</p><pre>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Finally, verify the Role creation by issuing a certificate for sample.example.com domain.</p><pre>$ vault write -format=json \<br>    pki_iss/issue/example_com \<br>    common_name=&quot;sample.example.com&quot; \<br>    ttl=&quot;5m&quot;</pre><pre>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            16:05:ec:8e:cb:c1:8c:63:3d:09:71:d5:a1:1d:ed:c4:47:1b:91:54<br>        Signature Algorithm: ecdsa-with-SHA256<br>        Issuer: O = Example, CN = Example Labs Issuing CA v1.1.1<br>        Validity<br>            Not Before: Jul 16 12:08:58 2023 GMT<br>            Not After : Jul 16 12:14:28 2023 GMT<br>        Subject: O = Example, CN = sample.example.com<br>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:b6:14:e9:c3:0a:79:fa:20:57:5a:d6:9e:5b:9f:<br>                    73:a3:61:27:57:5d:56:b3:3f:bc:8e:13:16:70:78:<br>                    b9:25:50:ff:c2:af:61:35:81:27:d8:9e:20:11:5a:<br>                    86:1d:db:6e:ed:8b:f7:9d:24:a4:28:1b:cd:c8:4d:<br>                    35:dd:14:7b:cd<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Digital Signature, Key Encipherment, Key Agreement<br>            X509v3 Extended Key Usage:<br>                TLS Web Server Authentication, TLS Web Client Authentication<br>            X509v3 Subject Key Identifier:<br>                4D:26:FB:D5:11:3C:25:45:51:08:01:00:0A:F0:A8:27:DC:6C:C3:67<br>            X509v3 Authority Key Identifier:<br>                6B:EB:EB:F7:20:E8:E2:C3:DE:84:C9:DE:81:80:89:D5:E0:21:37:F4<br>            X509v3 Subject Alternative Name:<br>                DNS:sample.example.com<br>    Signature Algorithm: ecdsa-with-SHA256<br>    Signature Value:<br>        30:46:02:21:00:ae:03:7f:2d:b8:2d:0d:a1:82:b3:4e:3a:c0:<br>        49:b0:3b:0f:e0:81:ea:df:7e:2b:8e:dc:c5:4c:da:2b:96:c3:<br>        6a:02:21:00:ae:51:f8:b0:a8:6a:07:5f:4b:6b:43:22:a6:5f:<br>        73:a6:02:c1:81:f1:d0:87:f7:95:a9:47:8c:6c:21:05:ee:9f</pre><p>Having successfully codified the PKI using Terraform, it is now time to proceed with the rotations of each CA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*Gz85Yb5RBAU00rKg.png" /></figure><h3>Rotate the Issuing CA</h3><p>First, you need to create a new issuer for the <strong>Issuing CA</strong>.</p><p>So, copy the file pki_iss_v1.1.1.tf configuration file into pki_iss_v1.1.2.tf, and replace v1.1.1 by v1.1.2.</p><pre># pki_iss_v1.1.2.tf<br>module &quot;issuer_v1_1_2&quot; {<br>  source = &quot;./modules/issuer_internal_ca&quot;<br>  issuer = {<br>    name             = &quot;v1.1.2&quot;<br>    backend          = &quot;pki_iss&quot;<br>    parent_backend   = &quot;pki_int&quot;<br>    organization     = &quot;Example&quot;<br>    certificate_name = &quot;Example Labs Issuing CA v1.1.2&quot;<br>    key_type         = &quot;ec&quot;<br>    key_bits         = 256<br>  }<br>  depends_on = [module.issuer_v1_1]<br>}<br><br>output &quot;certificate_v1_1_2&quot; {<br>  description = &quot;CRT for v1.1.2&quot;<br>  value       = module.issuer_v1_1_2.certificate<br>  sensitive   = true<br>}<br><br>output &quot;issuer_v1_1_2&quot; {<br>  description = &quot;Issuer ID for v1.1.2&quot;<br>  value       = module.issuer_v1_1_2.issuer_id<br>}</pre><p>Initialise the new module, plan and apply the plan to configure the <strong>Issuing CA </strong>backend.</p><pre>$ terraform init<br>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Then, verify the presence of the new issuer in the <strong>Issuing CA</strong>.</p><pre>$ vault list -detailed pki_iss/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>36dd2a84-7aeb-89d1-b241-bbc3bfa9e25e    false         n/a            n/a                                     e2:dc:ad:0f:3d:ba:28:e8:f3:62:e9:cb:87:fd:4e:ab<br>b5d00900-dda8-94fa-0e1f-7a36dc5ff7b1    true          v1.1.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    34:9b:68:13:93:e8:f7:36:07:7e:e0:f5:2d:56:cc:19:ff:33:9a:4a<br>e16fae6c-2b43-034f-e912-9a9fd859d031    false         v1.1.2         f1674fc0-3cc4-38a7-68d5-991582d23c56    3b:de:74:75:6b:48:f4:f8:bc:c7:47:91:ee:21:91:5b:70:bb:07:40</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*FwFDIS1Y4Hd6Z3S2.png" /><figcaption>Default issuer is still v1.1.1</figcaption></figure><p>The new issuer hasn’t been set as the default one. So, the role example_com will continue to issue certificates with v1.1.1 issuer.</p><p>To update the issuer configuration, use the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_config_issuers">vault_pki_secret_backend_config_issuers</a> resource</p><pre># main.tf<br>resource &quot;vault_pki_secret_backend_config_issuers&quot; &quot;iss&quot; {<br>  backend = &quot;pki_iss&quot;<br>  default = &quot;e16fae6c-2b43-034f-e912-9a9fd859d031&quot;<br>}</pre><p>Plan and apply the plan to configure the default issuer.</p><pre>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*lnGt3-IF2vJAd0Ej.png" /><figcaption>Default issuer is v1.1.2</figcaption></figure><p>Finally, verify the default issuer configuration in the <strong>Issuing CA</strong>, and issue a certificate for sample.example.com domain.</p><pre>$ vault list -detailed pki_iss/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>36dd2a84-7aeb-89d1-b241-bbc3bfa9e25e    false         n/a            n/a                                     e2:dc:ad:0f:3d:ba:28:e8:f3:62:e9:cb:87:fd:4e:ab<br>b5d00900-dda8-94fa-0e1f-7a36dc5ff7b1    false         v1.1.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    34:9b:68:13:93:e8:f7:36:07:7e:e0:f5:2d:56:cc:19:ff:33:9a:4a<br>e16fae6c-2b43-034f-e912-9a9fd859d031    true          v1.1.2         f1674fc0-3cc4-38a7-68d5-991582d23c56    3b:de:74:75:6b:48:f4:f8:bc:c7:47:91:ee:21:91:5b:70:bb:07:40</pre><pre>$ vault write -format=json \<br>    pki_iss/issue/example_com \<br>    common_name=&quot;sample.example.com&quot; \<br>    ttl=&quot;5m&quot;</pre><pre>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            2c:e6:f1:3f:19:c3:3e:8c:a1:c4:45:e2:6b:98:27:77:3f:a3:0c:ec<br>        Signature Algorithm: ecdsa-with-SHA256<br>        Issuer: O = Example, CN = Example Labs Issuing CA v1.1.2<br>        Validity<br>            Not Before: Jul 16 12:25:02 2023 GMT<br>            Not After : Jul 16 12:30:32 2023 GMT<br>        Subject: O = Example, CN = sample.example.com<br>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:78:72:51:34:60:a7:8e:ff:d4:7b:26:d0:7d:54:<br>                    bc:9d:d5:8b:dd:f0:89:28:eb:5c:66:80:28:59:0a:<br>                    28:49:4f:17:52:d6:5b:25:86:ac:e2:3e:11:86:df:<br>                    e1:42:b6:51:73:55:7c:43:c5:58:28:3f:20:70:61:<br>                    f7:50:59:b8:80<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Digital Signature, Key Encipherment, Key Agreement<br>            X509v3 Extended Key Usage:<br>                TLS Web Server Authentication, TLS Web Client Authentication<br>            X509v3 Subject Key Identifier:<br>                C8:4C:FF:03:B4:EC:76:F7:85:42:0C:DB:8C:16:AD:8F:3D:4A:68:E1<br>            X509v3 Authority Key Identifier:<br>                6B:EB:EB:F7:20:E8:E2:C3:DE:84:C9:DE:81:80:89:D5:E0:21:37:F4<br>            X509v3 Subject Alternative Name:<br>                DNS:sample.example.com<br>    Signature Algorithm: ecdsa-with-SHA256<br>    Signature Value:<br>        30:44:02:20:43:ba:c4:4c:49:c9:b7:d9:72:1b:e3:f6:a6:e8:<br>        64:77:b2:01:fd:d2:7f:4c:8f:80:e0:04:4d:67:28:b8:85:46:<br>        02:20:69:5e:81:32:9c:b4:12:79:bc:86:27:69:eb:ad:24:71:<br>        61:a1:f6:68:78:39:d2:50:96:f5:2e:96:cd:0c:9b:d6</pre><p>In the next section, the <strong>Intermediate CA</strong> is rotated.</p><h3>Rotate the Intermediate CA</h3><p>Now, let’s update the <strong>Intermediate CA</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*YSgRkcfxE-AkFhXV.png" /><figcaption>Generate v1.2 issuer for Intermediate CA</figcaption></figure><p>First, you need to create a new issuer for the <strong>Intermediate CA</strong>.</p><p>So, copy the file pki_int_v1.1.tf configuration file into pki_int_v1.2.tf, and replace v1.1 by v1.2.</p><pre># pki_int_v1.2.tf<br>module &quot;issuer_v1_2&quot; {<br>  source = &quot;./modules/issuer_external_ca&quot;<br>  issuer = {<br>    name             = &quot;v1.2&quot;<br>    backend          = &quot;pki_int&quot;<br>    organization     = &quot;Example&quot;<br>    certificate_name = &quot;Example Labs Intermediate CA v1.2&quot;<br>    key_type         = &quot;ec&quot;<br>    key_bits         = 256<br>    certificate      = null<br>  }<br>  depends_on = [vault_mount.pki_int]<br>}<br><br>output &quot;csr_v1_2&quot; {<br>  description = &quot;CSR for v1.2&quot;<br>  value       = module.issuer_v1_2.csr<br>  sensitive   = true<br>}<br><br>output &quot;certificate_v1_2&quot; {<br>  description = &quot;CRT for v1.2&quot;<br>  value       = module.issuer_v1_2.certificate<br>  sensitive   = true<br>}<br><br>output &quot;issuer_v1_2&quot; {<br>  description = &quot;v1.2 issuer ID&quot;<br>  value       = module.issuer_v1_2.issuer_id<br>}</pre><p>Initialise the new module, plan and apply the plan to generate the CSR.</p><pre>$ terraform init<br>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Extract the CSR from Terraform outputs, then generate and sign the certificate using the <strong>Root CA </strong>into pki_int_v1.2.crt file.</p><pre>$ terraform output -json &gt; pki_int_v1.2.json<br>$ jq -r .csr_v1_2.value pki_int_v1.2.json &gt; pki_int_v1.2.csr<br>$ certstrap --depot-path root sign \<br>  --CA &quot;Example Labs Root CA v1&quot; \<br>  --passphrase &quot;secret&quot; \<br>  --intermediate \<br>  --csr pki_int_v1.2.csr \<br>  --expires &quot;5 years&quot; \<br>  --path-length 1 \<br>  --cert pki_int_v1.2.crt \<br>  &quot;Example Labs Intermediate CA v1.2&quot;</pre><p>Use the generated certificate to update the pki_int_v1.2.tfconfiguration file by adding certificate = file(&quot;${path.root}/pki_int_v1.2.tf&quot;).</p><pre># pki_int_v1.2.tf<br>module &quot;issuer_v1_2&quot; {<br>    ...<br>    certificate      = file(&quot;${path.root}/pki_int_v1.2.tf&quot;)<br>    ...<br>}</pre><p>Then, plan and apply the plan to generate to store the resulting <strong>Certificate </strong>into the <strong>Intermediate CA </strong>backend.</p><pre>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Finally, verify the presence of the new issuer in the <strong>Intermedia CA</strong>.</p><pre>$ vault list -detailed pki_int/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>0e31e03b-2955-63b8-810c-1871b347ace7    true          v1.1           d15dfcee-bd40-335b-06fb-6487225aaacf    40:6e:7b:11:e2:02:7e:16:54:d4:31:89:3d:36:4f:dd<br>c17e8d1d-66b2-990d-61da-4c710ffcd3a6    false         v1.2           59344008-f547-1329-b9e5-12a35f220d79    60:fb:1a:ab:59:2e:22:53:9f:2b:88:af:18:b1:05:71</pre><p>The new issuer hasn’t been set as the default one.</p><p>To update the issuer configuration, use the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_config_issuers">vault_pki_secret_backend_config_issuers</a> resource</p><pre># main.tf<br>resource &quot;vault_pki_secret_backend_config_issuers&quot; &quot;int&quot; {<br>  backend = &quot;pki_int&quot;<br>  default = &quot;c17e8d1d-66b2-990d-61da-4c710ffcd3a6&quot;<br>}</pre><p>Plan and apply the plan to configure the default issuer.</p><pre>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Finally, verify the default issuer configuration in the <strong>Intermediate CA</strong>.</p><pre>$ vault list -detailed pki_int/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>0e31e03b-2955-63b8-810c-1871b347ace7    false         v1.1           d15dfcee-bd40-335b-06fb-6487225aaacf    40:6e:7b:11:e2:02:7e:16:54:d4:31:89:3d:36:4f:dd<br>c17e8d1d-66b2-990d-61da-4c710ffcd3a6    true          v1.2           59344008-f547-1329-b9e5-12a35f220d79    60:fb:1a:ab:59:2e:22:53:9f:2b:88:af:18:b1:05:71</pre><p>The <strong>Intermediate CA</strong> is now updated, let’s move to the update of the <strong>Issuing CA</strong> to use this new issuer.</p><h4>Update the Issuing CA</h4><p>First, you need to create a new issuer for the <strong>Issuing CA</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*eQBDNWRlXJD0dNW1.png" /><figcaption>Generate v1.2.1 issuer for Issuing CA</figcaption></figure><p>So, copy the file pki_iss_v1.1.1.tf configuration file into pki_iss_v1.2.1.tf, and replace v1.1.1 by v1.2.1.</p><pre># pki_iss_v1.2.1.tf<br>module &quot;issuer_v1_2_1&quot; {<br>  source = &quot;./modules/issuer_internal_ca&quot;<br>  issuer = {<br>    name             = &quot;v1.2.1&quot;<br>    backend          = &quot;pki_iss&quot;<br>    parent_backend   = &quot;pki_int&quot;<br>    organization     = &quot;Example&quot;<br>    certificate_name = &quot;Example Labs Issuing CA v1.2.1&quot;<br>    key_type         = &quot;ec&quot;<br>    key_bits         = 256<br>  }<br>  depends_on = [module.issuer_v1_2]<br>}<br><br>output &quot;certificate_v1_2_1&quot; {<br>  description = &quot;CRT for v1.2.1&quot;<br>  value       = module.issuer_v1_2_1.certificate<br>  sensitive   = true<br>}<br><br>output &quot;issuer_v1_2_1&quot; {<br>  description = &quot;Issuer ID for v1.2.1&quot;<br>  value       = module.issuer_v1_2_1.issuer_id<br>}</pre><p>Initialise the new module, plan and apply the plan to configure the <strong>Issuing CA </strong>backend.</p><pre>$ terraform init<br>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Then, verify the presence of the new issuer in the <strong>Issuing CA</strong>.</p><pre>$ vault list -detailed pki_iss/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>187fe1c5-ddee-aa2d-0b26-65295c4147a1    false         n/a            n/a                                     60:fb:1a:ab:59:2e:22:53:9f:2b:88:af:18:b1:05:71<br>36dd2a84-7aeb-89d1-b241-bbc3bfa9e25e    false         n/a            n/a                                     e2:dc:ad:0f:3d:ba:28:e8:f3:62:e9:cb:87:fd:4e:ab<br>b5d00900-dda8-94fa-0e1f-7a36dc5ff7b1    false         v1.1.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    34:9b:68:13:93:e8:f7:36:07:7e:e0:f5:2d:56:cc:19:ff:33:9a:4a<br>e16fae6c-2b43-034f-e912-9a9fd859d031    true          v1.1.2         f1674fc0-3cc4-38a7-68d5-991582d23c56    3b:de:74:75:6b:48:f4:f8:bc:c7:47:91:ee:21:91:5b:70:bb:07:40<br>f360913a-dc2d-ea2c-b2f1-653110f505df    false         v1.2.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    3f:73:a1:54:34:56:11:15:24:74:ad:36:56:6c:dd:cc:29:54:ee:5c</pre><p>The new issuer hasn’t been set as the default one. So, the role example_com will continue to issue certificates with v1.1.2 issuer.</p><p>To update the issuer configuration, use the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_config_issuers">vault_pki_secret_backend_config_issuers</a> resource</p><pre># main.tf<br>resource &quot;vault_pki_secret_backend_config_issuers&quot; &quot;iss&quot; {<br>  backend = &quot;pki_iss&quot;<br>  default = &quot;f360913a-dc2d-ea2c-b2f1-653110f505df&quot;<br>}</pre><p>Plan and apply the plan to configure the default issuer.</p><pre>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*SezwCfZQ-tW_sfv5.png" /><figcaption>Default issuer is v1.2.1</figcaption></figure><p>Finally, verify the default issuer configuration in the <strong>Issuing CA</strong>, and issue a certificate for sample.example.com domain.</p><pre>$ vault list -detailed pki_iss/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>187fe1c5-ddee-aa2d-0b26-65295c4147a1    false         n/a            n/a                                     60:fb:1a:ab:59:2e:22:53:9f:2b:88:af:18:b1:05:71<br>36dd2a84-7aeb-89d1-b241-bbc3bfa9e25e    false         n/a            n/a                                     e2:dc:ad:0f:3d:ba:28:e8:f3:62:e9:cb:87:fd:4e:ab<br>b5d00900-dda8-94fa-0e1f-7a36dc5ff7b1    false         v1.1.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    34:9b:68:13:93:e8:f7:36:07:7e:e0:f5:2d:56:cc:19:ff:33:9a:4a<br>e16fae6c-2b43-034f-e912-9a9fd859d031    false         v1.1.2         f1674fc0-3cc4-38a7-68d5-991582d23c56    3b:de:74:75:6b:48:f4:f8:bc:c7:47:91:ee:21:91:5b:70:bb:07:40<br>f360913a-dc2d-ea2c-b2f1-653110f505df    true          v1.2.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    3f:73:a1:54:34:56:11:15:24:74:ad:36:56:6c:dd:cc:29:54:ee:5c</pre><pre>$ vault write -format=json \<br>    pki_iss/issue/example_com \<br>    common_name=&quot;sample.example.com&quot; \<br>    ttl=&quot;5m&quot;</pre><pre>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            63:47:5d:72:1b:19:6e:13:4d:27:c0:85:7a:6a:ed:af:c6:33:4e:28<br>        Signature Algorithm: ecdsa-with-SHA256<br>        Issuer: O = Example, CN = Example Labs Issuing CA v1.2.1<br>        Validity<br>            Not Before: Jul 16 12:57:35 2023 GMT<br>            Not After : Jul 16 13:03:05 2023 GMT<br>        Subject: O = Example, CN = sample.example.com<br>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:40:cf:87:c9:aa:d3:1a:7b:d6:21:09:10:33:8d:<br>                    f2:8d:67:e2:87:b1:47:7c:3c:a4:eb:2c:eb:62:d3:<br>                    eb:71:ba:7d:28:f8:6c:e5:08:1b:fa:59:a7:2e:0b:<br>                    0a:c7:7e:82:fb:7e:da:93:1e:24:86:a7:bc:de:e7:<br>                    59:7a:47:69:1b<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Digital Signature, Key Encipherment, Key Agreement<br>            X509v3 Extended Key Usage:<br>                TLS Web Server Authentication, TLS Web Client Authentication<br>            X509v3 Subject Key Identifier:<br>                B5:9F:10:FB:65:ED:FA:2C:87:85:A0:86:F1:4C:26:E4:27:D0:0B:34<br>            X509v3 Authority Key Identifier:<br>                6B:EB:EB:F7:20:E8:E2:C3:DE:84:C9:DE:81:80:89:D5:E0:21:37:F4<br>            X509v3 Subject Alternative Name:<br>                DNS:sample.example.com<br>    Signature Algorithm: ecdsa-with-SHA256<br>    Signature Value:<br>        30:44:02:20:35:2d:c2:d3:1f:1f:5c:b9:b8:0b:e7:6b:0b:7e:<br>        93:3d:71:b5:a1:15:b2:e0:d3:c9:49:ce:04:78:06:f0:1c:d7:<br>        02:20:2b:1b:21:c3:de:2c:77:66:ba:ed:b1:58:1f:dc:62:ba:<br>        3e:64:ac:71:04:4f:c2:69:42:47:2e:4e:b4:f9:91:a0</pre><p>In the next section, the Root CA is rotated.</p><h3>Rotate the Root CA</h3><p>Now, let’s update the Root CA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*UoRHNabuEx8cSEuZ.png" /><figcaption>Generate Root CA v2</figcaption></figure><p>First, generate a self-signed <strong>Root CA</strong> v2 using certstrap</p><pre>$ certstrap --depot-path root \<br>    init \<br>    --organization &quot;Example&quot; \<br>    --common-name &quot;Example Labs Root CA v2&quot; \<br>    --expires &quot;10 years&quot; \<br>    --curve P-256 \<br>    --path-length 2 \<br>    --passphrase &quot;secret&quot;<br>Created root/Example_Labs_Root_CA_v2.key (encrypted by passphrase)<br>Created root/Example_Labs_Root_CA_v2.crt<br>Created root/Example_Labs_Root_CA_v2.crl</pre><p>The <strong>Root CA</strong> is now updated, let’s move to the update of the <strong>Intermediate CA</strong> to use this new <strong>Root CA</strong>.</p><h4>Update the Intermediate CA</h4><p>Now, let’s update the <strong>Intermediate CA</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*H1hjrPomNeDtnQ3e.png" /><figcaption>Generate v2.1 issuer for Intermediate CA</figcaption></figure><p>First, you need to create a new issuer for the <strong>Intermediate CA</strong>.</p><p>So, copy the file pki_int_v1.1.tf configuration file into pki_int_v2.1.tf, and replace v1.1 by v2.1.</p><pre># pki_int_v2.1.tf<br>module &quot;issuer_v2_1&quot; {<br>  source = &quot;./modules/issuer_external_ca&quot;<br>  issuer = {<br>    name             = &quot;v2.1&quot;<br>    backend          = &quot;pki_int&quot;<br>    organization     = &quot;Example&quot;<br>    certificate_name = &quot;Example Labs Intermediate CA v2.1&quot;<br>    key_type         = &quot;ec&quot;<br>    key_bits         = 256<br>    certificate      = null<br>  }<br>  depends_on = [vault_mount.pki_int]<br>}<br><br>output &quot;csr_v2_1&quot; {<br>  description = &quot;CSR for v2.1&quot;<br>  value       = module.issuer_v2_1.csr<br>  sensitive   = true<br>}<br><br>output &quot;certificate_v2_1&quot; {<br>  description = &quot;CRT for v2.1&quot;<br>  value       = module.issuer_v2_1.certificate<br>  sensitive   = true<br>}<br><br>output &quot;issuer_v2_1&quot; {<br>  description = &quot;v2.1 issuer ID&quot;<br>  value       = module.issuer_v2_1.issuer_id<br>}</pre><p>Initialise the new module, plan and apply the plan to generate the CSR.</p><pre>$ terraform init<br>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Extract the CSR from Terraform outputs, then generate and sign the certificate using the new <strong>Root CA </strong>into pki_int_v2.1.crt file.</p><pre>$ terraform output -json &gt; pki_int_v2.1.json<br>$ jq -r .csr_v2_1.value pki_int_v2.1.json &gt; pki_int_v2.1.csr<br>$ certstrap --depot-path root sign \<br>  --CA &quot;Example Labs Root CA v2&quot; \<br>  --passphrase &quot;secret&quot; \<br>  --intermediate \<br>  --csr pki_int_v2.1.csr \<br>  --expires &quot;5 years&quot; \<br>  --path-length 1 \<br>  --cert pki_int_v2.1.crt \<br>  &quot;Example Labs Intermediate CA v2.1&quot;</pre><p>Use the generated certificate to update the pki_int_v2.1.tfconfiguration file by adding certificate = file(&quot;${path.root}/pki_int_v2.1.tf&quot;).</p><pre># pki_int_v2.1.tf<br>module &quot;issuer_v2_1&quot; {<br>    ...<br>    certificate      = file(&quot;${path.root}/pki_int_v2.1.tf&quot;)<br>    ...<br>}</pre><p>Then, plan and apply the plan to generate to store the resulting <strong>Certificate </strong>into the <strong>Intermediate CA </strong>backend.</p><pre>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Finally, verify the presence of the new issuer in the <strong>Intermedia CA</strong>.</p><pre>$ vault list -detailed pki_int/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>0e31e03b-2955-63b8-810c-1871b347ace7    false         v1.1           d15dfcee-bd40-335b-06fb-6487225aaacf    40:6e:7b:11:e2:02:7e:16:54:d4:31:89:3d:36:4f:dd<br>c17e8d1d-66b2-990d-61da-4c710ffcd3a6    true          v1.2           59344008-f547-1329-b9e5-12a35f220d79    60:fb:1a:ab:59:2e:22:53:9f:2b:88:af:18:b1:05:71<br>02ed0617-823f-00b5-56e7-e71764c1576b    false         v2.1           59344008-f547-1329-b9e5-12a35f220d79    b2:a4:29:13:a9:87:be:00:d2:4c:a0:41:6a:f9:2e:0c</pre><p>The new issuer hasn’t been set as the default one.</p><p>To update the issuer configuration, use the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_config_issuers">vault_pki_secret_backend_config_issuers</a> resource</p><pre># main.tf<br>resource &quot;vault_pki_secret_backend_config_issuers&quot; &quot;int&quot; {<br>  backend = &quot;pki_int&quot;<br>  default = &quot;02ed0617-823f-00b5-56e7-e71764c1576b&quot;<br>}</pre><p>Plan and apply the plan to configure the default issuer.</p><pre>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Finally, verify the default issuer configuration in the <strong>Intermediate CA</strong>.</p><pre>$ vault list -detailed pki_int/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>0e31e03b-2955-63b8-810c-1871b347ace7    false         v1.1           d15dfcee-bd40-335b-06fb-6487225aaacf    40:6e:7b:11:e2:02:7e:16:54:d4:31:89:3d:36:4f:dd<br>c17e8d1d-66b2-990d-61da-4c710ffcd3a6    false         v1.2           59344008-f547-1329-b9e5-12a35f220d79    60:fb:1a:ab:59:2e:22:53:9f:2b:88:af:18:b1:05:71<br>02ed0617-823f-00b5-56e7-e71764c1576b    true          v2.1           59344008-f547-1329-b9e5-12a35f220d79    b2:a4:29:13:a9:87:be:00:d2:4c:a0:41:6a:f9:2e:0c</pre><p>The <strong>Intermediate CA</strong> is now updated, let’s move to the update of the <strong>Issuing CA</strong> to use this new issuer.</p><h4>Update the Issuing CA</h4><p>First, you need to create a new issuer for the <strong>Issuing CA</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*5LChtPTEP8aDGPp8.png" /><figcaption>Generate v2.1.1 issuer for Issuing CA</figcaption></figure><p>So, copy the file pki_iss_v1.1.1.tf configuration file into pki_iss_v2.1.1.tf, and replace v1.1.1 by v2.1.1.</p><pre># pki_iss_v2.1.1.tf<br>module &quot;issuer_v2_1_1&quot; {<br>  source = &quot;./modules/issuer_internal_ca&quot;<br>  issuer = {<br>    name             = &quot;v2.1.1&quot;<br>    backend          = &quot;pki_iss&quot;<br>    parent_backend   = &quot;pki_int&quot;<br>    organization     = &quot;Example&quot;<br>    certificate_name = &quot;Example Labs Issuing CA v2.1.1&quot;<br>    key_type         = &quot;ec&quot;<br>    key_bits         = 256<br>  }<br>  depends_on = [module.issuer_v2_1]<br>}<br><br>output &quot;certificate_v2_1_1&quot; {<br>  description = &quot;CRT for v2.1.1&quot;<br>  value       = module.issuer_v2_1_1.certificate<br>  sensitive   = true<br>}<br><br>output &quot;issuer_v2_1_1&quot; {<br>  description = &quot;Issuer ID for v2.1.1&quot;<br>  value       = module.issuer_v2_1_1.issuer_id<br>}</pre><p>Initialise the new module, plan and apply the plan to configure the <strong>Issuing CA </strong>backend.</p><pre>$ terraform init<br>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><p>Then, verify the presence of the new issuer in the <strong>Issuing CA</strong>.</p><pre>$ vault list -detailed pki_iss/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>187fe1c5-ddee-aa2d-0b26-65295c4147a1    false         n/a            n/a                                     60:fb:1a:ab:59:2e:22:53:9f:2b:88:af:18:b1:05:71<br>36dd2a84-7aeb-89d1-b241-bbc3bfa9e25e    false         n/a            n/a                                     e2:dc:ad:0f:3d:ba:28:e8:f3:62:e9:cb:87:fd:4e:ab<br>c53cb6f8-f9b6-525f-3503-457b0a82c349    false         n/a            n/a                                     b2:a4:29:13:a9:87:be:00:d2:4c:a0:41:6a:f9:2e:0c<br>b5d00900-dda8-94fa-0e1f-7a36dc5ff7b1    false         v1.1.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    34:9b:68:13:93:e8:f7:36:07:7e:e0:f5:2d:56:cc:19:ff:33:9a:4a<br>e16fae6c-2b43-034f-e912-9a9fd859d031    false         v1.1.2         f1674fc0-3cc4-38a7-68d5-991582d23c56    3b:de:74:75:6b:48:f4:f8:bc:c7:47:91:ee:21:91:5b:70:bb:07:40<br>f360913a-dc2d-ea2c-b2f1-653110f505df    true          v1.2.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    3f:73:a1:54:34:56:11:15:24:74:ad:36:56:6c:dd:cc:29:54:ee:5c<br>5a1fe736-4042-427a-a855-4597559a54d3    false         v2.1.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    4a:c6:71:32:ec:c4:6d:e7:cc:e7:ff:26:88:11:d2:f3:cc:5c:cb:4a</pre><p>The new issuer hasn’t been set as the default one. So, the role example_com will continue to issue certificates with v1.2.1 issuer.</p><p>To update the issuer configuration, use the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/pki_secret_backend_config_issuers">vault_pki_secret_backend_config_issuers</a> resource</p><pre># main.tf<br>resource &quot;vault_pki_secret_backend_config_issuers&quot; &quot;iss&quot; {<br>  backend = &quot;pki_iss&quot;<br>  default = &quot;5a1fe736-4042-427a-a855-4597559a54d3&quot;<br>}</pre><p>Plan and apply the plan to configure the default issuer.</p><pre>$ terraform plan -out plan.out<br>$ terraform apply plan.out</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/0*yB-ja0AseBqejF_r.png" /><figcaption>Default issuer is v2.1.1</figcaption></figure><p>Finally, verify the default issuer configuration in the <strong>Issuing CA</strong>, and issue a certificate for sample.example.com domain.</p><pre>$ vault list -detailed pki_iss/issuers<br>Keys                                    is_default    issuer_name    key_id                                  serial_number<br>----                                    ----------    -----------    ------                                  -------------<br>187fe1c5-ddee-aa2d-0b26-65295c4147a1    false         n/a            n/a                                     60:fb:1a:ab:59:2e:22:53:9f:2b:88:af:18:b1:05:71<br>36dd2a84-7aeb-89d1-b241-bbc3bfa9e25e    false         n/a            n/a                                     e2:dc:ad:0f:3d:ba:28:e8:f3:62:e9:cb:87:fd:4e:ab<br>c53cb6f8-f9b6-525f-3503-457b0a82c349    false         n/a            n/a                                     b2:a4:29:13:a9:87:be:00:d2:4c:a0:41:6a:f9:2e:0c<br>b5d00900-dda8-94fa-0e1f-7a36dc5ff7b1    false         v1.1.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    34:9b:68:13:93:e8:f7:36:07:7e:e0:f5:2d:56:cc:19:ff:33:9a:4a<br>e16fae6c-2b43-034f-e912-9a9fd859d031    false         v1.1.2         f1674fc0-3cc4-38a7-68d5-991582d23c56    3b:de:74:75:6b:48:f4:f8:bc:c7:47:91:ee:21:91:5b:70:bb:07:40<br>f360913a-dc2d-ea2c-b2f1-653110f505df    false         v1.2.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    3f:73:a1:54:34:56:11:15:24:74:ad:36:56:6c:dd:cc:29:54:ee:5c<br>5a1fe736-4042-427a-a855-4597559a54d3    true          v2.1.1         f1674fc0-3cc4-38a7-68d5-991582d23c56    4a:c6:71:32:ec:c4:6d:e7:cc:e7:ff:26:88:11:d2:f3:cc:5c:cb:4a</pre><pre>$ vault write -format=json \<br>    pki_iss/issue/example_com \<br>    common_name=&quot;sample.example.com&quot; \<br>    ttl=&quot;5m&quot;</pre><pre>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            52:9b:7f:2c:b5:27:09:f3:69:74:4b:02:e2:83:ce:6e:50:d9:62:cc<br>        Signature Algorithm: ecdsa-with-SHA256<br>        Issuer: O = Example, CN = Example Labs Issuing CA v2.1.1<br>        Validity<br>            Not Before: Jul 16 13:18:45 2023 GMT<br>            Not After : Jul 16 13:24:15 2023 GMT<br>        Subject: O = Example, CN = sample.example.com<br>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:e7:a7:58:a8:10:92:50:83:50:0d:df:e2:f8:c2:<br>                    92:fe:22:5c:32:88:0b:7d:4d:ae:08:f0:5b:85:81:<br>                    53:90:c0:72:64:25:9f:1f:f3:b2:3f:73:35:9d:83:<br>                    4d:ec:c6:ff:b3:82:9d:27:f2:ec:60:8f:95:dc:02:<br>                    fb:d7:dd:c9:8a<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Digital Signature, Key Encipherment, Key Agreement<br>            X509v3 Extended Key Usage:<br>                TLS Web Server Authentication, TLS Web Client Authentication<br>            X509v3 Subject Key Identifier:<br>                9F:01:C8:21:F8:56:9E:D2:4D:97:9C:30:75:A3:ED:05:9F:CD:51:60<br>            X509v3 Authority Key Identifier:<br>                6B:EB:EB:F7:20:E8:E2:C3:DE:84:C9:DE:81:80:89:D5:E0:21:37:F4<br>            X509v3 Subject Alternative Name:<br>                DNS:sample.example.com<br>    Signature Algorithm: ecdsa-with-SHA256<br>    Signature Value:<br>        30:46:02:21:00:fd:78:9a:3a:fa:be:06:f5:b5:a2:cf:90:e8:<br>        8b:9e:b5:ba:84:27:93:0c:63:fa:ba:4f:3d:9e:19:a8:63:e8:<br>        9d:02:21:00:9e:86:7a:81:f4:70:69:1b:2c:ae:5f:7e:0d:c9:<br>        c8:8e:06:0d:90:b3:2f:4f:bd:6e:1e:d2:41:dd:0c:b0:36:b8</pre><p>As a result, the <strong>Root CA</strong>, the <strong>Intermediate CA</strong> and the <strong>Issuing CA</strong> have been rotated, and the generation of leaf certificates is passed on seamlessly to the new issuer.</p><p>The following repository is the companion of this post:<br><a href="https://github.com/sestegra/vault_pki_terraform">https://github.com/sestegra/vault_pki_terraform</a></p><h3>Conclusion</h3><p>In summary, using Terraform to turn Vault’s Internal PKI into code has many advantages. It helps organizations ensure they always use the same secure practices by automating how they get and handle certificates and certificate authorities.</p><p>Keeping track of infrastructure changes and controlling different versions makes it easier to maintain and work together as a team. Terraform’s flexibility and Vault’s strength combine to make a powerful method that simplifies things and improves overall security.</p><p>Nevertheless, the PKI codification requires multiple states, especially when the Root CA is offline and when managing the CA rotations. So, multiple “Write, Plan, Apply” cycles are required when using only Terraform.</p><p>Is the complete automation of the PKI lifecycle through only Terraform optimal? For instance, can Consul-Terraform-Sync be another approach to manage dynamicity better? I will check this hypothesis and will write a future article on this subject.</p><h3>References</h3><ul><li><a href="https://github.com/sestegra/vault_pki_terraform">GitHub - sestegra/vault_pki_terraform</a></li><li><a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#notice-about-new-multi-issuer-functionalit">PKI - Secrets Engines - HTTP API | Vault | HashiCorp Developer</a></li><li><a href="https://registry.terraform.io/providers/hashicorp/vault">Terraform Registry</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0f760323813" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GitOps with Flux: Leveraging OCI Registry as a State Store]]></title>
            <link>https://sestegra.medium.com/gitops-with-flux-leveraging-oci-registry-as-a-state-store-ffe28dd64836?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffe28dd64836</guid>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[terraform-cloud]]></category>
            <category><![CDATA[flux-cd]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 18:43:08 GMT</pubDate>
            <atom:updated>2023-03-24T09:38:16.684Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UHa7xZKnsotBvBotc6_HFg.png" /><figcaption>Flux — <a href="https://www.cncf.io/projects/flux/">https://www.cncf.io/projects/flux/</a></figcaption></figure><h3>Introduction</h3><p>GitOps does not simply mean using Git with YAML configuration files and Kubernetes operators.</p><p>This article will explore what GitOps truly entails, its use cases, and available tools.</p><p>Furthermore, it will demonstrate how an OCI registry can be an alternative to a Git repository as a desired state store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4DdNpgcHkXruTDxDDc9MA.png" /><figcaption>OpenGitOps — <a href="https://opengitops.dev/">https://opengitops.dev/</a></figcaption></figure><h3>What’s GitOps</h3><p>According to <a href="https://opengitops.dev/">OpenGitOps</a> (<a href="https://landscape.cncf.io/?selected=open-git-ops">CNCF Sandbox project</a> owned by the <a href="https://github.com/cncf/tag-app-delivery/tree/main/gitops-wg">GitOps Working Group</a>), the <a href="https://opengitops.dev/#principles">GitOps Principles 1.0.0</a> are the following:</p><ol><li><strong>Declarative</strong>: A system managed by GitOps must have its desired state expressed declaratively.</li><li><strong>Versioned and Immutable:</strong> Desired state is stored in a way that enforces immutability, versioning and retains a complete version history.</li><li><strong>Pulled Automatically:</strong> Software agents automatically pull the desired state declarations from the source.</li><li><strong>Continuously Reconciled:</strong> Software agents continuously observe actual system state and attempt to apply the desired state.</li></ol><p>To better understand these important concepts, <a href="https://opengitops.dev/">OpenGitOps</a> has provided a list of terms to help for understanding the main ideas and details of each term. By using this list, these concepts can be applied in your work and can be explained to others more easily.</p><ul><li><strong>Continuous</strong>: “Continuous” is intended to match the industry standard term: <strong>reconciliation</strong> continues to happen, not that it must be instantaneous.</li><li><strong>Declarative Description</strong>: A configuration that describes the desired operating state of a system without specifying procedures for how that state will be achieved. This separates configuration (the desired state) from the implementation (commands, API calls, scripts etc.) used to achieve that state.</li><li><strong>Desired State:</strong> The aggregate of all configuration data that is sufficient to recreate the system so that instances of the system are behaviourally indistinguishable. This configuration data generally does not include persistent application data, eg. database contents, though often does include credentials for accessing that data, or configuration for data recovery tools running on that system.</li><li><strong>Drift</strong>: When a system’s actual state has moved or is in the process of moving away from the <strong>desired state</strong>, this is often referred to as drift.</li><li><strong>Reconciliation</strong>: The process of ensuring the actual state of a system matches its <strong>desired state</strong>. Contrary to traditional CI/CD where automation is generally driven by pre-set triggers, in GitOps reconciliation is triggered whenever there is a divergence. Divergence could be due to the actual state unintentionally <strong>drifting</strong> from the <strong>desired state</strong> declarations, or a new desired state declaration version having been changed intentionally. Actions are taken based on policies around <strong>feedback</strong> from the system and previous reconciliation attempts, in order to reduce deviation over time.</li><li><strong>Software System:</strong> A software system managed by GitOps includes:<br>1. One or more runtime environments consisting of resources under management<br>2. The management agents within each runtime<br>3. Policies for controlling access and management of repositories, deployments, runtimes</li><li><strong>State Store</strong>: A system for storing immutable versions of <strong>desired state</strong> <strong>declarations</strong>. This state store should provide access control and auditing on the changes to the <strong>desired state</strong>. Git, from which GitOps derives its name, is the canonical example used as this state store but any other system that meets these criteria may be used. In all cases, these state stores must be properly configured and precautions must be taken to comply with requirements set out in the GitOps Principles.</li><li><strong>Feedback</strong>: Open GitOps follows <a href="https://en.wikipedia.org/wiki/Control_theory">control-theory</a> and operates in a closed-loop. In control theory, feedback represents how previous attempts to apply a <strong>desired state</strong> have affected the actual state. For example if the <strong>desired state</strong> requires more resources than exist in a system, the software agent may make attempts to add resources, to automatically rollback to a previous version, or to send alerts to human operators.</li></ul><p>The GitOps principles and these terms are licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a> license by <a href="https://opengitops.dev/">OpenGitOps</a>.</p><p>Now that “What’s GitOps” was covered, let’s explore some of its use cases and take a closer look at some of the most common and impactful GitOps use cases.</p><h3>GitOps Use Cases</h3><p>The benefits of GitOps are numerous, including increased security, better auditability, and improved collaboration. In fact, GitOps has become so popular that it is now being used in a variety of different use cases such as the following.</p><ul><li><strong>Infrastructure management</strong>: GitOps allows you to manage infrastructure as code (IaC), making it easy to version control, review, and apply infrastructure changes. This approach reduces human error.</li><li><strong>Application deployment</strong>: GitOps simplifies application deployment by automating the process and maintaining the desired state in a state store. This enables easy rollbacks, and version control.</li><li><strong>Multi-environment and multi-tenant management</strong>: GitOps makes it easy to manage multiple environments (e.g., dev, staging, prod) and multiple tenants with different configurations.</li><li><strong>Compliance and auditing</strong>: GitOps provides a transparent history of all changes, making it easy to track and audit infrastructure and application changes. This is particularly useful for organizations that need to adhere to strict compliance regulations.</li><li><strong>Disaster recovery</strong>: GitOps helps in disaster recovery by maintaining the desired state in a state store. In case of a disaster, you can easily restore the system to its last known good state by applying the configurations from the state store.</li></ul><p>Leveraging the <strong>Platform Team</strong> through the implementation of these use cases can greatly enhance the effectiveness of GitOps.</p><p>Mainly, GitOps provides a streamlined approach to platform teams, enabling organizations to increase their efficiency. With the capability to centrally manage infrastructure and application deployment, developers can concentrate on their core responsibilities of software creation and improvement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*phG4PCbxtMafxwcY2q2KaQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/es/@tekton_tools?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Tekton</a> on <a href="https://unsplash.com/photos/SVpCSOCcCwA?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>GitOps tools</h3><p>To implement GitOps and leverage its benefits, organizations need the right tools and technologies. Fortunately, there are many GitOps tools available that can help teams implement this approach quickly and effectively.</p><p>Before proceeding, let’s review the GitOps principles through tooling.</p><h4><strong>Declarative Configuration</strong></h4><p>Just because something is declarative, it doesn’t mean that it must use YAML configuration files. It could also use other configuration files or software languages that compile, transform, or generate configurations. As long as the configuration can be stored and used as a source of trust in the right way, it can be considered declarative.</p><p>So, the possible solutions for defining a declarative configuration are:<br>- <a href="https://yaml.org/">YAML</a><br>- <a href="https://carvel.dev/ytt/">ytt</a> (from Carvel projet)<br>- <a href="https://www.pulumi.com/">Pulumi</a><br>- <a href="https://cuelang.org/">Cue Lang</a><br>- <a href="https://github.com/bazelbuild/starlark">Starlark</a><br>- <a href="https://github.com/hashicorp/hcl">HCL</a> (HCL is the HashiCorp configuration language)<br>- <a href="https://developer.hashicorp.com/terraform/cdktf">CDK for Terraform</a></p><h4><strong>Versioned and Immutable</strong></h4><p>Git’s versioning and immutability features are great, but not everyone enjoys the user experience using Git CLI. To address this, graphical user interfaces, automation, and other tools can be leveraged to improve the workflow. Possible UIs are the following:</p><ul><li>Git UI<br>- <a href="https://github.com/">GitHub</a><br>- <a href="https://about.gitlab.com/">Gitlab</a></li><li>GitOps UI<br>- <a href="https://argo-cd.readthedocs.io/en/stable">Argo CD</a> web UI<br>- <a href="https://docs.gitops.weave.works/">Weave GitOps</a> web UI for Flux<br>- <a href="https://fleet.rancher.io/">Rancher Fleet</a> in Rancher UI<br>- <a href="https://developer.hashicorp.com/terraform/tutorials/cloud-get-started/cloud-sign-up">Terraform Cloud</a> web UI (using VCS workflow)</li></ul><p>Then, most of GitOps tools rely on Git for the state store. In contrast, the <a href="https://fluxcd.io/flux/components/source/">Flux Source Controllers</a> can use a Git repository, a storage bucket, or an OCI registry (see dedicated section below).</p><h4><strong>Pulled Automatically and</strong> C<strong>ontinuously Reconciled</strong></h4><p>GitOps tools use a periodic timer as a trigger for pulling configurations from the state store. This trigger can usually be paused, enabled or forced manually.</p><p>The reconciliation does not mean that it must necessarily use Kubernetes operators, but other reconciliations can be used: for instance, the <a href="https://www.hashicorp.com/campaign/drift-detection-for-terraform-cloud">drift detection for Terraform Cloud</a> enables reconciliation using the Terraform state.</p><h4>GitOps Toolsets</h4><p>Combining GitOps principles, the following tools are possible GitOps toolsets with some useful extensions such as event notifications and deployment policy management:</p><ul><li><a href="https://argoproj.github.io/">Argo<br></a>- <a href="https://argoproj.github.io/cd">Argo CD</a><br>- <a href="https://argoproj.github.io/rollouts">Argo Rollouts</a><br>- <a href="https://argoproj.github.io/events">Argo Events</a></li><li><a href="https://fluxcd.io/flux/components/">Flux Toolkit</a><br>- <a href="https://fluxcd.io/flux/components/source/">Source Controllers</a><br>- <a href="https://fluxcd.io/flux/components/kustomize/">Kustomize Controllers</a><br>- <a href="https://fluxcd.io/flux/components/helm/">Helm Controllers</a><br>- <a href="https://fluxcd.io/flux/components/notification/">Notification Controller</a><br>- <a href="https://fluxcd.io/flux/components/image/">Image Automation Controller</a><br>- <a href="https://fluxcd.io/flagger/">Flagger</a><br>- <a href="https://weaveworks.github.io/tf-controller/">Terraform Controller</a></li><li><a href="https://fleet.rancher.io/architecture">Rancher Fleet</a></li><li><a href="https://developer.hashicorp.com/terraform/tutorials/cloud-get-started/cloud-sign-up">Terraform Cloud</a></li></ul><h3>OCI registry as state store</h3><p>OCI registry is a core component for the cloud native ecosystem.</p><p>More or more tools can relying on OCI registries to store their configurations. The following tools can leverage OCI registry as its source of trust.</p><ul><li><a href="https://github.com/GoogleContainerTools/kpt-config-sync">Config Sync</a> by Google (from <a href="https://kpt.dev/">kpt project</a>)</li><li><a href="https://fluxcd.io/">Flux</a> by CNCF (using <a href="https://fluxcd.io/flux/components/source/ocirepositories/">OCIRepositories</a>)</li><li><a href="https://helm.sh/">Helm</a> by CNCF (using <a href="https://helm.sh/docs/topics/registries/">OCI-based registries</a>)</li><li><a href="https://carvel.dev/imgpkg/">imgpkg</a> by CNCF (from <a href="https://carvel.dev/">Carvel project</a>)</li><li>…</li></ul><p>OCI registry can be used by Flux as a state store. The image tag immutability must be enforce to comply with the GitOps principles.</p><p>How to configure image tag immutability for the main registry providers.<br>- <a href="https://aws.amazon.com/ecr/">Amazon ECR</a> (using image tag immutability)<br>- <a href="https://azure.microsoft.com/en-us/products/container-registry">Azure Container Registry</a> (using tag locking policy)<br>- <a href="https://cloud.google.com/container-registry">Google Container Registry</a> (<a href="https://issuetracker.google.com/issues/243123217">feature request for image tag immutability</a>)<br>- <a href="https://goharbor.io/">Harbor</a> (using tag immutability rules)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*2PydZ8CmuMx2-IlY1TL0sw.png" /><figcaption>GitOps with GIt only — Flux source controller clones Git to get desired state</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*6WfDYNdyo7yj-MU7s8LHYA.png" /><figcaption>GitOps with OCI Registry — Flux pulls desired state from OCI Registry</figcaption></figure><p>Using an OCI registry as a state store for GitOps provides several advantages over using Git alone.</p><ul><li>Pulling an OCI image is a much less resource-intensive process compared to cloning a Git repository, making it more efficient for deployment purposes.</li><li>High available registries are easier to deploy than Git servers, making it easy to access and deploy container images from any location.</li><li>OCI repositories can scale out similarly to a Content Delivery Network, enabling platform team to distribute configurations globally with ease.</li><li>Flux uses Kubernetes workload identity and IAM to pull OCI artifacts from managed registries. This eliminates the need for key management, SSH key generation, and proprietary API usage for token generation. Instead, the same mechanism used for pulling container images for applications is used.</li><li>OCI images can be signed and verified during container deployment. Flux supports these verifications, out of the box.</li></ul><p>Overall, leveraging Flux with the use of an OCI registry as a state store can enhance the scalability, reliability, and security of GitOps deployments.</p><p>Moreover, using OCI instead of Git can be particularly useful when the Git repository doesn’t contain the final configuration files. If you’re using <a href="https://carvel.dev/ytt/">ytt, </a><a href="https://developer.hashicorp.com/terraform/cdktf">CDK for Terraform, </a><a href="https://www.pulumi.com/">Pulumi, </a><a href="https://cuelang.org/">Cue Lang, </a><a href="https://github.com/bazelbuild/starlark">Starlark</a>, or any other tool that generates configuration files, the generators can be run in a build pipeline and the resulting configuration can be published as OCI artifacts using the <a href="https://fluxcd.io/flux/cheatsheets/oci-artifacts/">Flux CLI</a> for instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UHa7xZKnsotBvBotc6_HFg.png" /></figure><h3>Conclusion</h3><p><a href="https://fluxcd.io/flux/components/">Flux GitOps Toolkit</a>, in addition to its composability, fully relies on the standard Kubernetes API and can extract the desired state configuration from OCI registries, which is a significant advantage over ArgoCD or Rancher Fleet when targeting multiple Kubernetes clusters.</p><p>On the other hand, <a href="https://developer.hashicorp.com/terraform/tutorials/cloud-get-started/cloud-sign-up">Terraform Cloud</a> can be used to implement GitOps principles to manage everything as code, such as infrastructure, networking, applications codification…</p><h3>Resources</h3><ul><li><strong>OpenGitOps — GitOps Principles<br></strong><a href="https://opengitops.dev/#principles">https://opengitops.dev/#principles</a></li><li><strong>OpenGitOps — GitOps Glossary<br></strong><a href="https://github.com/open-gitops/documents/blob/v1.0.0/GLOSSARY.md#software-system">https://github.com/open-gitops/documents/blob/v1.0.0/GLOSSARY.md#software-system</a></li><li><strong>YAML<br></strong><a href="https://yaml.org/">https://yaml.org/</a></li><li><strong>HCL configuration files<br></strong><a href="https://github.com/hashicorp/hcl">https://github.com/hashicorp/hcl</a></li><li><strong>CDK for Terraform<br></strong><a href="https://developer.hashicorp.com/terraform/cdktf">https://developer.hashicorp.com/terraform/cdktf</a></li><li><strong>Pulumi<br></strong><a href="https://www.pulumi.com/">https://www.pulumi.com/</a></li><li><strong>Cue Lang<br></strong><a href="https://cuelang.org/">https://cuelang.org/</a></li><li><strong>Starlark<br></strong><a href="https://github.com/bazelbuild/starlark">https://github.com/bazelbuild/starlark</a></li><li><strong>Argo<br></strong><a href="https://argoproj.github.io/">https://argoproj.github.io/</a></li><li><strong>Flux GitOps Toolkit<br></strong><a href="https://fluxcd.io/flux/components/">https://fluxcd.io/flux/components/</a></li><li><strong>Rancher Fleet<br></strong><a href="https://fleet.rancher.io/architecture">https://fleet.rancher.io/architecture</a></li><li><strong>Terraform Cloud<br></strong><a href="https://developer.hashicorp.com/terraform/tutorials/cloud-get-started/cloud-sign-up">https://developer.hashicorp.com/terraform/tutorials/cloud-get-started/cloud-sign-up</a></li><li><strong>Drift Detection for Terraform Cloud<br></strong><a href="https://www.hashicorp.com/campaign/drift-detection-for-terraform-cloud">https://www.hashicorp.com/campaign/drift-detection-for-terraform-cloud</a></li><li><strong>Open Container Initiative<br></strong><a href="https://opencontainers.org/">https://opencontainers.org/</a></li><li><strong>Flux — OCI cheatsheet<br></strong><a href="https://fluxcd.io/flux/cheatsheets/oci-artifacts/">https://fluxcd.io/flux/cheatsheets/oci-artifacts/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffe28dd64836" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securely store Public Certificates in Vault, generated by acme.sh]]></title>
            <link>https://sestegra.medium.com/securely-store-public-certificates-in-vault-generated-by-acme-sh-2d6e98c9d308?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d6e98c9d308</guid>
            <category><![CDATA[hashicorp-vault]]></category>
            <category><![CDATA[hashicorp]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Wed, 28 Sep 2022 18:38:39 GMT</pubDate>
            <atom:updated>2023-07-16T13:53:52.351Z</atom:updated>
            <content:encoded><![CDATA[<p>Automate your Certificates Lifecycle with Vault — Part 4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*geKaaDT51JxP5IZByAwHPA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@juvnsky?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Anton Maksimov 5642.su</a> on <a href="https://unsplash.com/s/photos/technology?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>This article is a part of a series about how to<br><a href="https://medium.com/@sestegra/automate-your-certificates-lifecycle-with-vault-bc7ffff2430c"><strong>Automate your Certificates Lifecycle with Vault</strong></a>.</blockquote><ol><li><a href="https://medium.com/@sestegra/build-an-internal-pki-with-vault-f7179306f18c">Build an Internal PKI with Vault</a></li><li><a href="https://medium.com/@sestegra/issue-deploy-and-renew-your-private-certificates-with-vault-and-consul-template-1f5e4fe5f15c">Issue, Deploy and Renew your Private Certificates with Vault and Consul-Template</a></li><li><a href="https://medium.com/@sestegra/rotate-your-ca-seamlessly-using-a-vault-pki-9262228b4afb">Rotate your CA seamlessly using a Vault PKI</a></li><li><a href="https://medium.com/@sestegra/securely-store-public-certificates-in-vault-generated-by-acme-sh-2d6e98c9d308"><strong>Securely store Public Certificates in Vault, generated by acme.sh</strong></a><strong> (this article)</strong></li><li><a href="https://medium.com/@sestegra/codify-vault-internal-pki-using-terraform-c0f760323813">Codify Vault Internal PKI using Terraform</a></li></ol><h3>Introduction</h3><p>This article presents a solution to manage your public certificates and securely store your public certificates in Vault, generated by acme.sh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*KNLHrQb2r0MHy6Wbmmd_kA.png" /><figcaption>ACME.sh</figcaption></figure><p>Then, as soon as the public certificates are stored in Vault, <strong>consul-template</strong> (or other similar solutions) can be used to deploy and automatically update the deployed certificate when ACME.sh renews certificates.</p><blockquote>Let’s Encrypt among other providers is compatible with ACME.sh as well. Here are the differences between ZeroSSL and Let’s Encrypt.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VBGJUrCAz3cVM2c9" /><figcaption>ZeroSSL vs Let’s Encrypt</figcaption></figure><h3>Pre-Requisites</h3><p>Launch Vault Server in Dev mode using root as a root token id. The root token is used on purpose to focus only on the KV secret engine features.</p><blockquote><strong>Disclaimer</strong>: On production<br>- Don’t use the root token<br>- Create auth methods, entities, groups and policies to grant or forbid access to KV features</blockquote><pre>$ <strong>vault server -dev -dev-root-token-id=root</strong></pre><h3>Create ZeroSSL credentials</h3><ul><li>First, let’s create a ZeroSSL account on <a href="https://zerossl.com/">https://zerossl.com</a></li><li>Then, go to <strong>Developer</strong> page</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OdWEMeUfqjAfvV4bB8FNkg.png" /></figure><ul><li>In <strong>EAB Credentials for ACME Clients</strong> section, click on the <strong>Generate</strong> button, then copy <strong>EAB KID</strong> and <strong>EAB HMAC Key</strong> fields.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*wZmw5cqKVAAQCGkx28Av4g.png" /></figure><h3>Install and Configure ACME.sh</h3><blockquote>For further details, please read the ACME.sh documentation.</blockquote><p>ACME.sh is a pure Unix shell script implementing ACME client protocol</p><p>To install and configure ACME.sh, follow these instructions.</p><ul><li>Install the script and the crontab entry to renew certificate automatically</li></ul><pre><strong>$ curl </strong><a href="https://get.acme.sh/"><strong>https://get.acme.sh</strong></a><strong> | sh -s email=me@example.com</strong></pre><ul><li>Register to ZeroSSL by using the copied values in previous section</li></ul><pre><strong>$ acme.sh --register-account \<br>    --server zerossl \<br>    --eab-kid &lt;EAB KID&gt; \<br>    --eab-hmac-key &lt;EAB HMAC Key&gt;</strong></pre><ul><li>Enable KV secret engine on Vault to store the certificate, key and CA chain</li></ul><pre><strong>$ vault secrets enable -path=acme kv</strong></pre><h3>Issue and Deploy Certificate</h3><ul><li>Let’s issue an ECDSA certificate using the DNS Challenge on CloudFlare, then verify it.</li></ul><pre><strong>$ export CF_Token=xxxxxxxxx</strong><br><strong>$ acme.sh --issue -k ec-256 --dns dns_cf \<br>    -d example.com --always-force-new-domain-key<br>...</strong></pre><pre><strong>$ openssl x509 -in ~/.acme.sh/example.com_ecc/example.com.cer \<br>    -issuer -subject -startdate -enddate -noout</strong><br>issuer=C = AT, O = ZeroSSL, CN = ZeroSSL ECC Domain Secure Site CA<br>subject=CN = example.com<br>notBefore=Sep 20 00:00:00 2022 GMT<br>notAfter=Dec 19 23:59:59 2022 GMT</pre><ul><li>Next, update .acme.sh/deploy/vault_cli.shto add ttl=0 in Vault commands at the end of the script. By doing so, the secret polling period is managed by <strong>consul-template </strong>configuration <strong>(</strong>see default_lease_duration in <strong>Consul Template</strong> section below)</li></ul><pre>if [ -n &quot;$FABIO&quot; ]; then<br>  $VAULT_CMD kv put ... key=@&quot;$_ckey&quot; || return 1<br>else<br>  $VAULT_CMD kv put ... value=@&quot;$_ccert&quot; <strong>ttl=0</strong> || return 1<br>  $VAULT_CMD kv put ... value=@&quot;$_ckey&quot; <strong>ttl=0</strong> || return 1<br>  $VAULT_CMD kv put ... value=@&quot;$_cca&quot; <strong>ttl=0</strong> || return 1<br>  $VAULT_CMD kv put ... value=@&quot;$_cfullchain&quot; <strong>ttl=0</strong> || return 1<br>fi</pre><ul><li>Finally, deploy the certificate to Vault</li></ul><pre><strong>$ export VAULT_ADDR=http://127.0.0.1:8200<br>$ export VAULT_TOKEN=root<br>$ acme.sh --deploy --ecc -d example.com --deploy-hook vault_cli<br></strong>Success! Data written to: acme/example.com/cert.pem<br>Success! Data written to: acme/example.com/cert.key<br>Success! Data written to: acme/example.com/chain.pem<br>Success! Data written to: acme/example.com/fullchain.pem</pre><pre><strong>$ vault kv list acme/example.com</strong><br>Keys<br>----<br>cert.key<br>cert.pem<br>chain.pem<br>fullchain.pem<br><strong>$ vault kv get acme/example.com/cert.pem<br>$ vault kv get acme/example.com/cert.key</strong></pre><h3><strong>Consul Template</strong></h3><p>The following templates query Vault to get respectively the private key, the certificate, the CA chain and the fullchain.</p><pre>{{- with <strong>secret &quot;acme/example.com/cert.key&quot;</strong> -}}<br>{{ <strong>.Data.value</strong> }}<br>{{- end -}}</pre><pre>{{- with <strong>secret &quot;acme/example.com/cert.pem&quot;</strong> -}}<br>{{ .Data.value }}<br>{{- end -}}</pre><pre>{{- with <strong>secret &quot;acme/example.com/chain.pem&quot;</strong> -}}<br>{{ .Data.value }}<br>{{- end -}}</pre><pre>{{- with <strong>secret &quot;acme/example.com/fullchain.pem&quot;</strong> -}}<br>{{ .Data.value }}<br>{{- end -}}</pre><p>First of all, the <strong>consul-template</strong> daemon should be configured with a dedicated configuration file:</p><ul><li>to connect to the Vault server</li><li>to generate files from specified templates</li></ul><blockquote>Read the <a href="https://github.com/hashicorp/consul-template/blob/main/docs/configuration.md">configuration documentation</a> for further information</blockquote><p>Here is a configuration file that queries cert.key and cert.crt from KV secret engine on acme mount for example.com domain.</p><blockquote><strong>Disclaimer</strong>: On production<br>- Don’t use the root token<br>- Create auth methods, entities, groups and policies to grant or forbid access to KV features</blockquote><pre>$ cat &lt;&lt;EOF &gt; <strong>consul-template-acme.hcl</strong><br>vault {<br>  address     = &quot;http://127.0.0.1:8200&quot;<br>  token       = &quot;root&quot;<br>  renew_token = false</pre><pre><strong>  default_lease_duration = &quot;10s&quot;<br></strong>}</pre><pre>template {<br>  contents = &lt;&lt;EOH<br>{{- with secret &quot;acme/example.com/cert.key&quot; -}}<br>{{ .Data.value }}<br>{{- end }}<br>EOH<br>  destination = &quot;cert.key&quot;<br>  exec {<br>    command = [ &quot;cat&quot;, &quot;cert.key&quot; ]<br>  }<br>}</pre><pre>template {<br>  contents = &lt;&lt;EOH<br>{{- with secret &quot;acme/example.com/cert.pem&quot; -}}<br>{{ .Data.value }}<br>{{- end }}<br>EOH<br>  destination = &quot;cert.crt&quot;<br>  exec {<br>    command = [ &quot;openssl&quot;, &quot;x509&quot;, &quot;-in&quot;, &quot;cert.crt&quot;, &quot;-text&quot;, &quot;-noout&quot; ]<br>  }<br>}<br>EOF</pre><ul><li>Start <strong>consul-template </strong>to check the generated files.</li></ul><pre><strong>$ consul-template -config=consul-template-acme.hcl -log-level info<br></strong>[INFO] consul-template v0.29.2 (06389a3d)<br>[INFO] (runner) creating new runner (dry: false, once: false)<br>[INFO] (runner) creating watcher<br>[INFO] (runner) starting<br>[INFO] (runner) rendered &quot;(dynamic)&quot; =&gt; &quot;cert.key&quot;<br>[INFO] (runner) executing command &quot;[\&quot;cat\&quot; \&quot;cert.key\&quot;]&quot; from &quot;(dynamic)&quot; =&gt; &quot;cert.key&quot;<br>[INFO] (child) spawning: cat cert.key<br>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIKk4jGLCfwcLyB913K+5bQDEOURBv2Ex+P1cnpxNvvcKoAoGCCqGSM49<br>AwEHoUQDQgAEoZNWBcOP4lABJdiz9CTeXW9FDirBD7mNPzsvGIJ69Y1vEby871iD<br>30nz2iKVrvx2/XUslneUdWCv77TYYfwtoA==<br>-----END EC PRIVATE KEY-----</pre><pre>[INFO] (runner) rendered &quot;(dynamic)&quot; =&gt; &quot;cert.crt&quot;<br>[INFO] (runner) executing command &quot;[\&quot;openssl\&quot; \&quot;x509\&quot; \&quot;-in\&quot; \&quot;cert.crt\&quot; \&quot;-text\&quot; \&quot;-noout\&quot;]&quot; from &quot;(dynamic)&quot; =&gt; &quot;cert.crt&quot;<br>[INFO] (child) spawning: openssl x509 -in cert.crt -text -noout<br>Certificate:<br>...<br>       Issuer: C = AT, O = ZeroSSL, CN = ZeroSSL ECC...<br>        Validity<br>            Not Before: Sep 20 00:00:00 2022 GMT<br>            Not After : Dec 19 23:59:59 2022 GMT<br>        Subject: CN = example.com</pre><h3>Renew Certificate</h3><p>The renewal is managed by ACME.sh using the crontab entry. By default, ACME.sh renews the certificate at 2/3 of the TTL (i.e. every 60 days).</p><p>To force the renewal, let’s launch the related ACME.sh command.</p><pre><strong>$ acme.sh --renew -d example.com --ecc --force</strong></pre><p>Now, let’s check the terminal where <strong>consul-template</strong> is running. After the renewal of the certificate, ACME.sh deploys it into Vault, then <strong>consul-template </strong>renders the updated certificate and key.</p><pre>[INFO] (runner) rendered &quot;(dynamic)&quot; =&gt; &quot;cert.key&quot;<br>[INFO] (runner) executing command &quot;[\&quot;cat\&quot; \&quot;cert.key\&quot;]&quot; from &quot;(dynamic)&quot; =&gt; &quot;cert.key&quot;<br>[INFO] (child) spawning: cat cert.key<br>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIKk4jGLCfwcLyB913K+5bQDEOURBv2Ex+P1cnpxNvvcKoAoGCCqGSM49<br>AwEHoUQDQgAEoZNWBcOP4lABJdiz9CTeXW9FDirBD7mNPzsvGIJ69Y1vEby871iD<br>30nz2iKVrvx2/XUslneUdWCv77TYYfwtoA==<br>-----END EC PRIVATE KEY-----</pre><pre>[INFO] (runner) rendered &quot;(dynamic)&quot; =&gt; &quot;cert.crt&quot;<br>[INFO] (runner) executing command &quot;[\&quot;openssl\&quot; \&quot;x509\&quot; \&quot;-in\&quot; \&quot;cert.crt\&quot; \&quot;-text\&quot; \&quot;-noout\&quot;]&quot; from &quot;(dynamic)&quot; =&gt; &quot;cert.crt&quot;<br>[INFO] (child) spawning: openssl x509 -in cert.crt -text -noout<br>Certificate:<br>...<br>       Issuer: C = AT, O = ZeroSSL, CN = ZeroSSL ECC...<br>        Validity<br>            Not Before: Sep 20 00:00:00 2022 GMT<br>            Not After : Dec 19 23:59:59 2022 GMT<br>        Subject: CN = example.com</pre><h3>Conclusion</h3><p>This article shows a solution to manage your public certificates and securely store your public certificates in Vault, generated by acme.sh.</p><p>Then, as soon as the public certificates are stored in Vault, <strong>consul-template</strong> (or other similar solutions) can be used to deploy and automatically update the deployed certificate when ACME.sh renews certificates.</p><h3>References</h3><ul><li><a href="https://acme.sh/">GitHub - acmesh-official/acme.sh: A pure Unix shell script implementing ACME client protocol</a></li><li><a href="https://www.rfc-editor.org/rfc/rfc8555">RFC 8555: Automatic Certificate Management Environment (ACME)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d6e98c9d308" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rotate your CA seamlessly using a Vault PKI]]></title>
            <link>https://sestegra.medium.com/rotate-your-ca-seamlessly-using-a-vault-pki-9262228b4afb?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9262228b4afb</guid>
            <category><![CDATA[hashicorp-vault]]></category>
            <category><![CDATA[hashicorp]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Wed, 28 Sep 2022 18:38:29 GMT</pubDate>
            <atom:updated>2023-07-16T13:49:13.385Z</atom:updated>
            <content:encoded><![CDATA[<p>Automate your Certificates Lifecycle with Vault — Part 3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ad_xyhvTPgyVJga-upiMog.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@dchestudio?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Daniel Chen</a> on <a href="https://unsplash.com/s/photos/rotate?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>This article is a part of a series about how to<br><a href="https://medium.com/@sestegra/automate-your-certificates-lifecycle-with-vault-bc7ffff2430c"><strong>Automate your Certificates Lifecycle with Vault</strong></a>.</blockquote><ol><li><a href="https://medium.com/@sestegra/build-an-internal-pki-with-vault-f7179306f18c">Build an Internal PKI with Vault</a></li><li><a href="https://medium.com/@sestegra/issue-deploy-and-renew-your-private-certificates-with-vault-and-consul-template-1f5e4fe5f15c">Issue, Deploy and Renew your Private Certificates with Vault and Consul-Template</a></li><li><a href="https://medium.com/@sestegra/rotate-your-ca-seamlessly-using-a-vault-pki-9262228b4afb"><strong>Rotate your CA seamlessly using a Vault PKI</strong></a><strong> (this article)</strong></li><li><a href="https://medium.com/@sestegra/securely-store-public-certificates-in-vault-generated-by-acme-sh-2d6e98c9d308">Securely store Public Certificates in Vault, generated by acme.sh</a></li><li><a href="https://medium.com/@sestegra/codify-vault-internal-pki-using-terraform-c0f760323813">Codify Vault Internal PKI using Terraform</a></li></ol><h3>Introduction</h3><p>This article contains a walkthrough to rotate the Issuing, Intermediate and Root CA from Vault PKI built in the first article of this series.</p><h3>Pre-Requisites</h3><ul><li>Create a three-tier PKI CA from the <a href="https://medium.com/@sestegra/build-an-internal-pki-with-vault-f7179306f18c">Build an Internal PKI with Vault</a> article with one of the following solutions:<br> — Follow the walkthrough step by step<br> — Follow the <a href="https://medium.com/@sestegra/build-an-internal-pki-with-vault-f7179306f18c#6258"><strong>Summary of commands</strong></a><strong> </strong>section<strong> </strong>(at the end of the article)</li><li>Launch <strong>consul-template</strong> with <a href="https://medium.com/@sestegra/issue-deploy-and-renew-your-private-certificates-with-vault-and-consul-template-1f5e4fe5f15c#7f31"><strong>Renew Certificate</strong></a> configuration from the previous article</li></ul><h3>Multi-Issuer Feature</h3><p>Since 1.11.0, Vault allows a single PKI secret engine mount to have multiple CA certificates (known as ‘issuer’ in Vault PKI configuration) for the purpose of facilitating rotation.</p><h4>Default issuer</h4><p>In the following diagrams, an issuer is represented by a squared box at the bottom of the CA. For instance, in the next diagram, the issuer is named <strong>v1</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*SYnPfSCbTZrx6TK6aEjHng.png" /><figcaption><strong>default</strong> issuer in CA and <strong>issuer_ref</strong> in role</figcaption></figure><p>By default, thedefault issuer refers to the first CA certificate created on the PKI secret engines (<strong>v1</strong> in the previous diagram).</p><p>By default, when creating a role, the default issuer is set as the default issuer_ref if not set. The issuer_ref is the reference to an existing issuer in the CA for issuing the leaf certificates.</p><p>As a result, the leaf certificates (generated by role X) are issued by the <strong>v1</strong> issuer (as issuer_ref = default = v1).</p><h4><strong>CA Rotation</strong></h4><p>In the following diagrams, the default issuer has a <strong>red border</strong>. For instance, in the next diagram, the default issuer is <strong>v1</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*qr9Ccl9pgkwnGEjAKqa8Uw.png" /><figcaption>Before rotation</figcaption></figure><p>In the ‘Before rotation’ diagram, a new issuer named <strong>v2</strong> has been created in addition to <strong>v1</strong>. The leaf certificates (generated by role X) are still issued by the <strong>v1</strong> issuer. Moreover, two new roles have been created as well:</p><ul><li><strong>role Y</strong> for issuing leaf certificates with the <strong>v1</strong> issuer because issuer_ref is equal to v1</li><li><strong>role Z</strong> for issuing leaf certificates with the <strong>v2</strong> issuer because issuer_ref is equal to v2</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*ZrHSUiTn066H4i_QVwPnBA.png" /><figcaption>After rotation</figcaption></figure><p>By updating the default issuer to the <strong>v2</strong> issuer in the CA configuration, the leaf certificates (generated by role X) are now issued by the <strong>v2</strong> issuer, and roles Y and Z are still issuing leaf certificates using, respectively, <strong>v1</strong> and <strong>v2</strong> issuers.</p><p>Thanks to this technique, you can manage the CA rotation seamlessly.</p><p>In the next three sections, the CA rotation is managed on the Vault PKI.</p><blockquote>Launch <strong>consul-template</strong> with <a href="https://medium.com/@sestegra/issue-deploy-and-renew-your-private-certificates-with-vault-and-consul-template-1f5e4fe5f15c#7f31"><strong>Renew Certificate</strong></a> configuration from the previous article and keep it running while following the next procedures in another terminal.</blockquote><pre><strong>$ consul-template -config=consul-template.hcl</strong><br>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIFEM5nkiEm2i/eEEP1XV3n7k9I8IZapKtNMc9EQLUu9NoAoGCCqGSM49<br>AwEHoUQDQgAEk7G6GdS1lcn16trtzA5eIUyXG28BTg8+Q5c5Z3LltBlSW/prcvgT<br>fzvHC7+/3eNFCKl0P2J8NJMRIvHA/TcUPg==<br>-----END EC PRIVATE KEY-----<br>issuer=O = Example, CN = Example Labs Issuing CA v1.1.1<br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 13:17:19 2022 GMT<br>notAfter=Sep 20 13:18:19 2022 GMT<br>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIOqeSC1afjMvPCuCMKoVsataoyIvu/DeF/B7PeZEVWx8oAoGCCqGSM49<br>AwEHoUQDQgAEwLQlUF99S0b9E4x3nSm8RuyaKv6kG5qbSIA5lu5K061B2SaGeNHN<br>lKhOmLuGf0aURfqpoU/iLjJt0K9jnznQvw==<br>-----END EC PRIVATE KEY-----<br>issuer=O = Example, CN = Example Labs Issuing CA v1.1.1<br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 13:17:46 2022 GMT<br>notAfter=Sep 20 13:18:46 2022 GMT<br>...</pre><h3>Rotate Issuing CA</h3><p>First, let’s update the Issuing CA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*EffJAhJNBXF0YIT4eXOpKw.png" /><figcaption>Rename issuers</figcaption></figure><p>To ease the next steps, let’s rename the issuers pointed by the default issuer of each CA.</p><ul><li>List and rename the default issuer of <strong>Intermediate CA</strong> to <strong>v1.1 </strong>using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#update-issuer">pki_int/issuer/default</a> endpoint</li></ul><pre><strong>$ vault list -detailed pki_int/issuers</strong><br>Keys                                    is_default    issuer_name<br>----                                    ----------    -----------<br>17438773-df12-5bab-a7ee-83a7305037fb    true          n/a<br><strong>$ vault write -format=json \<br>    pki_int/issuer/default \<br>    issuer_name=v1.1 \<br>    &gt; pki_int_v1.1.rename.json<br>$ cat pki_int_v1.1.rename.json</strong><br>{<br>  &quot;request_id&quot;: &quot;9e8ca209-b6ef-835c-cc32-0b7ea97f1c23&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB2DCCAX2gAwIBAgIRAMlAuLmxYK0hqR4uaheiDMowCgYIKoZIzj0EAwIwNDEQ\nMA4GA1UEChMHRXhhbXBsZTEgMB4GA1UEAxMXRXhhbXBsZSBMYWJzIFJvb3QgQ0Eg\ndjEwHhcNMjIwOTE5MTQ1NTA4WhcNMjcwOTE5MTUwNTA4WjA+MRAwDgYDVQQKEwdF\neGFtcGxlMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRpYXRlIENBIHYx\nLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATBv71in6dt4FYoFIUWPEl8/PTk\nN7vIryxD2sff7PY421erP9ZlWjG3dG5+1kFvHUrp26PGBYid304oVPIYWPHIo2Yw\nZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU\n1v5Vz/G4Ai+KsgSqLatba/3vJMIwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDIlZxg\n7z5RvXYwCgYIKoZIzj0EAwIDSQAwRgIhAIgYXf1QhKLiAZxp08viP0jU57qRkNMP\nxYSDwURq/rvoAiEAuq3Wytby/RsaMUvPhjOT0CR7fim9Pwaw1W5HdZ1WWg0=\n-----END CERTIFICATE-----\n&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIIB2DCCAX2gAwIBAgIRAMlAuLmxYK0hqR4uaheiDMowCgYIKoZIzj0EAwIwNDEQ\nMA4GA1UEChMHRXhhbXBsZTEgMB4GA1UEAxMXRXhhbXBsZSBMYWJzIFJvb3QgQ0Eg\ndjEwHhcNMjIwOTE5MTQ1NTA4WhcNMjcwOTE5MTUwNTA4WjA+MRAwDgYDVQQKEwdF\neGFtcGxlMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRpYXRlIENBIHYx\nLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATBv71in6dt4FYoFIUWPEl8/PTk\nN7vIryxD2sff7PY421erP9ZlWjG3dG5+1kFvHUrp26PGBYid304oVPIYWPHIo2Yw\nZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU\n1v5Vz/G4Ai+KsgSqLatba/3vJMIwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDIlZxg\n7z5RvXYwCgYIKoZIzj0EAwIDSQAwRgIhAIgYXf1QhKLiAZxp08viP0jU57qRkNMP\nxYSDwURq/rvoAiEAuq3Wytby/RsaMUvPhjOT0CR7fim9Pwaw1W5HdZ1WWg0=\n-----END CERTIFICATE-----\n&quot;,<br><strong>    &quot;issuer_id&quot;: &quot;17438773-df12-5bab-a7ee-83a7305037fb&quot;,<br>    &quot;issuer_name&quot;: &quot;v1.1&quot;,<br></strong>    &quot;key_id&quot;: &quot;abd74d58-4e4c-05a3-2b30-6ad9a8f66038&quot;,<br>    &quot;leaf_not_after_behavior&quot;: &quot;err&quot;,<br>    &quot;manual_chain&quot;: null,<br>    &quot;usage&quot;: &quot;read-only,issuing-certificates,crl-signing&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><ul><li>List and rename the default issuer of <strong>Issuing CA</strong> to <strong>v1.1.1</strong> using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#update-issuer">pki_iss/issuer/default</a> endpoint</li></ul><pre><strong>$ vault list -detailed pki_iss/issuers</strong><br>Keys                                    is_default    issuer_name<br>----                                    ----------    -----------<br>42149e44-785e-3dec-a7e1-ba9e1c4804a0    false         n/a<br>8b135654-2301-3efd-fd20-575e5d56e050    false         n/a<br>957c0c19-a66b-f2fa-b868-05f01bc142e5    true          n/a<strong><br>$ vault write -format=json \<br>    pki_iss/issuer/default \<br>    issuer_name=v1.1.1 \<br>    &gt; pki_iss_v1.1.1.rename.json</strong><br><strong>$ cat pki_iss_v1.1.1.rename.json<br></strong>{<br>  &quot;request_id&quot;: &quot;0f4ce3f2-1d83-a05e-07ec-beef3b319902&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIICWzCCAgGgAwIBAgIUTknVQDg1TmMqIYU/H4Z0j9q6q2IwCgYIKoZIzj0EAwIw\nPjEQMA4GA1UEChMHRXhhbXBsZTEqMCgGA1UEAxMhRXhhbXBsZSBMYWJzIEludGVy\nbWVkaWF0ZSBDQSB2MS4xMB4XDTIyMDkxOTE1MDQzOFoXDTIzMDkxOTE1MDUwOFow\nOzEQMA4GA1UEChMHRXhhbXBsZTEnMCUGA1UEAxMeRXhhbXBsZSBMYWJzIElzc3Vp\nbmcgQ0EgdjEuMS4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEWlU5PUeiItWC\nYyltWZaS4W8fNANZkSjmd2oShXp2nSVDwN4+Dvf2ixFdzUWbklo5cBRLZxweL59c\nhbYsbVgL9qOB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIB\nADAdBgNVHQ4EFgQUqUDW46qmyyNELSER3ILqIXbmgOIwHwYDVR0jBBgwFoAU1v5V\nz/G4Ai+KsgSqLatba/3vJMIwPwYIKwYBBQUHAQEEMzAxMC8GCCsGAQUFBzAChiNo\ndHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNVHR8ELjAsMCqg\nKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jcmwwCgYIKoZI\nzj0EAwIDSAAwRQIhALbt1mZx0pLyGMO8hyUDHfQpRAah0c3dZn5vusIW+vcCAiAz\n/WTjjxMm5QeaEh9KBLQrcXXN2jXV7PI886sLBE/xCQ==\n-----END CERTIFICATE-----\n&quot;,<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB2DCCAX2gAwIBAgIRAMlAuLmxYK0hqR4uaheiDMowCgYIKoZIzj0EAwIwNDEQ\nMA4GA1UEChMHRXhhbXBsZTEgMB4GA1UEAxMXRXhhbXBsZSBMYWJzIFJvb3QgQ0Eg\ndjEwHhcNMjIwOTE5MTQ1NTA4WhcNMjcwOTE5MTUwNTA4WjA+MRAwDgYDVQQKEwdF\neGFtcGxlMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRpYXRlIENBIHYx\nLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATBv71in6dt4FYoFIUWPEl8/PTk\nN7vIryxD2sff7PY421erP9ZlWjG3dG5+1kFvHUrp26PGBYid304oVPIYWPHIo2Yw\nZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU\n1v5Vz/G4Ai+KsgSqLatba/3vJMIwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDIlZxg\n7z5RvXYwCgYIKoZIzj0EAwIDSQAwRgIhAIgYXf1QhKLiAZxp08viP0jU57qRkNMP\nxYSDwURq/rvoAiEAuq3Wytby/RsaMUvPhjOT0CR7fim9Pwaw1W5HdZ1WWg0=\n-----END CERTIFICATE-----\n&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICWzCCAgGgAwIBAgIUTknVQDg1TmMqIYU/H4Z0j9q6q2IwCgYIKoZIzj0EAwIw\nPjEQMA4GA1UEChMHRXhhbXBsZTEqMCgGA1UEAxMhRXhhbXBsZSBMYWJzIEludGVy\nbWVkaWF0ZSBDQSB2MS4xMB4XDTIyMDkxOTE1MDQzOFoXDTIzMDkxOTE1MDUwOFow\nOzEQMA4GA1UEChMHRXhhbXBsZTEnMCUGA1UEAxMeRXhhbXBsZSBMYWJzIElzc3Vp\nbmcgQ0EgdjEuMS4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEWlU5PUeiItWC\nYyltWZaS4W8fNANZkSjmd2oShXp2nSVDwN4+Dvf2ixFdzUWbklo5cBRLZxweL59c\nhbYsbVgL9qOB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIB\nADAdBgNVHQ4EFgQUqUDW46qmyyNELSER3ILqIXbmgOIwHwYDVR0jBBgwFoAU1v5V\nz/G4Ai+KsgSqLatba/3vJMIwPwYIKwYBBQUHAQEEMzAxMC8GCCsGAQUFBzAChiNo\ndHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNVHR8ELjAsMCqg\nKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jcmwwCgYIKoZI\nzj0EAwIDSAAwRQIhALbt1mZx0pLyGMO8hyUDHfQpRAah0c3dZn5vusIW+vcCAiAz\n/WTjjxMm5QeaEh9KBLQrcXXN2jXV7PI886sLBE/xCQ==\n-----END CERTIFICATE-----\n&quot;,<br><strong>    &quot;issuer_id&quot;: &quot;957c0c19-a66b-f2fa-b868-05f01bc142e5&quot;,<br>    &quot;issuer_name&quot;: &quot;v1.1.1&quot;,<br></strong>    &quot;key_id&quot;: &quot;a9461b57-5fe0-7ba8-6abd-8b6766526f65&quot;,<br>    &quot;leaf_not_after_behavior&quot;: &quot;err&quot;,<br>    &quot;manual_chain&quot;: null,<br>    &quot;usage&quot;: &quot;read-only,issuing-certificates,crl-signing&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*oafi5l27rqNoVWaCbgWfXQ.png" /><figcaption>Generate v1.1.2 issuer for Issuing CA</figcaption></figure><p>Now, let’s generate a new issuer for Issuing CA.</p><ul><li>First, generate private key and CSR for <strong>v1.1.2</strong> issuer using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_iss/intermediate/generate/internal</a>endpoint</li></ul><pre><strong>$ vault write -format=json \<br>    pki_iss/intermediate/generate/internal \<br>    organization=&quot;Example&quot; \<br>    common_name=&quot;Example Labs Issuing CA v1.1.2&quot; \<br>    key_type=ec \<br>    key_bits=256 \<br>    &gt; pki_iss_v1.1.2.csr.json<br>$ cat pki_iss_v1.1.2.csr.json</strong><br>{<br>  &quot;request_id&quot;: &quot;e81eed25-bf87-9a0e-8f77-42b77eb79674&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;csr&quot;: &quot;-----BEGIN CERTIFICATE REQUEST-----\nMIH7MIGiAgEAMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhh\nbXBsZSBMYWJzIElzc3VpbmcgQ0EgdjEuMS4yMFkwEwYHKoZIzj0CAQYIKoZIzj0D\nAQcDQgAE3W9Ss1pVeWWZMKKZoSZq+k5HEesw7hyteyuswzHVxAgJ61ppHW0mOb3y\nJubTrYLDXqLaF77V6we6HYHVB8ElvKAAMAoGCCqGSM49BAMCA0gAMEUCIBbP6vvI\n0/+9GkW2agFpyj4LFaxczI8c8oi9aIsA5UhnAiEAkR0uqgpODwYMBgWy0c2Ro1py\ndXhbxna8mY+Pkh6Edbo=\n-----END CERTIFICATE REQUEST-----&quot;,<br>    &quot;key_id&quot;: &quot;70aef752-39ae-6af7-cdc7-38cf6bb3e029&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><ul><li>Extract the CSR from the response and verify it</li></ul><pre><strong>$ cat pki_iss_v1.1.2.csr.json | jq -r &#39;.data.csr&#39; \<br>    &gt; pki_iss_v1.1.2.csr<br>$ openssl req -text -noout -verify -in pki_iss_v1.1.2.csr<br></strong>verify OK<br>Certificate Request:<br>    Data:<br>        Version: 1 (0x0)<br><strong>        Subject: O = Example, CN = Example Labs Issuing CA v1.1.2<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:dd:6f:52:b3:5a:55:79:65:99:30:a2:99:a1:26:<br>                    6a:fa:4e:47:11:eb:30:ee:1c:ad:7b:2b:ac:c3:31:<br>                    d5:c4:08:09:eb:5a:69:1d:6d:26:39:bd:f2:26:e6:<br>                    d3:ad:82:c3:5e:a2:da:17:be:d5:eb:07:ba:1d:81:<br>                    d5:07:c1:25:bc<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        Attributes:<br>            a0:00<br>    Signature Algorithm: ecdsa-with-SHA256<br>         30:45:02:20:16:cf:ea:fb:c8:d3:ff:bd:1a:45:b6:6a:01:69:<br>         ca:3e:0b:15:ac:5c:cc:8f:1c:f2:88:bd:68:8b:00:e5:48:67:<br>         02:21:00:91:1d:2e:aa:0a:4e:0f:06:0c:06:05:b2:d1:cd:91:<br>         a3:5a:72:75:78:5b:c6:76:bc:99:8f:8f:92:1e:84:75:ba</pre><ul><li>Sign and generate a certificate using the CSR with Intermediate CA using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#sign-intermediate">pki_int/root/sign-intermediate</a><strong> </strong>endpoint<strong>.</strong></li></ul><pre><strong>$ vault write -format=json \<br>    pki_int/root/sign-intermediate \<br>    organization=&quot;Example&quot; \<br>    csr=@pki_iss_v1.1.2.csr \<br>    ttl=8760h \<br>    format=pem \<br>    &gt; pki_iss_v1.1.2.crt.json<br>$ cat pki_iss_v1.1.2.crt.json<br></strong>{<br>  &quot;request_id&quot;: &quot;dee3e028-816e-1d38-eab6-eed0a133b8f1&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIICXzCCAgagAwIBAgIUTlImmt7P5VGyZ0yInSv0dZfBOiwwCgYIKoZIzj0EAwIw\nPjEQMA4GA1UEChMHRXhhbXBsZTEqMCgGA1UEAxMhRXhhbXBsZSBMYWJzIEludGVy\nbWVkaWF0ZSBDQSB2MS4xMB4XDTIyMDkyMDEyNTYyN1oXDTIzMDkyMDEyNTY1N1ow\nQDEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMScwJQYDVQQDEx5FeGFtcGxlIExhYnMg\nSXNzdWluZyBDQSB2MS4xLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATdb1Kz\nWlV5ZZkwopmhJmr6TkcR6zDuHK17K6zDMdXECAnrWmkdbSY5vfIm5tOtgsNeotoX\nvtXrB7odgdUHwSW8o4HfMIHcMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG\nAQH/AgEAMB0GA1UdDgQWBBQ3Q5fp1oVoSM8dVztrwzQXVU8aIDAfBgNVHSMEGDAW\ngBTW/lXP8bgCL4qyBKotq1tr/e8kwjA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUH\nMAKGI2h0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NhMDUGA1UdHwQu\nMCwwKqAooCaGJGh0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NybDAK\nBggqhkjOPQQDAgNHADBEAiBwvCW87AC6E9dIeiqalklwLNQD18YJ2q6hOLxIwiVD\nKQIgYlUYXzkHNuPcvQXIbXY88g+EiMf8leGo3iOCQQ/MDRA=\n-----END CERTIFICATE-----&quot;,<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB2DCCAX2gAwIBAgIRAMlAuLmxYK0hqR4uaheiDMowCgYIKoZIzj0EAwIwNDEQ\nMA4GA1UEChMHRXhhbXBsZTEgMB4GA1UEAxMXRXhhbXBsZSBMYWJzIFJvb3QgQ0Eg\ndjEwHhcNMjIwOTE5MTQ1NTA4WhcNMjcwOTE5MTUwNTA4WjA+MRAwDgYDVQQKEwdF\neGFtcGxlMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRpYXRlIENBIHYx\nLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATBv71in6dt4FYoFIUWPEl8/PTk\nN7vIryxD2sff7PY421erP9ZlWjG3dG5+1kFvHUrp26PGBYid304oVPIYWPHIo2Yw\nZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU\n1v5Vz/G4Ai+KsgSqLatba/3vJMIwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDIlZxg\n7z5RvXYwCgYIKoZIzj0EAwIDSQAwRgIhAIgYXf1QhKLiAZxp08viP0jU57qRkNMP\nxYSDwURq/rvoAiEAuq3Wytby/RsaMUvPhjOT0CR7fim9Pwaw1W5HdZ1WWg0=\n-----END CERTIFICATE-----&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICXzCCAgagAwIBAgIUTlImmt7P5VGyZ0yInSv0dZfBOiwwCgYIKoZIzj0EAwIw\nPjEQMA4GA1UEChMHRXhhbXBsZTEqMCgGA1UEAxMhRXhhbXBsZSBMYWJzIEludGVy\nbWVkaWF0ZSBDQSB2MS4xMB4XDTIyMDkyMDEyNTYyN1oXDTIzMDkyMDEyNTY1N1ow\nQDEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMScwJQYDVQQDEx5FeGFtcGxlIExhYnMg\nSXNzdWluZyBDQSB2MS4xLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATdb1Kz\nWlV5ZZkwopmhJmr6TkcR6zDuHK17K6zDMdXECAnrWmkdbSY5vfIm5tOtgsNeotoX\nvtXrB7odgdUHwSW8o4HfMIHcMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG\nAQH/AgEAMB0GA1UdDgQWBBQ3Q5fp1oVoSM8dVztrwzQXVU8aIDAfBgNVHSMEGDAW\ngBTW/lXP8bgCL4qyBKotq1tr/e8kwjA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUH\nMAKGI2h0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NhMDUGA1UdHwQu\nMCwwKqAooCaGJGh0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NybDAK\nBggqhkjOPQQDAgNHADBEAiBwvCW87AC6E9dIeiqalklwLNQD18YJ2q6hOLxIwiVD\nKQIgYlUYXzkHNuPcvQXIbXY88g+EiMf8leGo3iOCQQ/MDRA=\n-----END CERTIFICATE-----&quot;,<br>    &quot;expiration&quot;: 1695214617,<br>    &quot;issuing_ca&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIIB2DCCAX2gAwIBAgIRAMlAuLmxYK0hqR4uaheiDMowCgYIKoZIzj0EAwIwNDEQ\nMA4GA1UEChMHRXhhbXBsZTEgMB4GA1UEAxMXRXhhbXBsZSBMYWJzIFJvb3QgQ0Eg\ndjEwHhcNMjIwOTE5MTQ1NTA4WhcNMjcwOTE5MTUwNTA4WjA+MRAwDgYDVQQKEwdF\neGFtcGxlMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRpYXRlIENBIHYx\nLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATBv71in6dt4FYoFIUWPEl8/PTk\nN7vIryxD2sff7PY421erP9ZlWjG3dG5+1kFvHUrp26PGBYid304oVPIYWPHIo2Yw\nZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU\n1v5Vz/G4Ai+KsgSqLatba/3vJMIwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDIlZxg\n7z5RvXYwCgYIKoZIzj0EAwIDSQAwRgIhAIgYXf1QhKLiAZxp08viP0jU57qRkNMP\nxYSDwURq/rvoAiEAuq3Wytby/RsaMUvPhjOT0CR7fim9Pwaw1W5HdZ1WWg0=\n-----END CERTIFICATE-----&quot;,<br>    &quot;serial_number&quot;: &quot;4e:52:26:9a:de:cf:e5:51:b2:67:4c:88:9d:2b:f4:75:97:c1:3a:2c&quot;<br>  },<br>  &quot;warnings&quot;: [<br>    &quot;Max path length of the signed certificate is zero. This certificate cannot be used to issue intermediate CA certificates.&quot;<br>  ]<br>}<br><strong>$ cat pki_iss_v1.1.2.crt.json | jq -r &#39;.data.certificate&#39; \<br>    &gt; pki_iss_v1.1.2.crt<br>$ openssl x509 -in pki_iss_v1.1.2.crt -text -noout<br></strong>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            4e:52:26:9a:de:cf:e5:51:b2:67:4c:88:9d:2b:f4:75:97:...<br>        Signature Algorithm: ecdsa-with-SHA256<br><strong>        Issuer: O = Example, CN = Example Labs Intermediate CA v1.1<br></strong>        Validity<br>            Not Before: Sep 20 12:56:27 2022 GMT<br>            Not After : Sep 20 12:56:57 2023 GMT<br><strong>        Subject: O = Example, CN = Example Labs Issuing CA v1.1.2<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:dd:6f:52:b3:5a:55:79:65:99:30:a2:99:a1:26:<br>                    6a:fa:4e:47:11:eb:30:ee:1c:ad:7b:2b:ac:c3:31:<br>                    d5:c4:08:09:eb:5a:69:1d:6d:26:39:bd:f2:26:e6:<br>                    d3:ad:82:c3:5e:a2:da:17:be:d5:eb:07:ba:1d:81:<br>                    d5:07:c1:25:bc<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Certificate Sign, CRL Sign<br>            X509v3 Basic Constraints: critical<br>                CA:TRUE, pathlen:0<br>            X509v3 Subject Key Identifier:<br>                37:43:97:E9:D6:85:68:48:CF:1D:57:3B:6B:C3:34:17:...<br>            X509v3 Authority Key Identifier:<br>                keyid:D6:FE:55:CF:F1:B8:02:2F:8A:B2:04:AA:2D:AB:...</pre><pre>            Authority Information Access:<br>                CA Issuers - URI:http://127.0.0.1:8200/v1/pki_int/ca</pre><pre>            X509v3 CRL Distribution Points:</pre><pre>                Full Name:<br>                  URI:http://127.0.0.1:8200/v1/pki_int/crl</pre><pre>Signature Algorithm: ecdsa-with-SHA256<br>         30:44:02:20:70:bc:25:bc:ec:00:ba:13:d7:48:7a:2a:9a:96:<br>         49:70:2c:d4:03:d7:c6:09:da:ae:a1:38:bc:48:c2:25:43:29:<br>         02:20:62:55:18:5f:39:07:36:e3:dc:bd:05:c8:6d:76:3c:f2:<br>         0f:84:88:c7:fc:95:e1:a8:de:23:82:41:0f:cc:0d:10</pre><ul><li>Store intermediate certificate and new issuing certificate into the Issuing CA using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_iss/intermediate/set-signed</a> endpoint<strong>.</strong></li></ul><pre><strong>$ cat pki_iss_v1.1.2.crt pki_int_v1.1.crt &gt; pki_iss_v1.1.2.chain.crt<br>$ vault write -format=json \<br>    pki_iss/intermediate/set-signed \<br>    certificate=@pki_iss_v1.1.2.chain.crt \<br>    &gt; pki_iss_v1.1.2.set-signed.json<br>$ cat pki_iss_v1.1.2.set-signed.json<br></strong>{<br>  &quot;request_id&quot;: &quot;6d6e0da8-ee81-1492-465f-c1ea35eff46d&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;imported_issuers&quot;: [<br><strong>      &quot;42149e44-785e-3dec-a7e1-ba9e1c4804a0&quot;<br></strong>    ],<br>    &quot;imported_keys&quot;: null,<br>    &quot;mapping&quot;: {<br>      &quot;42149e44-785e-3dec-a7e1-ba9e1c4804a0&quot;: &quot;70aef752-39ae-6af7-cdc7-38cf6bb3e029&quot;,<br>      &quot;8b135654-2301-3efd-fd20-575e5d56e050&quot;: &quot;&quot;<br>    }<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><ul><li>Extract the issuer_id from the previous response (here 42149e44-785e-3dec-a7e1-ba9e1c4804a0), then rename the new issuer to <strong>v1.1.2 </strong>using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#update-issuer">pki_iss/issuer/:issuer_ref</a> endpoint.</li></ul><pre><strong>$ cat pki_iss_v1.1.2.set-signed.json \<br>    | jq -r &#39;.data.imported_issuers[0]&#39; \<br>    &gt; pki_iss_v1.1.2.issuer_id<br>$ vault write -format=json \<br>    pki_iss/issuer/`cat pki_iss_v1.1.2.issuer_id` \<br>    issuer_name=v1.1.2 \<br>    &gt; pki_iss_v1.1.2.rename.json</strong><br><strong>$ cat pki_iss_v1.1.2.rename.json</strong><br>{<br>  &quot;request_id&quot;: &quot;867c84cc-31f8-6b80-75ec-d5c0b696d42b&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIICXzCCAgagAwIBAgIUTlImmt7P5VGyZ0yInSv0dZfBOiwwCgYIKoZIzj0EAwIw\nPjEQMA4GA1UEChMHRXhhbXBsZTEqMCgGA1UEAxMhRXhhbXBsZSBMYWJzIEludGVy\nbWVkaWF0ZSBDQSB2MS4xMB4XDTIyMDkyMDEyNTYyN1oXDTIzMDkyMDEyNTY1N1ow\nQDEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMScwJQYDVQQDEx5FeGFtcGxlIExhYnMg\nSXNzdWluZyBDQSB2MS4xLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATdb1Kz\nWlV5ZZkwopmhJmr6TkcR6zDuHK17K6zDMdXECAnrWmkdbSY5vfIm5tOtgsNeotoX\nvtXrB7odgdUHwSW8o4HfMIHcMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG\nAQH/AgEAMB0GA1UdDgQWBBQ3Q5fp1oVoSM8dVztrwzQXVU8aIDAfBgNVHSMEGDAW\ngBTW/lXP8bgCL4qyBKotq1tr/e8kwjA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUH\nMAKGI2h0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NhMDUGA1UdHwQu\nMCwwKqAooCaGJGh0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NybDAK\nBggqhkjOPQQDAgNHADBEAiBwvCW87AC6E9dIeiqalklwLNQD18YJ2q6hOLxIwiVD\nKQIgYlUYXzkHNuPcvQXIbXY88g+EiMf8leGo3iOCQQ/MDRA=\n-----END CERTIFICATE-----\n&quot;,<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB2DCCAX2gAwIBAgIRAMlAuLmxYK0hqR4uaheiDMowCgYIKoZIzj0EAwIwNDEQ\nMA4GA1UEChMHRXhhbXBsZTEgMB4GA1UEAxMXRXhhbXBsZSBMYWJzIFJvb3QgQ0Eg\ndjEwHhcNMjIwOTE5MTQ1NTA4WhcNMjcwOTE5MTUwNTA4WjA+MRAwDgYDVQQKEwdF\neGFtcGxlMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRpYXRlIENBIHYx\nLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATBv71in6dt4FYoFIUWPEl8/PTk\nN7vIryxD2sff7PY421erP9ZlWjG3dG5+1kFvHUrp26PGBYid304oVPIYWPHIo2Yw\nZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU\n1v5Vz/G4Ai+KsgSqLatba/3vJMIwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDIlZxg\n7z5RvXYwCgYIKoZIzj0EAwIDSQAwRgIhAIgYXf1QhKLiAZxp08viP0jU57qRkNMP\nxYSDwURq/rvoAiEAuq3Wytby/RsaMUvPhjOT0CR7fim9Pwaw1W5HdZ1WWg0=\n-----END CERTIFICATE-----\n&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICXzCCAgagAwIBAgIUTlImmt7P5VGyZ0yInSv0dZfBOiwwCgYIKoZIzj0EAwIw\nPjEQMA4GA1UEChMHRXhhbXBsZTEqMCgGA1UEAxMhRXhhbXBsZSBMYWJzIEludGVy\nbWVkaWF0ZSBDQSB2MS4xMB4XDTIyMDkyMDEyNTYyN1oXDTIzMDkyMDEyNTY1N1ow\nQDEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMScwJQYDVQQDEx5FeGFtcGxlIExhYnMg\nSXNzdWluZyBDQSB2MS4xLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATdb1Kz\nWlV5ZZkwopmhJmr6TkcR6zDuHK17K6zDMdXECAnrWmkdbSY5vfIm5tOtgsNeotoX\nvtXrB7odgdUHwSW8o4HfMIHcMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG\nAQH/AgEAMB0GA1UdDgQWBBQ3Q5fp1oVoSM8dVztrwzQXVU8aIDAfBgNVHSMEGDAW\ngBTW/lXP8bgCL4qyBKotq1tr/e8kwjA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUH\nMAKGI2h0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NhMDUGA1UdHwQu\nMCwwKqAooCaGJGh0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NybDAK\nBggqhkjOPQQDAgNHADBEAiBwvCW87AC6E9dIeiqalklwLNQD18YJ2q6hOLxIwiVD\nKQIgYlUYXzkHNuPcvQXIbXY88g+EiMf8leGo3iOCQQ/MDRA=\n-----END CERTIFICATE-----\n&quot;,<br><strong>    &quot;issuer_id&quot;: &quot;42149e44-785e-3dec-a7e1-ba9e1c4804a0&quot;,<br>    &quot;issuer_name&quot;: &quot;v1.1.2&quot;,<br></strong>    &quot;key_id&quot;: &quot;70aef752-39ae-6af7-cdc7-38cf6bb3e029&quot;,<br>    &quot;leaf_not_after_behavior&quot;: &quot;err&quot;,<br>    &quot;manual_chain&quot;: null,<br>    &quot;usage&quot;: &quot;read-only,issuing-certificates,crl-signing&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*oafi5l27rqNoVWaCbgWfXQ.png" /><figcaption>Default issuer is still v1.1.1</figcaption></figure><p>At this stage, the v1.1.2 issuer has been generated.</p><p>Let’s check the terminal where <strong>consul-template</strong> is running. As the default issuer is still <strong>v1.1.1</strong>, the issued leaf certificates are still with <strong>v1.1.1</strong> issuer.</p><pre>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIFEM5nkiEm2i/eEEP1XV3n7k9I8IZapKtNMc9EQLUu9NoAoGCCqGSM49<br>AwEHoUQDQgAEk7G6GdS1lcn16trtzA5eIUyXG28BTg8+Q5c5Z3LltBlSW/prcvgT<br>fzvHC7+/3eNFCKl0P2J8NJMRIvHA/TcUPg==<br>-----END EC PRIVATE KEY-----<br>issuer=O = Example, CN = Example Labs Issuing CA v1.1.1<br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 13:17:19 2022 GMT<br>notAfter=Sep 20 13:18:19 2022 GMT</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*dKKprqZ3-nvJKRyoHN5Mbg.png" /><figcaption>Set default issuer to v1.1.2</figcaption></figure><ul><li>Now, rotate the Issuing CA by setting the default issuer to <strong>v1.1.2 </strong>using<strong> </strong>the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#set-issuers-configuration">pki_iss/root/replace</a>endpoint.</li></ul><pre><strong>$ vault write -format=json \<br>    pki_iss/root/replace \<br>    default=v1.1.2 \<br>    &gt; pki_iss_v1.1.2.replace.json<br>$ cat pki_iss_v1.1.2.replace.json<br></strong>{<br>  &quot;request_id&quot;: &quot;78be6c7a-3dd4-2825-df32-d3fe04d12f70&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br><strong>    &quot;default&quot;: &quot;42149e44-785e-3dec-a7e1-ba9e1c4804a0&quot;<br></strong>  },<br>  &quot;warnings&quot;: null<br>}<br><strong>$ vault list -detailed pki_iss/issuers | grep -v &quot;n/a&quot;<br></strong>Keys                                    is_default    issuer_name<br>----                                    ----------    -----------<br>42149e44-785e-3dec-a7e1-ba9e1c4804a0    true          v1.1.2<br>957c0c19-a66b-f2fa-b868-05f01bc142e5    false         v1.1.1</pre><p>Let’s check the terminal where <strong>consul-template</strong> is running. As the default issuer has been replace by the <strong>v1.1.2 </strong>issuer, the issued leaf certificates are now with <strong>v1.1.2</strong> issuer. The CA chain is updated as well because the Issuing CA certificate is now the one from <strong>v1.1.2</strong> issuer.</p><pre>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIO8Mm3OX65AcxR/dehWyJ/tmwTbL6gG9tBj7isagnUZZoAoGCCqGSM49<br>AwEHoUQDQgAEYV3hVaLrMtFbMo072ZH7VPaazecX5VmdHqjsGDImawXdVeMAgvrw<br>ut+5O7CPriBhxTiCrV71YABVBsg9FD7mfw==<br>-----END EC PRIVATE KEY-----<br>issuer=O = Example, CN = Example Labs Issuing CA v1.1.1<br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 13:23:33 2022 GMT<br>notAfter=Sep 20 13:24:33 2022 GMT<br><strong>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIHfHYbilbIiWgT1UI8gIZW7BK8TDBf6wgkZfMrDCvUavoAoGCCqGSM49<br>AwEHoUQDQgAEvEn3LC16OyC43Z/HJRAmcQZov4hICgjcr/X1edKF4LliKq5ADkn1<br>2feYOMDJ6JJXg1LoJADRRxLZng71X9A1qw==<br>-----END EC PRIVATE KEY-----<br>issuer=O = Example, CN = Example Labs Issuing CA v1.1.2<br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 13:23:58 2022 GMT<br>notAfter=Sep 20 13:24:58 2022 GMT<br>-----BEGIN CERTIFICATE-----<br>MIICXzCCAgagAwIBAgIUTlImmt7P5VGyZ0yInSv0dZfBOiwwCgYIKoZIzj0EAwIw<br>PjEQMA4GA1UEChMHRXhhbXBsZTEqMCgGA1UEAxMhRXhhbXBsZSBMYWJzIEludGVy<br>bWVkaWF0ZSBDQSB2MS4xMB4XDTIyMDkyMDEyNTYyN1oXDTIzMDkyMDEyNTY1N1ow<br>QDEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMScwJQYDVQQDEx5FeGFtcGxlIExhYnMg<br>SXNzdWluZyBDQSB2MS4xLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATdb1Kz<br>WlV5ZZkwopmhJmr6TkcR6zDuHK17K6zDMdXECAnrWmkdbSY5vfIm5tOtgsNeotoX<br>vtXrB7odgdUHwSW8o4HfMIHcMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG<br>AQH/AgEAMB0GA1UdDgQWBBQ3Q5fp1oVoSM8dVztrwzQXVU8aIDAfBgNVHSMEGDAW<br>gBTW/lXP8bgCL4qyBKotq1tr/e8kwjA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUH<br>MAKGI2h0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NhMDUGA1UdHwQu<br>MCwwKqAooCaGJGh0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NybDAK<br>BggqhkjOPQQDAgNHADBEAiBwvCW87AC6E9dIeiqalklwLNQD18YJ2q6hOLxIwiVD<br>KQIgYlUYXzkHNuPcvQXIbXY88g+EiMf8leGo3iOCQQ/MDRA=<br>-----END CERTIFICATE-----<br>-----BEGIN CERTIFICATE-----<br>MIIB2DCCAX2gAwIBAgIRAMlAuLmxYK0hqR4uaheiDMowCgYIKoZIzj0EAwIwNDEQ<br>MA4GA1UEChMHRXhhbXBsZTEgMB4GA1UEAxMXRXhhbXBsZSBMYWJzIFJvb3QgQ0Eg<br>djEwHhcNMjIwOTE5MTQ1NTA4WhcNMjcwOTE5MTUwNTA4WjA+MRAwDgYDVQQKEwdF<br>eGFtcGxlMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRpYXRlIENBIHYx<br>LjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATBv71in6dt4FYoFIUWPEl8/PTk<br>N7vIryxD2sff7PY421erP9ZlWjG3dG5+1kFvHUrp26PGBYid304oVPIYWPHIo2Yw<br>ZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU<br>1v5Vz/G4Ai+KsgSqLatba/3vJMIwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDIlZxg<br>7z5RvXYwCgYIKoZIzj0EAwIDSQAwRgIhAIgYXf1QhKLiAZxp08viP0jU57qRkNMP<br>xYSDwURq/rvoAiEAuq3Wytby/RsaMUvPhjOT0CR7fim9Pwaw1W5HdZ1WWg0=<br>-----END CERTIFICATE-----<br></strong>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIJLESZuhH7B4FbrlolGQBwiMf5jQNbmJvN7u0fhzv8esoAoGCCqGSM49<br>AwEHoUQDQgAEf3/pMWH4OGy5a4nw/KHIWovCKOEJjwNKQiwtVQbHU6XQnWVk1vGL<br>pDPLPMQ44FmHP+8RibCtwTkgMtge/Gmnow==<br>-----END EC PRIVATE KEY-----<br><strong>issuer=O = Example, CN = Example Labs Issuing CA v1.1.2<br></strong>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 13:24:24 2022 GMT<br>notAfter=Sep 20 13:25:24 2022 GMT</pre><p>As a result, the issuing CA has been rotated, and the automatic generation of leaf certificates is passed on seamlessly to the new issuer.</p><p>In the next section, the Intermediate CA is rotated.</p><h3>Rotate Intermediate CA</h3><p>Now, let’s update the Intermediate CA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*2zMVQsBBkjLWTNtZ3TXxyQ.png" /><figcaption>Generate v1.2 issuer for Intermediate CA</figcaption></figure><p>Let’s generate a new issuer for the Intermediate CA.</p><ul><li>Generate private key and CSR for <strong>v1.2</strong> issuer using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_int/intermediate/generate/internal</a>endpoint.</li></ul><pre><strong>$ vault write -format=json \<br>    pki_int/intermediate/generate/internal \<br>    organization=&quot;Example&quot; \<br>    common_name=&quot;Example Labs Intermediae CA v1.2&quot; \<br>    key_type=ec \<br>    key_bits=256 \<br>    | jq -r &#39;.data.csr&#39; &gt; pki_int_v1.2.csr</strong></pre><ul><li>Sign and generate a certificate using the CSR with Root CA v1</li></ul><pre><strong>$ certstrap --depot-path root sign \<br>    --CA &quot;Example Labs Root CA v1&quot; \<br>    --passphrase &quot;secret&quot; \<br>    --intermediate \<br>    --csr pki_int_v1.2.csr \<br>    --expires &quot;5 years&quot; \<br>    --path-length 1 \<br>    --cert pki_int_v1.2.crt \<br>    &quot;Example Labs Intermediate CA v1.2&quot;</strong><br>Building intermediate<br><strong>$ openssl x509 -in pki_int_v1.2.crt -text -noout<br></strong>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            1b:ca:05:50:05:fc:3e:55:7e:91:d2:d6:a0:22:f3:17<br>        Signature Algorithm: ecdsa-with-SHA256<br><strong>        Issuer: O = Example, CN = Example Labs Root CA v1<br></strong>        Validity<br>            Not Before: Sep 20 13:48:18 2022 GMT<br>            Not After : Sep 20 13:58:18 2027 GMT<br><strong>        Subject: O = Example, CN = Example Labs Intermediae CA v1.2<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:a3:12:fe:9c:ca:bb:63:ce:77:ad:f2:e5:31:8e:<br>                    e9:8f:89:fd:dc:0f:49:be:51:1b:2c:e8:a5:ed:a0:<br>                    3d:af:3f:a9:c3:5a:ba:b7:0f:12:22:cd:4e:f8:e9:<br>                    61:3e:b4:5f:6e:18:1e:b1:f9:1b:1b:ee:50:db:0f:<br>                    3e:de:8e:b1:bb<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Certificate Sign, CRL Sign<br>            X509v3 Basic Constraints: critical<br><strong>                CA:TRUE, pathlen:1<br></strong>            X509v3 Subject Key Identifier:<br>                89:14:DC:23:34:8B:23:4B:21:EE:44:67:29:66:1C:18:...<br>            X509v3 Authority Key Identifier:<br>                keyid:C2:49:FB:2B:5C:B3:31:12:FB:14:B0:C8:95:9C:...</pre><pre>Signature Algorithm: ecdsa-with-SHA256<br>         30:44:02:20:58:91:c1:82:d1:ce:ed:85:74:e1:5f:55:5e:c2:<br>         58:e2:0b:c1:e5:59:45:fe:de:23:d0:46:4e:53:42:d8:0c:1e:<br>         02:20:6c:ff:8f:91:8b:a7:9e:c4:f9:e9:8f:10:b9:1c:a1:32:<br>         35:d5:8a:3b:5f:da:b4:39:d6:29:e2:7c:a3:06:b2:b2</pre><ul><li>Store intermediate certificate into the Intermediate CA using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_int/intermediate/set-signed</a>endpoint</li></ul><pre><strong>$ vault write -format=json \<br>    pki_int/intermediate/set-signed \<br>    certificate=@pki_int_v1.2.crt \<br>    &gt; pki_int_v1.2.set-signed.json<br>$ cat pki_int_v1.2.set-signed.json<br></strong>{<br>  &quot;request_id&quot;: &quot;ce5b613e-0f3e-5efa-0855-d1ff2a8ca772&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;imported_issuers&quot;: [<br><strong>      &quot;08ca0f1e-abad-4a6a-f632-6199adc0a9d4&quot;<br></strong>    ],<br>    &quot;imported_keys&quot;: null,<br>    &quot;mapping&quot;: {<br>      &quot;08ca0f1e-abad-4a6a-f632-6199adc0a9d4&quot;: &quot;7bafaabe-a63b-2731-9bd1-ad6ca515cbe6&quot;<br>    }<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><ul><li>Extract the issuer_id from the previous response (here 09ca0f1e-abad-4a6a-f632-6199adv0a9d4), then rename the new issuer to <strong>v1.2</strong> using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#update-issuer">pki_int/issuer/:issuer_ref</a> endpoint.</li></ul><pre><strong>$ cat pki_int_v1.2.set-signed.json \<br>    | jq -r &#39;.data.imported_issuers[0]&#39; \<br>    &gt; pki_int_v1.2.issuer_ref<br>$ vault write -format=json \<br>    pki_int/issuer/`cat pki_int_v1.2.issuer_ref` \<br>    issuer_name=v1.2 \<br>    &gt; pki_int_v1.2.rename.json<br></strong>{<br>  &quot;request_id&quot;: &quot;e7cb577f-1b2e-6aac-ac6f-b1df867f378a&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB2TCCAYCgAwIBAgIQG8oFUAX8PlV+kdLWoCLzFzAKBggqhkjOPQQDAjA0MRAw\nDgYDVQQKEwdFeGFtcGxlMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9vdCBDQSB2\nMTAeFw0yMjA5MjAxMzQ4MThaFw0yNzA5MjAxMzU4MThaMEIxFTATBgNVBAoTDEV4\nYW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVkaWFlIENB\nIHYxLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASjEv6cyrtjznet8uUxjumP\nif3cD0m+URss6KXtoD2vP6nDWrq3DxIizU746WE+tF9uGB6x+Rsb7lDbDz7ejrG7\no2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4E\nFgQUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDI\nlZxg7z5RvXYwCgYIKoZIzj0EAwIDRwAwRAIgWJHBgtHO7YV04V9VXsJY4gvB5VlF\n/t4j0EZOU0LYDB4CIGz/j5GLp57E+emPELkcoTI11Yo7X9q0OdYp4nyjBrKy\n-----END CERTIFICATE-----\n&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIIB2TCCAYCgAwIBAgIQG8oFUAX8PlV+kdLWoCLzFzAKBggqhkjOPQQDAjA0MRAw\nDgYDVQQKEwdFeGFtcGxlMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9vdCBDQSB2\nMTAeFw0yMjA5MjAxMzQ4MThaFw0yNzA5MjAxMzU4MThaMEIxFTATBgNVBAoTDEV4\nYW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVkaWFlIENB\nIHYxLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASjEv6cyrtjznet8uUxjumP\nif3cD0m+URss6KXtoD2vP6nDWrq3DxIizU746WE+tF9uGB6x+Rsb7lDbDz7ejrG7\no2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4E\nFgQUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDI\nlZxg7z5RvXYwCgYIKoZIzj0EAwIDRwAwRAIgWJHBgtHO7YV04V9VXsJY4gvB5VlF\n/t4j0EZOU0LYDB4CIGz/j5GLp57E+emPELkcoTI11Yo7X9q0OdYp4nyjBrKy\n-----END CERTIFICATE-----\n&quot;,<br>    &quot;issuer_id&quot;: &quot;08ca0f1e-abad-4a6a-f632-6199adc0a9d4&quot;,<br><strong>    &quot;issuer_name&quot;: &quot;v1.2&quot;,<br></strong>    &quot;key_id&quot;: &quot;7bafaabe-a63b-2731-9bd1-ad6ca515cbe6&quot;,<br>    &quot;leaf_not_after_behavior&quot;: &quot;err&quot;,<br>    &quot;manual_chain&quot;: null,<br>    &quot;usage&quot;: &quot;read-only,issuing-certificates,crl-signing&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*nD35UUtj9tTbDf0h8Ga69Q.png" /><figcaption>Generate v1.2.1 issuer for Issuing CA</figcaption></figure><p>Now, let’s generate a new issuer for the Issuing CA.</p><ul><li>Generate private key and CSR for <strong>v1.2.1</strong> issuer using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_int/intermediate/generate/internal</a>endpoint.</li></ul><pre><strong>$ vault write -format=json \<br>    pki_iss/intermediate/generate/internal \<br>    organization=&quot;Example&quot; \<br>    common_name=&quot;Example Labs Issuing CA v1.2.1&quot; \<br>    key_type=ec \<br>    key_bits=256 \<br>    | jq -r &#39;.data.csr&#39; &gt; pki_iss_v1.2.1.csr</strong></pre><ul><li>Sign and generate a certificate using the CSR with <strong>Intermediate CA v1.2 </strong>using <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#sign-intermediate">pki_int/issuer/:issuer_ref/sign-intermediate</a> endpoint</li></ul><blockquote>The <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#sign-intermediate">pki_int/root/sign-intermediate</a><strong> </strong>endpoint uses the default issuer. So, it can’t be used because the default issuer for Intermediate CA isn’t set to v1.2.</blockquote><pre><strong>$ vault write -format=json \<br>    pki_int/issuer/v1.2/sign-intermediate \<br>    organization=&quot;Example&quot; \<br>    csr=@pki_iss_v1.2.1.csr \<br>    ttl=8760h \<br>    format=pem \<br>    &gt; pki_iss_v1.2.1.crt.json</strong><br><strong>$ cat pki_iss_v1.2.1.crt.json</strong><br>{<br>  &quot;request_id&quot;: &quot;ed5b2b2b-1d7c-35d3-e1cb-c54273fa4912&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIICZDCCAgqgAwIBAgIUMEo78R2WbVUklZKtRK29YZyWj6IwCgYIKoZIzj0EAwIw\nQjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYWUgQ0EgdjEuMjAeFw0yMjA5MjAxNDIxNThaFw0yMzA5MjAxNDIy\nMjhaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM\nYWJzIElzc3VpbmcgQ0EgdjEuMi4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nb25UxYE/Wk3cmJGmgq7H0RA5gBJNTuHfG+nszNlmjvr0hlbl2eb6c2nHPUDnVm06\n8xiX+YEp5o4k5WKbpAWLB6OB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/\nBAgwBgEB/wIBADAdBgNVHQ4EFgQUGj9YO8B8HiPIinLrhn+m5t0q3J4wHwYDVR0j\nBBgwFoAUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwPwYIKwYBBQUHAQEEMzAxMC8GCCsG\nAQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV\nHR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j\ncmwwCgYIKoZIzj0EAwIDSAAwRQIhAP9R8GYDrQ+dbalPeHAUc72RazDvVFOFt5zR\nF2XoLB3gAiABK9YOSpdV/UCyjs+plIHmkIg27+tfABZ/WduS0cplUg==\n-----END CERTIFICATE-----&quot;,<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB2TCCAYCgAwIBAgIQG8oFUAX8PlV+kdLWoCLzFzAKBggqhkjOPQQDAjA0MRAw\nDgYDVQQKEwdFeGFtcGxlMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9vdCBDQSB2\nMTAeFw0yMjA5MjAxMzQ4MThaFw0yNzA5MjAxMzU4MThaMEIxFTATBgNVBAoTDEV4\nYW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVkaWFlIENB\nIHYxLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASjEv6cyrtjznet8uUxjumP\nif3cD0m+URss6KXtoD2vP6nDWrq3DxIizU746WE+tF9uGB6x+Rsb7lDbDz7ejrG7\no2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4E\nFgQUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDI\nlZxg7z5RvXYwCgYIKoZIzj0EAwIDRwAwRAIgWJHBgtHO7YV04V9VXsJY4gvB5VlF\n/t4j0EZOU0LYDB4CIGz/j5GLp57E+emPELkcoTI11Yo7X9q0OdYp4nyjBrKy\n-----END CERTIFICATE-----&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICZDCCAgqgAwIBAgIUMEo78R2WbVUklZKtRK29YZyWj6IwCgYIKoZIzj0EAwIw\nQjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYWUgQ0EgdjEuMjAeFw0yMjA5MjAxNDIxNThaFw0yMzA5MjAxNDIy\nMjhaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM\nYWJzIElzc3VpbmcgQ0EgdjEuMi4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nb25UxYE/Wk3cmJGmgq7H0RA5gBJNTuHfG+nszNlmjvr0hlbl2eb6c2nHPUDnVm06\n8xiX+YEp5o4k5WKbpAWLB6OB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/\nBAgwBgEB/wIBADAdBgNVHQ4EFgQUGj9YO8B8HiPIinLrhn+m5t0q3J4wHwYDVR0j\nBBgwFoAUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwPwYIKwYBBQUHAQEEMzAxMC8GCCsG\nAQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV\nHR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j\ncmwwCgYIKoZIzj0EAwIDSAAwRQIhAP9R8GYDrQ+dbalPeHAUc72RazDvVFOFt5zR\nF2XoLB3gAiABK9YOSpdV/UCyjs+plIHmkIg27+tfABZ/WduS0cplUg==\n-----END CERTIFICATE-----&quot;,<br>    &quot;expiration&quot;: 1695219748,<br>    &quot;issuing_ca&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIIB2TCCAYCgAwIBAgIQG8oFUAX8PlV+kdLWoCLzFzAKBggqhkjOPQQDAjA0MRAw\nDgYDVQQKEwdFeGFtcGxlMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9vdCBDQSB2\nMTAeFw0yMjA5MjAxMzQ4MThaFw0yNzA5MjAxMzU4MThaMEIxFTATBgNVBAoTDEV4\nYW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVkaWFlIENB\nIHYxLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASjEv6cyrtjznet8uUxjumP\nif3cD0m+URss6KXtoD2vP6nDWrq3DxIizU746WE+tF9uGB6x+Rsb7lDbDz7ejrG7\no2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4E\nFgQUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDI\nlZxg7z5RvXYwCgYIKoZIzj0EAwIDRwAwRAIgWJHBgtHO7YV04V9VXsJY4gvB5VlF\n/t4j0EZOU0LYDB4CIGz/j5GLp57E+emPELkcoTI11Yo7X9q0OdYp4nyjBrKy\n-----END CERTIFICATE-----&quot;,<br>    &quot;serial_number&quot;: &quot;30:4a:3b:f1:1d:96:6d:55:24:95:92:ad:44:ad:bd:61:9c:96:8f:a2&quot;<br>  },<br>  &quot;warnings&quot;: [<br>    &quot;Max path length of the signed certificate is zero. This certificate cannot be used to issue intermediate CA certificates.&quot;<br>  ]<br>}<br><strong>$ cat pki_iss_v1.2.1.crt.json \<br>    | jq -r &#39;.data.certificate&#39; \<br>    &gt; pki_iss_v1.2.1.crt<br>$ openssl x509 -in pki_iss_v1.2.1.crt -text -noout<br></strong>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            30:4a:3b:f1:1d:96:6d:55:24:95:92:ad:44:ad:bd:61:9c:...<br>        Signature Algorithm: ecdsa-with-SHA256<br><strong>        Issuer: O = Example, CN = Example Labs Intermediae CA v1.2<br></strong>        Validity<br>            Not Before: Sep 20 14:21:58 2022 GMT<br>            Not After : Sep 20 14:22:28 2023 GMT<br><strong>        Subject: O = Example, CN = Example Labs Issuing CA v1.2.1<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:6f:6e:54:c5:81:3f:5a:4d:dc:98:91:a6:82:ae:<br>                    c7:d1:10:39:80:12:4d:4e:e1:df:1b:e9:ec:cc:d9:<br>                    66:8e:fa:f4:86:56:e5:d9:e6:fa:73:69:c7:3d:40:<br>                    e7:56:6d:3a:f3:18:97:f9:81:29:e6:8e:24:e5:62:<br>                    9b:a4:05:8b:07<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Certificate Sign, CRL Sign<br>            X509v3 Basic Constraints: critical<br><strong>                CA:TRUE, pathlen:0<br></strong>            X509v3 Subject Key Identifier:<br>                1A:3F:58:3B:C0:7C:1E:23:C8:8A:72:EB:86:7F:A6:E6:...<br>            X509v3 Authority Key Identifier:<br>                keyid:89:14:DC:23:34:8B:23:4B:21:EE:44:67:29:66:...</pre><pre>            Authority Information Access:<br>                CA Issuers - URI:http://127.0.0.1:8200/v1/pki_int/ca</pre><pre>            X509v3 CRL Distribution Points:</pre><pre>                Full Name:<br>                  URI:http://127.0.0.1:8200/v1/pki_int/crl</pre><pre>Signature Algorithm: ecdsa-with-SHA256<br>         30:45:02:21:00:ff:51:f0:66:03:ad:0f:9d:6d:a9:4f:78:70:<br>         14:73:bd:91:6b:30:ef:54:53:85:b7:9c:d1:17:65:e8:2c:1d:<br>         e0:02:20:01:2b:d6:0e:4a:97:55:fd:40:b2:8e:cf:a9:94:81:<br>         e6:90:88:36:ef:eb:5f:00:16:7f:59:db:92:d1:ca:65:52</pre><ul><li>Store the new intermediate certificate and the new issuing certificate into the Issuing CA using the<a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_iss/intermediate/set-signed</a> endpoint<strong>.</strong></li></ul><pre><strong>$ cat pki_iss_v1.2.1.crt pki_int_v1.2.crt &gt; pki_iss_v1.2.1.chain.crt<br>$ vault write -format=json \<br>    pki_iss/intermediate/set-signed \<br>    certificate=@pki_iss_v1.2.1.chain.crt \<br>    &gt; pki_iss_v1.2.1.set-signed.json<br>$ cat pki_iss_v1.2.1.set-signed.json</strong><br>{<br>  &quot;request_id&quot;: &quot;07efbab3-cd52-cb48-8d8d-c77d98619464&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;imported_issuers&quot;: [<br><strong>      &quot;b0074a43-589b-b59e-5683-f4c6f8b3348a&quot;,<br></strong>      &quot;0531724f-5b62-fc93-03f1-d7c3bef99f1b&quot;<br>    ],<br>    &quot;imported_keys&quot;: null,<br>    &quot;mapping&quot;: {<br>      &quot;0531724f-5b62-fc93-03f1-d7c3bef99f1b&quot;: &quot;&quot;,<br>      &quot;b0074a43-589b-b59e-5683-f4c6f8b3348a&quot;: &quot;b25aae5e-21f9-a18a-6dbe-e9c0ec1d9c25&quot;<br>    }<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><ul><li>Extract the issuer_id from the previous response, then rename the new issuer to <strong>v1.2.1 </strong>using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#update-issuer">pki_iss/issuer/:issuer_ref</a>endpoint.</li></ul><pre><strong>$ cat pki_iss_v1.2.1.set-signed.json \<br>    | jq -r &#39;.data.imported_issuers[0]&#39; \<br>    &gt; pki_iss_v1.2.1.issuer_ref<br>$ vault write -format=json \<br>    pki_iss/issuer/`cat pki_iss_v1.2.1.issuer_ref` \<br>    issuer_name=v1.2.1 \<br>    &gt; pki_iss_v1.2.1.rename.json<br>$ cat pki_iss_v1.2.1.rename.json</strong><br>{<br>  &quot;request_id&quot;: &quot;bb29f6ac-7bd7-5585-6d13-284d38f8a871&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIICZDCCAgqgAwIBAgIUMEo78R2WbVUklZKtRK29YZyWj6IwCgYIKoZIzj0EAwIw\nQjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYWUgQ0EgdjEuMjAeFw0yMjA5MjAxNDIxNThaFw0yMzA5MjAxNDIy\nMjhaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM\nYWJzIElzc3VpbmcgQ0EgdjEuMi4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nb25UxYE/Wk3cmJGmgq7H0RA5gBJNTuHfG+nszNlmjvr0hlbl2eb6c2nHPUDnVm06\n8xiX+YEp5o4k5WKbpAWLB6OB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/\nBAgwBgEB/wIBADAdBgNVHQ4EFgQUGj9YO8B8HiPIinLrhn+m5t0q3J4wHwYDVR0j\nBBgwFoAUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwPwYIKwYBBQUHAQEEMzAxMC8GCCsG\nAQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV\nHR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j\ncmwwCgYIKoZIzj0EAwIDSAAwRQIhAP9R8GYDrQ+dbalPeHAUc72RazDvVFOFt5zR\nF2XoLB3gAiABK9YOSpdV/UCyjs+plIHmkIg27+tfABZ/WduS0cplUg==\n-----END CERTIFICATE-----\n&quot;,<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB2TCCAYCgAwIBAgIQG8oFUAX8PlV+kdLWoCLzFzAKBggqhkjOPQQDAjA0MRAw\nDgYDVQQKEwdFeGFtcGxlMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9vdCBDQSB2\nMTAeFw0yMjA5MjAxMzQ4MThaFw0yNzA5MjAxMzU4MThaMEIxFTATBgNVBAoTDEV4\nYW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVkaWFlIENB\nIHYxLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASjEv6cyrtjznet8uUxjumP\nif3cD0m+URss6KXtoD2vP6nDWrq3DxIizU746WE+tF9uGB6x+Rsb7lDbDz7ejrG7\no2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4E\nFgQUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDI\nlZxg7z5RvXYwCgYIKoZIzj0EAwIDRwAwRAIgWJHBgtHO7YV04V9VXsJY4gvB5VlF\n/t4j0EZOU0LYDB4CIGz/j5GLp57E+emPELkcoTI11Yo7X9q0OdYp4nyjBrKy\n-----END CERTIFICATE-----\n&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICZDCCAgqgAwIBAgIUMEo78R2WbVUklZKtRK29YZyWj6IwCgYIKoZIzj0EAwIw\nQjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYWUgQ0EgdjEuMjAeFw0yMjA5MjAxNDIxNThaFw0yMzA5MjAxNDIy\nMjhaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM\nYWJzIElzc3VpbmcgQ0EgdjEuMi4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nb25UxYE/Wk3cmJGmgq7H0RA5gBJNTuHfG+nszNlmjvr0hlbl2eb6c2nHPUDnVm06\n8xiX+YEp5o4k5WKbpAWLB6OB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/\nBAgwBgEB/wIBADAdBgNVHQ4EFgQUGj9YO8B8HiPIinLrhn+m5t0q3J4wHwYDVR0j\nBBgwFoAUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwPwYIKwYBBQUHAQEEMzAxMC8GCCsG\nAQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV\nHR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j\ncmwwCgYIKoZIzj0EAwIDSAAwRQIhAP9R8GYDrQ+dbalPeHAUc72RazDvVFOFt5zR\nF2XoLB3gAiABK9YOSpdV/UCyjs+plIHmkIg27+tfABZ/WduS0cplUg==\n-----END CERTIFICATE-----\n&quot;,<br><strong>    &quot;issuer_id&quot;: &quot;b0074a43-589b-b59e-5683-f4c6f8b3348a&quot;,<br>    &quot;issuer_name&quot;: &quot;v1.2.1&quot;,<br></strong>    &quot;key_id&quot;: &quot;b25aae5e-21f9-a18a-6dbe-e9c0ec1d9c25&quot;,<br>    &quot;leaf_not_after_behavior&quot;: &quot;err&quot;,<br>    &quot;manual_chain&quot;: null,<br>    &quot;usage&quot;: &quot;read-only,issuing-certificates,crl-signing&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><p>At this stage, the <strong>v1.2</strong> and <strong>v1.2.1</strong> issuers have been generated.</p><p>Let’s check the terminal where <strong>consul-template</strong> is running. As the default issuer is still <strong>v1.1.2</strong>, the issued leaf certificates are still with <strong>v1.1.2</strong> issuer.</p><pre>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEILirPGC01CN6f74ALnRVT+Ro24TBk6VIROOGkjkJEAgNoAoGCCqGSM49<br>AwEHoUQDQgAEYJFAFWFoB1FBx1kUKXBwzBlMrtv4iA4wpogAXpNPLJnSWMQx6l70<br>K2JJtaOXm3AUaUNYEU6I0XlumYNhZ9rg/Q==<br>-----END EC PRIVATE KEY-----<br><strong>issuer=O = Example, CN = Example Labs Issuing CA v1.1.2<br></strong>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 14:34:25 2022 GMT<br>notAfter=Sep 20 14:35:25 2022 GMT<br>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIBqV1hRGpfLYz/3e5B7MH3U9ysdvwFoKrWuGbyqHw2XioAoGCCqGSM49<br>AwEHoUQDQgAEBbgqffirdifrmnzRFKe3JQfv0Msi+djaSSQlc4QXF0xpwsFZ3mpX<br>cXNUEEMuHeVumEJY8MrXnTmnfn/bc2D3uA==<br>-----END EC PRIVATE KEY-----<br><strong>issuer=O = Example, CN = Example Labs Issuing CA v1.1.2<br></strong>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 14:34:53 2022 GMT<br>notAfter=Sep 20 14:35:53 2022 GMT</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*RnPByqA4lPGqg8L7m8CNGQ.png" /><figcaption>Set default issuer to v1.2</figcaption></figure><ul><li>Now, rotate the Intermediate CA by setting the default issuer to <strong>v1.2 </strong>using<strong> </strong>the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#set-issuers-configuration">pki_int/root/replace</a>endpoint.</li></ul><pre><strong>$ vault write -format=json \<br>    pki_int/root/replace \<br>    default=v1.2 \<br>    &gt; pki_int_v1.2.replace.json<br>$ cat pki_int_v1.2.replace.json<br></strong>{<br>  &quot;request_id&quot;: &quot;4e469221-c1e8-5eb0-2815-58b031b2e276&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br><strong>    &quot;default&quot;: &quot;08ca0f1e-abad-4a6a-f632-6199adc0a9d4&quot;<br></strong>  },<br>  &quot;warnings&quot;: null<br>}<br><strong>$ vault list -detailed pki_int/issuers<br></strong>Keys                                    is_default    issuer_name<br>----                                    ----------    -----------<br>08ca0f1e-abad-4a6a-f632-6199adc0a9d4    true          v1.2<br>17438773-df12-5bab-a7ee-83a7305037fb    false         v1.1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*k6jgLLIsgDCgwq9dTbwgMg.png" /><figcaption>Set default issuer to v1.2.1</figcaption></figure><ul><li>Now, rotate the Issuing CA by setting the default issuer to <strong>v1.2.1 </strong>using<strong> </strong>the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#set-issuers-configuration">pki_iss/root/replace</a>endpoint.</li></ul><pre><strong>$ vault write -format=json \<br>    pki_iss/root/replace \<br>    default=v1.2.1 \<br>    &gt; pki_iss_v1.2.1.replace.json<br>$ cat pki_iss_v1.2.1.replace.json<br></strong>{<br>  &quot;request_id&quot;: &quot;053a5a0d-96cc-bf9b-5e9a-d037581d6443&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br><strong>    &quot;default&quot;: &quot;b0074a43-589b-b59e-5683-f4c6f8b3348a&quot;<br></strong>  },<br>  &quot;warnings&quot;: null<br>}<br><strong>$ vault list -detailed pki_iss/issuers | grep -v &quot;n/a&quot;</strong><br>Keys                                    is_default    issuer_name<br>----                                    ----------    -----------<br>42149e44-785e-3dec-a7e1-ba9e1c4804a0    false         v1.1.2<br>957c0c19-a66b-f2fa-b868-05f01bc142e5    false         v1.1.1<br>b0074a43-589b-b59e-5683-f4c6f8b3348a    true          v1.2.1</pre><p>Let’s check the terminal where <strong>consul-template</strong> is running. As the default issuer has been replace by the <strong>v1.2.1 </strong>issuer, the issued leaf certificates are now with <strong>v1.2.1</strong> issuer. The CA chain is updated as well because the Intermediate CA and the Issuing CA certificates are now respectively from the <strong>v1.2</strong> and the <strong>v1.1.2</strong> issuers.</p><pre>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIGJG0DeO+g0Bm45IAZiXSyTtmEaVfsl3fyq3yUYoPf4poAoGCCqGSM49<br>AwEHoUQDQgAEdOjXpuQmByDMhwReZSiz6LWQ/IlW3m3ywykQgeC9afsNlqKoB1y1<br>Szfek5wcfLwB/5Afs/pG1TTkF0tcKa+oAQ==<br>-----END EC PRIVATE KEY-----<br><strong>issuer=O = Example, CN = Example Labs Issuing CA v1.1.2<br></strong>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 14:38:23 2022 GMT<br>notAfter=Sep 20 14:39:23 2022 GMT<br><strong>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIORzgwnBQLRiXg0VlKw2rvlmVyw1zBfUSmege4MZ35ykoAoGCCqGSM49<br>AwEHoUQDQgAEvaDezFf31ErSxJw3vniiAWylYXYcnL5/SaTOg7Fh2fGFE4BVkUxF<br>5wMWU7H+OYoj5nGBxjwXyLcn1jT9v4IuyQ==<br>-----END EC PRIVATE KEY-----<br>issuer=O = Example, CN = Example Labs Issuing CA v1.2.1<br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 14:38:51 2022 GMT<br>notAfter=Sep 20 14:39:51 2022 GMT<br>-----BEGIN CERTIFICATE-----<br>MIICZDCCAgqgAwIBAgIUMEo78R2WbVUklZKtRK29YZyWj6IwCgYIKoZIzj0EAwIw<br>QjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg<br>SW50ZXJtZWRpYWUgQ0EgdjEuMjAeFw0yMjA5MjAxNDIxNThaFw0yMzA5MjAxNDIy<br>MjhaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM<br>YWJzIElzc3VpbmcgQ0EgdjEuMi4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE<br>b25UxYE/Wk3cmJGmgq7H0RA5gBJNTuHfG+nszNlmjvr0hlbl2eb6c2nHPUDnVm06<br>8xiX+YEp5o4k5WKbpAWLB6OB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/<br>BAgwBgEB/wIBADAdBgNVHQ4EFgQUGj9YO8B8HiPIinLrhn+m5t0q3J4wHwYDVR0j<br>BBgwFoAUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwPwYIKwYBBQUHAQEEMzAxMC8GCCsG<br>AQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV<br>HR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j<br>cmwwCgYIKoZIzj0EAwIDSAAwRQIhAP9R8GYDrQ+dbalPeHAUc72RazDvVFOFt5zR<br>F2XoLB3gAiABK9YOSpdV/UCyjs+plIHmkIg27+tfABZ/WduS0cplUg==<br>-----END CERTIFICATE-----<br>-----BEGIN CERTIFICATE-----<br>MIIB2TCCAYCgAwIBAgIQG8oFUAX8PlV+kdLWoCLzFzAKBggqhkjOPQQDAjA0MRAw<br>DgYDVQQKEwdFeGFtcGxlMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9vdCBDQSB2<br>MTAeFw0yMjA5MjAxMzQ4MThaFw0yNzA5MjAxMzU4MThaMEIxFTATBgNVBAoTDEV4<br>YW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVkaWFlIENB<br>IHYxLjIwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASjEv6cyrtjznet8uUxjumP<br>if3cD0m+URss6KXtoD2vP6nDWrq3DxIizU746WE+tF9uGB6x+Rsb7lDbDz7ejrG7<br>o2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4E<br>FgQUiRTcIzSLI0sh7kRnKWYcGJ9zOIkwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDI<br>lZxg7z5RvXYwCgYIKoZIzj0EAwIDRwAwRAIgWJHBgtHO7YV04V9VXsJY4gvB5VlF<br>/t4j0EZOU0LYDB4CIGz/j5GLp57E+emPELkcoTI11Yo7X9q0OdYp4nyjBrKy<br>-----END CERTIFICATE-----</strong><br>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIJJeN5J3GzrOw0xosA30ZLv9nA87c0kkcp95/lGVG0CooAoGCCqGSM49<br>AwEHoUQDQgAEhr2YsJN2Ss0eR9TGhKIDpo777Dk5G6/PfU+r7LbSFqZwx5DcCwMf<br>c/iZC41alZ75ycYA7ZJSwh93xzqOJIE6dw==<br>-----END EC PRIVATE KEY-----<br><strong>issuer=O = Example, CN = Example Labs Issuing CA v1.2.1<br></strong>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 14:39:17 2022 GMT<br>notAfter=Sep 20 14:40:17 2022 GMT</pre><p>As a result, the Intermediate CA and the Issuing CA have been rotated, and the automatic generation of leaf certificates is passed on seamlessly to the new issuer.</p><p>In the next section, the Root CA is rotated.</p><h3>Rotate Root CA</h3><p>Now, let’s update the Root CA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*1lckQsYDsQCKhesSsK16aw.png" /><figcaption>Generate Root CA v2</figcaption></figure><p>First, generate a self-signed Root CA v2 using certstrap</p><pre><strong>$ certstrap --depot-path root \<br>    init \<br>    --organization &quot;Example&quot; \<br>    --common-name &quot;Example Labs Root CA v2&quot; \<br>    --expires &quot;10 years&quot; \<br>    --curve P-256 \<br>    --path-length 2 \<br>    --passphrase &quot;secret&quot;</strong><br>Created root/Example_Labs_Root_CA_v2.key (encrypted by passphrase)<br>Created root/Example_Labs_Root_CA_v2.crt<br>Created root/Example_Labs_Root_CA_v2.crl</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*3mtTnF4inqyVe92y6IWRHQ.png" /><figcaption>Generate v2.1 issuer for Intermediate CA</figcaption></figure><p>Let’s generate a new issuer for the Intermediate CA.</p><ul><li>Generate private key and CSR for <strong>v2.1</strong> issuer using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_int/intermediate/generate/internal</a>endpoint.</li></ul><pre><strong>$ vault write -format=json \<br>    pki_int/intermediate/generate/internal \<br>    organization=&quot;Example&quot; \<br>    common_name=&quot;Example Labs Intermediae CA v2.1&quot; \<br>    key_type=ec \<br>    key_bits=256 \<br>    | jq -r &#39;.data.csr&#39; &gt; pki_int_v2.1.csr</strong></pre><ul><li>Sign and generate a certificate using the CSR with Root CA v2</li></ul><pre><strong>$ certstrap --depot-path root \<br>    sign \<br>    --CA &quot;Example Labs Root CA v2&quot; \<br>    --passphrase &quot;secret&quot; \<br>    --intermediate \<br>    --csr pki_int_v2.1.csr \<br>    --expires &quot;5 years&quot; \<br>    --path-length 1 \<br>    --cert pki_int_v2.1.crt \<br>    &quot;Example Labs Intermediate CA v2.1&quot;</strong><br>Building intermediate<br><strong>$ openssl x509 -in pki_int_v2.1.crt -text -noout</strong><br>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            c2:60:be:af:06:ab:b2:c0:cd:09:46:89:e6:29:01:35<br>        Signature Algorithm: ecdsa-with-SHA256<br><strong>        Issuer: O = Example, CN = Example Labs Root CA v2</strong><br>        Validity<br>            Not Before: Sep 20 14:44:54 2022 GMT<br>            Not After : Sep 20 14:54:54 2027 GMT<br><strong>        Subject: O = Example, CN = Example Labs Intermediae CA v2.1<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:97:68:be:e1:f5:b9:60:8c:df:b3:93:b0:df:32:<br>                    da:db:d1:2f:d9:d2:c3:dc:23:f4:65:06:b7:93:34:<br>                    ab:20:fe:ab:5f:a4:cf:7c:5b:f2:98:9a:a7:56:9a:<br>                    9b:ee:68:60:f7:4d:b0:ac:3a:2d:6f:83:5b:f9:bb:<br>                    d5:05:03:14:9b<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Certificate Sign, CRL Sign<br>            X509v3 Basic Constraints: critical<br><strong>                CA:TRUE, pathlen:1<br></strong>            X509v3 Subject Key Identifier:<br>                F5:4C:47:59:A7:46:E5:98:A7:F4:6D:DB:55:F6:58:5E:...<br>            X509v3 Authority Key Identifier:<br>                keyid:51:49:EE:AF:2A:CD:6B:7C:EE:96:03:60:F2:0C:...</pre><pre>Signature Algorithm: ecdsa-with-SHA256<br>         30:46:02:21:00:a5:cc:ec:ad:36:6e:9b:b7:76:75:2f:68:3d:<br>         c4:88:03:55:4c:72:70:89:88:1b:80:8e:e2:4e:59:74:cc:c5:<br>         38:02:21:00:8f:a9:1f:c4:36:fb:bb:20:01:39:3d:5a:e2:65:<br>         b6:4d:4b:43:bc:18:8d:0d:f9:25:c3:5d:e4:2d:87:8b:cb:88</pre><ul><li>Store intermediate certificate into the Intermediate CA using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_int/intermediate/set-signed</a>endpoint</li></ul><pre><strong>$ vault write -format=json \<br>    pki_int/intermediate/set-signed \<br>    certificate=@pki_int_v2.1.crt \<br>    &gt; pki_int_v2.1.set-signed.json<br>$ cat pki_int_v2.1.set-signed.json<br></strong>{<br>  &quot;request_id&quot;: &quot;de4c817e-3cd7-f6a1-1baf-d201a2435a3b&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;imported_issuers&quot;: [<br><strong>      &quot;b2549f1f-3304-3e76-1e72-f02510a4659d&quot;<br></strong>    ],<br>    &quot;imported_keys&quot;: null,<br>    &quot;mapping&quot;: {<br>      &quot;b2549f1f-3304-3e76-1e72-f02510a4659d&quot;: &quot;85c8cf07-047a-e44b-7a73-0b3a0261af7a&quot;<br>    }<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><ul><li>Extract the issuer_id from the previous response, then rename the new issuer to <strong>v2.1 </strong>using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#update-issuer">pki_int/issuer/:issuer_ref</a> endpoint.</li></ul><pre><strong>$ cat pki_int_v2.1.set-signed.json \<br>    | jq -r &#39;.data.imported_issuers[0]&#39; \<br>    &gt; pki_int_v2.1.issuer_ref<br>$ vault write -format=json \<br>    pki_int/issuer/`cat pki_int_v2.1.issuer_ref` \<br>    issuer_name=v2.1 \<br>    &gt; pki_int_v2.1.rename.json<br>$ cat pki_int_v2.1.rename.json<br></strong>{<br>  &quot;request_id&quot;: &quot;f617c3ba-8eb9-8885-0690-3a94a628f38e&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB4TCCAYagAwIBAgIRAMJgvq8Gq7LAzQlGieYpATUwCgYIKoZIzj0EAwIwOTEV\nMBMGA1UEChMMRXhhbXBsZSBMYWJzMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9v\ndCBDQSB2MjAeFw0yMjA5MjAxNDQ0NTRaFw0yNzA5MjAxNDU0NTRaMEIxFTATBgNV\nBAoTDEV4YW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVk\naWFlIENBIHYyLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASXaL7h9blgjN+z\nk7DfMtrb0S/Z0sPcI/RlBreTNKsg/qtfpM98W/KYmqdWmpvuaGD3TbCsOi1vg1v5\nu9UFAxSbo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd\nBgNVHQ4EFgQU9UxHWadG5Zin9G3bVfZYXp0XZb8wHwYDVR0jBBgwFoAUUUnuryrN\na3zulgNg8gyXQ59isjowCgYIKoZIzj0EAwIDSQAwRgIhAKXM7K02bpu3dnUvaD3E\niANVTHJwiYgbgI7iTll0zMU4AiEAj6kfxDb7uyABOT1a4mW2TUtDvBiNDfklw13k\nLYeLy4g=\n-----END CERTIFICATE-----\n&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIIB4TCCAYagAwIBAgIRAMJgvq8Gq7LAzQlGieYpATUwCgYIKoZIzj0EAwIwOTEV\nMBMGA1UEChMMRXhhbXBsZSBMYWJzMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9v\ndCBDQSB2MjAeFw0yMjA5MjAxNDQ0NTRaFw0yNzA5MjAxNDU0NTRaMEIxFTATBgNV\nBAoTDEV4YW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVk\naWFlIENBIHYyLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASXaL7h9blgjN+z\nk7DfMtrb0S/Z0sPcI/RlBreTNKsg/qtfpM98W/KYmqdWmpvuaGD3TbCsOi1vg1v5\nu9UFAxSbo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd\nBgNVHQ4EFgQU9UxHWadG5Zin9G3bVfZYXp0XZb8wHwYDVR0jBBgwFoAUUUnuryrN\na3zulgNg8gyXQ59isjowCgYIKoZIzj0EAwIDSQAwRgIhAKXM7K02bpu3dnUvaD3E\niANVTHJwiYgbgI7iTll0zMU4AiEAj6kfxDb7uyABOT1a4mW2TUtDvBiNDfklw13k\nLYeLy4g=\n-----END CERTIFICATE-----\n&quot;,<br><strong>    &quot;issuer_id&quot;: &quot;b2549f1f-3304-3e76-1e72-f02510a4659d&quot;,<br>    &quot;issuer_name&quot;: &quot;v2.1&quot;,<br></strong>    &quot;key_id&quot;: &quot;85c8cf07-047a-e44b-7a73-0b3a0261af7a&quot;,<br>    &quot;leaf_not_after_behavior&quot;: &quot;err&quot;,<br>    &quot;manual_chain&quot;: null,<br>    &quot;usage&quot;: &quot;read-only,issuing-certificates,crl-signing&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*lpLgL4U7GmRDuZRQbY9D2A.png" /><figcaption>Generate v2.1.1 issuer for Issuing CA</figcaption></figure><p>Now, let’s generate a new issuer for Issuing CA.</p><ul><li>First, generate private key and CSR for <strong>v2.1.1</strong> issuer using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_iss/intermediate/generate/internal</a>endpoint</li></ul><pre><strong>$ vault write -format=json \<br>    pki_iss/intermediate/generate/internal \<br>    organization=&quot;Example&quot; \<br>    common_name=&quot;Example Labs Issuing CA v2.1.1&quot; \<br>    key_type=ec \<br>    key_bits=256 \<br>    | jq -r &#39;.data.csr&#39; &gt; pki_iss_v2.1.1.csr</strong></pre><ul><li>Sign and generate a certificate using the CSR with Intermediate CA <strong>v2.1 </strong>using <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#sign-intermediate">pki_int/issuer/:issuer_ref/sign-intermediate</a> endpoint</li></ul><blockquote>The <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#sign-intermediate">pki_int/root/sign-intermediate</a><strong> </strong>endpoint uses the default issuer. So, it can’t be used because the default issuer for Intermediate CA isn’t set to v2.1.</blockquote><pre><strong>$ vault write -format=json \<br>    pki_int/issuer/v2.1/sign-intermediate \<br>    organization=&quot;Example&quot; \<br>    csr=@pki_iss_v2.1.1.csr \<br>    ttl=8760h \<br>    format=pem \<br>    &gt; pki_iss_v2.1.1.crt.json<br>$ cat pki_iss_v2.1.1.crt.json</strong><br>{<br>  &quot;request_id&quot;: &quot;fad0a282-b007-668f-1a9c-fcadfdaa174f&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIICZDCCAgqgAwIBAgIUPie9Pf1M0IH7dBNvrkYx4BSIlxUwCgYIKoZIzj0EAwIw\nQjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYWUgQ0EgdjIuMTAeFw0yMjA5MjAxNjI1NTNaFw0yMzA5MjAxNjI2\nMjNaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM\nYWJzIElzc3VpbmcgQ0EgdjIuMS4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nEexLHdGKeYFlBhMwjSlgLxvLNPrWSBgbzfhpUX4gaWSk9A/VeYFy1sxqblPImXZT\npMSAMeGmT120NnAqMDvHhaOB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/\nBAgwBgEB/wIBADAdBgNVHQ4EFgQUh0VbbLaqHCDv2IwgZxsN3alDPXYwHwYDVR0j\nBBgwFoAU9UxHWadG5Zin9G3bVfZYXp0XZb8wPwYIKwYBBQUHAQEEMzAxMC8GCCsG\nAQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV\nHR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j\ncmwwCgYIKoZIzj0EAwIDSAAwRQIhAPHuWMYBr9ivWAjLLWxVrQynpxl3pdd7v/i/\nXfpvl5jOAiAePmQMgmaNRMZ81mttNm7L2nmuA8Gr7ep6SmwWLVnVkA==\n-----END CERTIFICATE-----&quot;,<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB4TCCAYagAwIBAgIRAMJgvq8Gq7LAzQlGieYpATUwCgYIKoZIzj0EAwIwOTEV\nMBMGA1UEChMMRXhhbXBsZSBMYWJzMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9v\ndCBDQSB2MjAeFw0yMjA5MjAxNDQ0NTRaFw0yNzA5MjAxNDU0NTRaMEIxFTATBgNV\nBAoTDEV4YW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVk\naWFlIENBIHYyLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASXaL7h9blgjN+z\nk7DfMtrb0S/Z0sPcI/RlBreTNKsg/qtfpM98W/KYmqdWmpvuaGD3TbCsOi1vg1v5\nu9UFAxSbo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd\nBgNVHQ4EFgQU9UxHWadG5Zin9G3bVfZYXp0XZb8wHwYDVR0jBBgwFoAUUUnuryrN\na3zulgNg8gyXQ59isjowCgYIKoZIzj0EAwIDSQAwRgIhAKXM7K02bpu3dnUvaD3E\niANVTHJwiYgbgI7iTll0zMU4AiEAj6kfxDb7uyABOT1a4mW2TUtDvBiNDfklw13k\nLYeLy4g=\n-----END CERTIFICATE-----&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICZDCCAgqgAwIBAgIUPie9Pf1M0IH7dBNvrkYx4BSIlxUwCgYIKoZIzj0EAwIw\nQjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYWUgQ0EgdjIuMTAeFw0yMjA5MjAxNjI1NTNaFw0yMzA5MjAxNjI2\nMjNaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM\nYWJzIElzc3VpbmcgQ0EgdjIuMS4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nEexLHdGKeYFlBhMwjSlgLxvLNPrWSBgbzfhpUX4gaWSk9A/VeYFy1sxqblPImXZT\npMSAMeGmT120NnAqMDvHhaOB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/\nBAgwBgEB/wIBADAdBgNVHQ4EFgQUh0VbbLaqHCDv2IwgZxsN3alDPXYwHwYDVR0j\nBBgwFoAU9UxHWadG5Zin9G3bVfZYXp0XZb8wPwYIKwYBBQUHAQEEMzAxMC8GCCsG\nAQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV\nHR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j\ncmwwCgYIKoZIzj0EAwIDSAAwRQIhAPHuWMYBr9ivWAjLLWxVrQynpxl3pdd7v/i/\nXfpvl5jOAiAePmQMgmaNRMZ81mttNm7L2nmuA8Gr7ep6SmwWLVnVkA==\n-----END CERTIFICATE-----&quot;,<br>    &quot;expiration&quot;: 1695227183,<br>    &quot;issuing_ca&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIIB4TCCAYagAwIBAgIRAMJgvq8Gq7LAzQlGieYpATUwCgYIKoZIzj0EAwIwOTEV\nMBMGA1UEChMMRXhhbXBsZSBMYWJzMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9v\ndCBDQSB2MjAeFw0yMjA5MjAxNDQ0NTRaFw0yNzA5MjAxNDU0NTRaMEIxFTATBgNV\nBAoTDEV4YW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVk\naWFlIENBIHYyLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASXaL7h9blgjN+z\nk7DfMtrb0S/Z0sPcI/RlBreTNKsg/qtfpM98W/KYmqdWmpvuaGD3TbCsOi1vg1v5\nu9UFAxSbo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd\nBgNVHQ4EFgQU9UxHWadG5Zin9G3bVfZYXp0XZb8wHwYDVR0jBBgwFoAUUUnuryrN\na3zulgNg8gyXQ59isjowCgYIKoZIzj0EAwIDSQAwRgIhAKXM7K02bpu3dnUvaD3E\niANVTHJwiYgbgI7iTll0zMU4AiEAj6kfxDb7uyABOT1a4mW2TUtDvBiNDfklw13k\nLYeLy4g=\n-----END CERTIFICATE-----&quot;,<br>    &quot;serial_number&quot;: &quot;3e:27:bd:3d:fd:4c:d0:81:fb:74:13:6f:ae:46:31:e0:14:88:97:15&quot;<br>  },<br>  &quot;warnings&quot;: [<br>    &quot;Max path length of the signed certificate is zero. This certificate cannot be used to issue intermediate CA certificates.&quot;<br>  ]<br>}<br><strong>$ cat pki_iss_v2.1.1.crt.json \<br>  | jq -r &#39;.data.certificate&#39; \<br>  &gt; pki_iss_v2.1.1.crt<br>$ openssl x509 -in pki_iss_v2.1.1.crt -text -noout</strong><br>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            3e:27:bd:3d:fd:4c:d0:81:fb:74:13:6f:ae:46:31:e0:...<br>        Signature Algorithm: ecdsa-with-SHA256<br><strong>        Issuer: O = Example, CN = Example Labs Intermediae CA v2.1<br></strong>        Validity<br>            Not Before: Sep 20 16:25:53 2022 GMT<br>            Not After : Sep 20 16:26:23 2023 GMT<br><strong>        Subject: O = Example, CN = Example Labs Issuing CA v2.1.1<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:11:ec:4b:1d:d1:8a:79:81:65:06:13:30:8d:29:<br>                    60:2f:1b:cb:34:fa:d6:48:18:1b:cd:f8:69:51:7e:<br>                    20:69:64:a4:f4:0f:d5:79:81:72:d6:cc:6a:6e:53:<br>                    c8:99:76:53:a4:c4:80:31:e1:a6:4f:5d:b4:36:70:<br>                    2a:30:3b:c7:85<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Certificate Sign, CRL Sign<br>            X509v3 Basic Constraints: critical<br><strong>                CA:TRUE, pathlen:0<br></strong>            X509v3 Subject Key Identifier:<br>                87:45:5B:6C:B6:AA:1C:20:EF:D8:8C:20:67:1B:0D:...<br>            X509v3 Authority Key Identifier:<br>                keyid:F5:4C:47:59:A7:46:E5:98:A7:F4:6D:DB:55:F6:...</pre><pre>            Authority Information Access:<br>                CA Issuers - URI:http://127.0.0.1:8200/v1/pki_int/ca</pre><pre>            X509v3 CRL Distribution Points:</pre><pre>                Full Name:<br>                  URI:http://127.0.0.1:8200/v1/pki_int/crl</pre><pre>Signature Algorithm: ecdsa-with-SHA256<br>         30:45:02:21:00:f1:ee:58:c6:01:af:d8:af:58:08:cb:2d:6c:<br>         55:ad:0c:a7:a7:19:77:a5:d7:7b:bf:f8:bf:5d:fa:6f:97:98:<br>         ce:02:20:1e:3e:64:0c:82:66:8d:44:c6:7c:d6:6b:6d:36:6e:<br>         cb:da:79:ae:03:c1:ab:ed:ea:7a:4a:6c:16:2d:59:d5:90</pre><ul><li>Store the new intermediate certificate and the new issuing certificate into the Issuing CA using the<a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_iss/intermediate/set-signed</a> endpoint<strong>.</strong></li></ul><pre><strong>$ cat pki_iss_v2.1.1.crt pki_int_v2.1.crt &gt; pki_iss_v2.1.1.chain.crt<br>$ vault write -format=json \<br>    pki_iss/intermediate/set-signed \<br>    certificate=@pki_iss_v2.1.1.chain.crt \<br>    &gt; pki_iss_v2.1.1.set-signed.json<br>$ cat pki_iss_v2.1.1.set-signed.json<br></strong>{<br>  &quot;request_id&quot;: &quot;51eb024e-c4fa-1ac7-bf61-bbb5a1b535e4&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;imported_issuers&quot;: [<br><strong>      &quot;68c43ef3-f6f8-5ac6-ee21-e320d96f68f0&quot;,<br></strong>      &quot;396e8878-26e0-74d0-9b2b-d02943c65902&quot;<br>    ],<br>    &quot;imported_keys&quot;: null,<br>    &quot;mapping&quot;: {<br>      &quot;396e8878-26e0-74d0-9b2b-d02943c65902&quot;: &quot;&quot;,<br>      &quot;68c43ef3-f6f8-5ac6-ee21-e320d96f68f0&quot;: &quot;ec038893-b95b-e19f-179f-5cbda0cdab2f&quot;<br>    }<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><ul><li>Extract the issuer_id from the previous response, then rename the new issuer to <strong>v2.1.1 </strong>using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#update-issuer">pki_iss/issuer/:issuer_ref</a> endpoint.</li></ul><pre><strong>$ cat pki_iss_v2.1.1.set-signed.json \<br>    | jq -r &#39;.data.imported_issuers[0]&#39; \<br>    &gt; pki_iss_v2.1.1.issuer_ref<br>$ vault write -format=json \<br>    pki_iss/issuer/`cat pki_iss_v2.1.1.issuer_ref` \<br>    issuer_name=v2.1.1 \<br>    &gt; pki_iss_v2.1.1.rename.json<br>$ cat pki_iss_v2.1.1.rename.json</strong><br>{<br>  &quot;request_id&quot;: &quot;ab5e3d2a-d33c-c462-cbfe-7a5f180d2909&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIICZDCCAgqgAwIBAgIUPie9Pf1M0IH7dBNvrkYx4BSIlxUwCgYIKoZIzj0EAwIw\nQjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYWUgQ0EgdjIuMTAeFw0yMjA5MjAxNjI1NTNaFw0yMzA5MjAxNjI2\nMjNaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM\nYWJzIElzc3VpbmcgQ0EgdjIuMS4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nEexLHdGKeYFlBhMwjSlgLxvLNPrWSBgbzfhpUX4gaWSk9A/VeYFy1sxqblPImXZT\npMSAMeGmT120NnAqMDvHhaOB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/\nBAgwBgEB/wIBADAdBgNVHQ4EFgQUh0VbbLaqHCDv2IwgZxsN3alDPXYwHwYDVR0j\nBBgwFoAU9UxHWadG5Zin9G3bVfZYXp0XZb8wPwYIKwYBBQUHAQEEMzAxMC8GCCsG\nAQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV\nHR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j\ncmwwCgYIKoZIzj0EAwIDSAAwRQIhAPHuWMYBr9ivWAjLLWxVrQynpxl3pdd7v/i/\nXfpvl5jOAiAePmQMgmaNRMZ81mttNm7L2nmuA8Gr7ep6SmwWLVnVkA==\n-----END CERTIFICATE-----\n&quot;,<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB4TCCAYagAwIBAgIRAMJgvq8Gq7LAzQlGieYpATUwCgYIKoZIzj0EAwIwOTEV\nMBMGA1UEChMMRXhhbXBsZSBMYWJzMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9v\ndCBDQSB2MjAeFw0yMjA5MjAxNDQ0NTRaFw0yNzA5MjAxNDU0NTRaMEIxFTATBgNV\nBAoTDEV4YW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVk\naWFlIENBIHYyLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASXaL7h9blgjN+z\nk7DfMtrb0S/Z0sPcI/RlBreTNKsg/qtfpM98W/KYmqdWmpvuaGD3TbCsOi1vg1v5\nu9UFAxSbo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd\nBgNVHQ4EFgQU9UxHWadG5Zin9G3bVfZYXp0XZb8wHwYDVR0jBBgwFoAUUUnuryrN\na3zulgNg8gyXQ59isjowCgYIKoZIzj0EAwIDSQAwRgIhAKXM7K02bpu3dnUvaD3E\niANVTHJwiYgbgI7iTll0zMU4AiEAj6kfxDb7uyABOT1a4mW2TUtDvBiNDfklw13k\nLYeLy4g=\n-----END CERTIFICATE-----\n&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICZDCCAgqgAwIBAgIUPie9Pf1M0IH7dBNvrkYx4BSIlxUwCgYIKoZIzj0EAwIw\nQjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYWUgQ0EgdjIuMTAeFw0yMjA5MjAxNjI1NTNaFw0yMzA5MjAxNjI2\nMjNaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM\nYWJzIElzc3VpbmcgQ0EgdjIuMS4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nEexLHdGKeYFlBhMwjSlgLxvLNPrWSBgbzfhpUX4gaWSk9A/VeYFy1sxqblPImXZT\npMSAMeGmT120NnAqMDvHhaOB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/\nBAgwBgEB/wIBADAdBgNVHQ4EFgQUh0VbbLaqHCDv2IwgZxsN3alDPXYwHwYDVR0j\nBBgwFoAU9UxHWadG5Zin9G3bVfZYXp0XZb8wPwYIKwYBBQUHAQEEMzAxMC8GCCsG\nAQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV\nHR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j\ncmwwCgYIKoZIzj0EAwIDSAAwRQIhAPHuWMYBr9ivWAjLLWxVrQynpxl3pdd7v/i/\nXfpvl5jOAiAePmQMgmaNRMZ81mttNm7L2nmuA8Gr7ep6SmwWLVnVkA==\n-----END CERTIFICATE-----\n&quot;,<br><strong>    &quot;issuer_id&quot;: &quot;68c43ef3-f6f8-5ac6-ee21-e320d96f68f0&quot;,<br>    &quot;issuer_name&quot;: &quot;v2.1.1&quot;,<br></strong>    &quot;key_id&quot;: &quot;ec038893-b95b-e19f-179f-5cbda0cdab2f&quot;,<br>    &quot;leaf_not_after_behavior&quot;: &quot;err&quot;,<br>    &quot;manual_chain&quot;: null,<br>    &quot;usage&quot;: &quot;issuing-certificates,crl-signing,read-only&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*Gyo1Al-hiK1uaKDZMS2SPA.png" /><figcaption>Set default issuer to v2.1</figcaption></figure><ul><li>Now, rotate the Intermediate CA by setting the default issuer to <strong>v2.1 </strong>using<strong> </strong>the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#set-issuers-configuration">pki_int/root/replace</a>endpoint.</li></ul><pre><strong>$ vault write -format=json \<br>    pki_int/root/replace \<br>    default=v2.1 \<br>    &gt; pki_int_v2.1.replace.json<br>$ cat pki_int_v2.1.replace.json</strong><br>{<br>  &quot;request_id&quot;: &quot;f30cde61-31bc-582f-818c-bfeaf60f9edd&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br><strong>    &quot;default&quot;: &quot;b2549f1f-3304-3e76-1e72-f02510a4659d&quot;<br></strong>  },<br>  &quot;warnings&quot;: null<br>}<br><strong>$ vault list -detailed pki_int/issuers</strong><br>Keys                                    is_default    issuer_name<br>----                                    ----------    -----------<br>08ca0f1e-abad-4a6a-f632-6199adc0a9d4    false         v1.2<br>17438773-df12-5bab-a7ee-83a7305037fb    false         v1.1<br>b2549f1f-3304-3e76-1e72-f02510a4659d    true          v2.1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*CUaFx8YZoPlWYFBj2t-5pQ.png" /><figcaption>Set default issuer to v2.1.1</figcaption></figure><ul><li>Now, rotate the Issuing CA by setting the default issuer to <strong>v2.1.1 </strong>using<strong> </strong>the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#set-issuers-configuration">pki_iss/root/replace</a>endpoint.</li></ul><pre><strong>$ vault write -format=json \<br>    pki_iss/root/replace \<br>    default=v2.1.1 \<br>    &gt; pki_iss_v2.1.1.replace.json</strong><br><strong>$ cat pki_iss_v2.1.1.replace.json<br></strong>{<br>  &quot;request_id&quot;: &quot;dc969f74-3a99-1497-0ea0-1c3506fde036&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br><strong>    &quot;default&quot;: &quot;68c43ef3-f6f8-5ac6-ee21-e320d96f68f0&quot;<br></strong>  },<br>  &quot;warnings&quot;: null<br>}<br><strong>$ vault list -detailed pki_iss/issuers | grep -v &quot;n/a&quot;<br></strong>Keys                                    is_default    issuer_name<br>----                                    ----------    -----------<br>42149e44-785e-3dec-a7e1-ba9e1c4804a0    false         v1.1.2<br>68c43ef3-f6f8-5ac6-ee21-e320d96f68f0    true          v2.1.1<br>957c0c19-a66b-f2fa-b868-05f01bc142e5    false         v1.1.1<br>b0074a43-589b-b59e-5683-f4c6f8b3348a    false         v1.2.1</pre><p>Let’s check the terminal where <strong>consul-template</strong> is running. As the default issuer has been replace by the <strong>v2.1.1 </strong>issuer, the issued leaf certificates are now with <strong>v2.1.1</strong> issuer. The CA chain is updated as well because the Intermediate CA and the Issuing CA certificates are now respectively from the <strong>v2.1</strong> and the <strong>v2.1.1</strong> issuers.</p><pre>----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIK9Gxr0XfGYxjt1CVZ7F8wRkdxZf4Qz/Bkl5Ar9K5LpNoAoGCCqGSM49<br>AwEHoUQDQgAEGlLdQQurLXgTETFEExH+WQVDLWtBO/gLc9HAvHpPtvJGgi32mA44<br>6lD0j+SsYmnWclodPbMWt1CgQItI/aoydQ==<br>-----END EC PRIVATE KEY-----<br><strong>issuer=O = Example, CN = Example Labs Issuing CA v1.2.1</strong><br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 16:36:56 2022 GMT<br>notAfter=Sep 20 16:37:56 2022 GMT<br><strong>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEICcqlkR22J+f+BWuATUkbbtkQ9+NvJV64HdCNoxaFjj1oAoGCCqGSM49<br>AwEHoUQDQgAEzV2HpXpZYP14HmKD2IEi9Tl0xYIF9Vll6LivJX76oK0hWuvitPkt<br>GGVEnzCmWliPpdoSN2ZFZIB158GSlKN1iA==<br>-----END EC PRIVATE KEY-----<br>issuer=O = Example, CN = Example Labs Issuing CA v2.1.1<br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 16:37:22 2022 GMT<br>notAfter=Sep 20 16:38:22 2022 GMT<br>-----BEGIN CERTIFICATE-----<br>MIICZDCCAgqgAwIBAgIUPie9Pf1M0IH7dBNvrkYx4BSIlxUwCgYIKoZIzj0EAwIw<br>QjEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSkwJwYDVQQDEyBFeGFtcGxlIExhYnMg<br>SW50ZXJtZWRpYWUgQ0EgdjIuMTAeFw0yMjA5MjAxNjI1NTNaFw0yMzA5MjAxNjI2<br>MjNaMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhhbXBsZSBM<br>YWJzIElzc3VpbmcgQ0EgdjIuMS4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE<br>EexLHdGKeYFlBhMwjSlgLxvLNPrWSBgbzfhpUX4gaWSk9A/VeYFy1sxqblPImXZT<br>pMSAMeGmT120NnAqMDvHhaOB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/<br>BAgwBgEB/wIBADAdBgNVHQ4EFgQUh0VbbLaqHCDv2IwgZxsN3alDPXYwHwYDVR0j<br>BBgwFoAU9UxHWadG5Zin9G3bVfZYXp0XZb8wPwYIKwYBBQUHAQEEMzAxMC8GCCsG<br>AQUFBzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNV<br>HR8ELjAsMCqgKKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9j<br>cmwwCgYIKoZIzj0EAwIDSAAwRQIhAPHuWMYBr9ivWAjLLWxVrQynpxl3pdd7v/i/<br>Xfpvl5jOAiAePmQMgmaNRMZ81mttNm7L2nmuA8Gr7ep6SmwWLVnVkA==<br>-----END CERTIFICATE-----<br>-----BEGIN CERTIFICATE-----<br>MIIB4TCCAYagAwIBAgIRAMJgvq8Gq7LAzQlGieYpATUwCgYIKoZIzj0EAwIwOTEV<br>MBMGA1UEChMMRXhhbXBsZSBMYWJzMSAwHgYDVQQDExdFeGFtcGxlIExhYnMgUm9v<br>dCBDQSB2MjAeFw0yMjA5MjAxNDQ0NTRaFw0yNzA5MjAxNDU0NTRaMEIxFTATBgNV<br>BAoTDEV4YW1wbGUgTGFiczEpMCcGA1UEAxMgRXhhbXBsZSBMYWJzIEludGVybWVk<br>aWFlIENBIHYyLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASXaL7h9blgjN+z<br>k7DfMtrb0S/Z0sPcI/RlBreTNKsg/qtfpM98W/KYmqdWmpvuaGD3TbCsOi1vg1v5<br>u9UFAxSbo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd<br>BgNVHQ4EFgQU9UxHWadG5Zin9G3bVfZYXp0XZb8wHwYDVR0jBBgwFoAUUUnuryrN<br>a3zulgNg8gyXQ59isjowCgYIKoZIzj0EAwIDSQAwRgIhAKXM7K02bpu3dnUvaD3E<br>iANVTHJwiYgbgI7iTll0zMU4AiEAj6kfxDb7uyABOT1a4mW2TUtDvBiNDfklw13k<br>LYeLy4g=<br>-----END CERTIFICATE-----<br></strong>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIBQk/EcAdTT/H3rOndgshCZ4kpd0H5SqPur56gnWbFIGoAoGCCqGSM49<br>AwEHoUQDQgAEYCpMUaAIX025yCm/8obgOCiibPSsh0jGhIr8kXG9jXpt3H0Di3x/<br>LCQ1MAC9ZpPkRa5G35w/mt8iCLCH4hmyjg==<br>-----END EC PRIVATE KEY-----<br><strong>issuer=O = Example, CN = Example Labs Issuing CA v2.1.1<br></strong>subject=O = Example, CN = test.example.com<br>notBefore=Sep 20 16:37:49 2022 GMT<br>notAfter=Sep 20 16:38:49 2022 GMT</pre><p>As a result, the Root CA, the Intermediate CA and the Issuing CA have been rotated, and the automatic generation of leaf certificates is passed on seamlessly to the new issuer.</p><h3>Conclusion</h3><p>By introducing Multi-Issuer Feature on Vault 1.11.0, the certificates lifecycle is now easier than previous version where a PKI secret engine and a new role had to be created to manage the change of each CA which involved changing the consul-template configuration.</p><p>Thus, after rotating the Issuing, Intermediate and Root CA from a Vault PKI, the automatic generation of leaf certificates is passed on seamlessly: no more change is required on roles or on consul-template configuration.</p><p>This configuration can be codified using the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs">Terraform Vault provider</a> to do this, read the <a href="https://medium.com/@sestegra/codify-vault-internal-pki-using-terraform-c0f760323813">Codify Vault Internal PKI using Terraform</a> article.</p><h3>Next Steps</h3><p>The next article (Part 4) presents a solution to manage your public certificates and <a href="https://medium.com/@sestegra/securely-store-public-certificates-in-vault-generated-by-acme-sh-2d6e98c9d308">securely store Public Certificates in Vault, generated by acme.sh</a>.</p><h3>References</h3><ul><li><a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#notice-about-new-multi-issuer-functionality">PKI - Secrets Engines - HTTP API | Vault | HashiCorp Developer</a></li><li><a href="https://registry.terraform.io/providers/hashicorp/vault">Terraform Registry</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9262228b4afb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Issue, Deploy and Renew your Private Certificates with Vault and Consul-Template]]></title>
            <link>https://sestegra.medium.com/issue-deploy-and-renew-your-private-certificates-with-vault-and-consul-template-1f5e4fe5f15c?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f5e4fe5f15c</guid>
            <category><![CDATA[hashicorp-vault]]></category>
            <category><![CDATA[hashicorp]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Wed, 28 Sep 2022 18:38:22 GMT</pubDate>
            <atom:updated>2023-07-16T13:53:25.833Z</atom:updated>
            <content:encoded><![CDATA[<p>Automate your Certificates Lifecycle with Vault — Part 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3nk8uqPrz8HbCnmVtj_vAg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@sortino?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Joshua Sortino</a> on <a href="https://unsplash.com/s/photos/technology?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>This article is a part of a series about how to<br><a href="https://medium.com/@sestegra/automate-your-certificates-lifecycle-with-vault-bc7ffff2430c"><strong>Automate your Certificates Lifecycle with Vault</strong></a>.</blockquote><ol><li><a href="https://medium.com/@sestegra/build-an-internal-pki-with-vault-f7179306f18c">Build an Internal PKI with Vault</a></li><li><a href="https://medium.com/@sestegra/issue-deploy-and-renew-your-private-certificates-with-vault-and-consul-template-1f5e4fe5f15c"><strong>Issue, Deploy and Renew your Private Certificates with Vault and Consul-Template</strong></a><strong> (this article)</strong></li><li><a href="https://medium.com/@sestegra/rotate-your-ca-seamlessly-using-a-vault-pki-9262228b4afb">Rotate your CA seamlessly using a Vault PKI</a></li><li><a href="https://medium.com/@sestegra/securely-store-public-certificates-in-vault-generated-by-acme-sh-2d6e98c9d308">Securely store Public Certificates in Vault, generated by acme.sh</a></li><li><a href="https://medium.com/@sestegra/codify-vault-internal-pki-using-terraform-c0f760323813">Codify Vault Internal PKI using Terraform</a></li></ol><h3>Introduction</h3><p>This article contains a walkthrough to issue, deploy and renew your private certificates using the Vault PKI built in the previous article of this series.</p><h3>Pre-Requisites</h3><ul><li>Install <a href="https://github.com/hashicorp/consul-template#installation"><strong>consul-template</strong></a> 0.29.0 or higher</li><li>Create a three-tier PKI CA from the <a href="https://medium.com/@sestegra/build-an-internal-pki-with-vault-f7179306f18c">Build an Internal PKI with Vault</a> article with one of the following solutions:<br> — Follow the walkthrough step by step<br> — Follow the <a href="https://medium.com/@sestegra/build-an-internal-pki-with-vault-f7179306f18c#6258"><strong>Summary of commands</strong></a><strong> </strong>section<strong> </strong>(at the end of the article)</li></ul><h3>Consul-Template</h3><p><strong>Consul-Template</strong> is a template rendering daemon that queries a <a href="https://www.consul.io/">Consul</a>, <a href="https://www.vaultproject.io/">Vault</a>, or <a href="https://www.nomadproject.io/">Nomad</a> cluster and updates any number of specified templates on the filesystem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/0*TSLye8q7MKZPX5Hy" /><figcaption>Consul-Template and Vault</figcaption></figure><p>Consul-Template uses the <a href="https://pkg.go.dev/text/template">Go Template</a> format with <a href="https://github.com/hashicorp/consul-template/blob/main/docs/templating-language.md#sprig-functions">additional functions</a>. The dedicated functions for Vault are <a href="https://github.com/hashicorp/consul-template/blob/main/docs/templating-language.md#secret">secret</a>, <a href="https://github.com/hashicorp/consul-template/blob/main/docs/templating-language.md#secrets">secrets</a> and <a href="https://github.com/hashicorp/consul-template/blob/main/docs/templating-language.md#pkicert">pkiCert</a>.</p><blockquote>Before using pkiCert, read the <strong>Special Note</strong> carefully to understand its usage. The rendered file is used as a cache and must contain the certificate.</blockquote><p>For instance, here are the following templates that issue the private key, the certificate, and the CA chain for the issued leaf certificate test.example.com. The last one queries the CA chain stored in pki_iss without issuing any leaf certificate.</p><pre>{{- with <strong>secret</strong> &quot;<strong>pki_iss/issue/example</strong>&quot; &quot;common_name=test.example.com&quot; -}}<br>{{ <strong>.Data.private_key</strong> }}<br>{{- end -}}</pre><pre>{{- with <strong>secret</strong> &quot;<strong>pki_iss/issue/example</strong>&quot; &quot;common_name=test.example.com&quot; -}}<br>{{ <strong>.Data.certificate</strong> }}<br>{{- end -}}</pre><pre>{{- with <strong>secret</strong> &quot;<strong>pki_iss/issue/example</strong>&quot; &quot;common_name=test.example.com&quot; -}}<br>{{ <strong>.Data.ca_chain</strong> }}<br>{{- end -}}</pre><pre>{{- with <strong>secret</strong> &quot;<strong>pki_iss/cert/ca_chain</strong>&quot; -}}<br>{{ <strong>.Data.ca_chain</strong> }}<br>{{- end -}}</pre><h3>Issue and Deploy Certificate</h3><p>First of all, the <strong>consul-template</strong> daemon should be configured with a dedicated configuration file:</p><ul><li>to connect to the Vault server</li><li>to generate files from specified templates</li></ul><blockquote>Read the <a href="https://github.com/hashicorp/consul-template/blob/main/docs/configuration.md">configuration documentation</a> for further information</blockquote><p>Here is a configuration file that uses the exemple role (built in the previous article) to generate cert.key, cert.crt and cert.ca files related to an issued certificate for test.example.com.</p><blockquote><strong>Disclaimer</strong>: On production<br>- Don’t use the root token<br>- Create auth methods, entities, groups and policies to grant or forbid access to PKI features</blockquote><pre>$ cat &lt;&lt;EOF &gt; <strong>consul-template.hcl</strong><br>vault {<br>  address     = &quot;http://127.0.0.1:8200&quot;<br>  token       = &quot;root&quot;<br>  renew_token = false<br>}</pre><pre>template {<br>  contents = &lt;&lt;EOH<br>{{- with secret &quot;pki_iss/issue/example&quot; &quot;common_name=test.example.com&quot; -}}<br>{{ .Data.private_key }}<br>{{- end }}<br>EOH<br>  destination = &quot;cert.key&quot;<br>}</pre><pre>template {<br>  contents = &lt;&lt;EOH<br>{{- with secret &quot;pki_iss/issue/example&quot; &quot;common_name=test.example.com&quot; -}}<br>{{ .Data.certificate }}<br>{{- end }}<br>EOH<br>  destination = &quot;cert.crt&quot;<br>}</pre><pre>template {<br>  contents = &lt;&lt;EOH<br>{{- with secret &quot;pki_iss/issue/example&quot; &quot;common_name=test.example.com&quot; -}}<br>{{- range .Data.ca_chain -}}<br>{{ . }}<br>{{ end -}}<br>{{- end -}}<br>EOH<br>  destination = &quot;cert.ca&quot;<br>}</pre><pre>EOF</pre><p>Start <strong>consul-template</strong>, but only once, not in a daemon mode to check the generated files. Next, check the rendered files.</p><pre><strong>$ consul-template -config=consul-template.hcl -log-level info -once<br></strong>[INFO] consul-template v0.29.2 (06389a3d)<br>[INFO] (runner) creating new runner (dry: false, once: true)<br>[INFO] (runner) creating watcher<br>[INFO] (runner) starting<br>[INFO] (runner) rendered &quot;(dynamic)&quot; =&gt; &quot;cert.key&quot;<br>[INFO] (runner) rendered &quot;(dynamic)&quot; =&gt; &quot;cert.crt&quot;<br>[INFO] (runner) rendered &quot;(dynamic)&quot; =&gt; &quot;cert.ca&quot;<br>[INFO] (runner) once mode and all templates rendered<br>[INFO] (runner) stopping<br>$ <strong>cat cert.key</strong><br>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIJm+Ep54nx2009V3EXIl5l4TmnEvsr4RiFxp7ryQFcS8oAoGCCqGSM49<br>AwEHoUQDQgAEVfh8VvQ/eKeKqvIYHvu59cpAr+G/aXU5xKhd//gn2wdBmaUCyZdj<br>aqtUo1muPKjAhROaNukXFu8DeJYJJoEJ2Q==<br>-----END EC PRIVATE KEY-----<br><strong>$ cat cert.crt<br></strong>-----BEGIN CERTIFICATE-----<br>MIICfjCCAiSgAwIBAgIUT0UMUxONeUwDTrK8wrpZCoeDJ9AwCgYIKoZIzj0EAwIw<br>QDEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMScwJQYDVQQDEx5FeGFtcGxlIExhYnMg<br>SXNzdWluZyBDQSB2MS4xLjEwHhcNMjIwOTE5MTQ0MjU0WhcNMjIxMDIxMTQ0MzI0<br>WjAyMRUwEwYDVQQKEwxFeGFtcGxlIExhYnMxGTAXBgNVBAMTEHRlc3QuZXhhbXBs<br>ZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARV+HxW9D94p4qq8hge+7n1<br>ykCv4b9pdTnEqF3/+CfbB0GZpQLJl2Nqq1SjWa48qMCFE5o26RcW7wN4lgkmgQnZ<br>o4IBCDCCAQQwDgYDVR0PAQH/BAQDAgOoMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggr<br>BgEFBQcDAjAdBgNVHQ4EFgQUWV8iJwDXTuATSIYPrd1QYjr3fi0wHwYDVR0jBBgw<br>FoAU3j+4uC3xM3gfb2709xpS0G9Jp8UwPwYIKwYBBQUHAQEEMzAxMC8GCCsGAQUF<br>BzAChiNodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2lzcy9jYTAbBgNVHREE<br>FDASghB0ZXN0LmV4YW1wbGUuY29tMDUGA1UdHwQuMCwwKqAooCaGJGh0dHA6Ly8x<br>MjcuMC4wLjE6ODIwMC92MS9wa2lfaXNzL2NybDAKBggqhkjOPQQDAgNIADBFAiB0<br>asvZHDOB/XQGkEkd9OCGtXL8lbEDsacvxckhzWUmYQIhAIlVoA10TSZk8pbOc3p2<br>6o0MxJV7FRfSLSZHwngiWaAr<br>-----END CERTIFICATE-----<br><strong>$ cat cert.ca<br></strong>-----BEGIN CERTIFICATE-----<br>MIICYDCCAgagAwIBAgIUfzDvhr6caTp7VORPG2TMW1YxW/kwCgYIKoZIzj0EAwIw<br>PjEQMA4GA1UEChMHRXhhbXBsZTEqMCgGA1UEAxMhRXhhbXBsZSBMYWJzIEludGVy<br>bWVkaWF0ZSBDQSB2MS4xMB4XDTIyMDkxOTE0MTkxMloXDTIzMDkxOTE0MTk0Mlow<br>QDEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMScwJQYDVQQDEx5FeGFtcGxlIExhYnMg<br>SXNzdWluZyBDQSB2MS4xLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASlLm4w<br>h3+pun+oJ1LMvJ22rZRgxSPOkJJPBCUKONeM6n5Q0HF4ntcfzW0WHJfYDZWy1J0C<br>D0sFTMTMye5DSAQSo4HfMIHcMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG<br>AQH/AgEAMB0GA1UdDgQWBBTeP7i4LfEzeB9vbvT3GlLQb0mnxTAfBgNVHSMEGDAW<br>gBTWcE1m0LHFXpHrZqaGizi1A1PjtzA/BggrBgEFBQcBAQQzMDEwLwYIKwYBBQUH<br>MAKGI2h0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NhMDUGA1UdHwQu<br>MCwwKqAooCaGJGh0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaW50L2NybDAK<br>BggqhkjOPQQDAgNIADBFAiAOkTLPtqcMIhm7MxRJ+TEUlqo6uyeBSgMSdlTslL3q<br>xwIhALzEQPavjZDWvMqrqv++RPaEO2Jn9LqIrIDMjRwHwzFX<br>-----END CERTIFICATE-----<br>-----BEGIN CERTIFICATE-----<br>MIIB1zCCAX2gAwIBAgIRAOOa8Aj6bj5pqA/EADwcgRQwCgYIKoZIzj0EAwIwNDEQ<br>MA4GA1UEChMHRXhhbXBsZTEgMB4GA1UEAxMXRXhhbXBsZSBMYWJzIFJvb3QgQ0Eg<br>djEwHhcNMjIwOTE5MTQwOTQyWhcNMjcwOTE5MTQxOTQyWjA+MRAwDgYDVQQKEwdF<br>eGFtcGxlMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRpYXRlIENBIHYx<br>LjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASBVFRRBZk5UAk5Cc6ikbrexDaQ<br>+HqhGEoANTQni7aGAPIBL7jnTjk9XP4qovrdtWCfc5xc4Q3DsZmmCuJieqbko2Yw<br>ZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU<br>1nBNZtCxxV6R62amhos4tQNT47cwHwYDVR0jBBgwFoAUU8mUMKg2/sC1c1b+QhK3<br>MQkdqXAwCgYIKoZIzj0EAwIDSAAwRQIga3l340j1PM+2DCno8mXqJg0fpc8a01Cf<br>KyxEpOG9t14CIQDO0AIX9uIcg7bvraAIGMjQ7iEXMo36Op0gt/gI3XUymQ==<br>-----END CERTIFICATE-----<br><strong>$ openssl x509 -in cert.crt -text -noout<br></strong>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            4f:45:0c:53:13:8d:79:4c:03:4e:b2:bc:c2:ba:59:0a:87:83:27:d0<br>        Signature Algorithm: ecdsa-with-SHA256<br><strong>        Issuer: O = Example, CN = Example Labs Issuing CA v1.1.1<br></strong>        Validity<br>            Not Before: Sep 19 14:42:54 2022 GMT<br>            Not After : Oct 21 14:43:24 2022 GMT<br><strong>        Subject: O = Example, CN = test.example.com<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:55:f8:7c:56:f4:3f:78:a7:8a:aa:f2:18:1e:fb:<br>                    b9:f5:ca:40:af:e1:bf:69:75:39:c4:a8:5d:ff:f8:<br>                    27:db:07:41:99:a5:02:c9:97:63:6a:ab:54:a3:59:<br>                    ae:3c:a8:c0:85:13:9a:36:e9:17:16:ef:03:78:96:<br>                    09:26:81:09:d9<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Digital Signature, Key Encipherment, Key Agreement<br>            X509v3 Extended Key Usage:<br>                TLS Web Server Authentication, TLS Web Client Auth<br>            X509v3 Subject Key Identifier:<br>                59:5F:22:27:00:D7:4E:E0:13:48:86:0F:AD:DD:50:62:...<br>            X509v3 Authority Key Identifier:<br>                keyid:DE:3F:B8:B8:2D:F1:33:78:1F:6F:6E:F4:F7:1A:...</pre><pre>            Authority Information Access:<br>                CA Issuers - URI:http://127.0.0.1:8200/v1/pki_iss/ca</pre><pre>            X509v3 Subject Alternative Name:<br><strong>                DNS:test.example.com<br></strong>            X509v3 CRL Distribution Points:</pre><pre>                Full Name:<br>                  URI:http://127.0.0.1:8200/v1/pki_iss/crl</pre><pre>Signature Algorithm: ecdsa-with-SHA256<br>         30:45:02:20:74:6a:cb:d9:1c:33:81:fd:74:06:90:49:1d:f4:<br>         e0:86:b5:72:fc:95:b1:03:b1:a7:2f:c5:c9:21:cd:65:26:61:<br>         02:21:00:89:55:a0:0d:74:4d:26:64:f2:96:ce:73:7a:76:ea:<br>         8d:0c:c4:95:7b:15:17:d2:2d:26:47:c2:78:22:59:a0:2b</pre><h3>Renew Certificate</h3><p>By default, the certificate (as a non-renewable secret) is automatically renewed by Consul-Template at 90% of its TTL. The default TTL has been set to one month in theexamplerole. To test more often, let’s reduce the TTL to 30 seconds to see a renewal of the certificate (ttl=30s).</p><p>Consul-Template can optionally run arbitrary commands when the template is rendered and the output has changed. The exec block in the configuration should be added to execute a command.</p><pre><strong>exec {<br>  command = [ &quot;systemctl&quot;, &quot;reload”, &quot;nginx&quot; ]<br>  timeout = “30s”<br>}</strong></pre><p>So, you can reload or restart a service or an application that uses the certificate. For the sake of the demo, the command outputs the rendered template (cat cert.key) or the parsed certificate (openssl x509 -in cert.crt -issuer -subject -startdate -enddate -noout).</p><p>Here is the updated <strong>consul-template</strong> configuration file.</p><pre>$ cat &lt;&lt;EOF &gt; <strong>consul-template.hcl</strong><br>vault {<br>  address     = &quot;http://127.0.0.1:8200&quot;<br>  token       = &quot;root&quot;<br>  renew_token = false<br>}</pre><pre>template {<br>  contents = &lt;&lt;EOH<br>{{- with secret &quot;pki_iss/issue/example&quot; &quot;common_name=test.example.com&quot; <strong>&quot;ttl=30s&quot;</strong> -}}<br>{{ .Data.private_key }}<br>{{- end }}<br>EOH<br>  destination = &quot;cert.key&quot;<br>  exec {<br><strong>    command = [ &quot;cat&quot;, &quot;cert.key&quot; ]<br></strong>  }<br>}</pre><pre>template {<br>  contents = &lt;&lt;EOH<br>{{- with secret &quot;pki_iss/issue/example&quot; &quot;common_name=test.example.com&quot; <strong>&quot;ttl=30s&quot;</strong> -}}<br>{{ .Data.certificate }}<br>{{- end }}<br>EOH<br>  destination = &quot;cert.crt&quot;<br>  exec {<br><strong>    command = [<br>      &quot;openssl&quot;, &quot;x509&quot;, &quot;-in&quot;, &quot;cert.crt&quot;,<br>      &quot;-issuer&quot;, &quot;-subject&quot;, &quot;-startdate&quot;, &quot;-enddate&quot;,<br>      &quot;-noout&quot;<br></strong>    ]<br>  }<br>}</pre><pre>template {<br>  contents = &lt;&lt;EOH<br>{{- with secret &quot;pki_iss/issue/example&quot; &quot;common_name=test.example.com&quot; <strong>&quot;ttl=30s&quot;</strong> -}}<br>{{- range .Data.ca_chain -}}<br>{{ . }}<br>{{ end -}}<br>{{- end -}}<br>EOH<br>  destination = &quot;cert.ca&quot;<br>  exec {<br><strong>    command = [ &quot;cat&quot;, &quot;cert.ca&quot; ]<br></strong>  }<br>}</pre><pre>EOF</pre><p>So, let’s start the <strong>consul-template</strong> daemon.</p><pre><strong>$ consul-template -config=consul-template.hcl<br></strong>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIDe+3rXfvouGK/bymTvuCG++mVtJU+V5/VF2/ouBrp1moAoGCCqGSM49<br>AwEHoUQDQgAERpPVrgsyT3OvTfKqxEkFqSklcKYShrWuWHlZpWwNTa0WMHS6eTvm<br>1Ly7WLeMkMPHgsoalMEjFx6HIVgWZjEvAw==<br>-----END EC PRIVATE KEY-----<br>issuer=O = Example, CN = Example Labs Issuing CA v1.1.1<br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 19 16:30:24 2022 GMT<br>notAfter=Sep 19 16:31:24 2022 GMT<br>-----BEGIN CERTIFICATE-----<br>MIICWzCCAgGgAwIBAgIUTknVQDg1TmMqIYU/H4Z0j9q6q2IwCgYIKoZIzj0EAwIw<br>PjEQMA4GA1UEChMHRXhhbXBsZTEqMCgGA1UEAxMhRXhhbXBsZSBMYWJzIEludGVy<br>bWVkaWF0ZSBDQSB2MS4xMB4XDTIyMDkxOTE1MDQzOFoXDTIzMDkxOTE1MDUwOFow<br>OzEQMA4GA1UEChMHRXhhbXBsZTEnMCUGA1UEAxMeRXhhbXBsZSBMYWJzIElzc3Vp<br>bmcgQ0EgdjEuMS4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEWlU5PUeiItWC<br>YyltWZaS4W8fNANZkSjmd2oShXp2nSVDwN4+Dvf2ixFdzUWbklo5cBRLZxweL59c<br>hbYsbVgL9qOB3zCB3DAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIB<br>ADAdBgNVHQ4EFgQUqUDW46qmyyNELSER3ILqIXbmgOIwHwYDVR0jBBgwFoAU1v5V<br>z/G4Ai+KsgSqLatba/3vJMIwPwYIKwYBBQUHAQEEMzAxMC8GCCsGAQUFBzAChiNo<br>dHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jYTA1BgNVHR8ELjAsMCqg<br>KKAmhiRodHRwOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2ludC9jcmwwCgYIKoZI<br>zj0EAwIDSAAwRQIhALbt1mZx0pLyGMO8hyUDHfQpRAah0c3dZn5vusIW+vcCAiAz<br>/WTjjxMm5QeaEh9KBLQrcXXN2jXV7PI886sLBE/xCQ==<br>-----END CERTIFICATE-----<br>-----BEGIN CERTIFICATE-----<br>MIIB2DCCAX2gAwIBAgIRAMlAuLmxYK0hqR4uaheiDMowCgYIKoZIzj0EAwIwNDEQ<br>MA4GA1UEChMHRXhhbXBsZTEgMB4GA1UEAxMXRXhhbXBsZSBMYWJzIFJvb3QgQ0Eg<br>djEwHhcNMjIwOTE5MTQ1NTA4WhcNMjcwOTE5MTUwNTA4WjA+MRAwDgYDVQQKEwdF<br>eGFtcGxlMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRpYXRlIENBIHYx<br>LjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATBv71in6dt4FYoFIUWPEl8/PTk<br>N7vIryxD2sff7PY421erP9ZlWjG3dG5+1kFvHUrp26PGBYid304oVPIYWPHIo2Yw<br>ZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU<br>1v5Vz/G4Ai+KsgSqLatba/3vJMIwHwYDVR0jBBgwFoAUwkn7K1yzMRL7FLDIlZxg<br>7z5RvXYwCgYIKoZIzj0EAwIDSQAwRgIhAIgYXf1QhKLiAZxp08viP0jU57qRkNMP<br>xYSDwURq/rvoAiEAuq3Wytby/RsaMUvPhjOT0CR7fim9Pwaw1W5HdZ1WWg0=<br>-----END CERTIFICATE-----</pre><p>After 27 seconds (=30*0.90), the following output is shown. Only the new cert.key and cert.crt are displayed because the CA chain is unchanged.</p><pre>-----BEGIN EC PRIVATE KEY-----<br>MHcCAQEEIBn/Km4pnfB8OTOfmiSjHeqUtfdUtQVJ/kSX1pdRwM05oAoGCCqGSM49<br>AwEHoUQDQgAEALSYUgTvSjZw8Eb5gEL7RLtcpDSpi1neCM2dHXY+XbeKeDKWxYP3<br>DUHYu0A5mJZFzt/Yy/CZFkg50JABNPRyjg==<br>-----END EC PRIVATE KEY-----<br>issuer=O = Example, CN = Example Labs Issuing CA v1.1.1<br>subject=O = Example, CN = test.example.com<br>notBefore=Sep 19 16:30:50 2022 GMT<br>notAfter=Sep 19 16:31:50 2022 GMT</pre><h3>Conclusion</h3><p>This article shows how to issue, deploy and renew your private certificates using Vault PKI and Consul-Template.</p><p>Consul-Template features are also available in:</p><ul><li>Vault Agent on VM</li><li>Vault Agent on Kubernetes (using <a href="https://developer.hashicorp.com/vault/docs/platform/k8s">vault-k8s</a>)</li><li>Nomad</li></ul><p>Vault Agent can use <a href="https://developer.hashicorp.com/vault/docs/agent/autoauth">Auto-Auth</a> to simplify the generation of the required token to query Vault.</p><p>Nomad replaces the exec block with thechange_modeparameter that specifies the behavior Nomad should take if the rendered template changes.</p><ul><li><a href="https://www.nomadproject.io/docs/job-specification/template#noop">&quot;noop&quot;</a> - take no action (continue running the task)</li><li><a href="https://www.nomadproject.io/docs/job-specification/template#restart">&quot;restart&quot;</a> - restart the task</li><li><a href="https://www.nomadproject.io/docs/job-specification/template#signal">&quot;signal&quot;</a> - send a configurable signal to the task</li><li><a href="https://www.nomadproject.io/docs/job-specification/template#script">&quot;script&quot;</a> - run a script</li></ul><p>On top of this, if you have to manage multiple nodes and applications, Nomad is easier than Consul-Template daemons or Vault Agent to configure and manage.</p><h3>Next Steps</h3><p>The next article (Part 3) explains how to <a href="https://medium.com/@sestegra/rotate-your-ca-seamlessly-using-a-vault-pki-9262228b4afb">rotate your CA seamlessly</a>.</p><h3>References</h3><ul><li><a href="https://github.com/hashicorp/consul-template">GitHub - hashicorp/consul-template: Template rendering, notifier, and supervisor for @HashiCorp Consul and Vault data.</a></li><li><a href="https://github.com/hashicorp/consul-template/blob/main/docs/configuration.md">consul-template/configuration.md at main · hashicorp/consul-template</a></li><li><a href="https://pkg.go.dev/text/template">template</a></li><li><a href="https://github.com/hashicorp/consul-template/blob/main/docs/templating-language.md">consul-template/templating-language.md at main · hashicorp/consul-template</a></li><li><a href="https://developer.hashicorp.com/vault/docs/platform/k8s">Kubernetes | Vault | HashiCorp Developer</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f5e4fe5f15c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build an Internal PKI with Vault]]></title>
            <link>https://sestegra.medium.com/build-an-internal-pki-with-vault-f7179306f18c?source=rss-a605ad9e51a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7179306f18c</guid>
            <category><![CDATA[hashicorp-vault]]></category>
            <category><![CDATA[hashicorp]]></category>
            <dc:creator><![CDATA[Stéphane Este-Gracias]]></dc:creator>
            <pubDate>Wed, 28 Sep 2022 18:38:15 GMT</pubDate>
            <atom:updated>2023-07-16T13:50:00.823Z</atom:updated>
            <content:encoded><![CDATA[<p>Automate your Certificates Lifecycle with Vault — Part 1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-GrqrF2rXweIE2KTQ9oXg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@theshubhamdhage?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">GuerrillaBuzz Crypto PR</a> on <a href="https://unsplash.com/s/photos/technology?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><blockquote>This article is a part of a series about how to<br><a href="https://medium.com/@sestegra/automate-your-certificates-lifecycle-with-vault-bc7ffff2430c"><strong>Automate your Certificates Lifecycle with Vault</strong></a>.</blockquote><ol><li><a href="https://medium.com/@sestegra/build-an-internal-pki-with-vault-f7179306f18c"><strong>Build an Internal PKI with Vault</strong></a><strong> (this article)</strong></li><li><a href="https://medium.com/@sestegra/issue-deploy-and-renew-your-private-certificates-with-vault-and-consul-template-1f5e4fe5f15c">Issue, Deploy and Renew your Private Certificates with Vault and Consul-Template</a></li><li><a href="https://medium.com/@sestegra/rotate-your-ca-seamlessly-using-a-vault-pki-9262228b4afb">Rotate your CA seamlessly using a Vault PKI</a></li><li><a href="https://medium.com/@sestegra/securely-store-public-certificates-in-vault-generated-by-acme-sh-2d6e98c9d308">Securely store Public Certificates in Vault, generated by acme.sh</a></li><li><a href="https://medium.com/@sestegra/codify-vault-internal-pki-using-terraform-c0f760323813">Codify Vault Internal PKI using Terraform</a></li></ol><h3>Introduction</h3><p>This article contains a walkthrough to building a branch of a three-tier PKI CA with Vault using an offline Root CA generated with certstrap. Then, a dedicated role is created to issue a leaf certificate.</p><p>A summary of commands is given at the end of the article to quickly create the three-tier PKI CA.</p><h3>Three-Tier PKI CA Hierarchy</h3><p>In order to respect the IT security principle of Least Privilege And Separation Of Duties and to obtain flexibility of use, the Vault PKI built in this article is a branch of a three-tier PKI Certification Authority hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fNTeWb8DYLRr3BgHHrC4Jw.png" /><figcaption>Three-Tier PKI Certification Authority Hierarchy</figcaption></figure><p>Usually, the root of trust is anchored within an existing company Root CA outside of Vault. So, the <strong>Root CA</strong> is stored offline, namely outside of Vault.</p><p>Then, the <strong>Intermediate CA</strong> and <strong>Issuing CA</strong> are stored inside of Vault using a dedicated <a href="https://developer.hashicorp.com/vault/docs/secrets/pki">PKI secret engine</a> for each. Moreover, a dedicated <strong>Role</strong> is required for issuing Leaf Certificates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*sMYBNPkOgfr0PsOl6f9VsA.png" /><figcaption>PKI CA Hierarchy with Vault</figcaption></figure><p>Regarding the cryptology algorithms, each CAs uses the Elliptic Curve Digital Signature Algorithm (ECDSA) using 256-bit keys and SHA-256 as the hash algorithm.</p><h4>Pre-Requisites</h4><ul><li>Install <a href="https://developer.hashicorp.com/vault/docs/install"><strong>vault</strong></a> 1.11.0 or higher</li><li>Install <a href="https://github.com/square/certstrap"><strong>certstrap</strong></a> 1.3.0 or higher</li><li>Install <a href="https://stedolan.github.io/jq/"><strong>jq</strong></a> 1.6 or higher</li></ul><h4>Vault Server in Dev mode</h4><p>First, launch Vault Server in Dev mode using root as a root token id. The root token is used on purpose to focus only on the PKI secret engine features.</p><blockquote><strong>Disclaimer</strong>: On production<br>- Don’t use the root token<br>- Create auth methods, entities, groups and policies to grant or forbid access to PKI features</blockquote><pre>$ <strong>vault server -dev -dev-root-token-id=root</strong></pre><p>In a second terminal, export Vault variables and check its status.</p><pre>$ <strong>export VAULT_ADDR=http://127.0.0.1:8200</strong><br>$ <strong>export VAULT_TOKEN=root</strong><br>$ <strong>vault status</strong><br>Key             Value<br>---             -----<br>Seal Type       shamir<br>Initialized     true<br>Sealed          false<br>Total Shares    1<br>Threshold       1<br>Version         1.11.3<br>Build Date      2022-08-26T10:27:10Z<br>Storage Type    inmem<br>Cluster Name    vault-cluster-80f46c53<br>Cluster ID      075e1954-dd54-6614-f8a0-09351c840504<br>HA Enabled      false</pre><p>So, the Vault server is running now.</p><h4><strong>Root CA</strong></h4><p>Let’s start with the Root CA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*jdCZHHD7p_JnJOznxXhDmg.png" /></figure><p>The offline Root CA is simulated using <a href="https://github.com/square/certstrap"><strong>certstrap</strong></a> open source tool from <a href="https://squareup.com/">Square</a>.</p><pre>$ <strong>certstrap --depot-path root init \<br>    --organization &quot;Example&quot; \<br>    --common-name &quot;Example Labs Root CA v1&quot; \<br>    --expires &quot;10 years&quot; \<br>    --curve P-256 \<br>    --path-length 2 \<br>    --passphrase &quot;secret&quot;</strong><br>Created root/Example_Labs_Root_CA_v1.key (encrypted by passphrase)<br>Created root/Example_Labs_Root_CA_v1.crt<br>Created root/Example_Labs_Root_CA_v1.crl</pre><p>The private key and certificate are stored in root folder.</p><h4>Intermediate CA</h4><p>Then, let’s create the <strong>Intermediate CA</strong> on the pki_int path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*XP9VVlyIxrVQgh_Fa_jAZw.png" /></figure><ul><li>Enable and tune PKI secrets engine</li></ul><pre><strong>$ vault secrets enable -path=pki_int pki</strong><br>Success! Enabled the pki secrets engine at: pki_int/<br><strong>$ vault secrets tune -max-lease-ttl=43800h pki_int</strong><br>Success! Tuned the secrets engine at: pki_int/</pre><ul><li>Configure CA and CRL URLs</li></ul><pre><strong>$ vault write pki_int/config/urls \<br>    issuing_certificates=&quot;http://127.0.0.1:8200/v1/pki_int/ca&quot; \<br>    crl_distribution_points=&quot;http://127.0.0.1:8200/v1/pki_int/crl&quot;</strong><br>Success! Data written to: pki_int/config/urls</pre><ul><li>Generate private key and CSR for Intermediate CA using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_int/intermediate/generate/internal</a> endpoint<strong>.</strong></li></ul><pre><strong>$ vault write -format=json \<br>    pki_int/intermediate/generate/internal \<br>    organization=&quot;Example&quot; \<br>    common_name=&quot;Example Labs Intermediate CA v1.1&quot; \<br>    key_type=ec \<br>    key_bits=256 \<br>    &gt; pki_int_v1.1.csr.json<br>$ cat pki_int_v1.1.csr.json</strong><br>{<br>  &quot;request_id&quot;: &quot;938dab2e-6691-190d-b2d2-9f5bb7b13296&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;csr&quot;: &quot;-----BEGIN CERTIFICATE REQUEST-----\nMIH9MIGlAgEAMEMxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEqMCgGA1UEAxMhRXhh\nbXBsZSBMYWJzIEludGVybWVkaWF0ZSBDQSB2MS4xMFkwEwYHKoZIzj0CAQYIKoZI\nzj0DAQcDQgAEGh1SLApRANMRLvXwkCWlRy5N1oCMCGYRKgXU9gU2CWACHvp0N3Jr\neWIMyy+yCLQPa7PDuywOTLGC3Ko2JY0QxaAAMAoGCCqGSM49BAMCA0cAMEQCIFQa\nllfzyF0m+U3JbLPNJNteiRHNS9q529CLnYFRlev+AiBWcT+wGEC5HPe62sUsapcD\ng8x12Qwbc9/U9VoDzm1vig==\n-----END CERTIFICATE REQUEST-----&quot;,<br>    &quot;key_id&quot;: &quot;26617b65-c536-9249-c3ba-9108c7662c2a&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><ul><li>Extract the CSR from the response and verify it</li></ul><pre><strong>$ cat pki_int_v1.1.csr.json | jq -r &#39;.data.csr&#39; &gt; pki_int_v1.1.csr<br>$ openssl req -text -noout -verify -in pki_int_v1.1.csr<br></strong>verify OK<br>Certificate Request:<br>    Data:<br>        Version: 1 (0x0)<br><strong>        Subject: O = Example, CN = Example Labs Intermediate CA v1.1<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:1a:1d:52:2c:0a:51:00:d3:11:2e:f5:f0:90:25:<br>                    a5:47:2e:4d:d6:80:8c:08:66:11:2a:05:d4:f6:05:<br>                    36:09:60:02:1e:fa:74:37:72:6b:79:62:0c:cb:2f:<br>                    b2:08:b4:0f:6b:b3:c3:bb:2c:0e:4c:b1:82:dc:aa:<br>                    36:25:8d:10:c5<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        Attributes:<br>            a0:00<br>    Signature Algorithm: ecdsa-with-SHA256<br>         30:44:02:20:54:1a:96:57:f3:c8:5d:26:f9:4d:c9:6c:b3:cd:<br>         24:db:5e:89:11:cd:4b:da:b9:db:d0:8b:9d:81:51:95:eb:fe:<br>         02:20:56:71:3f:b0:18:40:b9:1c:f7:ba:da:c5:2c:6a:97:03:<br>         83:cc:75:d9:0c:1b:73:df:d4:f5:5a:03:ce:6d:6f:8a</pre><ul><li>Sign and generate a certificate using the CSR with Root CA</li></ul><pre><strong>$ certstrap --depot-path root sign \<br>    --CA &quot;Example Labs Root CA v1&quot; \<br>    --passphrase &quot;secret&quot; \<br>    --intermediate \<br>    --csr pki_int_v1.1.csr \<br>    --expires &quot;5 years&quot; \<br>    --path-length 1 \<br>    --cert pki_int_v1.1.crt \<br>    &quot;Example Labs Intermediate CA v1.1&quot;</strong><br>Building intermediate<br><strong>$ openssl x509 -in pki_int_v1.1.crt -text -noout<br></strong>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            48:ce:f6:1d:3d:94:d6:74:c8:e7:db:c6:f4:36:7a:4c<br>        Signature Algorithm: ecdsa-with-SHA256<br>        <strong>Issuer: O = Example, CN = Example Labs Root CA v1</strong><br>        Validity<br>            Not Before: Sep 19 11:09:07 2022 GMT<br>            Not After : Sep 19 11:19:07 2027 GMT<br>        <strong>Subject: O = Example, CN = Example Labs Intermediate CA v1.1</strong><br>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:1a:1d:52:2c:0a:51:00:d3:11:2e:f5:f0:90:25:<br>                    a5:47:2e:4d:d6:80:8c:08:66:11:2a:05:d4:f6:05:<br>                    36:09:60:02:1e:fa:74:37:72:6b:79:62:0c:cb:2f:<br>                    b2:08:b4:0f:6b:b3:c3:bb:2c:0e:4c:b1:82:dc:aa:<br>                    36:25:8d:10:c5<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Certificate Sign, CRL Sign<br>            X509v3 Basic Constraints: critical<br>                <strong>CA:TRUE, pathlen:1</strong><br>            X509v3 Subject Key Identifier:<br>                A5:CD:22:67:C9:EA:DF:72:A9:6A:B8:62:A8:64:5D:EA:...<br>            X509v3 Authority Key Identifier:<br>                keyid:B0:14:CF:35:5A:2F:89:AA:FE:06:90:E4:04:06:...</pre><pre>Signature Algorithm: ecdsa-with-SHA256<br>         30:45:02:21:00:92:6f:89:12:17:a9:73:11:64:b9:f3:48:fe:<br>         d5:c2:8e:70:3d:d2:47:26:2f:8c:e8:c3:14:3c:5f:c8:ed:f9:<br>         2e:02:20:57:d8:9c:ee:9a:7b:48:46:e6:75:1e:10:f8:4b:21:<br>         6a:0b:fe:93:76:ee:e7:45:c5:34:e9:7f:c9:f0:1b:57:2f</pre><ul><li>Store the resulting certificate into the Intermediate CA using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_int/intermediate/set-signed</a> endpoint<strong>.</strong></li></ul><pre><strong>$ vault write -format=json \<br>    pki_int/intermediate/set-signed \<br>    certificate=@pki_int_v1.1.crt \<br>    &gt; pki_int_v1.1.set-signed.json<br>$ cat pki_int_v1.1.set-signed.json</strong><br>{<br>  &quot;request_id&quot;: &quot;75530a92-af31-e65a-9b49-140c58759ebd&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;imported_issuers&quot;: [<br>      &quot;9287d791-412b-29a5-220d-64ecd4431ed2&quot;<br>    ],<br>    &quot;imported_keys&quot;: null,<br>    &quot;mapping&quot;: {<br>      &quot;9287d791-412b-29a5-220d-64ecd4431ed2&quot;: &quot;26617b65-c536-9249-c3ba-9108c7662c2a&quot;<br>    }<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><h4>Issuing CA</h4><p>Next, let’s create the <strong>Issuing CA</strong> on the pki_intpath. The steps are similar to the previous ones, except for the “Sign and generate certificate” step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*ZVrTHBBGBew0HZZpj09fyA.png" /></figure><ul><li>Enable and tune PKI secrets engine for issuing CA</li></ul><pre><strong>$ vault secrets enable -path=pki_iss pki</strong><br>Success! Enabled the pki secrets engine at: pki_iss/<br><strong>$ vault secrets tune -max-lease-ttl=8760h pki_iss</strong><br>Success! Tuned the secrets engine at: pki_iss/</pre><ul><li>Configure CA and CRL URLs</li></ul><pre><strong>$ vault write pki_iss/config/urls \<br>    issuing_certificates=&quot;http://127.0.0.1:8200/v1/pki_iss/ca&quot; \<br>    crl_distribution_points=&quot;http://127.0.0.1:8200/v1/pki_iss/crl&quot;<br></strong>Success! Data written to: pki_iss/config/urls</pre><ul><li>Generate private key and CSR for Issuing CA using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_iss/intermediate/generate/internal</a> endpoint<strong>.</strong></li></ul><pre><strong>$ vault write -format=json \<br>    pki_iss/intermediate/generate/internal \<br>    organization=&quot;Example&quot; \<br>    common_name=&quot;Example Labs Issuing CA v1.1.1&quot; \<br>    key_type=ec \<br>    key_bits=256 \<br>    &gt; pki_iss_v1.1.1.csr.json</strong><br>$ cat pki_iss_v1.1.1.csr.json<br>{<br>  &quot;request_id&quot;: &quot;e6d63846-5b30-bbe9-3605-4757056f64c5&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;csr&quot;: &quot;-----BEGIN CERTIFICATE REQUEST-----\nMIH7MIGiAgEAMEAxFTATBgNVBAoTDEV4YW1wbGUgTGFiczEnMCUGA1UEAxMeRXhh\nbXBsZSBMYWJzIElzc3VpbmcgQ0EgdjEuMS4xMFkwEwYHKoZIzj0CAQYIKoZIzj0D\nAQcDQgAEm26d0gE96prsTtEjGMmvmMr8tlDPWB14+VhRfCCHeKgOv9F+9dhjvEf2\nx3QsiymJi5DlTWKwzqjLn0n43urJbKAAMAoGCCqGSM49BAMCA0gAMEUCIQDEAxSk\ntIb7hNx6igTeVrj5KURZzS2bjw1avWaKf8mQTAIgSbnA3LkAfuoIdMLU/n1QJDrm\nfQYmYlM0unAe5FmXd9o=\n-----END CERTIFICATE REQUEST-----&quot;,<br>    &quot;key_id&quot;: &quot;da214457-a9c4-40db-964a-019183e42a67&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><ul><li>Extract the CSR from the response and verify it</li></ul><pre><strong>$ cat pki_iss_v1.1.1.csr.json | jq -r &#39;.data.csr&#39; \<br>    &gt; pki_iss_v1.1.1.csr<br>$ openssl req -text -noout -verify -in pki_iss_v1.1.1.csr</strong><br>verify OK<br>Certificate Request:<br>    Data:<br>        Version: 1 (0x0)<br><strong>        Subject: O = Example, CN = Example Labs Issuing CA v1.1.1<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:9b:6e:9d:d2:01:3d:ea:9a:ec:4e:d1:23:18:c9:<br>                    af:98:ca:fc:b6:50:cf:58:1d:78:f9:58:51:7c:20:<br>                    87:78:a8:0e:bf:d1:7e:f5:d8:63:bc:47:f6:c7:74:<br>                    2c:8b:29:89:8b:90:e5:4d:62:b0:ce:a8:cb:9f:49:<br>                    f8:de:ea:c9:6c<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        Attributes:<br>            a0:00<br>    Signature Algorithm: ecdsa-with-SHA256<br>         30:45:02:21:00:c4:03:14:a4:b4:86:fb:84:dc:7a:8a:04:de:<br>         56:b8:f9:29:44:59:cd:2d:9b:8f:0d:5a:bd:66:8a:7f:c9:90:<br>         4c:02:20:49:b9:c0:dc:b9:00:7e:ea:08:74:c2:d4:fe:7d:50:<br>         24:3a:e6:7d:06:26:62:53:34:ba:70:1e:e4:59:97:77:da</pre><ul><li>Sign and generate a certificate using the CSR with the Intermediate CA using <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#sign-intermediate">pki_int/root/sign-intermediate</a> endpoint</li></ul><pre><strong>$ vault write -format=json \</strong><br><strong>    pki_int/root/sign-intermediate \<br>    organization=&quot;Example&quot; \<br>    csr=@pki_iss_v1.1.1.csr \<br>    ttl=8760h \<br>    format=pem \<br>    &gt; pki_iss_v1.1.1.crt.json<br>$ cat pki_iss_v1.1.1.crt.json<br></strong>{<br>  &quot;request_id&quot;: &quot;86aa268b-b1cd-0d22-56aa-5340e9d14965&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIICZjCCAgugAwIBAgIUb/TNrUqmLxColUUIBJqiMrUDYmcwCgYIKoZIzj0EAwIw\nQzEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSowKAYDVQQDEyFFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYXRlIENBIHYxLjEwHhcNMjIwOTE5MTEzNzQ2WhcNMjMwOTE5MTEz\nODE2WjBAMRUwEwYDVQQKEwxFeGFtcGxlIExhYnMxJzAlBgNVBAMTHkV4YW1wbGUg\nTGFicyBJc3N1aW5nIENBIHYxLjEuMTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBJtundIBPeqa7E7RIxjJr5jK/LZQz1gdePlYUXwgh3ioDr/RfvXYY7xH9sd0LIsp\niYuQ5U1isM6oy59J+N7qyWyjgd8wgdwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB\n/wQIMAYBAf8CAQAwHQYDVR0OBBYEFEMj0q23fAXh0YqfZ+4alw5sIwv9MB8GA1Ud\nIwQYMBaAFKXNImfJ6t9yqWq4YqhkXer93+3rMD8GCCsGAQUFBwEBBDMwMTAvBggr\nBgEFBQcwAoYjaHR0cDovLzEyNy4wLjAuMTo4MjAwL3YxL3BraV9pbnQvY2EwNQYD\nVR0fBC4wLDAqoCigJoYkaHR0cDovLzEyNy4wLjAuMTo4MjAwL3YxL3BraV9pbnQv\nY3JsMAoGCCqGSM49BAMCA0kAMEYCIQDxERcoTQP3/1o74ZQzIEZGyggEJRwBSmTq\n/M4aZl0v/AIhAM3cJkSZo3DgQ7bFPtktxg1gtT5RaPjzpq+XM3eK50A+\n-----END CERTIFICATE-----&quot;,<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB4DCCAYagAwIBAgIQSM72HT2U1nTI59vG9DZ6TDAKBggqhkjOPQQDAjA5MRUw\nEwYDVQQKEwxFeGFtcGxlIExhYnMxIDAeBgNVBAMTF0V4YW1wbGUgTGFicyBSb290\nIENBIHYxMB4XDTIyMDkxOTExMDkwN1oXDTI3MDkxOTExMTkwN1owQzEVMBMGA1UE\nChMMRXhhbXBsZSBMYWJzMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRp\nYXRlIENBIHYxLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQaHVIsClEA0xEu\n9fCQJaVHLk3WgIwIZhEqBdT2BTYJYAIe+nQ3cmt5YgzLL7IItA9rs8O7LA5MsYLc\nqjYljRDFo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd\nBgNVHQ4EFgQUpc0iZ8nq33KparhiqGRd6v3f7eswHwYDVR0jBBgwFoAUsBTPNVov\niar+BpDkBAZDn2FOpBkwCgYIKoZIzj0EAwIDSAAwRQIhAJJviRIXqXMRZLnzSP7V\nwo5wPdJHJi+M6MMUPF/I7fkuAiBX2JzumntIRuZ1HhD4SyFqC/6Tdu7nRcU06X/J\n8BtXLw==\n-----END CERTIFICATE-----&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICZjCCAgugAwIBAgIUb/TNrUqmLxColUUIBJqiMrUDYmcwCgYIKoZIzj0EAwIw\nQzEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSowKAYDVQQDEyFFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYXRlIENBIHYxLjEwHhcNMjIwOTE5MTEzNzQ2WhcNMjMwOTE5MTEz\nODE2WjBAMRUwEwYDVQQKEwxFeGFtcGxlIExhYnMxJzAlBgNVBAMTHkV4YW1wbGUg\nTGFicyBJc3N1aW5nIENBIHYxLjEuMTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBJtundIBPeqa7E7RIxjJr5jK/LZQz1gdePlYUXwgh3ioDr/RfvXYY7xH9sd0LIsp\niYuQ5U1isM6oy59J+N7qyWyjgd8wgdwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB\n/wQIMAYBAf8CAQAwHQYDVR0OBBYEFEMj0q23fAXh0YqfZ+4alw5sIwv9MB8GA1Ud\nIwQYMBaAFKXNImfJ6t9yqWq4YqhkXer93+3rMD8GCCsGAQUFBwEBBDMwMTAvBggr\nBgEFBQcwAoYjaHR0cDovLzEyNy4wLjAuMTo4MjAwL3YxL3BraV9pbnQvY2EwNQYD\nVR0fBC4wLDAqoCigJoYkaHR0cDovLzEyNy4wLjAuMTo4MjAwL3YxL3BraV9pbnQv\nY3JsMAoGCCqGSM49BAMCA0kAMEYCIQDxERcoTQP3/1o74ZQzIEZGyggEJRwBSmTq\n/M4aZl0v/AIhAM3cJkSZo3DgQ7bFPtktxg1gtT5RaPjzpq+XM3eK50A+\n-----END CERTIFICATE-----&quot;,<br>    &quot;expiration&quot;: 1695123496,<br>    &quot;issuing_ca&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIIB4DCCAYagAwIBAgIQSM72HT2U1nTI59vG9DZ6TDAKBggqhkjOPQQDAjA5MRUw\nEwYDVQQKEwxFeGFtcGxlIExhYnMxIDAeBgNVBAMTF0V4YW1wbGUgTGFicyBSb290\nIENBIHYxMB4XDTIyMDkxOTExMDkwN1oXDTI3MDkxOTExMTkwN1owQzEVMBMGA1UE\nChMMRXhhbXBsZSBMYWJzMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRp\nYXRlIENBIHYxLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQaHVIsClEA0xEu\n9fCQJaVHLk3WgIwIZhEqBdT2BTYJYAIe+nQ3cmt5YgzLL7IItA9rs8O7LA5MsYLc\nqjYljRDFo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd\nBgNVHQ4EFgQUpc0iZ8nq33KparhiqGRd6v3f7eswHwYDVR0jBBgwFoAUsBTPNVov\niar+BpDkBAZDn2FOpBkwCgYIKoZIzj0EAwIDSAAwRQIhAJJviRIXqXMRZLnzSP7V\nwo5wPdJHJi+M6MMUPF/I7fkuAiBX2JzumntIRuZ1HhD4SyFqC/6Tdu7nRcU06X/J\n8BtXLw==\n-----END CERTIFICATE-----&quot;,<br>    &quot;serial_number&quot;: &quot;6f:f4:cd:ad:4a:a6:2f:10:a8:95:45:08:04:9a:a2:32:b5:03:62:67&quot;<br>  },<br>  &quot;warnings&quot;: [<br>    &quot;Max path length of the signed certificate is zero. This certificate cannot be used to issue intermediate CA certificates.&quot;<br>  ]<br>}<br><strong>$ cat pki_iss_v1.1.1.crt.json | jq -r &#39;.data.certificate&#39; \<br>    &gt; pki_iss_v1.1.1.crt<br>$ openssl x509 -in pki_iss_v1.1.1.crt -text -noout</strong><br>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            6f:f4:cd:ad:4a:a6:2f:10:a8:95:45:08:04:9a:a2:32:...<br>        Signature Algorithm: ecdsa-with-SHA256<br><strong>        Issuer: O = Example, CN = Example Labs Intermediate CA v1.1</strong><br>        Validity<br>            Not Before: Sep 19 11:37:46 2022 GMT<br>            Not After : Sep 19 11:38:16 2023 GMT<br><strong>        Subject: O = Example, CN = Example Labs Issuing CA v1.1.1<br></strong>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:9b:6e:9d:d2:01:3d:ea:9a:ec:4e:d1:23:18:c9:<br>                    af:98:ca:fc:b6:50:cf:58:1d:78:f9:58:51:7c:20:<br>                    87:78:a8:0e:bf:d1:7e:f5:d8:63:bc:47:f6:c7:74:<br>                    2c:8b:29:89:8b:90:e5:4d:62:b0:ce:a8:cb:9f:49:<br>                    f8:de:ea:c9:6c<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Certificate Sign, CRL Sign<br>            X509v3 Basic Constraints: critical<br><strong>                CA:TRUE, pathlen:0<br></strong>            X509v3 Subject Key Identifier:<br>                43:23:D2:AD:B7:7C:05:E1:D1:8A:9F:67:EE:1A:97:0E:...<br>            X509v3 Authority Key Identifier:<br>                keyid:A5:CD:22:67:C9:EA:DF:72:A9:6A:B8:62:A8:64:...</pre><pre>            Authority Information Access:<br>                CA Issuers - URI:http://127.0.0.1:8200/v1/pki_int/ca</pre><pre>            X509v3 CRL Distribution Points:</pre><pre>                Full Name:<br>                  URI:http://127.0.0.1:8200/v1/pki_int/crl</pre><pre>Signature Algorithm: ecdsa-with-SHA256<br>         30:46:02:21:00:f1:11:17:28:4d:03:f7:ff:5a:3b:e1:94:33:<br>         20:46:46:ca:08:04:25:1c:01:4a:64:ea:fc:ce:1a:66:5d:2f:<br>         fc:02:21:00:cd:dc:26:44:99:a3:70:e0:43:b6:c5:3e:d9:2d:<br>         c6:0d:60:b5:3e:51:68:f8:f3:a6:af:97:33:77:8a:e7:40:3e</pre><ul><li>Store intermediate and issuing certificates into the Issuing CA using the <a href="https://developer.hashicorp.com/vault/api-docs/secret/pki#generate-intermediate-csr">pki_iss/intermediate/set-signed</a> endpoint<strong>.</strong></li></ul><pre><strong>$ cat pki_iss_v1.1.1.crt pki_int_v1.1.crt &gt; pki_iss_v1.1.1.chain.crt<br>$ vault write -format=json \<br>    pki_iss/intermediate/set-signed \<br>    certificate=@pki_iss_v1.1.1.chain.crt \<br>    &gt; pki_iss_v1.1.1.set-signed.json<br>$ cat pki_iss_v1.1.1.set-signed.json<br></strong>{<br>  &quot;request_id&quot;: &quot;58a6a706-f041-afb8-2d9e-539eefdea001&quot;,<br>  &quot;lease_id&quot;: &quot;&quot;,<br>  &quot;lease_duration&quot;: 0,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;imported_issuers&quot;: [<br>      &quot;6d72b3c8-ccf4-ab81-eb87-3c656daaa497&quot;,<br>      &quot;a17129a6-fcf2-6ada-4dcd-c57bce0d2317&quot;<br>    ],<br>    &quot;imported_keys&quot;: null,<br>    &quot;mapping&quot;: {<br>      &quot;6d72b3c8-ccf4-ab81-eb87-3c656daaa497&quot;: &quot;da214457-a9c4-40db-964a-019183e42a67&quot;,<br>      &quot;a17129a6-fcf2-6ada-4dcd-c57bce0d2317&quot;: &quot;&quot;<br>    }<br>  },<br>  &quot;warnings&quot;: null<br>}</pre><h4><strong>Cr</strong>eate Role</h4><p>Finally, let’s create a role for Issuing CA secret engine to issue leaf certificates on the example.com domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*D2jKCHZMz3ErHdDFNp9uRg.png" /></figure><ul><li>Create an issuing role</li></ul><pre><strong>$ vault write pki_iss/roles/example \<br>    organization=&quot;Example&quot; \<br>    allowed_domains=&quot;example.com&quot; \<br>    allow_subdomains=true \<br>    allow_wildcard_certificates=false \<br>    key_type=ec \<br>    key_bits=256 \<br>    generate_lease=true \<br>    max_ttl=2160h</strong><br>Success! Data written to: pki_iss/roles/example</pre><ul><li>Issue a leaf certificate</li></ul><pre><strong>$ vault write -format=json \<br>    pki_iss/issue/example \<br>    common_name=&quot;sample.example.com&quot; \</strong><br>    <strong>&gt; pki_iss_v1.1.1.sample.crt.json</strong><br><strong>$ cat pki_iss_v1.1.1.sample.crt.json</strong><br>{<br>  &quot;request_id&quot;: &quot;7967516f-6d6b-fce1-4328-0cd23970c1a1&quot;,<br>  &quot;lease_id&quot;: &quot;pki_iss/issue/example/TN1U6h8CQIVC4Y38XgETBsUr&quot;,<br>  &quot;lease_duration&quot;: 2764800,<br>  &quot;renewable&quot;: false,<br>  &quot;data&quot;: {<br>    &quot;ca_chain&quot;: [<br>      &quot;-----BEGIN CERTIFICATE-----\nMIICZjCCAgugAwIBAgIUb/TNrUqmLxColUUIBJqiMrUDYmcwCgYIKoZIzj0EAwIw\nQzEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSowKAYDVQQDEyFFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYXRlIENBIHYxLjEwHhcNMjIwOTE5MTEzNzQ2WhcNMjMwOTE5MTEz\nODE2WjBAMRUwEwYDVQQKEwxFeGFtcGxlIExhYnMxJzAlBgNVBAMTHkV4YW1wbGUg\nTGFicyBJc3N1aW5nIENBIHYxLjEuMTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBJtundIBPeqa7E7RIxjJr5jK/LZQz1gdePlYUXwgh3ioDr/RfvXYY7xH9sd0LIsp\niYuQ5U1isM6oy59J+N7qyWyjgd8wgdwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB\n/wQIMAYBAf8CAQAwHQYDVR0OBBYEFEMj0q23fAXh0YqfZ+4alw5sIwv9MB8GA1Ud\nIwQYMBaAFKXNImfJ6t9yqWq4YqhkXer93+3rMD8GCCsGAQUFBwEBBDMwMTAvBggr\nBgEFBQcwAoYjaHR0cDovLzEyNy4wLjAuMTo4MjAwL3YxL3BraV9pbnQvY2EwNQYD\nVR0fBC4wLDAqoCigJoYkaHR0cDovLzEyNy4wLjAuMTo4MjAwL3YxL3BraV9pbnQv\nY3JsMAoGCCqGSM49BAMCA0kAMEYCIQDxERcoTQP3/1o74ZQzIEZGyggEJRwBSmTq\n/M4aZl0v/AIhAM3cJkSZo3DgQ7bFPtktxg1gtT5RaPjzpq+XM3eK50A+\n-----END CERTIFICATE-----&quot;,<br>      &quot;-----BEGIN CERTIFICATE-----\nMIIB4DCCAYagAwIBAgIQSM72HT2U1nTI59vG9DZ6TDAKBggqhkjOPQQDAjA5MRUw\nEwYDVQQKEwxFeGFtcGxlIExhYnMxIDAeBgNVBAMTF0V4YW1wbGUgTGFicyBSb290\nIENBIHYxMB4XDTIyMDkxOTExMDkwN1oXDTI3MDkxOTExMTkwN1owQzEVMBMGA1UE\nChMMRXhhbXBsZSBMYWJzMSowKAYDVQQDEyFFeGFtcGxlIExhYnMgSW50ZXJtZWRp\nYXRlIENBIHYxLjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQaHVIsClEA0xEu\n9fCQJaVHLk3WgIwIZhEqBdT2BTYJYAIe+nQ3cmt5YgzLL7IItA9rs8O7LA5MsYLc\nqjYljRDFo2YwZDAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAd\nBgNVHQ4EFgQUpc0iZ8nq33KparhiqGRd6v3f7eswHwYDVR0jBBgwFoAUsBTPNVov\niar+BpDkBAZDn2FOpBkwCgYIKoZIzj0EAwIDSAAwRQIhAJJviRIXqXMRZLnzSP7V\nwo5wPdJHJi+M6MMUPF/I7fkuAiBX2JzumntIRuZ1HhD4SyFqC/6Tdu7nRcU06X/J\n8BtXLw==\n-----END CERTIFICATE-----&quot;<br>    ],<br>    &quot;certificate&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICgTCCAiigAwIBAgIUXvZikxkJM0hkxEBMbM6fUZWWCAgwCgYIKoZIzj0EAwIw\nQDEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMScwJQYDVQQDEx5FeGFtcGxlIExhYnMg\nSXNzdWluZyBDQSB2MS4xLjEwHhcNMjIwOTE5MTE1MDU3WhcNMjIxMDIxMTE1MTI3\nWjA0MRUwEwYDVQQKEwxFeGFtcGxlIExhYnMxGzAZBgNVBAMTEnNhbXBsZS5leGFt\ncGxlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABJjgzrukSR8oYWALhaL1\n+sYoddtjyXJ4308iwqnoXh99MFNta+SGMJHK1uIzAnNzSbwo0lWLf0KRVFMI4ppk\nUcujggEKMIIBBjAOBgNVHQ8BAf8EBAMCA6gwHQYDVR0lBBYwFAYIKwYBBQUHAwEG\nCCsGAQUFBwMCMB0GA1UdDgQWBBTARFqr/RtctV5Ye13yM5e8tqA18zAfBgNVHSME\nGDAWgBRDI9Ktt3wF4dGKn2fuGpcObCML/TA/BggrBgEFBQcBAQQzMDEwLwYIKwYB\nBQUHMAKGI2h0dHA6Ly8xMjcuMC4wLjE6ODIwMC92MS9wa2lfaXNzL2NhMB0GA1Ud\nEQQWMBSCEnNhbXBsZS5leGFtcGxlLmNvbTA1BgNVHR8ELjAsMCqgKKAmhiRodHRw\nOi8vMTI3LjAuMC4xOjgyMDAvdjEvcGtpX2lzcy9jcmwwCgYIKoZIzj0EAwIDRwAw\nRAIgFe0xNmg2r3XaDI9+tgrOyFBGEaxsHA96W2TutAVrgigCIEtZ9i0qmMJTb6HA\nUbA/fIZTlIgE0/c+Q2vsZWh0dwux\n-----END CERTIFICATE-----&quot;,<br>    &quot;expiration&quot;: 1666353087,<br>    &quot;issuing_ca&quot;: &quot;-----BEGIN CERTIFICATE-----\nMIICZjCCAgugAwIBAgIUb/TNrUqmLxColUUIBJqiMrUDYmcwCgYIKoZIzj0EAwIw\nQzEVMBMGA1UEChMMRXhhbXBsZSBMYWJzMSowKAYDVQQDEyFFeGFtcGxlIExhYnMg\nSW50ZXJtZWRpYXRlIENBIHYxLjEwHhcNMjIwOTE5MTEzNzQ2WhcNMjMwOTE5MTEz\nODE2WjBAMRUwEwYDVQQKEwxFeGFtcGxlIExhYnMxJzAlBgNVBAMTHkV4YW1wbGUg\nTGFicyBJc3N1aW5nIENBIHYxLjEuMTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBJtundIBPeqa7E7RIxjJr5jK/LZQz1gdePlYUXwgh3ioDr/RfvXYY7xH9sd0LIsp\niYuQ5U1isM6oy59J+N7qyWyjgd8wgdwwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB\n/wQIMAYBAf8CAQAwHQYDVR0OBBYEFEMj0q23fAXh0YqfZ+4alw5sIwv9MB8GA1Ud\nIwQYMBaAFKXNImfJ6t9yqWq4YqhkXer93+3rMD8GCCsGAQUFBwEBBDMwMTAvBggr\nBgEFBQcwAoYjaHR0cDovLzEyNy4wLjAuMTo4MjAwL3YxL3BraV9pbnQvY2EwNQYD\nVR0fBC4wLDAqoCigJoYkaHR0cDovLzEyNy4wLjAuMTo4MjAwL3YxL3BraV9pbnQv\nY3JsMAoGCCqGSM49BAMCA0kAMEYCIQDxERcoTQP3/1o74ZQzIEZGyggEJRwBSmTq\n/M4aZl0v/AIhAM3cJkSZo3DgQ7bFPtktxg1gtT5RaPjzpq+XM3eK50A+\n-----END CERTIFICATE-----&quot;,<br>    &quot;private_key&quot;: &quot;-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIIMX1kUxgTuEEzO9TBK+uOkEGAvIKtUfSdvFLg01hrI5oAoGCCqGSM49\nAwEHoUQDQgAEmODOu6RJHyhhYAuFovX6xih122PJcnjfTyLCqeheH30wU21r5IYw\nkcrW4jMCc3NJvCjSVYt/QpFUUwjimmRRyw==\n-----END EC PRIVATE KEY-----&quot;,<br>    &quot;private_key_type&quot;: &quot;ec&quot;,<br>    &quot;serial_number&quot;: &quot;5e:f6:62:93:19:09:33:48:64:c4:40:4c:6c:ce:9f:51:95:96:08:08&quot;<br>  },<br>  &quot;warnings&quot;: null<br>}<br><strong>$ cat pki_iss_v1.1.1.sample.crt.json | jq -r .data.certificate \<br>    | openssl x509 -text -noout<br></strong>Certificate:<br>    Data:<br>        Version: 3 (0x2)<br>        Serial Number:<br>            5e:f6:62:93:19:09:33:48:64:c4:40:4c:6c:ce:9f:51:95:...<br>        Signature Algorithm: ecdsa-with-SHA256<br><strong>        Issuer: O = Example, CN = Example Labs Issuing CA v1.1.1<br></strong>        Validity<br>            Not Before: Sep 19 11:50:57 2022 GMT<br>            Not After : Oct 21 11:51:27 2022 GMT<br><strong>        Subject: O = Example Labs, CN = sample.example.com</strong><br>        Subject Public Key Info:<br>            Public Key Algorithm: id-ecPublicKey<br>                Public-Key: (256 bit)<br>                pub:<br>                    04:98:e0:ce:bb:a4:49:1f:28:61:60:0b:85:a2:f5:<br>                    fa:c6:28:75:db:63:c9:72:78:df:4f:22:c2:a9:e8:<br>                    5e:1f:7d:30:53:6d:6b:e4:86:30:91:ca:d6:e2:33:<br>                    02:73:73:49:bc:28:d2:55:8b:7f:42:91:54:53:08:<br>                    e2:9a:64:51:cb<br>                ASN1 OID: prime256v1<br>                NIST CURVE: P-256<br>        X509v3 extensions:<br>            X509v3 Key Usage: critical<br>                Digital Signature, Key Encipherment, Key Agreement<br>            X509v3 Extended Key Usage:<br>                TLS Web Server Authentication, TLS Web Client Auth<br>            X509v3 Subject Key Identifier:<br>                C0:44:5A:AB:FD:1B:5C:B5:5E:58:7B:5D:F2:33:97:BC:...<br>            X509v3 Authority Key Identifier:<br>                keyid:43:23:D2:AD:B7:7C:05:E1:D1:8A:9F:67:EE:1A:...</pre><pre>            Authority Information Access:<br>                CA Issuers - URI:http://127.0.0.1:8200/v1/pki_iss/ca</pre><pre>            X509v3 Subject Alternative Name:<br>                <strong>DNS:sample.example.com</strong><br>            X509v3 CRL Distribution Points:</pre><pre>                Full Name:<br>                  URI:http://127.0.0.1:8200/v1/pki_iss/crl</pre><pre>Signature Algorithm: ecdsa-with-SHA256<br>         30:44:02:20:15:ed:31:36:68:36:af:75:da:0c:8f:7e:b6:0a:<br>         ce:c8:50:46:11:ac:6c:1c:0f:7a:5b:64:ee:b4:05:6b:82:28:<br>         02:20:4b:59:f6:2d:2a:98:c2:53:6f:a1:c0:51:b0:3f:7c:86:<br>         53:94:88:04:d3:f7:3e:43:6b:ec:65:68:74:77:0b:b1</pre><h3>Conclusion</h3><p>This article shows a walkthrough to building a three-tier PKI CA with Vault using an offline Root CA generated with certstrap is presented. Then, a dedicated role has been created to issue a leaf certificate.</p><p>This configuration can be codified using the <a href="https://registry.terraform.io/providers/hashicorp/vault/latest/docs">Terraform Vault provider</a> to do this, read <a href="https://medium.com/@sestegra/codify-vault-internal-pki-using-terraform-c0f760323813">Codify Vault Internal PKI using Terraform</a> article.</p><h3>Next Steps</h3><p>The next article (Part 2) explains how to <a href="https://medium.com/@sestegra/issue-deploy-and-renew-your-private-certificates-with-vault-and-consul-template-1f5e4fe5f15c">Issue, Deploy and Renew your Private Certificates with Vault and Consul-Template</a> using this Vault PKI.</p><h3>References</h3><ul><li><a href="https://developer.hashicorp.com/vault/docs/secrets/pki">PKI - Secrets Engines | Vault | HashiCorp Developer</a></li><li><a href="https://github.com/square/certstrap">GitHub - square/certstrap: Tools to bootstrap CAs, certificate requests, and signed certificates.</a></li><li><a href="https://developer.hashicorp.com/vault/api-docs/secret/pki">PKI - Secrets Engines - HTTP API | Vault | HashiCorp Developer</a></li></ul><h3>Summary of commands</h3><p>First, install <a href="https://developer.hashicorp.com/vault/docs/install"><strong>vault</strong></a> 1.11.0 or higher, <a href="https://github.com/square/certstrap"><strong>certstrap</strong></a> 1.3.0 or higher, and <a href="https://stedolan.github.io/jq/"><strong>jq</strong></a> 1.6 or higher.</p><p>Next, to quickly create or recreate the three-tier PKI CA, here is the summary of the commands to be launched.</p><ul><li>On the first terminal, launch the following command.</li></ul><pre>vault server -dev -dev-root-token-id=root</pre><ul><li>On a second terminal, launch the following commands.</li></ul><pre>export VAULT_ADDR=http://127.0.0.1:8200<br>export VAULT_TOKEN=root<br>certstrap --depot-path root init \<br>    --organization &quot;Example&quot; \<br>    --common-name &quot;Example Labs Root CA v1&quot; \<br>    --expires &quot;10 years&quot; \<br>    --curve P-256 \<br>    --path-length 2 \<br>    --passphrase &quot;secret&quot;<br>vault secrets enable -path=pki_int pki<br>vault secrets tune -max-lease-ttl=43800h pki_int<br>vault write pki_int/config/urls \<br>    issuing_certificates=&quot;http://127.0.0.1:8200/v1/pki_int/ca&quot; \<br>    crl_distribution_points=&quot;http://127.0.0.1:8200/v1/pki_int/crl&quot;<br>vault write -format=json \<br>    pki_int/intermediate/generate/internal \<br>    organization=&quot;Example&quot; \<br>    common_name=&quot;Example Labs Intermediate CA v1.1&quot; \<br>    key_type=ec \<br>    key_bits=256 \<br>    | jq -r &#39;.data.csr&#39; &gt; pki_int_v1.1.csr<br>certstrap --depot-path root sign \<br>    --CA &quot;Example Labs Root CA v1&quot; \<br>    --passphrase &quot;secret&quot; \<br>    --intermediate \<br>    --csr pki_int_v1.1.csr \<br>    --expires &quot;5 years&quot; \<br>    --path-length 1 \<br>    --cert pki_int_v1.1.crt \<br>    &quot;Example Labs Intermediate CA v1.1&quot;<br>vault write -format=json \<br>    pki_int/intermediate/set-signed \<br>    certificate=@pki_int_v1.1.crt<br>vault secrets enable -path=pki_iss pki<br>vault secrets tune -max-lease-ttl=8760h pki_iss<br>vault write pki_iss/config/urls \<br>    issuing_certificates=&quot;http://127.0.0.1:8200/v1/pki_iss/ca&quot; \<br>    crl_distribution_points=&quot;http://127.0.0.1:8200/v1/pki_iss/crl&quot;<br>vault write -format=json \<br>    pki_iss/intermediate/generate/internal \<br>    organization=&quot;Example&quot; \<br>    common_name=&quot;Example Labs Issuing CA v1.1.1&quot; \<br>    key_type=ec \<br>    key_bits=256 \<br>    | jq -r &#39;.data.csr&#39; &gt; pki_iss_v1.1.1.csr<br>vault write -format=json \<br>    pki_int/root/sign-intermediate \<br>    organization=&quot;Example&quot; \<br>    csr=@pki_iss_v1.1.1.csr \<br>    ttl=8760h \<br>    format=pem \<br>    | jq -r &#39;.data.certificate&#39; &gt; pki_iss_v1.1.1.crt<br>cat pki_iss_v1.1.1.crt pki_int_v1.1.crt &gt; pki_iss_v1.1.1.chain.crt<br>vault write -format=json \<br>    pki_iss/intermediate/set-signed \<br>    certificate=@pki_iss_v1.1.1.chain.crt<br>vault write pki_iss/roles/example \<br>    organization=&quot;Example&quot; \<br>    allowed_domains=&quot;example.com&quot; \<br>    allow_subdomains=true \<br>    allow_wildcard_certificates=false \<br>    key_type=ec \<br>    key_bits=256 \<br>    generate_lease=true \<br>    max_ttl=2160h</pre><ul><li>Check the generated three-tier PKI CA with the following commands:</li></ul><pre>tree root<br>vault list -detailed pki_int/issuers<br>vault list -detailed pki_iss/issuers<br>vault read pki_iss/roles/example</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7179306f18c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>