<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alpine Linux &#8211; 開発記録</title>
	<atom:link href="https://www.kthksgy.com/tag/alpine-linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kthksgy.com</link>
	<description>開発メモです。現在レイアウトが一部崩れている箇所があります。</description>
	<lastBuildDate>Wed, 22 Apr 2020 03:43:25 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.2</generator>
	<item>
		<title>Alpine LinuxとCertbotでLet&#8217;s Encryptする</title>
		<link>https://www.kthksgy.com/linux/alpine-certbot/</link>
					<comments>https://www.kthksgy.com/linux/alpine-certbot/#respond</comments>
		
		<dc:creator><![CDATA[kthksgy]]></dc:creator>
		<pubDate>Tue, 21 Apr 2020 23:01:42 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Alpine Linux]]></category>
		<guid isPermaLink="false">https://www.kthksgy.com/?p=2</guid>

					<description><![CDATA[最近のブラウザではSSLでないサイトは問答無用で悪という風潮なので、Webサイトを公開する時は必ずSSL化する必要が有ります。 Certbotの動かし方は諸説ありますが、今回はDockerでCertbotを動かしたいので&#8230;]]></description>
										<content:encoded><![CDATA[<p>最近のブラウザではSSLでないサイトは問答無用で悪という風潮なので、Webサイトを公開する時は必ずSSL化する必要が有ります。</p>
<p>Certbotの動かし方は諸説ありますが、今回はDockerでCertbotを動かしたいので、まずはそもそもAlpine LinuxでCertbotを使えるのかを確認しました。</p>
<p>また、サブドメインでWebサイトを開設する事があるので、ついでにワイルドカード認証も行います。</p>
<h2>DockerでAlpine Linuxを実行する</h2>
<p>以下のコマンドでイメージのダウンロードからコンテナの起動まで自動でやってくれます。</p>
<pre><code class="language-shell line-numbers">$ docker run -it --rm alpine
</code></pre>
<p>以降はコンテナ内のシェルで操作を行います。</p>
<h2>環境</h2>
<p>イメージのタグ指定は行わなかったので<code>latest</code>が起動します。この時のバージョンは以下の通りでした。</p>
<pre><code class="language-shell line-numbers">$ cat /etc/alpine-release
3.11.5
</code></pre>
<h2>Certbotのインストール</h2>
<p>Alpine Linuxでは<code>apk</code>というパッケージマネージャが標準でインストールされていますので、これを使ってCertbotをインストールします。</p>
<pre><code class="language-shell line-numbers">$ apk update &amp;&amp; apk add certbot
</code></pre>
<h2>Certbot</h2>
<p>以下のコマンドを実行すると対話的に認証が進みます。今回はApacheやnginx等のWebサーバーを用意していないので、DNS設定のみで認証が行えるDNS認証を行います。</p>
<p>コマンドを実行したらいくつかの質問に答えます。</p>
<pre><code class="language-shell line-numbers">$ certbot certonly --server https://acme-v02.api.letsencrypt.org/directory --agree-tos --manual --preferred-challenges dns -d "*.kthksgy.com,kthksgy.com"
</code></pre>
<p>今回はWebサイトを開設するサーバー上で実行しているので、<code>Y</code>と入力してEnterします。</p>
<pre><code class="language-shell line-numbers">Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for kthksgy.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
</code></pre>
<p>次に、DNS認証を行っているので、ドメインのDNSレコードに<code>TXT</code>レコードとして以下の文字列<code>J6coMQx4a5mFwt2JFN7UUKiEAd8POcs3yuv9sKSRiqE</code>を追加します。</p>
<p><strong>追加したら、DNSレコードが反映されるまでEnterキーを押さないでください。押した場合は認証用文字列が変更されて、再度DNSレコードの設定が必要となります。</strong></p>
<p><code>nslookup</code>で反映されたか一応確認出来ますが、一応5分くらい時間を置くと良いです。</p>
<pre><code class="language-shell line-numbers"># 反映されていない場合の表示
$ nslookup -q=txt _acme-challenge.kthksgy.com
Server:         127.0.0.53
Address:        127.0.0.53#53

** server can't find _acme-challenge.kthksgy.com: NXDOMAIN
</code></pre>
<pre><code class="language-shell line-numbers"># 反映された場合の表示
$ nslookup -q=txt _acme-challenge.kthksgy.com
Server:         127.0.0.53
Address:        127.0.0.53#53

Non-authoritative answer:
_acme-challenge.kthksgy.com     text = "J6coMQx4a5mFwt2JFN7UUKiEAd8POcs3yuv9sKSRiqE"

Authoritative answers can be found from:
</code></pre>
<p>5分程待ったら、Enterキーを押してみます。</p>
<pre><code class="language-shell line-numbers">- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.kthksgy.com with the following value:

J6coMQx4a5mFwt2JFN7UUKiEAd8POcs3yuv9sKSRiqE

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
</code></pre>
<p>認証が完了すると、以下のような表示になります。</p>
<pre><code class="language-shell line-numbers">Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/kthksgy.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/kthksgy.com/privkey.pem
   Your cert will expire on 2020-07-18. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le
</code></pre>
<p><code>/etc/letsencrypt/</code>以下に証明書関連のファイルが作成されます。ファイルの実体は<code>/etc/letsencrypt/archive/</code>にありますが、利用する際はそこへのシンボリックリンクが<code>/etc/letsencrypt/live/</code>にあるので、それを参照してください。</p>
<pre><code class="language-shell line-numbers">$ pwd
/etc/letsencrypt/live/kthksgy.com
$ ls -la
total 12
drwxr-xr-x    2 root     root          4096 Apr 19 14:09 .
drwx------    3 root     root          4096 Apr 19 14:09 ..
-rw-r--r--    1 root     root           692 Apr 19 14:09 README
lrwxrwxrwx    1 root     root            35 Apr 19 14:09 cert.pem -&gt; ../../archive/kthksgy.com/cert1.pem
lrwxrwxrwx    1 root     root            36 Apr 19 14:09 chain.pem -&gt; ../../archive/kthksgy.com/chain1.pem
lrwxrwxrwx    1 root     root            40 Apr 19 14:09 fullchain.pem -&gt; ../../archive/kthksgy.com/fullchain1.pem
lrwxrwxrwx    1 root     root            38 Apr 19 14:09 privkey.pem -&gt; ../../archive/kthksgy.com/privkey1.pem
</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.kthksgy.com/linux/alpine-certbot/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
