<?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 Abbas Ali Zaidi on Medium]]></title>
        <description><![CDATA[Stories by Abbas Ali Zaidi on Medium]]></description>
        <link>https://medium.com/@abbasalizaidi1990?source=rss-4032066a7367------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*k0ihM9IwN9ivupvg.</url>
            <title>Stories by Abbas Ali Zaidi on Medium</title>
            <link>https://medium.com/@abbasalizaidi1990?source=rss-4032066a7367------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 00:30:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abbasalizaidi1990/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[Dynamic Database Credentials — PoC to Production]]></title>
            <link>https://medium.com/@abbasalizaidi1990/dynamic-database-credentials-poc-to-production-242b60b906c1?source=rss-4032066a7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/242b60b906c1</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[vault]]></category>
            <category><![CDATA[dynamic-credentials]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[database-security]]></category>
            <dc:creator><![CDATA[Abbas Ali Zaidi]]></dc:creator>
            <pubDate>Wed, 19 Apr 2023 18:26:26 GMT</pubDate>
            <atom:updated>2023-04-19T18:26:26.626Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dynamic Database Credentials — PoC to Production</h3><p>Credential management can be fussy, especially when it comes to databases. I have worked for organisations where dedicated resources were available just for basic database administration, and a lot of their time went into just facilitating database access. AWS has definitely helped in offloading a lot of work from the administrators, but access management is still an arduous activity which requires continuous monitoring and maintenance. In case you are wondering about IAM database authentication, which is a decent solution for those problems but not better than HashiCorp’s Vault dynamic database secrets.</p><p>Here is why :</p><ul><li><strong>Transparency</strong>: I would rather take on the problem myself than depend on a bunch of API error codes.</li><li><strong>Granular control</strong>: It&#39;s good to have the option to provide granular access to users though it largely depends on how you have implemented your databases.</li><li><strong>Self-Serving capability</strong>: Developers can request credentials by themselves. There is no need to keep de-provisioning users from the database.</li><li><strong>Robust key rotation mechanism</strong>: One switch for forcefully rotating the credentials ( not the optimum technique, but valueable to have that control )</li><li><strong>Support</strong>: All significant data stores are supported. <a href="https://developer.hashicorp.com/vault/docs/secrets/databases">( More here )</a></li><li><strong>Compliance and Audit: </strong>You will never have to worry about compliance and audit requirements for database access controls.</li><li><strong>First-class integration Hashicorp’s tools ecosystem</strong>: Terraform, consul-template etc.</li></ul><p>When I started at SecurityScorecard, I was tasked with meeting compliance requirements for our databases in RDS. As I began scratching the surface, I found significant issues related to database credentials management. The most pressing issue was reusable credentials. Everyone had access to production databases, and there wasn’t any audit history for it though we were using HashiCorp’s vault to store those credentials.</p><p>The organisation was growing rapidly, so I sensed that soon enough, the SREs will be tasked with rotating all those credentials. I couldn’t help imagining myself rotating credentials manually and updating them to the vault and everywhere else in the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*Fi6UZ52wYo48pZ1s.gif" /></figure><p>Though we manage everything by code (Terraform), rotating and updating them could have been an inefficient use of anyone’s skill and time. After a couple of brainstorming and demo sessions with the team, I decided that the quick and easy way to solve this problem is to use Vault’s database secret engine.</p><p>Factors we considered while deciding this solution.</p><ul><li><strong><em>Cost in dollars </em>💵</strong></li><li><strong><em>Cost in terms of operational effort</em></strong></li><li><strong><em>Adaptability</em></strong></li></ul><blockquote><strong>Opinion</strong></blockquote><blockquote>The last one is super important for me. I often see people rushing to implement solutions without fully considering the cost and effort required to put them into practice. For me personally, as someone who values adaptable and productive workflows, it can be frustrating when a solution hinders my workflow or hinders the ability to continuously improve it.</blockquote><h3><strong>Implementation</strong></h3><blockquote>It’s important to have a sound idea, but the really important thing is the implementation. ~ Wilbur Ross</blockquote><p>Ideas are more often great than their execution plan. Especially when you are rolling out a change that affects your whole organisation. You have to tailor a solution that is least destructive and fits most use cases, which is not easy.</p><p>After a fruitful architecture meeting, there were questions like</p><ul><li>How often will the credentials rotate?</li><li>Are applications also going to use dynamic credentials?</li><li>Countless concerns around setting default TTLs.</li><li>OMG! I don’t want my service to crash when the credentials expire.</li><li>Database Migration scripts 😱</li><li>Some were convinced to put the retrial logic into the app. Love them 🙂</li></ul><blockquote><strong>Pro Tip: Progress not perfection</strong></blockquote><blockquote>Sometimes questions like those can throw you off and make you question why you picked this problem because it asks for things which you haven’t figured out and it start looking more intimidating. I would say iterate over the solution enough and you will find the sweet spot where everything works</blockquote><p>We know very well that everything works in a dummy app, but all hell breaks loose during demos and production rollouts. Fortunately, that did not happen with us in production, as we sweat a lot in non-production environments, but it worked like a charm in production. There were a few hiccups due to misconfigurations, but no major outage has occurred. It is safe to say that, as it has been <strong>more than a year</strong> since we switched to dynamic credentials<strong>. 🤞</strong></p><p>The concept of Dynamic database credentials is not something unique that we invented here at SecurityScorecard. Still, only a handful of organisations I know have successfully implemented it. I would say the architecture here was very forgiving; otherwise, a complex solution like this requires a lot of changes to the applications.</p><h3>Learnings</h3><p>There is an abundance of information available online about implementing dynamic database credentials with Vault in the form of articles, blogs, and tutorials. While I will not go into implementation specifics, I would like to share the insights and lessons we gained from transitioning from a proof-of-concept to a production environment.</p><p><strong>Database migrations</strong></p><p>One interesting problem I encountered is because of the way Postgres manages ownership of objects in the database. Vault created a database user, which ran a migration during the deployment and ended up creating objects in the database with a dynamic username ( user created by vault ). The idea of having database objects owned by random users which don’t exist in DB and the myriad of issues it can create in the DB was horrifying.</p><p>Finally, the combination of <strong>SET, RESET and REASSIGNED OWNED BY </strong>helped. Check out the block of <strong>revocation_statements.</strong></p><pre>resource &quot;vault_database_secret_backend_role&quot; &quot;readwrite_role&quot; {<br>  backend = var.vault_mount_path[var.environment]<br>  name    = &quot;service-${var.dbname}&quot;<br>  db_name = vault_database_secret_backend_connection.postgres.name<br><br>  creation_statements = [<br>    &quot;CREATE ROLE \&quot;{{name}}\&quot; WITH LOGIN PASSWORD &#39;{{password}}&#39; VALID UNTIL &#39;{{expiration}}&#39; INHERIT;&quot;,<br>    &quot;GRANT ${var.dbuser} TO \&quot;{{name}}\&quot;;&quot;,<br>    &quot;ALTER ROLE \&quot;{{name}}\&quot; SET pgaudit.log=&#39;DDL,ROLE&#39;;&quot;<br>  ]<br><br>  revocation_statements = [<br>    &quot;SET ROLE \&quot;{{name}}\&quot;;&quot;,<br>    &quot;REASSIGN OWNED BY \&quot;{{name}}\&quot; to ${var.dbuser};&quot;,<br>    &quot;RESET ROLE;&quot;,<br>    &quot;DROP ROLE \&quot;{{name}}\&quot;;&quot;<br>  ]<br><br>  default_ttl = var.default_ttl_readwrite<br>  max_ttl     = var.max_ttl_readwrite<br>}</pre><blockquote><em>Note: Only the owner of the objects can reassign the DB objects to another user in database, even a user with superadmin role can’t do it.</em></blockquote><p><strong>TTLs</strong></p><p>Time to live for credentials remained our focus during the entire implementation phase. There are two types of TTLs, <strong>default_ttl</strong> and <strong>max_ttl.</strong> This was our 20 out of 80/20 principle of cause and effect.</p><blockquote><strong>Pro tip</strong></blockquote><blockquote>Set the <strong>default_ttl</strong> and <strong>max_ttl</strong> apart enough to avoid restarting your app/container too frequently.</blockquote><p>We used pipeline metrics from Jenkins to determine how often an app is deployed on average. If it is deployed fortnightly, that means your credentials will be rotated every 15 days. You can adjust the <strong>max_ttl</strong> accordingly, so in the worst case, the application will crash and restart itself after the 15th day.</p><p><strong>App crashes and Retry Logic.</strong></p><p>The application will crash when the <strong>max_ttl</strong> is about to reach. For graceful restarts, make sure the app is tuned to respond to graceful shutdown/restart. We use consul-template, which helps us achieve the same. I would highly recommend learning about the retry logic in the consul-template repository here — <a href="https://github.com/hashicorp/consul-template/blob/38ffca4cc7f5a9afe14a0b08e1644a491acfa416/config/retry.go">retry.go</a></p><p>Consul-template has a built-in robust retry logic in case the vault becomes unavailable for some time without killing the vault cluster. (Imagine thousands of containers retrying at the same time)</p><p><strong>Vault Performance monitoring</strong></p><p>We use Datadog to measure the efficacy and performance of our systems. I would recommend keeping a check on the following metrics to monitor the health of your solution. If any of these metrics show spiky behaviour, troubleshoot it. A lot of damage can be avoided if things are caught early on.</p><pre>vault.token.create.count<br>vault.expire.num_leases<br>vault.expire.revoke<br>vault.expire.renew<br>vault.core.handle_request</pre><p>I have been using this aggregate metric from vault logs grouped by roles to check if lease renewals are going on smoothly.</p><pre>derivative(cumsum(count[@request.path:&quot;sys/leases/renew&quot;]))</pre><p>More on Vault performance monitoring <a href="https://www.datadoghq.com/blog/monitor-vault-metrics-and-logs/">here</a>.</p><h4>Resources to learn more about Vault Ephemeral Credentials</h4><ul><li><a href="https://developer.hashicorp.com/vault/tutorials/db-credentials/database-secrets">https://developer.hashicorp.com/vault/tutorials/db-credentials/database-secrets</a></li><li><a href="https://github.com/BenchLabs/talk-vault-ephemeral-credentials">https://github.com/BenchLabs/talk-vault-ephemeral-credentials</a></li></ul><p>Thanks for reading!</p><p>Follow us for more — <a href="https://techblog.securityscorecard.com/">https://techblog.securityscorecard.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=242b60b906c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>