Boxfuse SSL Config with GoDaddy Certs - spring-boot

I have an Spring Boot App deployed at AWS with Boxfuse . I am trying to make the SSL work with "mydomain.com" .I got the certs from Godaddy . It works well with self-signed certificates. But when I tried it with GoDaddy certs , it says that Payload failed to come up within 300s . Do I need to configure anything at AWS or Godaddy .Right now I am having following configuration in my application.properties file .
server.port=443
server.ssl.enabled=true
server.ssl.key-store=classpath:example.jks
server.ssl.key-store-password=myS3cr3tPwd
server.ssl.trust-store=/cacerts/example.jks
server.ssl.trust-store-password=my0th3rPwd
Logs says this :
2017-01-19 09:22:38.315 INFO 895 --- [ main] s.b.c.e.t.TomcatEmbedded
ServletContainer : Tomcat started on port(s): 443 (https)
2017-01-19 09:22:38.338 INFO 895 --- [ main] com.unoiatech.o3.Applica
tion : Started Application in 50.814 seconds (JVM running for 51.171
)
The system is going down NOW!
Sent SIGTERM to all processes
2017-01-19 09:26:34.501 INFO 895 --- [ Thread-4] ationConfigEmbeddedWebAp
plicationContext : Closing org.springframework.boot.context.embedded.AnnotationC
onfigEmbeddedWebApplicationContext#73f0f3d4: startup date [Thu Jan 19 09:21:48 G
MT 2017]; root of context hierarchy
2017-01-19 09:26:34.530 INFO 895 --- [ Thread-4] o.s.j.e.a.AnnotationMBea
nExporter : Unregistering JMX-exposed beans on shutdown
2017-01-19 09:26:34.553 INFO 895 --- [ Thread-4] j.LocalContainerEntityMa
nagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'defaul
t'
Sent SIGKILL to all processes
Requesting system poweroff
[ 290.976653] reboot: Power down
I have no clue where to look for the issue . Any help would be appreciated .
Edit :
It is a t2.micro instance .
Command to run the app : boxfuse run myapp:1.x -env=test ,
Edit After adding port to command :
Also, It is working with port 8443.

Use PKCS12 format
I faced same issue solved using below command
openssl pkcs12 -export -in f8f628911xyzc.crt -inkey mydomain.com.key
-certfile gd_bundle-g2-g1.crt -out mydomain.p12

Related

Could not reach the docker container web application even it run successfully

I wrote a simple backend application by spring boot and kotlin, here you can see the full settings https://github.com/lifeodyssey/demo
this bug performed as
I can start and access the application by ./gradlew bootRun
I can start and access the application by java -jar demo.jar
But I could not access the application when I try to start it in a container, even I can see a successful log by docker logs containerID. The log is given below
2022-11-12 15:50:33.017 INFO 1 --- [ main] com.example.demo.DemoApplicationKt : Starting DemoApplicationKt using Java 11.0.16 on eeb1dfe09e6a with PID 1 (/Demo-0.0.1.jar started by root in /)
2022-11-12 15:50:33.029 INFO 1 --- [ main] com.example.demo.DemoApplicationKt : No active profile set, falling back to 1 default profile: "default"
2022-11-12 15:50:34.315 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2022-11-12 15:50:34.320 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2022-11-12 15:50:34.346 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 15 ms. Found 0 MongoDB repository interfaces.
2022-11-12 15:50:35.564 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8000 (http)
2022-11-12 15:50:35.595 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-11-12 15:50:35.596 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68]
2022-11-12 15:50:35.787 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-11-12 15:50:35.788 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2628 ms
2022-11-12 15:50:38.155 WARN 1 --- [ main] o.s.b.a.m.MustacheAutoConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Mustache configuration, or set spring.mustache.check-template-location=false)
2022-11-12 15:50:38.346 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8000 (http) with context path ''
2022-11-12 15:50:38.412 INFO 1 --- [ main] com.example.demo.DemoApplicationKt : Started DemoApplicationKt in 6.588 seconds (JVM running for 7.745)
And here is the Dockerfile
FROM openjdk:11
COPY /build/libs/demo-0.0.1-SNAPSHOT.jar Demo-0.0.1.jar
EXPOSE 8000
ENTRYPOINT ["java","-jar","/Demo-0.0.1.jar"]
Here is the commmand I used to build image and run container
docker build -t demo .
docker run -dp 8000:8000 demo:latest
I could not find where is the problem. Can you help me with it ?
Update
Thanks for the comments below, here is what showed when I access localhost
This site can’t be reached localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
I have tried change -dp 8000 to -d -p 8000, but nothing changed.
Try to connect to it using 127.0.0.1:8000 instead of localhost:8000, maybe localhost is not resolving to 127.0.0.1.
If not try a different port and/or browser. Finally your firewall might be blocking your server so check that.
I finally found the issue.
I installed two application two run my docker. One is colima, another is Docker Desktop.
I guess the problem is that docker do not know which one is the "localhost".
This problem fixed after I uninstall docker desktop and link docker to colima.

How to connect docker db from dockerized spring boot app?

I am beginner on docker stuff and try to learn but I am stuck so hard.
When I only run db from docker-compose.yml and run the spring app called dockerdeneme directly from IDE then it connects to db, no problem. But when I try to run both from docker-compose.yml file then the app cannot connect to db. My docker-compose.yml file is:
version: '3.9'
services:
mysql:
platform: linux/amd64
image: mysql:8
container_name: mysqlcustomerdb
domainname: nishcustomer
hostname: localhost
ports:
- '3306:3306'
volumes:
- ~/apps/mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=1234
- MYSQL_PASSWORD=1234
- MYSQL_DATABASE=mysqlcustomerdb
- DATABASE_HOST=mysqlcustomerdb
- MYSQL_ROOT_HOST=%
- lower_case_table_names=1
- init-connect='GRANT CREATE USER ON . TO 'root'#'%';FLUSH PRIVILEGES;'
dockerdeneme:
container_name: dockerdeneme
domainname: nishcustomer
hostname: localhost
image: dockerdeneme
build: ./
ports:
- '8080:8080'
environment:
- MYSQL_ROOT_PASSWORD=1234
- MYSQL_PASSWORD=1234
- MYSQL_USER=root
- MYSQL_DATABASE=mysqlcustomerdb
depends_on:
- mysql
volumes:
cache:
driver: local
Result of docker ps is:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fb0037e10702 mysql:8 "docker-entrypoint.s…" 22 seconds ago Up 21 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysqlcustomerdb
If I run the application from IDE with following application.properties then it is working good:
spring.datasource.url=jdbc:mysql://localhost:3306/mysqlcustomerdb
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
And it is the output of failing dockerized app:
2022-04-14 21:28:56.106 INFO 1 --- [ main] c.e.d.DockerdenemeApplication : Starting DockerdenemeApplication v0.0.1-SNAPSHOT using Java 11.0.14.1 on localhost with PID 1 (/app.jar started by root in /)
2022-04-14 21:28:56.107 INFO 1 --- [ main] c.e.d.DockerdenemeApplication : No active profile set, falling back to 1 default profile: "default"
2022-04-14 21:28:56.467 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-04-14 21:28:56.493 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 21 ms. Found 1 JPA repository interfaces.
2022-04-14 21:28:57.024 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-04-14 21:28:57.037 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-04-14 21:28:57.037 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.60]
2022-04-14 21:28:57.105 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-04-14 21:28:57.105 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 937 ms
2022-04-14 21:28:57.250 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-04-14 21:28:57.256 WARN 1 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2022-04-14 21:28:58.334 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.28.jar!/:8.0.28]
I think I am doing something wrong with port mapping or hostname/domain name but I am stuck.
Can someone show me what am I doing wrong, ports or hostname etc?
localhost don't work for docker-compose apps. As a summary, use the ip of the host or a well configured docker network. Check:
https://stackoverflow.com/a/52213178/3957754
Pay special attention to : extra_hosts:
How to connect API with Web SPA through docker
Here you have a similar docker-compose with mysql and wordpress:
https://github.com/usil/wordpress-docker/blob/master/docker-compose.yml

Not able to access springboot application running inside a container on MacOs

I have a springboot application running inside a container on macOS Catalina. Logs show that the application is up and running inside the container however I cannot reach it from browser.
I have tried accessing it using :
localhost:8081/
0.0.0.0:8081/ and
127.0.0.1/8081/
But nothing helped. I have also added server.address=0.0.0.0 to my application.properties file but that didn't help either.
This is how I run my container:
docker run --name spring_boot_docker -it --link mysql-dev-server:db -p 8081:8081 demo_docker_kubernetes
Logs show application is running fine:
2020-04-12 00:21:40.149 INFO 1 --- [ main]
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService
'applicationTaskExecutor'
2020-04-12 00:21:40.632 INFO 1 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with
context path ''
2020-04-12 00:21:40.637 INFO 1 --- [ main] com.microservice.DemoApplication
: Started DemoApplication in 8.519 seconds (JVM running for 9.391)
2020-04-12 00:21:52.209 INFO 1 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]
: Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-04-12 00:21:52.210 INFO 1 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet
: Initializing Servlet 'dispatcherServlet'
2020-04-12 00:21:52.227 INFO 1 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet
: Completed initialization in 17 ms
When I do docker container ls I get below output under "ports":
0.0.0.0:8081->8081/tcp if that helps anyway?
I have referred almost all other posts that suggest to include server.address=0.0.0.0 in application.properties but as I mentioned that has not helped me.
Any idea what I could be doing wrong here? Thanks
If you run your application Production mode then by default it uses HTTPS and you might be using localhost(HTTP) to access the host.
You need to remove the --link in your docker run to access it.
--link is a deprecated Docker feature, so there may be a docker network being created between those two containers. Rendering your -p 8081:8081 useless.

Docker, Mongodb,Spring Boot on Windows getting Connection refused error

I am using default docker image of MongoDB and trying to connect using simple spring Boot application on windows box.
mongoDB image is getting stared correctly
IP in mongoDB image
I have spring-boot-starter-data-mongodb in my class path. i am using all spring boot default and only using below property in application.properties.
spring.data.mongodb.host=192.168.99.100
On application startup getting Connection refused: connect error
Logs
019-03-06 06:15:06.096 INFO 4664 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[192.168.99.100:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2019-03-06 06:15:06.096 INFO 4664 --- [ main] org.mongodb.driver.cluster : Adding discovered server 192.168.99.100:27017 to client view of cluster
2019-03-06 06:15:06.356 WARN 4664 --- [ main] o.s.d.m.c.m.BasicMongoPersistentProperty : Customizing field name for id property not allowed! Custom name will not be considered!
2019-03-06 06:15:06.928 INFO 4664 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-03-06 06:15:07.164 INFO 4664 --- [68.99.100:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 192.168.99.100:27017
What i am missing here ?
Not a MongoDB expert, but a moderate Docker user speaking: It looks like you are not publishing the port MongoDB runs by default: 27017. That's why your spring application could not get a connection and throws this exception:
Exception in monitor thread while connecting to server 192.168.99.100:27017
So you may try publishing the port by using -p 27017:27017when initiating mongo container.

Spring Boot Jetty server not works over https (SSL)

I have a Spring Boot application which runs on a remote server. When I build it to work over HTTP everything works fine. But when I am trying to setup SSL the application not work. It doesn't throw errors or anything. But I can't access any page in the browser (I have tried https://www.example.com, https://www.example.com:8443, https://example.com etc).
I have built keystore.jks on remote server machine from certificate.crt (which I have bought for my domain on ssl).
I have the following application.properties:
server.port=8443
server.ssl.key-store=classpath:keystore.jks
server.ssl.key-store-password=PASSWORD
server.ssl.key-password=PASSWORD
I have tried different configurations but no results. The same story happens when I trying to run it on my local machine (I thought it is because of I am going to localhost when the certificate is for example.com but maybe it is the same problem).
Here is the server output:
INFO 11041 --- [ main] o.e.jetty.util.ssl.SslContextFactory : x509=X509#2a492f2a(jetty,h=[www.example.com, example.com],w=[]) for >SslContextFactory#3277e499(jar:file:/root/application.jar!/BOOT->INF/classes!/keystore.jks,null)
2018-05-13 13:21:56.175 INFO 11041 --- [ main] >o.e.jetty.server.AbstractConnector : Started >ServerConnector#7ac2e39b{SSL,[ssl, http/1.1]}{0.0.0.0:8443}
2018-05-13 13:21:56.176 INFO 11041 --- [ main] >.s.b.c.e.j.JettyEmbeddedServletContainer : Jetty started on port(s) 8443 (ssl, http/1.1)
2018-05-13 13:21:56.179 INFO 11041 --- [ main] >c.b.product.BootApplication : Started BootApplication in 4.786 seconds (JVM running for 5.151)
So everything seems to be fine but it doesn't work.
Problem solved. It was just wrong generated keystore.jks.

Resources