<?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 Valerio Capponi on Medium]]></title>
        <description><![CDATA[Stories by Valerio Capponi on Medium]]></description>
        <link>https://medium.com/@valerio_98009?source=rss-0cf629cbb2cf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*X4uB-zP1oFIhreNjhORNYw.jpeg</url>
            <title>Stories by Valerio Capponi on Medium</title>
            <link>https://medium.com/@valerio_98009?source=rss-0cf629cbb2cf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:41:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@valerio_98009/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[Your Secrets Aren’t Safe Just Because Nobody Found Them Yet]]></title>
            <link>https://medium.com/@valerio_98009/your-secrets-arent-safe-just-because-nobody-found-them-yet-a91ba8667190?source=rss-0cf629cbb2cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/a91ba8667190</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[secret-management-tools]]></category>
            <category><![CDATA[hashicorp-vault]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Valerio Capponi]]></dc:creator>
            <pubDate>Fri, 06 Nov 2026 10:14:01 GMT</pubDate>
            <atom:updated>2026-11-06T10:14:01.523Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*67wncLjQOoFeL5hPnvAihA.png" /></figure><p>A database password in a config file that “only the team knows about.” An admin panel at /backoffice-7xk2 instead of /admin. An internal API with no authentication because “it sits behind the VPN.” SSH moved to port 2222, because: Sure! Nobody will guess that.</p><p>None of these is a security control. It’s just a bet that nobody will look.</p><p>We call it security through obscurity, and everyone agrees it’s bad, however it still shows up in a lot of environments that I review, regulated ones included.</p><h3>What it looks like in the wild</h3><p>The textbook definition is quite simple: <em>“Relying on the secrecy of a design or implementation as your main security control”</em>. In practice, nobody thinks they’re doing it. From the inside, it may even look like a reasonable shortcut.</p><h3>Credentials in “safe” places</h3><p>Passwords in config files, .env files committed to private repos, Confluence pages with “restricted” access, or the classic: attached to a Jira ticket next to the deployment instructions.</p><p>The reasoning is always some version of “only the team can see this.” But the team isn’t a fixed group. People join, leave and change roles. Repos get cloned, forked and mirrored. Tickets get exported. The credential committed in 2021 is probably still valid, and you can’t say who has a copy.</p><p><strong>During a workshop in a regulated environment it came out that a strategy for security lifecycle and a proper JML (Joiners, movers, leavers) process was in place for the obvious things like emails and main accounts, but nobody ever thought about the shared credentials that that person had access to. Were they easy to remember? Had they been copied somewhere else… nobody knew…</strong></p><h3>Secrets in collaboration tools</h3><p>API keys in Slack. Database credentials in a shared Google Doc. Cloud access keys in a team wiki. These tools were built to make information easy to find and share, the opposite of what a secret needs. Slack is searchable, docs get shared with “anyone with the link,” and wiki permissions change every time the org chart does.</p><h3>Internal APIs with no authentication</h3><p>A service that exposes user lookups, configuration changes or data exports with no auth at all, because it’s only reachable from the internal network. The real security model here is “the network perimeter is our authentication.” That holds until an attacker gets a foothold inside, someone opens a debug proxy, or a load balancer rule is misconfigured. Then the internal API is reachable from places you never intended.</p><h3>Hidden URLs, odd ports and “invisible” hostnames</h3><p>The network version of the same idea: /admin renamed to /management-console-x9f3, SSH on 2222, and internal hostnames like vault-prod.corp.local that feel private. Scanners like ffuf and gobuster don’t guess paths, they enumerate them. An nmap scan finds every open port in seconds. A hostname is one leaked config file or one SSRF bug away from being public. None of these is a secret you can keep.</p><h3>Why it feels like it works</h3><p><strong>The real problem is that obscurity fails silently.</strong></p><p>A firewall rule that blocks a connection writes a log entry. A failed login triggers an alert. An expired certificate throws a visible error. Real controls leave a trace whether they hold or not.</p><p>Obscurity gives you nothing like that. Nobody gets an alert when someone finds the hidden admin panel, pulls a credential out of a repo they cloned months ago, or maps your internal DNS.</p><p>So a system that has never been breached tells you very little. Either it’s well protected, or nobody has looked yet, and from the inside the two look the same. You can’t test it, and you only learn it failed after the damage is done.</p><h3>Find it, then make it noisy</h3><p>Two things help: finding what’s already exposed, and adding the alerting that obscurity never had.</p><p><strong>Scan the history, not just the code.</strong> A secret deleted in the last commit still lives in every commit before it. Run a scanner across the full git history of every repo:</p><pre>gitleaks git -v .</pre><p>Tools like gitleaks and trufflehog find keys, tokens and connection strings, and trufflehog can also check whether a found credential is still live. Then block new ones: pre-commit hooks locally, and push protection on your Git platform so a commit with a secret is rejected before it lands. Treat every finding as a credential to rotate. Deleting the line from the file doesn’t help.</p><p><strong>Plant honeytokens.</strong> You can’t get a log from a secret someone silently copied. But you can plant decoys that only an attacker would ever touch: a fake cloud access key in an old config file, a fake database user in a wiki page, a decoy path in Vault that no workload has a reason to read. Wire an alert to any use of them. It’s one of the few ways to get an alert out of something that otherwise fails silently.</p><p>In Vault this is also very easy. Enable an audit device, create a decoy secret, and alert on any audit entry for that path. No legitimate client reads it, so every hit is a real signal.</p><h3>What actually works</h3><h3>The best secret is no secret</h3><p>Where you can, don’t issue a credential at all. For a lot of workloads the platform can already prove who the workload is:</p><ul><li>An Azure VM or function app uses a managed identity to reach Key Vault, Storage or SQL. No password exists anywhere.</li><li>A GitHub Actions or GitLab CI pipeline uses OIDC federation to get a short-lived cloud token. No access key stored in the CI variables.</li><li>A Kubernetes pod authenticates to Vault with its service account token through the Kubernetes auth method. No bootstrap secret baked into the image.</li></ul><p>In all three examples, the platform vouches for the workload, so there’s nothing to store. In a design review, the first question about any secret should be whether it needs to exist.</p><h3>When you need a secret, make it short-lived</h3><p>Some systems still need a traditional username and password: databases, legacy apps, third-party services. For those, stop storing static credentials and issue them on demand, with an expiry.</p><p>With the Vault database secrets engine, the setup for a PostgreSQL database looks like this:</p><pre>vault secrets enable database<br><br>vault write database/config/payments-db \<br>    plugin_name=postgresql-database-plugin \<br>    connection_url=&quot;postgresql://{{username}}:{{password}}@db.internal:5432/payments&quot; \<br>    allowed_roles=&quot;app-readonly&quot; \<br>    username=&quot;vault-admin&quot; password=&quot;&lt;initial password&gt;&quot;<br><br># Rotate the admin password so only Vault knows it<br>vault write -force database/rotate-root/payments-db<br><br>vault write database/roles/app-readonly \<br>    db_name=payments-db \<br>    creation_statements=&quot;CREATE ROLE \&quot;{{name}}\&quot; WITH LOGIN PASSWORD &#39;{{password}}&#39; VALID UNTIL &#39;{{expiration}}&#39;; GRANT SELECT ON ALL TABLES IN SCHEMA public TO \&quot;{{name}}\&quot;;&quot; \<br>    default_ttl=1h max_ttl=24h</pre><p>The application then asks for credentials when it needs them:</p><pre>vault read database/creds/app-readonly</pre><p>Vault creates a database user just for that request, with a one hour lease, and drops it when the lease expires. A credential that leaks into a log is useless a week later. Each app instance gets its own user, so the database logs and the Vault audit log agree on who connected. And if something looks wrong, vault lease revoke -prefix database/creds/app-readonly revokes everything that role has issued.</p><p>This is where projects usually get stuck. The application has to handle renewal, and connection pools have to cope with credentials that expire under them. In practice you either use a client library that renews the lease, or put Vault Agent next to the app to fetch and refresh credentials and render them to a file. Budget for it from the start, because it’s most of the real work.</p><h3>Authenticate every call, authenticate everything</h3><p>If an internal API has no authentication because “it’s behind the VPN,” the fix is to authenticate every request, whatever network it comes from.</p><p>The rule is that network location grants nothing. Services prove who they are with mutual TLS, signed tokens or platform identity, and a service that can’t present a valid identity doesn’t get in.</p><p>Your admin panel can live at /admin, as long as there’s MFA, RBAC and audit logging behind it, the actual path doesn’t really matter. Your database can run on port 5432, as long as only the hosts that need it can reach it and every attempt is logged and so on.</p><h3>Secrets must live in a secrets manager</h3><p>Not in Slack, Confluence, Google Docs or Jira. In a wiki, anyone with access can copy a secret without leaving a trace. In a secrets manager it has an owner, a policy and an audit trail, and you can revoke it.</p><h3>Obscurity as a layer, not a strategy</h3><p>Obscurity isn’t completely useless, though.</p><p>Renaming default admin paths adds a little friction for lazy attackers. Moving SSH off port 22 cuts the noise in your logs. Not advertising your stack is basic hygiene, and so on.</p><p>These are fine as extra layers on top of real controls. The test is simple: <strong>if someone discovers the hidden thing, does your security collapse?</strong></p><p>If an attacker finds your admin panel and hits MFA, RBAC and session management, finding it got them nothing. If they’re straight in with full access, the obscurity was your only control.</p><h3>Where to start</h3><p>Obscurity survives because it’s cheap and nobody gets alerted when it fails. Real controls cost more: tooling, design work, and some uncomfortable conversations about trust boundaries. What you get back is an audit trail of who accessed what, when, and who tried and failed.</p><p>If you take one thing from this, run a secret scanner over your git history this week. What you will find, it could make the argument better than I can.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a91ba8667190" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Assume breach: Think about your blast radius]]></title>
            <link>https://medium.com/@valerio_98009/assume-breach-think-about-your-blast-radius-316c4f0f20a4?source=rss-0cf629cbb2cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/316c4f0f20a4</guid>
            <category><![CDATA[information-technology]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[it-architecture]]></category>
            <dc:creator><![CDATA[Valerio Capponi]]></dc:creator>
            <pubDate>Tue, 12 May 2026 11:00:25 GMT</pubDate>
            <atom:updated>2026-05-12T11:00:25.353Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KjboNLv6Mvx4W5z5-n-20A.png" /></figure><p>Most people start with the wrong question when they talk about securing a secrets platform. They ask, how do we stop a breach?</p><p>You get the usual answers: network segmentation, identity boundaries, least privilege, auditing, monitoring. All of these are useful and necessary. But they miss the real question you need to answer after something goes wrong: what can an attacker actually reach once they are inside?</p><p>That is the real question behind blast radius.</p><p>Blast radius thinking starts with a simple truth: sooner or later, one of your layers will fail. Maybe a pod gets compromised. An identity is stolen. Maybe a namespace admin clicks a phishing link. Maybe your cloud provider screws up. This is not a theory. It happens, even to companies with top-notch security teams. The real question is not if you will have a failure. It is what an attacker can do in the first hour after it happens.</p><p>For a secrets platform, this question matters more than almost anywhere else. Secrets are the pivot point. If an attacker gets control of the system that holds your credentials, they can go everywhere those credentials let them. Losing a web server is bad. Losing the system that hands out database passwords, IAM credentials, service principals, and TLS keys is much worse. This is why you cannot treat a secrets platform like just another app.</p><h4>A realistic attack chain</h4><p>A workload runs in a Kubernetes cluster on Azure. Its pod has a user-assigned managed identity, which the application uses to access Azure services. One of those services is an Azure Key Vault that stores the recovery keys for a HashiCorp Vault instance. That Vault instance uses the same Key Vault for auto-unseal.</p><p>An attacker gets code execution inside the pod. The initial foothold could come from almost anywhere, the entry point matters less than the outcome. The attacker now has code running in a pod with a managed identity.</p><p>From there, they query Azure Instance Metadata Service and obtain a token for that identity. With it, they call Azure APIs, enumerate permissions, and discover the identity that can read secrets from Key Vault. They read the recovery keys.</p><p>Next, they need access to the HashiCorp Vault API. In many environments, that is not hard. If Vault is reachable from the cluster network, and the attacker already has execution inside the cluster, they can probably reach it. With the recovery keys, they can initiate a root token generation using the recovery keys.</p><p>The attacker did not breach the secrets platform directly. They breached a pod, and the secrets platform became the blast radius.</p><h4>What blast radius thinking actually asks</h4><p>The point here is not that you need to defend against this exact scenario. The point is that every step in this chain is a design question you should be asking about your own setup.</p><p>Could a compromised pod reach Azure Instance Metadata Service? In many clusters, yes. You can block that with network policy or avoid IMDS entirely with something like azure-workload-identity, but many environments still leave the default in place.</p><p>Could the managed identity read the Key Vault secret? Yes, because at some point it was granted that permission, perhaps intentionally, perhaps as part of a more extensive role that appeared harmless at the time.</p><p>Could the attacker reach the Vault API from inside the cluster? Probably. That is usually the point of running Vault there. The better question is whether every pod should have that path, or only a tightly defined set of service accounts.</p><p>Could the recovery keys in Key Vault actually unseal or rekey Vault? Yes. That is their purpose. The more important question is whether those keys belong in the same cloud account, subscription, and identity boundary as the workloads Vault is protecting.</p><p>Could the attacker use the new root token long enough to do meaningful damage? In most environments, yes. Root token events are logged, but often not monitored with enough urgency to matter.</p><p>Every one of these questions has a possible fix, and every fix comes with a cost. The point of blast radius thinking is not to throw every control at the problem. It is to make those trade-offs on purpose, not discover them in the middle of an incident.</p><h4>Layers that actually contain blast radius</h4><p>Some controls actually shrink your blast radius, others just make people feel better. That difference is important. (I will talk more about this in my next article)</p><p>Vault namespaces are a clear example of a control that actually works. If a user, application, or token in one namespace gets compromised, the attacker is usually stuck inside that namespace’s secrets and policies. The trade-off is more organizational complexity; a proper namespace structure needs to be in place.</p><p>Separating the auto-unseal mechanism from the workloads Vault serves is another control that actually matters. If your unseal keys live in the same Azure subscription as the workloads using Vault, then the identity boundary around unseal is probably your weakest link. Move that Key Vault into a separate subscription with its own identity controls, and you can shrink the blast radius a lot.</p><p>Short TTLs on dynamic secrets are one of the best ways to control blast radius. A database password that expires after twelve hours is much less useful to an attacker than a static password that has been sitting in a config file for years. Even if someone steals it, the window for abuse closes by itself.</p><p>Network boundaries matter, but mostly inside your trust boundary. A network policy that restricts pod-to-Vault access by service account can actually stop lateral movement. A perimeter firewall usually cannot, because the attacker is already inside.</p><p>Audit logging matters, but only if someone acts on it. Vault logs root token creation, broad secret reads, and new auth backends. If nobody is watching those events, the logs are only useful after the fact. They do not help you contain the incident while it is happening.</p><h4>Controls that feel good but do not contain blast radius</h4><p>Some controls get sold as blast radius reducers, but they do not really change the outcome.</p><p>Rotating the root token on a schedule is a good example. The problem with a root token is not how old it is. The problem is that it exists at all. The better approach is to revoke it after setup and only recreate it for specific emergency tasks.</p><p>Putting Vault behind a WAF is another one. In this kind of attack, the attacker is not coming through the public edge. They are moving through a legitimate internal path from a compromised pod.</p><p>Extra encryption at rest in the storage backend is overrated here. Vault already encrypts its own data before writing it out, so the backend is just storing ciphertext. Wrapping it again almost never changes what an attacker can do.</p><h4>Designing from the breach backward</h4><p>The practical shift is simple. Do not just list controls and assume you are covered. Map out how each one fails and what the attacker can reach next. Do this as an architecture exercise, not just a red-team drill.</p><p>This process usually turns up some uncomfortable truths. A stolen managed identity can read unseal keys. A compromised web-tier pod can reach the Vault API. A namespace admin compromise hits more applications than you expected. These are not abstract risks. They are design decisions you can see in the open.</p><p>This is not being pessimistic. It is being specific. Saying ‘we have defense in depth’ is just a slogan. Saying ‘if an attacker compromises a pod with managed identity X, they can reach secrets Y and Z, and we accept that trade-off because the alternative costs W’ is a position you can actually defend.</p><p>That level of specificity matters most in a secrets platform because the blast radius is huge. You can afford to be vague about the blast radius of a logging pipeline. You cannot be vague about the system that holds credentials for everything else.</p><p>Design from the breach backward. Assume one layer fails, then trace what the attacker can reach next. Do it for the pod. Do it for the managed identity. Do it for the namespace admin. Do it for the cloud KMS holding your unseal keys. Every path ends somewhere. That endpoint is your blast radius. If you do not like where it ends, change the design.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=316c4f0f20a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Legacy workflow and HashiCorp Vault]]></title>
            <link>https://medium.com/@valerio_98009/legacy-workflow-and-hashicorp-vault-a5991e29012d?source=rss-0cf629cbb2cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5991e29012d</guid>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[legacy]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[hashicorp-vault]]></category>
            <dc:creator><![CDATA[Valerio Capponi]]></dc:creator>
            <pubDate>Wed, 22 Apr 2026 08:38:36 GMT</pubDate>
            <atom:updated>2026-04-22T08:38:36.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zo8puNidFAYCd3ILh1Sfnw.png" /></figure><p>When people think about HashiCorp Vault, they often picture shiny, cloud-native architectures: Kubernetes clusters with sidecar injectors, dynamic secrets flowing into pods, zero-trust everywhere, service meshes humming along in the background.</p><p>And then they look at their own reality.</p><p><em>“We still run critical workloads on VMs. Some of them are old. Some are fragile. Vault is probably not for us.”</em></p><p>That assumption is wrong, and it is costing enterprises a lot of time and risk.</p><p>You do not need to rewrite your applications, containerise everything, or migrate to Kubernetes to get real value from Vault. Even legacy workflows running on plain virtual machines can benefit significantly, especially when it comes to certificate management and rotation. In fact, the VM estate is often where the biggest wins sit, because that is where the oldest manual processes tend to live.</p><p>Let’s look at a very concrete example: rotating private TLS certificates on VMs using Vault Agent.</p><h3>The classic VM certificate problem</h3><p>In many companies, private certificates are handled roughly like this. A ticket is raised. A PKI administrator generates a certificate with a long TTL, usually a year, sometimes longer. The certificate and, worryingly often, the private key itself, are attached to the ticket or dropped into a shared folder. Someone copies them to the target VM, restarts the service, and moves on.</p><p>Then the certificate sits there, quietly, until it is close to expiry or something breaks.</p><p>This pattern produces a familiar set of problems. Expired certificates cause outages at the worst possible moment, usually on a Friday evening or right before a board demo. The same certificate ends up reused across multiple machines because reissuing is painful, so the blast radius of any compromise grows. Private keys live unencrypted on disk, and copies of them linger in ticket systems, email threads, and chat logs. Ownership is unclear. The audit trail is a mix of screenshots and human memory. And because rotation is manual and risky, teams avoid it or postpone it somewhere in the future in some team calendar.</p><p>Vault does not magically modernise your applications. It will not refactor your monolith or move it into a container for you. What it does do, and does very well, is modernise the way secrets and certificates are delivered to that application.</p><h3>Enter Vault Agent</h3><p>Vault Agent is the key enabler here. It runs as a lightweight process on the VM, next to your application, and it handles all interaction with Vault on the application’s behalf. That means authentication, token management, renewals, template rendering, and reload hooks, all outside the application’s code path.</p><p>From the application’s point of view, nothing changes. It still reads the certificate and private key from the same paths on disk, or from the same Windows certificate store location. It still reloads them the same way it always has, whether that is a SIGHUP, a service restart, an IIS recycle, or a timed reload.</p><p>The only difference is that Vault Agent quietly keeps those files fresh, valid, and backed by a real identity.</p><p>This is the part that tends to surprise people. You do not need to make your application “Vault aware”. You do not need a library, an SDK, or a code change. You only need to decide where the files should land and how the service should reload them.</p><h3>How the flow works</h3><p>The setup has a few moving parts, but the flow itself is straightforward.</p><p>Vault’s PKI secrets engine is configured as an issuing CA, typically an intermediate that chains up to your corporate root. A PKI role defines what kind of certificates can be issued: allowed common names, SANs, key types, key usages, and the maximum TTL. Rather than issuing year-long certificates, you set the TTL to something short: a few days, or even a few hours, depending on the workload.</p><p>On the VM, Vault Agent runs as a systemd unit on Linux or as a Windows service. Its configuration tells it three things: how to authenticate to Vault, what to render, and where to put the result.</p><p>For authentication, you pick the method that best matches the environment. (Cloud native or not)</p><p>Once authenticated, Vault Agent asks the PKI engine to issue a certificate that matches the template you have defined. It writes the certificate, the private key, and the CA chain to the paths your application expects. Before the certificate’s TTL runs out, it asks for a new one and rewrites the files. You can also configure a command to run after each render, so the service picks up the new material without human intervention. That might be a systemctl reload nginx, a net stop/start on Windows, or a custom script that moves the files into a platform-specific store.</p><p>The application, again, sees none of this. It just sees a valid certificate on disk, always.</p><h3>A local rendering example</h3><p>A minimal Vault Agent configuration for this pattern looks roughly like the snippet below. It authenticates with AppRole (recommended when as Cloud native authentication method is not available), renders a certificate and its private key from the PKI engine, and reloads the service after each rotation.</p><pre>pid_file = &quot;/var/run/vault-agent.pid&quot;<br><br>vault {<br>  address = &quot;https://vault.example.internal:8200&quot;<br>}<br>auto_auth {<br>  method &quot;approle&quot; {<br>    config = {<br>      role_id_file_path = &quot;/etc/vault-agent/role-id&quot;<br>      secret_id_file_path = &quot;/etc/vault-agent/secret-id&quot;<br>      remove_secret_id_file_after_reading = true<br>    }<br>  }<br>  sink &quot;file&quot; {<br>    config = {<br>      path = &quot;/etc/vault-agent/token&quot;<br>    }<br>  }<br>}<br>template {<br>  contents = &lt;&lt;-EOT<br>    {{ with pkiCert &quot;pki_int/issue/web-server&quot; &quot;common_name=app01.example.internal&quot; &quot;ttl=72h&quot; }}<br>    {{ .Cert }}<br>    {{ .CA }}<br>    {{ .Key | writeToFile &quot;/etc/tls/app.key&quot; &quot;vault&quot; &quot;vault&quot; &quot;0600&quot; }}<br>    {{ end }}<br>  EOT<br>  destination = &quot;/etc/tls/app.crt&quot;<br>  command     = &quot;systemctl reload nginx&quot;<br>}</pre><p>A few details are worth pointing out, because they matter in practice and are easy to miss.</p><p>The pkiCert function is the one you want for certificate rendering. Plain secret works too, but pkiCert is smarter about when to reissue: it inspects the certificate already on disk and only requests a new one when the existing one is close to expiry, rather than churning out a new certificate every time the agent restarts or re-authenticates. That distinction makes a real difference to your PKI audit trail, because otherwise every agent restart looks like an issuance event.</p><p>The private key is written separately, with explicit ownership and file mode. Certificates are public, but the key is not, and having it land with mode 0600 owned by the service user, rather than whatever umask the agent process happened to have, is the kind of detail a security reviewer will check first.</p><p>The command field triggers a reload after each successful render. Keep that command idempotent and fast. If your service needs something more elaborate, a small wrapper script is easier to reason about than a chain of shell operators inside the template.</p><p>One thing Vault Agent does not do is track revocation. If you revoke a certificate in Vault, the agent will not notice on its own, because pkiCert only reacts to expiry, not to CRL or OCSP state. In the rare case you need to force a reissue, the operational answer is to clear the rendered file on the VM and restart the agent. This is worth knowing before a security incident, not during one.</p><h3>Example: an Azure Windows VM with IIS</h3><p>The Linux example is the easy case. Windows on Azure is where this pattern tends to be the most useful, because that is where most legacy IIS estates still live and where certificate rotation is most often still a ticket-driven process.</p><p>Assume a Windows Server VM running in Azure, hosting an IIS site that needs a TLS certificate for HTTPS on port 443. The goal is the same as before: short-lived certificates, rotated automatically, with no change to the application. The two things that differ are the authentication method and the delivery target. Instead of AppRole, we let Azure vouch for the VM’s identity through a Managed Identity. Instead of writing a PEM file to disk, we land the certificate in the Windows certificate store, where IIS expects to find it.</p><h4>Authenticating with Managed Identity</h4><p>Azure Managed Identity removes the secret zero problem entirely. There is no Role ID, no Secret ID, no credential to provision, rotate, or accidentally commit to Git. The VM has an identity assigned to it by Azure, system-assigned or user-assigned, and Vault can be configured to trust tokens issued to that identity.</p><p>On the Vault side, the Azure auth method is enabled and configured with the tenant ID, the application registration that Vault uses to validate MSI tokens, and a role that pins the managed identity to a specific resource group, VM name, or subscription. Those bindings are what prevent a rogue VM elsewhere in the tenant from claiming the same identity and pulling certificates it should not have. The role is also mapped to a Vault policy that grants nothing more than the ability to issue certificates from the PKI role you want this VM to use.</p><p>On the VM side, Vault Agent runs as a Windows service. Its configuration is almost identical to the Linux one, with two differences: the auto_auth block uses the azure method, and the template writes a PFX file rather than a PEM pair, because that is what the Windows certificate store consumes natively.</p><pre>pid_file = &quot;C:\\ProgramData\\vault-agent\\vault-agent.pid&quot;<br><br>vault {<br>  address = &quot;https://vault.example.internal:8200&quot;<br>}<br>auto_auth {<br>  method &quot;azure&quot; {<br>    config = {<br>      role     = &quot;iis-web-server&quot;<br>      resource = &quot;https://vault.hashicorp.com/&quot;<br>    }<br>  }<br>  sink &quot;file&quot; {<br>    config = {<br>      path = &quot;C:\\ProgramData\\vault-agent\\token&quot;<br>    }<br>  }<br>}<br>template {<br>  contents = &lt;&lt;-EOT<br>    {{ with pkiCert &quot;pki_int/issue/iis-web-server&quot; &quot;common_name=web01.example.internal&quot; &quot;ttl=168h&quot; }}<br>    {{ .Cert }}<br>    {{ .CA }}<br>    {{ .Key }}<br>    {{ end }}<br>  EOT<br>  destination = &quot;C:\\ProgramData\\vault-agent\\iis\\web01.pem&quot;<br>  command     = &quot;powershell.exe -ExecutionPolicy Bypass -File C:\\ProgramData\\vault-agent\\bind-iis.ps1&quot;<br>}</pre><p>The resource value must match whatever was configured as the resource URI on the Vault Azure auth method, which is how Azure knows which audience to sign the MSI token for. When using a system-assigned identity, no further identification is needed; the VM&#39;s own identity is picked up automatically from the Instance Metadata Service. If you use a user-assigned identity instead, which is the pattern I tend to recommend for anything beyond a single VM because it survives the VM being rebuilt, you add a client_id to the config pointing at that specific identity.</p><p>Running Vault Agent itself as a Windows service is supported natively. The practical detail that trips people up is the service account: the service needs to run as a principal that has read access to the Instance Metadata Service (which, on an Azure VM, any local account does) and write access to the directories where the rendered file and the sink live. Local System works and keeps the configuration simple.</p><h4>Landing the certificate in the Windows certificate store</h4><p>IIS does not read PEM files. It reads from the Windows certificate store, typically from the local machine Personal store, and it binds a site to a certificate by thumbprint, not by path. That means the rendering step is only half the job. The second half is a small PowerShell script that converts the PEM bundle to a PFX, imports it into the right store, and rebinds the IIS site if the thumbprint has changed.</p><p>The script below is a minimal but realistic version of what that looks like. It is triggered by the command field in the template stanza, so it runs immediately after each successful render.</p><pre># C:\ProgramData\vault-agent\bind-iis.ps1<br><br>$ErrorActionPreference = &#39;Stop&#39;<br>Import-Module WebAdministration<br>$PemPath   = &#39;C:\ProgramData\vault-agent\iis\web01.pem&#39;<br>$PfxPath   = &#39;C:\ProgramData\vault-agent\iis\web01.pfx&#39;<br>$SiteName  = &#39;Default Web Site&#39;<br>$BindingIp = &#39;*&#39;<br>$Port      = 443<br>$Hostname  = &#39;web01.example.internal&#39;<br># 1. Convert the PEM bundle rendered by Vault Agent into a PFX.<br>#    OpenSSL ships with recent Windows Server builds; otherwise use<br>#    the portable binary that your base image provides.<br>$PfxPassword = [System.Web.Security.Membership]::GeneratePassword(32, 4)<br>&amp; openssl pkcs12 -export `<br>    -in  $PemPath `<br>    -out $PfxPath `<br>    -password &quot;pass:$PfxPassword&quot; | Out-Null<br># 2. Import the PFX into the LocalMachine\My store.<br>$SecurePwd = ConvertTo-SecureString -String $PfxPassword -AsPlainText -Force<br>$NewCert = Import-PfxCertificate `<br>    -FilePath         $PfxPath `<br>    -CertStoreLocation &#39;Cert:\LocalMachine\My&#39; `<br>    -Password          $SecurePwd<br># 3. Make sure the HTTPS binding exists, then (re)bind it to the new cert.<br>$Binding = Get-WebBinding -Name $SiteName -Protocol &#39;https&#39; `<br>    -ErrorAction SilentlyContinue<br>if (-not $Binding) {<br>    New-WebBinding -Name $SiteName -IPAddress $BindingIp `<br>        -Port $Port -HostHeader $Hostname -Protocol &#39;https&#39; -SslFlags 1<br>    $Binding = Get-WebBinding -Name $SiteName -Protocol &#39;https&#39;<br>}<br>$Binding.AddSslCertificate($NewCert.Thumbprint, &#39;My&#39;)<br># 4. Clean up the PFX and the PEM from disk. The private key now lives<br>#    in the certificate store, protected by the machine&#39;s DPAPI key.<br>Remove-Item $PfxPath -Force<br>Remove-Item $PemPath -Force</pre><p>A few things are worth calling out, because the defaults are not always what you want.</p><p>The PFX password is generated on the fly and never persisted. It exists only long enough to hand the bundle to Import-PfxCertificate, and is discarded as soon as the import succeeds. Once the certificate is in the store, the private key is protected by DPAPI under the machine account, which is the standard Windows model and what IIS expects.</p><p>The rendered PEM and the intermediate PFX are deleted at the end of the script. The store now holds the authoritative copy, and leaving loose copies of the private key on disk defeats most of the point of moving to short-lived certificates in the first place.</p><p>The binding is updated with AddSslCertificate regardless of whether the binding already existed. This cmdlet is a bit of a misnomer. If a certificate is already bound to the site, it replaces it. That is exactly the behaviour we want during a rotation: the next TLS handshake picks up the new certificate without restarting the site, and there is no window where IIS is bound to nothing.</p><p>Older certificates accumulate in LocalMachine\My unless you clean them up. For a web server this rarely causes a functional problem, but it is tidy to add a step that removes any certificate from the same PKI role whose NotAfter is in the past. I have left that out of the example to keep it readable, but it is a one-liner with Get-ChildItem Cert:\LocalMachine\My | Where-Object NotAfter -lt (Get-Date).</p><h4>What this gives you</h4><p>Put together, the Azure VM now behaves like this. Vault Agent authenticates to Vault using the VM’s managed identity, with no credential on disk. It requests a certificate from Vault’s PKI engine with a TTL of a week. It writes the rendered bundle to a working directory, triggers the PowerShell script, which lands the certificate in LocalMachine\My and updates the IIS binding. A few days later, well before the certificate expires, the agent quietly does the same thing again. IIS keeps serving HTTPS on port 443. Nobody opens a ticket. Nobody copies a PFX over RDP. Nobody emails a private key.</p><p>The application, once again, has not changed. IIS is doing exactly what it has always done: reading a certificate from the store and binding it to a site. What has changed is the workflow that puts the certificate there.</p><h3>Closing thought</h3><p>There is a tendency to treat Vault as a cloud-native tool, and to postpone adopting it until the rest of the platform catches up. That is the wrong way round. The VMs running your oldest, most fragile, most business-critical workloads are the ones that benefit the most from short-lived certificates, automated rotation, and a proper identity for every machine. Vault Agent is the bridge that makes this possible without touching the application.</p><p>You do not modernise a legacy estate by rewriting it all at once. You modernise it by changing the workflow around it, one control at a time. Certificate rotation is a good place to start, because it is both painful enough to justify the effort and contained enough to finish. Once that pattern is in place, the next secret, and the one after, come almost for free.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5991e29012d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>