{"id":1924,"date":"2022-05-06T16:47:26","date_gmt":"2022-05-06T15:47:26","guid":{"rendered":"https:\/\/www.codingfriends.com\/?p=1924"},"modified":"2022-05-07T12:36:58","modified_gmt":"2022-05-07T11:36:58","slug":"azure-wildcard-certbot-certificate-with-azure-dns-txt-updates","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2022\/05\/06\/azure-wildcard-certbot-certificate-with-azure-dns-txt-updates\/","title":{"rendered":"Azure wildcard certbot certificate with Azure DNS TXT updates"},"content":{"rendered":"\n<p>The requirement was to set up a wildcard certificate on azure, so I used a nice tool called <a rel=\"noreferrer noopener\" href=\"https:\/\/certbot.eff.org\/\" target=\"_blank\">certbot<\/a> that can generate single subdomain certificates or a wild card certificate.<\/p>\n\n\n\n<p>For the creation of a wild car certificate, we need to be able to alter the DNS TXT records and via azure we can achieve this via the<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Install certbot onto a server (I am using a linux server)<\/li><li>User role to only allow DNS TXT record updates<\/li><li>Allow the managed identity (in essence the server that is altering the DNS TXT records)<\/li><\/ol>\n\n\n\n<p>So, to start things off lets install the certbot and I am using the <a rel=\"noreferrer noopener\" href=\"https:\/\/snapcraft.io\/\" data-type=\"URL\" data-id=\"https:\/\/snapcraft.io\/\" target=\"_blank\">snap<\/a> package manager and also the <a href=\"https:\/\/www.nginx.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">nginx<\/a> as the web server.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>snap install core<br>snap refresh core<br>snap install &#8211;classic certbot<br>ln -s \/snap\/bin\/certbot \/usr\/bin\/certbot<\/p><\/blockquote>\n\n\n\n<p>The certbot plugin to converse with the azure dns is <a rel=\"noreferrer noopener\" href=\"https:\/\/certbot-dns-azure.readthedocs.io\/en\/latest\/\" target=\"_blank\">certbot-dns-azure<\/a>, as this isn&#8217;t part of the offical packages we have to use the &#8220;&#8211;edge&#8221; option below and also allow the certbot trust this plugin.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>snap set certbot trust-plugin-with-root=ok<br>snap install &#8211;edge certbot-dns-azure<br>snap connect certbot:plugin certbot-dns-azure<\/p><\/blockquote>\n\n\n\n<p>For the certbot dns azure plugin to function automatically we need to create a file within the .azure folder called dns.ini ( e.g. \/root\/.azure\/dns.ini or ~\/.azure\/dns.ini)<\/p>\n\n\n\n<p>certbot renew &#8211;dry-run<br><\/p>\n\n\n\n<p>To fill in the options below are as below (small hint! the subscription ID + resource group name could be obtained from the URL when you goto the dns zone within azure you want to use!)<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>linux server ID = I got this after the creation of the role access <\/li><li>dns cloud name = is the azure named resource of your dns zone<\/li><li>subscriptionID = your subscription ID<\/li><li>resource groupname = the groupname of resource<\/li><\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-style-default is-layout-flow wp-block-quote-is-layout-flow\"><p>dns_azure_msi_client_id = &lt;linux server ID&gt;<\/p><p>dns_azure_zone1 = &lt;dns cloud name&gt;:\/subscriptions\/&lt;subscriptionID&gt;\/resourceGroups\/&lt;resource groupname&gt;\/providers\/Microsoft.Network\/dnsZones\/&lt;dns cloudname&gt;<\/p><\/blockquote>\n\n\n\n<p>The last part of this solution is to allow the managed identy (e.g. the linux server) to update the DNS TXT records for the azure dns zone.<\/p>\n\n\n\n<p>Iif you goto your subscription -&gt; access control (IAM) &#8212; On the left menu -&gt; Add(top bar) custom role<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"445\" height=\"159\" src=\"https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image.png\" alt=\"\" class=\"wp-image-1928\" srcset=\"https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image.png 445w, https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-300x107.png 300w\" sizes=\"auto, (max-width: 445px) 100vw, 445px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In the new custom role, please define the basics e.g. name, but within the permissions use the &#8220;add permission&#8221; and include the one below (Microsoft.Network\/dnszones\/TXT<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"388\" height=\"187\" src=\"https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-1.png\" alt=\"\" class=\"wp-image-1929\" srcset=\"https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-1.png 388w, https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-1-300x145.png 300w\" sizes=\"auto, (max-width: 388px) 100vw, 388px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The json would be something akin to<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{ \"id\": \"\/subscriptions\/&lt;subscriptionID&gt;\/providers\/Microsoft.Authorization\/roleDefinitions\/&lt;roleID&gt;\", \n\"properties\": { \"roleName\": \"DNS TXT Contributor\", \"description\": \"User role only allows DNS TXT updates.\", \"assignableScopes\": [ \"\/subscriptions\/&lt;subscriptionID&gt;\" ], \"permissions\": [ { \"actions\": [ \"Microsoft.Network\/dnszones\/TXT\/read\", \"Microsoft.Network\/dnszones\/TXT\/write\" ], \"notActions\": [], \"dataActions\": [], \"notDataActions\": [] } ] }}<\/pre>\n\n\n\n<p>and then within the DNS Zone (your DNS configuration) go to Access Control (IAM) and then click &#8220;add role assignment&#8221; where the role will be the role that you created above<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"487\" height=\"152\" src=\"https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-2.png\" alt=\"\" class=\"wp-image-1930\" srcset=\"https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-2.png 487w, https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-2-300x94.png 300w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/figure>\n\n\n\n<p>and then we just need to associate it (members) with your managed identities (e.g. your webserver!)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"521\" height=\"173\" src=\"https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-3.png\" alt=\"\" class=\"wp-image-1931\" srcset=\"https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-3.png 521w, https:\/\/www.codingfriends.com\/wp-content\/uploads\/2022\/05\/image-3-300x100.png 300w\" sizes=\"auto, (max-width: 521px) 100vw, 521px\" \/><\/figure>\n\n\n\n<p>The next post (once I have created it, there will be a link here!) will be about how to create the certificate and then convert it into a PFX file for uploading into the azure key vault file storage.<\/p>\n\n\n\n<p>AND THAT IS IT \ud83d\ude42  &#8212; if you need any more advice on certain areas please say!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The requirement was to set up a wildcard certificate on azure, so I used a nice tool called certbot that can generate single subdomain certificates or a wild card certificate. For the creation of a wild car certificate, we need to be able to alter the DNS TXT records and via azure we can achieve &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2022\/05\/06\/azure-wildcard-certbot-certificate-with-azure-dns-txt-updates\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Azure wildcard certbot certificate with Azure DNS TXT updates<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[418,422,421],"tags":[],"class_list":["post-1924","post","type-post","status-publish","format-standard","hentry","category-azure","category-certbot","category-hosting"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1924","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1924"}],"version-history":[{"count":11,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1924\/revisions"}],"predecessor-version":[{"id":1957,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1924\/revisions\/1957"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}