I want to add an application in Spring Boot services, but I want it to only run as root. When I try to run it as a different user, I have an error:
Failed to start component [Connector[HTTP/1.1-8081]]
org.apache.catalina.LifecycleException: Protocol handler start failed
https://pastecode.xyz/view/2410ddfc
When I run it with sudo
it starts correctly.
The application works with the Let's Encrypt certificate, I do not know if it matters.
In my opinion, there is no permission to run Tomcat. :-(
I do not know what to do anymore.
Thank you for your help.
As your stack trace reads, you are not permitted to acces the file:
/etc/letsencrypt/live/dawid.cloud/keystore.p12 (Permission denied)
org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:960) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) [tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:259) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:197) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) [spring-context-5.1.2.RELEASE.jar!/:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at dawid.cloud.spotkanieklasowe.SpotkanieklasoweApplication.main(SpotkanieklasoweApplication.java:10) [classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [spotkanieklasowe-0.0.1.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [spotkanieklasowe-0.0.1.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [spotkanieklasowe-0.0.1.jar:na]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [spotkanieklasowe-0.0.1.jar:na]
Caused by: java.lang.IllegalArgumentException: /etc/letsencrypt/live/dawid.cloud/keystore.p12 (Permission denied)
at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:114) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:85) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:224) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1108) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:550) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:957) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
... 22 common frames omitted
Caused by: java.io.FileNotFoundException: /etc/letsencrypt/live/dawid.cloud/keystore.p12 (Permission denied)
at java.io.FileInputStream.open0(Native Method) ~[na:1.8.0_191]
at java.io.FileInputStream.open(FileInputStream.java:195) ~[na:1.8.0_191]
at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[na:1.8.0_191]
at java.io.FileInputStream.<init>(FileInputStream.java:93) ~[na:1.8.0_191]
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90) ~[na:1.8.0_191]
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188) ~[na:1.8.0_191]
at org.apache.tomcat.util.file.ConfigFileLoader.getInputStream(ConfigFileLoader.java:89) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.SSLUtilBase.getStore(SSLUtilBase.java:141) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.SSLHostConfigCertificate.getCertificateKeystore(SSLHostConfigCertificate.java:204) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.jsse.JSSEUtil.getKeyManagers(JSSEUtil.java:184) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:112) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
... 27 common frames omitted
The bottom most caused by
statement always is the root cause of an exception.
If your server shall run as a [user]
other than root, which indeed is absolutly a good idea, make this file accessible for that particular [user]
.
As a workaround as root:
mkdir /home/[user]/key
cp -p /etc/letsencrypt/live/dawid.cloud/keystore.p12 /home/[user]/key/
chown -R [user].[user] /home/[user]/key
Where [user]
is your user name.
I bet there's a more streight forward solution to automate this using the certbot
or what ever tool you use to obtain the Let's Encrypt certificate.
Edit: certbot deploy hook
seemes to be a good next search term as pointed out in an answer on superuser.com