Linux/Apache.md
... ...
@@ -244,7 +244,7 @@ SSLCertificateChainFile /etc/letsencrypt/live/<ドメイン1>/chain.pem
244 244
- [Certbot](https://certbot.eff.org/)
245 245
- [Webサーバー間通信内容暗号化(Apache+mod_SSL+Certbot) - CentOSで自宅サーバー構築](http://centossrv.com/apache-certbot.shtml)
246 246
247
-## Certbot 使用(ワイルドカード)
247
+## Certbot 使用(ワイルドカード, 手動)
248 248
- Certbot インストール (EPEL リポジトリ)
249 249
```
250 250
# yum -y install yum-utils
... ...
@@ -366,6 +366,149 @@ NotAfter=`openssl x509 -noout -dates -in /etc/letsencrypt/live/${CommonName}/ful
366 366
echo ${NotAfter}
367 367
```
368 368
369
+## Certbot 使用(ワイルドカード, 自動)
370
+- Certbot, DNS Plugin インストール (EPEL リポジトリ)
371
+```
372
+# yum -y install yum-utils
373
+# yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
374
+# yum install certbot-apache python2-certbot-dns-rfc2136
375
+```
376
+
377
+- BIND 用認証キーの作成
378
+Kcertbot-key.+165+43987.key, Kcertbot-key.+165+43987.private の2つのファイルが作成される。
379
+```
380
+# cd /etc/named/
381
+# dnssec-keygen -a HMAC-SHA512 -b 512 -n HOST certbot-key
382
+```
383
+
384
+- 認証ファイル /etc/named/certbot_rfc2136.ini , ファイルモード 600
385
+```
386
+# Target DNS server
387
+dns_rfc2136_server = 127.0.0.1
388
+# Target DNS port
389
+dns_rfc2136_port = 53
390
+# TSIG key name
391
+dns_rfc2136_name = certbot-key.
392
+# TSIG key secret
393
+dns_rfc2136_secret = <Kcertbot-key.+165+43987.key のハッシュ値>
394
+# TSIG key algorithm
395
+dns_rfc2136_algorithm = HMAC-SHA512
396
+```
397
+
398
+- /etc/named.conf に追加
399
+```
400
+key "certbot-key." {
401
+ algorithm hmac-sha512;
402
+ secret "<Kcertbot-key.+165+43987.key のハッシュ値>";
403
+};
404
+
405
+view "internal" {
406
+ match-clients { localhost; localnets; };
407
+ match-destinations { localhost; localnets; };
408
+ recursion yes;
409
+
410
+ zone "." IN {
411
+ type hint;
412
+ file "named.ca";
413
+ };
414
+
415
+ include "/etc/named.rfc1912.zones";
416
+ include "/etc/named.root.key";
417
+ include "/etc/named/<ドメイン>.lan.zone";
418
+};
419
+
420
+view "external" {
421
+ match-clients { any; };
422
+ match-destinations { any; };
423
+ recursion no;
424
+ include "/etc/named/<ドメイン>.wan.zone";
425
+ include "/etc/named/_acme-challenge.<ドメイン>.wan.zone";
426
+};
427
+```
428
+
429
+- /etc/named/<ドメイン>.lan.zone
430
+```
431
+zone "<ドメイン>" {
432
+ type master;
433
+ file "<ドメイン>.lan.db";
434
+ update-policy {
435
+ grant certbot-key. name _acme-challenge.<ドメイン>. txt;
436
+ };
437
+};
438
+```
439
+
440
+- /etc/named/<ドメイン>.wan.zone
441
+```
442
+zone "<ドメイン>" {
443
+ type master;
444
+ file "<ドメイン>.wan.db";
445
+ allow-query { any; };
446
+ update-policy {
447
+ grant certbot-key. name _acme-challenge.<ドメイン>. txt;
448
+ };
449
+};
450
+```
451
+
452
+- /etc/named/_acme-challenge.<ドメイン>.wan.zone
453
+```
454
+zone "_acme-challenge.<ドメイン>" {
455
+ type master;
456
+ file "_acme-challenge.<ドメイン>.wan.db";
457
+ allow-query { any; };
458
+ update-policy {
459
+ grant certbot-key. name _acme-challenge.<ドメイン>. txt;
460
+ };
461
+};
462
+```
463
+
464
+- /var/named/<ドメイン>.wan.db
465
+```
466
+$TTL 86400
467
+@ IN SOA ns1.<ドメイン>. root.<ドメイン>. (
468
+ 2018090500 ; Serial
469
+ 28800 ; Refresh
470
+ 14400 ; Retry
471
+ 2592000 ; Expire
472
+ 86400 ; Minimum
473
+ )
474
+ IN NS ns1.<ドメイン>.
475
+ IN MX 10 mail.<ドメイン>.
476
+@ IN A <グローバル IP アドレス>
477
+ns1 IN A <グローバル IP アドレス>
478
+www IN A <グローバル IP アドレス>
479
+mail IN A <グローバル IP アドレス>
480
+_acme-challenge IN NS ns1.<ドメイン>.
481
+* IN A <グローバル IP アドレス>
482
+<ドメイン>. IN TXT "v=spf1 a mx ~all"
483
+```
484
+
485
+- /var/named/_acme-challenge.<ドメイン>.wan.db
486
+```
487
+$TTL 86400
488
+@ IN SOA ns1.<ドメイン>. root.<ドメイン>. (
489
+ 2018090500 ; Serial
490
+ 1h ; Refresh
491
+ 15m ; Retry
492
+ 30d ; Expire
493
+ 1h ; Minimum
494
+ )
495
+ IN NS ns1.<ドメイン>.
496
+```
497
+
498
+- `<ドメイン>.jnl: create: permission denied`(/var/named/data/named.run) 対策
499
+```
500
+# chmod 770 /var/named/
501
+# setsebool -P named_write_master_zones 1
502
+```
503
+
504
+- 証明書取得
505
+```
506
+# certbot certonly \
507
+ --dns-rfc2136 \
508
+ --dns-rfc2136-credentials /etc/named/certbot_rfc2136.ini \
509
+ -d "*.<ドメイン>" -d <ドメイン>
510
+```
511
+
369 512
# mod_security
370 513
## インストール
371 514
- EPELリポジトリ