<?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 Pedro Coca on Medium]]></title>
        <description><![CDATA[Stories by Pedro Coca on Medium]]></description>
        <link>https://medium.com/@pedro_coca?source=rss-d80b1add7b68------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*RbWDB9sQtbOprL-i.jpg</url>
            <title>Stories by Pedro Coca on Medium</title>
            <link>https://medium.com/@pedro_coca?source=rss-d80b1add7b68------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:27:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pedro_coca/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[Systemd Service File for Vault]]></title>
            <link>https://medium.com/hashicorp-engineering/systemd-service-file-for-vault-3e339ff86bc6?source=rss-d80b1add7b68------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e339ff86bc6</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hashicorp]]></category>
            <category><![CDATA[vault]]></category>
            <category><![CDATA[systemd]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Pedro Coca]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 21:34:42 GMT</pubDate>
            <atom:updated>2020-01-14T21:34:42.565Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s see how Vault gets along with the default init system for most of the Linux distributions, <a href="https://en.wikipedia.org/wiki/Systemd">systemd</a>, by analysing, testing and tinkering with the Vault service unit file!</p><p>When you deploy Hashicorp Vault on Linux you need to deal with the init system of your machine to set how Vault or any other service will start and run, what needs to be done before or afterwards, and some other details. This is addressed in the <a href="https://learn.hashicorp.com/vault/operations/ops-deployment-guide#step-3-configure-systemd">Vault Deployment Guide</a>, but let’s analyse each part, tinkering a bit with the restart parameters, showing the metadata in actual commands output and covering things a bit more in depth, including the Linux capabilities and the resource limits. Ready? Let’s go!</p><p>The init system of a Linux machine… well, it doesn’t matter if you have a very pragmatic approach on the matter or <a href="https://www.youtube.com/watch?v=-97qqUHwzGM">you went over the five (six!) stages of grieving (systemd!)</a>: you are most likely dealing with systemctl and other <a href="https://www.freedesktop.org/wiki/Software/systemd/">systemd</a> tools anyway. Let’s see how Vault and systemd get along then.</p><p>If you follow the aforementioned deployment guide, you will find the service unit file <strong>vault.service</strong>, going along with the .service suffix convention. A unit in systemd lingo is simply a resource that will be managed by systemd. In this particular case, the content of this file determines how systemd will start and run Vault, what it does and some other things.</p><p>Unit files can live in several different places. In the deployment guide, it is stated that the Vault service unit file lives at the /etc/systemd/system path, which is the usual place for local unit files. Systemd will give the highest priority to the files living under /etc.</p><p>The section names of the unit file (Unit, Service and Install) are well defined, and it is good to remember that they are case-sensitive! :)</p><pre><strong>[Unit]</strong><br>Description=&quot;HashiCorp Vault - A tool for managing secrets&quot; Documentation=https://www.vaultproject.io/docs/<br>Requires=network-online.target<br>After=network-online.target ConditionFileNotEmpty=/etc/vault.d/vault.hcl StartLimitIntervalSec=60<br>StartLimitBurst=3<br><br><strong>[Service]</strong><br>User=vault<br>Group=vault<br>ProtectSystem=full<br>ProtectHome=read-only<br>PrivateTmp=yes<br>PrivateDevices=yes<br>SecureBits=keep-caps<br>AmbientCapabilities=CAP_IPC_LOCK<br>Capabilities=CAP_IPC_LOCK+ep<br>CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK<br>NoNewPrivileges=yes<br>ExecStart=/usr/local/bin/vault server -config=/etc/vault.d/vault.hcl ExecReload=/bin/kill --signal HUP $MAINPID <br>KillMode=process <br>KillSignal=SIGINT <br>Restart=on-failure <br>RestartSec=5<br>TimeoutStopSec=30<br>StartLimitInterval=60<br>StartLimitIntervalSec=60<br>StartLimitBurst=3<br>LimitNOFILE=65536<br>LimitMEMLOCK=infinity<br><br><strong>[Install]</strong><br>WantedBy=multi-user.target</pre><blockquote>The format actually brings some memories… those .ini files that I discovered as a kid with my first steps using my first MS-DOS version: 3.3 :)</blockquote><p>Now that we have introduced our dear friend, the vault service unit file, let’s analyse each section:</p><h3>The [Unit] Section of the Vault Service Unit File</h3><p>This section is generally used for the definition of some information and metadata for the service unit itself. You might also find some directives regarding the relationship of the Vault service unit to other units:</p><pre><strong>[Unit]</strong><br>Description=&quot;HashiCorp Vault - A tool for managing secrets&quot; Documentation=https://www.vaultproject.io/docs/<br>Requires=network-online.target<br>After=network-online.target ConditionFileNotEmpty=/etc/vault.d/vault.hcl StartLimitIntervalSec=60<br>StartLimitBurst=3</pre><p>The Description directive is generally used to describe the name and basic functionality, so we will simply state “HashiCorp Vault — A tool for managing secrets”.</p><p>The Documentation directive in this case is an external URL that points to the <a href="https://www.vaultproject.io/docs/">Vault project docs</a>.</p><p>This info is returned by some systemd tools such as systemctl as we can see in the screenshot, so it is better to set this to something short, specific, and informative:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XucqIbhh9nROL4NEoHrdWQ.png" /><figcaption>systemctl status for the Vault service returning the information stated in the directives of the service unit file</figcaption></figure><p>The Requires directive lists any units upon which Vault depends. If the Vault service unit is activated, the unit listed here (network-online.target) will also be activated; if any of them fail, then so will the Vault service unit.</p><p>The After directive configure an ordering dependency between units. The units listed here will be fully started before starting the Vault service unit. In this case the network-online.target unit is fully started up before the Vault service unit is started.</p><p>The ConditionFileNotEmpty directive allows us to test certain conditions prior to starting the Vault service unit, like in this case that the Vault configuration file (/etc/vault.d/vault.hcl) exists and is not empty.</p><p>The StartLimitBurst and StartLimitIntervalSec directives will set the limit on the number of times the Vault service unit can be started within an interval of time; in this case, 3 times in 60 seconds will be the limit.</p><p>If we try to restart Vault more than 3 times in a minute we will get an error: if we check the details with systemctl or journalctl<strong>,</strong> we will see the message that the Vault service failed with result “start-limit-hit” as the “start request repeated too quickly”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pf5t6GKiLIjWSHN-viWUNA.png" /><figcaption>systemctl status output after restarting Vault several times and hit the “StartLimitBurst” number</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*81EpBGsKL-ebYI05Do2qPQ.png" /><figcaption>journalctl output after restarting Vault several times and hit the “StartLimitBurst” number</figcaption></figure><h3>The [Service] Section of the Vault Service Unit File</h3><p>This section is a type-specific one for services and is used to provide configuration data applicable for the Vault service:</p><pre><strong>[Service]</strong><br>User=vault<br>Group=vault<br>ProtectSystem=full<br>ProtectHome=read-only<br>PrivateTmp=yes<br>PrivateDevices=yes<br>SecureBits=keep-caps<br>AmbientCapabilities=CAP_IPC_LOCK<br>Capabilities=CAP_IPC_LOCK+ep<br>CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK<br>NoNewPrivileges=yes<br>ExecStart=/usr/local/bin/vault server -config=/etc/vault.d/vault.hcl ExecReload=/bin/kill --signal HUP $MAINPID <br>KillMode=process <br>KillSignal=SIGINT <br>Restart=on-failure <br>RestartSec=5<br>TimeoutStopSec=30<br>StartLimitInterval=60<br>StartLimitIntervalSec=60<br>StartLimitBurst=3<br>LimitNOFILE=65536<br>LimitMEMLOCK=infinity</pre><h4><strong>Who is calling the shots?</strong></h4><p>In order to define who is calling the shots (running the process) we have the User and Group directives that will set the Linux user and group that the Vault processes are executed as. For the Vault service unit file we will operate with the vaultuser and the vaultgroup.</p><h4>Sandboxing</h4><p>There are a few sandboxing options that are an effective way to limit the exposure of the system to the unit’s processes, namely the ProtectSystem directive, which when set to full will mount the/etc directory read-only in addition to the /usr and /boot directories that will be read-only for processes invoked by the Vault service unit. Note that this directive will have no effect if the Linux kernel is built without file system <a href="http://man7.org/linux/man-pages/man7/namespaces.7.html">namespaces</a>.</p><p>The ProtectHome directive will affect the directories /home, /root, and /run/user that in this case will be read-only for processes invoked by this unit since the value of this directive is set to “read-only”.</p><p>Setting the directive PrivateTmp to true will configure a new file system namespace for the Vault processes and mount private directories (/tmp and /var/tmp)inside that namespace. These directories are not shared by other processes outside of the namespace, so it is useful in order to secure the access to temporary files of the Vault processes.</p><p>The PrivateDevices directive when set to yes will turn off physical device access by the Vault processes and will set up a new /dev mount for the Vault processes with access to /dev/null, /dev/zero and /dev/random, etc., but no access to physical devices, system memory or system ports.</p><h4>Linux capabilities</h4><p>There are also several <a href="http://man7.org/linux/man-pages/man7/capabilities.7.html">capabilities</a> directives that are a way to provide a subset of the root privileges to a process, so you can grant a fine-grained set of privileges to the <em>unprivileged</em> processes (whose effective UID is nonzero).</p><p>In this case, the SecureBits, AmbientCapabilities, Capabilities and CapabilityBoundingSet directives will model the permissions that we will grant the Vault process to allow things such as locking memory (cap_ipc_lock) or performing privileged syslog operations (cap_syslog). We can always check which capabilities have been granted to our Vault process by checking the /proc filesystem and piping the output with capsh:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rYvkPHnFNwFtwbaNWUt92w.png" /></figure><h4>Avoiding privilege elevation</h4><p>Setting the directive NoNewPrivileges to yes ensures that the Vault process and all its children can never gain new privileges; so, the Vault process can never elevate its own privileges.</p><h4>Service lifecycle</h4><p>In order to define how the service is started, restarted, reloaded or killed we have several directives that will define the commands with their arguments that are executed when Vault is started (<strong>ExecStart</strong>):</p><pre>/usr/local/bin/vault server -config=/etc/vault.d/vault.hcl</pre><p>The commands to trigger a Vault configuration reload (<strong>ExecReload</strong>):</p><pre>/bin/kill --signal HUP $MAINPID</pre><p>Or the process killing procedure configuration with the directives KillMode that will have the value processto say that only the main process itself is killed or the directive KillSignal that will be set to SIGINT in order to send an interrupt signal (2).</p><p>The directive Restart will determine whether the service shall be restarted whenever the service process exits, is killed, or a timeout is reached. As we are setting this directive to on-failure, the Vault service will be restarted in a number of failure scenarios: when the process exits with a non-zero exit code, when it is terminated by a signal, etc.</p><p>The RestartSec directive will set the number of seconds before restarting the Vault service, in this case 5 seconds.</p><p>Let&#39;s be a little patient with the TimeoutStopSec directive set to 30 to wait half a minute for a clean stop, otherwise: no kidding… as it will be terminated by SIGKILL</p><p>And finally, if Vault is started more than 3 times within a minute, it will not be allowed to start any more, which is configured setting the StartLimitIntervalSec to 60 (seconds) and the StartLimitBurst directive to 3 (attempts)</p><h4>Process properties</h4><p>We can set soft and hard limits on several resources for the Vault process. In this case, we will use the LimitNOFILE directive with the value 65536 to limit the number of File Descriptors and we will get rid of the limitation on the amount of memory the Vault process can use with LimitMEMLOCK set to the string <em>infinity.</em></p><h3>The [Install] section of the Vault service unit file</h3><p>This section is optional and is is not interpreted by systemd during runtime. It is mainly used to state the behaviour of the Vault service unit if it is enabled or disabled. The section carries “installation information” for the Vault service unit.</p><pre><strong>[Install]</strong><br>WantedBy=multi-user.target</pre><p>The WantedBy directive creates a weak dependency of Vault being started by the multi-user run level.</p><p>With this line systemctl will know that the Vault service unit is related to a group of unit files called multi-user.target.which is the systemd terminology for the runlevel 3 in the systemV world.</p><p>We can list the target units with systemctl list-units --type target:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*GNFXxBNzM7wsEVjZMzG6SA.png" /><figcaption>multi-user.target unit showing up on the list of target units</figcaption></figure><p>And we can see the details of the multi-user.target unit with systemctl:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Y4lDwYHezxLO9g71Pa16w.png" /><figcaption>multi-user.target unit</figcaption></figure><p>Many times we need to pass information to Vault such as auto-unseal parameters. In order to manage that scenario, the <a href="https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Environment=">Environment</a> directive within the Service section comes in handy. The following will set an environment variable for the Vault process:</p><pre><strong>[Service]<br>...<br></strong>Environment=&quot;MY_KEY=my_favourite_value_today&quot;<br>...</pre><p>That’s all! I hope you have enjoyed covering a bit more in depth the Vault service unit file for systemd and remember that if there is a full consensus around systemd, you can always bring up text editors, DKMS, and open source licenses to heat up those watercooler conversations ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e339ff86bc6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hashicorp-engineering/systemd-service-file-for-vault-3e339ff86bc6">Systemd Service File for Vault</a> was originally published in <a href="https://medium.com/hashicorp-engineering">HashiCorp Solutions Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vault debug]]></title>
            <link>https://medium.com/hashicorp-engineering/vault-debug-7fd2f2f70f38?source=rss-d80b1add7b68------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fd2f2f70f38</guid>
            <category><![CDATA[debug]]></category>
            <category><![CDATA[hashicorp]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[vault]]></category>
            <dc:creator><![CDATA[Pedro Coca]]></dc:creator>
            <pubDate>Sun, 15 Dec 2019 23:41:26 GMT</pubDate>
            <atom:updated>2019-12-15T23:41:26.398Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Could you please send me the “<em>logs</em>”?</strong></p><p>We often find ourselves facing the need to either gather data from a particular service or to send that data to other people or teams. On our daily job we are often dealing with Vault <strong>server logs</strong> that contain information about internal Vault operations, with Vault <strong>audit trails</strong> that include data about requests and responses or with Vault <strong>telemetry </strong>to know about the performance of the different Vault subsystems.</p><p>Gathering data from different places at different times makes things a bit more complicated, ending up with information that lack completeness and is not consistent. As a result of this, triage, escalation and utterly the resolution of configuration issues, bugs, et cetera. might take more time.</p><p>Data from an initial configuration of Vault at “t” can be gathered at t+1 with the CLI, at t+2 with the API, at t+3 with the telemetry, and again with the API at t+4. But that info might be affected by some event or configuration change that can happen between the data samples we were taken. In this case between t+2 and t+3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-qxCp1LhltppUBXFnLkiw.png" /><figcaption>evolution in time of a Vault interaction</figcaption></figure><p>One of the features of Vault 1.3 is the ability to get a bundle of information that is consistent and complete with <strong>vault debug</strong>:</p><pre>❯ vault debug<br>==&gt; Starting debug capture...<br>         Vault Address: <a href="http://127.0.0.1:8200/">http://127.0.0.1:8200</a><br>        Client Version: 1.3.0<br>              Duration: 2m0s<br>              Interval: 30s<br>      Metrics Interval: 10s<br>               Targets: config, host, metrics, pprof, replication-status, server-status<br>                Output: vault-debug-2019-12-14T19-24-22Z.tar.gz</pre><pre>==&gt; Capturing static information...<br>2019-12-14T19:24:22.338Z [INFO]  capturing configuration state</pre><pre>==&gt; Capturing dynamic information...<br>2019-12-14T19:24:22.346Z [INFO]  capturing metrics: count=0<br>2019-12-14T19:24:22.346Z [INFO]  capturing pprof data: count=0<br>2019-12-14T19:24:22.346Z [INFO]  capturing host information: count=0<br>2019-12-14T19:24:22.346Z [INFO]  capturing server status: count=0<br><br>...</pre><pre>2019-12-14T19:26:22.345Z [INFO]  capturing metrics: count=12<br>2019-12-14T19:26:22.345Z [INFO]  capturing host information: count=4<br>2019-12-14T19:26:22.345Z [INFO]  capturing server status: count=4<br>2019-12-14T19:26:22.345Z [INFO]  capturing replication status: count=4<br>2019-12-14T19:26:22.590Z [INFO]  capturing pprof data: count=4<br>Finished capturing information, bundling files...<br>Success! Bundle written to: vault-debug-2019-12-14T19-24-22Z.tar.gz</pre><p>Vault debug allows you to standardise on a debugging bundle for an easier consumption of consistent and complete data that will lead to faster triaging (and resolution :) or faster escalation (and resolution :).</p><p>As a practical example, we will gather specific data about the replication process on our vault clusters. It is important to know that some of the targets for Vault debug require specific permissions to be queried. We will use a root token to avoid any permission issues and get the data for the <strong><em>replication-status</em></strong> target during 30 seconds with intervals of 5 seconds:</p><pre>vault debug -target replication-status -duration=30s -interval=5s -metrics-interval=5s -compress=false</pre><p>Getting the following output:</p><pre>==&gt; Starting debug capture...<br>         Vault Address: <a href="http://127.0.0.1:8200/">http://127.0.0.1:8200</a><br>        Client Version: 1.3.0<br>              Duration: 30s<br>              Interval: 5s<br>      Metrics Interval: 5s<br>               Targets: replication-status<br>                Output: vault-debug-2019-12-14T19-43-39Z</pre><pre>==&gt; Capturing static information...</pre><pre>==&gt; Capturing dynamic information...<br>2019-12-14T19:43:39.227Z [INFO]  capturing replication status: count=0<br>2019-12-14T19:43:44.230Z [INFO]  capturing replication status: count=1<br>2019-12-14T19:43:49.230Z [INFO]  capturing replication status: count=2<br>2019-12-14T19:43:54.230Z [INFO]  capturing replication status: count=3<br>2019-12-14T19:43:59.230Z [INFO]  capturing replication status: count=4<br>2019-12-14T19:44:04.230Z [INFO]  capturing replication status: count=5<br>2019-12-14T19:44:09.227Z [INFO]  capturing replication status: count=6<br>Finished capturing information, bundling files...<br>Success! Bundle written to: vault-debug-2019-12-14T19-43-39Z</pre><p>After that we will be able to inspect the replication status with a simple cat on the pertinent file of the debug output:</p><pre>❯ cat ./vault-debug-2019-12-14T19-43-39Z/replication_status.json<br>[<br>  {<br>    &quot;mode&quot;: &quot;disabled&quot;,<br>    &quot;timestamp&quot;: &quot;2019-12-14T19:43:39.227865Z&quot;<br>  },<br>  {<br>    &quot;mode&quot;: &quot;disabled&quot;,<br>    &quot;timestamp&quot;: &quot;2019-12-14T19:43:44.232115Z&quot;<br>  },<br>  {<br>    &quot;mode&quot;: &quot;disabled&quot;,<br>    &quot;timestamp&quot;: &quot;2019-12-14T19:43:49.23361Z&quot;<br>  },<br>  {<br>    &quot;mode&quot;: &quot;disabled&quot;,<br>    &quot;timestamp&quot;: &quot;2019-12-14T19:43:54.23268Z&quot;<br>  },<br>  {<br>    &quot;mode&quot;: &quot;disabled&quot;,<br>    &quot;timestamp&quot;: &quot;2019-12-14T19:43:59.232733Z&quot;<br>  },<br>  {<br>    &quot;mode&quot;: &quot;disabled&quot;,<br>    &quot;timestamp&quot;: &quot;2019-12-14T19:44:04.232732Z&quot;<br>  },<br>  {<br>    &quot;mode&quot;: &quot;disabled&quot;,<br>    &quot;timestamp&quot;: &quot;2019-12-14T19:44:09.229048Z&quot;<br>  }<br>]%</pre><p>As simple as that!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fd2f2f70f38" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hashicorp-engineering/vault-debug-7fd2f2f70f38">Vault debug</a> was originally published in <a href="https://medium.com/hashicorp-engineering">HashiCorp Solutions Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[More entropy!]]></title>
            <link>https://medium.com/hashicorp-engineering/more-entropy-60a5acb776b2?source=rss-d80b1add7b68------2</link>
            <guid isPermaLink="false">https://medium.com/p/60a5acb776b2</guid>
            <category><![CDATA[vault]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[entropy]]></category>
            <dc:creator><![CDATA[Pedro Coca]]></dc:creator>
            <pubDate>Mon, 02 Dec 2019 22:39:54 GMT</pubDate>
            <atom:updated>2019-12-04T22:33:44.058Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Entropy </strong>is often described as a “<em>measurement of disorder” </em>in some contexts. Some people define entropy simply as a “counter” of the number of possible configurations on a given system, but before you close the tab on your browser, let’s not delve into complex matters such as the Boltzmann’s formula or anything like that… We would rather focus on what is <strong>information entropy</strong> and why is relevant in security, showing a practical example about how to augment the entropy when we generate cryptographic material with tools like <strong>Hashicorp Vault</strong> and a <strong>Hardware Security Module</strong> (HSM).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*T5sDe9uMJ0DFysNauchhKg.png" /><figcaption>Boltzmann’s grave with a bust of the physicist and his entropy formula (Vienna)</figcaption></figure><p>In computing, thanks to the contributions of Claude Shannon, the <a href="http://www.math.harvard.edu/~ctm/home/text/others/shannon/entropy/entropy.pdf"><strong>information entropy</strong></a> is defined as a <strong>measurement of the uncertainty associated with a random variable</strong>.</p><p>Adequate levels of entropy are critical in security as <strong>random number generation</strong> (RNG) plays a very relevant role for cryptographic applications. If the random numbers are predictable, the cryptographic material can be potentially compromised.</p><p>For some tasks is often enough with the levels of entropy that many operating systems such as Linux offers since its early versions through /dev/random and other similar devices. The source of entropy is often the environmental noise collected from device drivers.</p><p>For other tasks, those levels of entropy are not enough and need to be augmented to avoid a potential compromise. Many times is even a requirement of some regulatory frameworks and examples of these attacks are not that rare indeed, as the vulnerabilities and incidents of <a href="http://www.cs.ru.nl/~flaviog/publications/Attack.MIFARE.ps">the pervasive MIFARE cards from NXP</a>, the <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-0166">OpenSSL package of Debian</a> or <a href="https://www.schneier.com/blog/archives/2011/01/sony_ps3_securi.html">Sony with their Playstation 3</a> revealed the consequences of operating with inadequate levels of entropy, as <a href="https://www.owasp.org/index.php/Insecure_Randomness">insecure randomness is a vulnerability</a>.</p><p>In order to augment the entropy, we will use the <a href="https://github.com/hashicorp/vault/blob/master/CHANGELOG.md">recently released version of Hashicorp Vault 1.3</a> and a cloud HSM that supports the PKCS11 interface in a public cloud provider.</p><p>For this example we will use a Cloud HSM cluster of a single instance on AWS that will be spun up in the eu-west-2 region (London):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UysNB2Pj0MRgBvGYAQe2og.png" /><figcaption>Cloud HSM cluster configuration Web UI on Amazon Web Services</figcaption></figure><p>After creating the cluster and the HSM instance within the cluster, we will <a href="https://docs.aws.amazon.com/cloudhsm/latest/userguide/initialize-cluster.html">initialise</a> it. Make sure the Vault instance can talk with the HSM in order to start managing the HSM. Remember to check the Security Groups or you will spend some time wondering what is going on. It happened to a friend of mine ;)</p><p>Once the HSM cluster is up and running we can check it out:</p><pre>ubuntu@ip-10–0–101–51:~$ <strong>pkcs11-tool — module /opt/cloudhsm/lib/libcloudhsm_pkcs11.so -L</strong><br>Available slots:<br>Slot 0 (0x1): Cavium Slot<br>  token label : cavium<br>  token manufacturer : Cavium Networks<br>  token model : NITROX-III CNN35<br>  token flags : login required, token initialized<br>  hardware version : 3.1<br>  firmware version : 2.4<br>  serial num : 3.1G1741-ICM0002<br>  pin min/max : 117440512/536870912</pre><p>And get connected to it:</p><pre>ubuntu@ip-10–0–101–51:~$ <strong>/opt/cloudhsm/bin/cloudhsm_mgmt_util /opt/cloudhsm/etc/cloudhsm_mgmt_util.cfg</strong><br>Ignoring E2E enable flag in the configuration file<br>Connecting to the server(s), it may take time depending on the server(s) load, please wait…<br>Connecting to server ‘10.0.101.14’: hostname ‘10.0.101.14’, port 2225…<br>Connected to server ‘10.0.101.14’: hostname ‘10.0.101.14’, port 2225.<br>E2E enabled on server 0(10.0.101.14)<br>aws-cloudhsm&gt;</pre><p>We should create a new user for our test and then simply configure the <strong>seal</strong> and <strong>entropy</strong> stanzas of our vault instance:</p><pre>seal &quot;pkcs11&quot; {<br>  lib = &quot;/opt/cloudhsm/lib/libcloudhsm_pkcs11.so&quot;<br>  slot = &quot;1&quot;<br>  pin = &quot;vault:mysecretpassword&quot;<br>  key_label = &quot;entropy_demo&quot;<br>  hmac_key_label = &quot;entropy_hmac_demo&quot;<br>  generate_key = &quot;true&quot;<br>}<br><br>entropy &quot;seal&quot; {<br>    mode = &quot;augmentation&quot;<br>}</pre><p>Now everything is ready to leverage an external source of entropy such as our HSM cluster, so Vault will allow us to do <a href="https://learn.hashicorp.com/vault/encryption-as-a-service/eaas-transit">encryption as a service</a> with augmented entropy, just add the -external-entropy-access flag when you are enabling EaaS:</p><pre>ubuntu@ip-10–0–101–51:~$ vault secrets enable -path=augmented-entropy-transit <strong>-external-entropy-access</strong> transit<br>Success! Enabled the transit secrets engine at: augmented-entropy-transit/</pre><p>That’s it! You can now leverage the <a href="https://www.vaultproject.io/docs/configuration/entropy-augmentation/index.html">entropy augmentation</a> using <a href="https://learn.hashicorp.com/vault/encryption-as-a-service/eaas-transit">Encryption as a Service</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60a5acb776b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hashicorp-engineering/more-entropy-60a5acb776b2">More entropy!</a> was originally published in <a href="https://medium.com/hashicorp-engineering">HashiCorp Solutions Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>