Ssl-Certificate

certmonger 為 nginx 保存鍊式證書

  • January 19, 2017

我們使用 certmonger 為後端系統頒發證書,這對 apache 很好,但是對於 nginx,我必須指定一個鍊式證書。

getcert request -f /etc/pki/tls/certs/$(hostname).crt -k /etc/pki/tls/private/$(hostname).key -r -F /etc/pki/tls/certs/intermediate.crt 

選項 1) 我可以讓 certmonger 以兩種格式保存證書嗎?(首選)

選項 2)我可以告訴 nginx 為我連結證書嗎?(類似於 apache 的做法)

我想避免編寫腳本,但如果我必須這樣做也沒關係。

例子:

/etc/pki/tls/certs/$(hostname).crt

-----BEGIN CERTIFICATE-----
MIIHHjCCBgagAwIBAgIQDhG71w1UtxDQxvVAtrUspDANBgkqhkiG9w0BAQsFADBw
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMS8wLQYDVQQDEyZEaWdpQ2VydCBTSEEyIEhpZ2ggQXNz
dXJhbmNlIFNlcnZlciBDQTAeFw0xNjA1MjEwMDAwMDBaFw0xOTA4MTQxMjAwMDBa
MGoxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJOWTERMA8GA1UEBxMITmV3IFlvcmsx
HTAbBgNVBAoTFFN0YWNrIEV4Y2hhbmdlLCBJbmMuMRwwGgYDVQQDDBMqLnN0YWNr
ZXhjaGFuZ2UuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr0YD
zscT5i6T2FaRsTGNCiLB8OtPXu8N9iAyuaROh/nS0kRRsN8wUMk1TmgZhPuYM6oF
S377V8W2LqhLBMrPXi7lnhvKt2DFWCyw38RrDbEsM5dzVGErmhux3F0QqcTI92zj
VW61DmE7NSQLiR4yonVpTpdAaO4jSPJxn8d+4p1sIlU2JGSk8LZSWFqaROc7KtXt
lWP4HahNRZtdwvL5dIEGGNWx+7B+XVAfY1ygc/UisldkA+a3D2+3WAtXgFZRZZ/1
CWFjKWJNMAI6ZBAt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nL6VpPX/78whQYwvwt/Tv9XBZ0k7YXDK/umdaisLRbvfXknsuvCnQsH6qqF
0wGjIChBWUMo0oHjqvbsezt3tkBigAVBRQHvFwY+3sAzm2fTYS5yh+Rp/BIAV0Ae
cPUeybQ=
-----END CERTIFICATE-----

而且由於它使用狗牌,我希望它能夠自動更新。

與往常一樣,答案是Selinux

type=AVC msg=audit(1484834941.587:22023): avc:  denied  { execute } for  pid=21252 comm="certmonger" name="after.sh" dev="dm-0" ino=244 scontext=system_u:system_r:certmonger_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=file
type=SYSCALL msg=audit(1484834941.587:22023): arch=c000003e syscall=59 success=no exit=-13 a0=7f3d5b2bdb10 a1=7f3d5b2bda90 a2=7f3d5b2c08c0 a3=7f3d57f932e0 items=0 ppid=3219 pid=21252 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="certmonger" exe="/usr/sbin/certmonger" subj=system_u:system_r:certmonger_t:s0 key=(null)

腳本很好,只需要添加之前/之後的命令。

sudo ipa-getcert request -f /etc/pki/tls/certs/$(hostname).crt -k /etc/pki/tls/private/$(hostname).key -r -F /etc/pki/tls/certs/intermediate.crt -B /temp/before.sh -C /temp/after.sh

引用自:https://serverfault.com/questions/827123