Ubuntu

讓我們加密tomcat8 ubuntu伺服器的證書權限

  • October 13, 2017

我正在嘗試為我的 ubuntu 伺服器 VPS 的 Apache HTTPD 和 TOMCAT 服務使用 let’s encrypt 證書。

我發現在哪裡有letsencrypt儲存的證書來查看apache配置,它是由certboot腳本編寫的,Apache可以很好地使用這個證書。

我對 tomcat server.xml 配置使用相同的連結,但在其日誌中出現權限被拒絕錯誤:

SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-apr-8443"]
java.lang.Exception: Unable to load certificate key /etc/letsencrypt/live/mysite.org/privkey.pem (error:0200100D:system library:fopen:Permission denied)
       at org.apache.tomcat.jni.SSLContext.setCertificate(Native Method)
       at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:657)
       at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:742)
       at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:458)
       at org.apache.catalina.connector.Connector.initInternal(Connector.java:960)
       at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
       at org.apache.catalina.core.StandardService.initInternal(StandardService.java:568)
       at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
       at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:851)
       at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
       at org.apache.catalina.startup.Catalina.load(Catalina.java:580)
       at org.apache.catalina.startup.Catalina.load(Catalina.java:603)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:498)
       at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:310)
       at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484)

Oct 11, 2017 9:40:07 AM org.apache.catalina.core.StandardService initInternal
SEVERE: Failed to initialize connector [Connector[HTTP/1.1-8443]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-8443]]
       at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
       at org.apache.catalina.core.StandardService.initInternal(StandardService.java:568)
       at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
       at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:851)
       at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
       at org.apache.catalina.startup.Catalina.load(Catalina.java:580)
       at org.apache.catalina.startup.Catalina.load(Catalina.java:603)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:498)
       at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:310)
       at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484)
Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
       at org.apache.catalina.connector.Connector.initInternal(Connector.java:964)
       at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
       ... 12 more
Caused by: java.lang.Exception: Unable to load certificate key /etc/letsencrypt/live/mysite.org/privkey.pem (error:0200100D:system library:fopen:Permission denied)
       at org.apache.tomcat.jni.SSLContext.setCertificate(Native Method)
       at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:657)
       at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:742)
       at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:458)
       at org.apache.catalina.connector.Connector.initInternal(Connector.java:960)
       ... 13 more

Oct 11, 2017 9:40:07 AM org.apache.catalina.startup.Catalina load

調查許可我發現了這個:

root@myvps:~# ls -la /etc/letsencrypt/live/mysite.org/
total 12
drwxr-xr-x 2 root root 4096 Sep 20 06:30 .
drwx------ 4 root root 4096 May 23 07:27 ..
lrwxrwxrwx 1 root root   39 Sep 20 06:30 cert.pem -> ../../archive/mysite.org/cert3.pem
lrwxrwxrwx 1 root root   40 Sep 20 06:30 chain.pem -> ../../archive/mysite.org/chain3.pem
lrwxrwxrwx 1 root root   44 Sep 20 06:30 fullchain.pem -> ../../archive/mysite.org/fullchain3.pem
lrwxrwxrwx 1 root root   42 Sep 20 06:30 privkey.pem -> ../../archive/mysite.org/privkey3.pem
-rw-r--r-- 1 root root  543 May 23 07:27 README
root@myvps:~# ls -la /etc/letsencrypt/archive/mysite.org/
total 56
drwxr-xr-x 2 root root 4096 Sep 20 06:30 .
drwx------ 4 root root 4096 May 23 07:27 ..
-rw-r--r-- 1 root root 1818 May 23 07:27 cert1.pem
-rw-r--r-- 1 root root 1814 Jul 22 06:30 cert2.pem
-rw-r--r-- 1 root root 1814 Sep 20 06:30 cert3.pem
-rw-r--r-- 1 root root 1647 May 23 07:27 chain1.pem
-rw-r--r-- 1 root root 1647 Jul 22 06:30 chain2.pem
-rw-r--r-- 1 root root 1647 Sep 20 06:30 chain3.pem
-rw-r--r-- 1 root root 3465 May 23 07:27 fullchain1.pem
-rw-r--r-- 1 root root 3461 Jul 22 06:30 fullchain2.pem
-rw-r--r-- 1 root root 3461 Sep 20 06:30 fullchain3.pem
-rw-r--r-- 1 root root 1704 May 23 07:27 privkey1.pem
-rw-r--r-- 1 root root 1704 Jul 22 06:30 privkey2.pem
-rw-r--r-- 1 root root 1704 Sep 20 06:30 privkey3.pem

據我所知,這個對 ls 命令的回答表明每個人都有符號連結和真實文件的 READ 權限。我對嗎?那麼,如果我將其證書指向,為什麼 tomcat 會抱怨權限/etc/letsencrypt/live/mysite.org/cert.pem

問題是 /etc/letsencrypt/live和**/etc/letsencrypt/archive** 文件夾只能由具有權限700的 root 訪問。然後,如果內部文件是可訪問的,tomcat 在遍歷它時由於父文件夾權限而無法讀取它們。

我必須將 /etc/letsencrypt/live 和 /etc/letsencrypt/archive 的文件夾權限更改為750並將 tomcat 添加到使用者組根目錄,現在它可以工作了。

也許最好將這些文件夾的組所有者更改為根組以外的其他組,例如 ssl-cert。

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