{"id":152,"date":"2023-06-20T03:55:17","date_gmt":"2023-06-20T03:55:17","guid":{"rendered":"https:\/\/lance.conryclan.com\/home\/?p=152"},"modified":"2023-06-20T04:11:44","modified_gmt":"2023-06-20T04:11:44","slug":"updating-lan-ssl-certificates","status":"publish","type":"post","link":"http:\/\/lance.conryclan.com\/home\/updating-lan-ssl-certificates\/","title":{"rendered":"Updating LAN SSL certificates"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Renewing LAN based SSL certificates and installing them to a Synology NAS and RouterOS device was a bit of a hullabaloo, so want it documented for when it breaks in three years, by which time I will have forgotten how it was configured.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">This approach was inspired by <a href=\"https:\/\/www.christosgeo.com\/2022\/02\/03\/renew-lets-encrypt-certificates-on-synology-using-acme-sh\/\">Renew Let&#8217;s Encrypt certificates on Synology using acme.sh &#8211; Christos Georgiadis<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The updating is via a monthly CRON script which runs on my Synology NAS device (SINO).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/acmesh-official\/acme.sh\">acme.sh<\/a> is used to do the updating, but rather than install it directly on SINO, it will be run from within the <a href=\"https:\/\/hub.docker.com\/r\/neilpang\/acme.sh\">neilpang\/acme.sh docker image<\/a>. For context, I used to have it installed directly on SINO, but with a host of permission issues, it needed to run as root, and was never entirely stable.  Using Docker will allow me to keep things simple, with the least setup should it need to be moved to a different host.  the image is based on Alpine Linux, so only about 5MB.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SINO Setup<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install the Docker app onto Synology.<\/li>\n\n\n\n<li>From Docker, download the neilpang\/acme.sh docker image.<\/li>\n\n\n\n<li>SSH into SINO and create the following folder: <code class=\"\" data-line=\"\">\/volume1\/docker\/acme<\/code><\/li>\n\n\n\n<li>From the Synology control panel, create a user with the following permissions:\n<ul class=\"wp-block-list\">\n<li>Disallow user to change password<\/li>\n\n\n\n<li>Groups: Administrators, Users<\/li>\n\n\n\n<li>Share Permissions: docker<\/li>\n\n\n\n<li>Applications: DSM<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Mikrotik Setup<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a new user group with the following permissions:\n<ul class=\"wp-block-list\">\n<li>ssh, ftp, read, write, password, sensitive<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Create a new user, and assign to the newly created group<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SSH Configuration<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to update the Mikrotik RouterOS, we will need to be able to connect via SSH.  For this to work, we need to setup several things.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a pair of SSH keys with <code class=\"\" data-line=\"\">ssh-keygen<\/code>.<\/li>\n\n\n\n<li>Copy the keys to <code class=\"\" data-line=\"\">\/volume1\/docker\/acme<\/code> on Redbeard.<\/li>\n\n\n\n<li>Copy the public key (probably id_rsa.pub) to the Mikrotik router, and assign it to the user we created under System -&gt; Users -&gt; SSH Keys<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Renewal Script<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a bash script to run the renewal steps and save it to <code class=\"\" data-line=\"\">\/volume1\/docker\/acme<\/code><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\">&lt;code class=&quot;language-bash&quot;&gt;# DNS verification variables\nexport DH_API_KEY=&#039;ZZZ-ZZZ&#039;\n# Synology deployment variables\nexport SYNO_Server=&#039;192.16.1.1&#039;\nexport SYNO_Username=&#039;sinoUser&#039;\nexport SYNO_Password=&#039;xxxx-xxxx&#039;\n# RouterOS deployment variables\nexport ROUTER_OS_USERNAME=mikUser\nexport ROUTER_OS_PASSWORD=&#039;yyyy-yyyy&#039;\nexport ROUTER_OS_HOST=192.168.2.2\nexport ROUTER_OS_PORT=22\n# setup acme\nacme.sh --upgrade\nacme.sh --set-default-ca  --server  letsencrypt\n# get certificates\nacme.sh --issue --dns dns_dreamhost -d &amp;lt;gaul&#039;s domain name&gt; --dnssleep 300\nacme.sh --issue --dns dns_dreamhost -d &amp;lt;sino&#039;s domain name&gt; --dnssleep 300\n#deploy to Synology NAS\nacme.sh --deploy -d &amp;lt;sino&#039;s domain name&gt; --deploy-hook synology_dsm\n# deploy to RouterOS\n# Setup SSH before we can deploy to RouterOS.\nmkdir \/root\/.ssh\ncp \/acmeConf\/id_rsa \/root\/.ssh\/\nchmod 600 \/root\/.ssh\/id_rsa\nssh-keyscan -H $SOUTER_OS_HOST &gt;&gt; \/root\/.ssh\/known_hosts\necho &quot;Host *\nHostKeyAlgorithms +ssh-rsa\nPubkeyAcceptedKeyTypes +ssh-rsa&quot; &gt;&gt; \/root\/.ssh\/config\nacme.sh --deploy -d &amp;lt;gaul&#039;s domain name&gt; --deploy-hook routeros&lt;\/code&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Wiring it all up<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The final step is to create a cron job on SINO to renew the certs every two months.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>SSH into SINO, and elivate the terminal with sudo -i.<\/li>\n\n\n\n<li>Add the following line to the crontab file (note, tabs, not spaces):<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\">&lt;code class=&quot;language-bash&quot;&gt;0\t0\t1\t*\/2\t*\troot\tbin\/su -c &#039;docker run --rm --mount type=bind,source=\/volume1\/docker\/acme,target=\/acmeConf neilpang\/acme.sh .\/acmeConf\/dockerRenew.sh &gt;&gt; \/volume1\/docker\/acme\/certInstall.log&#039; sslUpdator &lt;\/code&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Some blurb to remind me of what&#8217;s going on.<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The docker image is raw; no changes are made to it, so we can grab a new image with a new version of acme.sh, and no additional changes will be required to the image.<\/li>\n\n\n\n<li>All config is found on SINO at \/volume1\/docker\/acme.<\/li>\n\n\n\n<li>When docker starts the container, it binds the config folder to the container, making it available within the running docker container.<\/li>\n\n\n\n<li>The docker container is not long running.  The bash script starts the container up, causes it to execute our script, then shuts down the container.  The log file is saved to the config folder.<\/li>\n\n\n\n<li>Oh, and Lance, remember that the scripts are in your GitHub repository.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Renewing LAN based SSL certificates and installing them to a Synology NAS and RouterOS device was a bit of a hullabaloo, so want it documented for when it breaks in three years, by which time I will have forgotten how it was configured.<\/p>\n","protected":false},"author":1,"featured_media":154,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":3,"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":156,"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/posts\/152\/revisions\/156"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/media\/154"}],"wp:attachment":[{"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}