#Spring Boot SSL

1 messages · Page 1 of 1 (latest)

crimson plaza
#

Hey I have a normal Backend in Spring Boot and it only runs on Port 8080 (HTTP)…I have this Backend in a Docker container where I exposed this Port. Everytime someone tries to connect via my Domain, my Nginx Proxy Manager reroutes the connection with SSL to my backend. Should I continue this method or should I rather activate SSL on my Spring Boot Backend too?

twin wadiBOT
#

<@&987246964494204979> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

to my backend, they have to use http://<ip>:8080. Now I want to secure the communication between the client and the backend by using SSL/TLS. How can I achieve this in Spring Boot?

To enable SSL/TLS in your Spring Boot application, you need to follow these steps:

  1. Generate a self-signed SSL certificate or obtain a valid SSL certificate from a trusted Certificate Authority (CA). You can use tools like OpenSSL to generate a self-signed certificate.

  2. Place the generated SSL certificate and private key in a keystore file. The keystore file is typically in Java KeyStore (JKS) format.

  3. Configure your Spring Boot application to use the SSL certificate and private key by adding the following properties to your application.properties or application.yml file:

#
   server.port=8443
   server.ssl.key-store-type=JKS
   server.ssl.key-store=classpath:keystore.jks
   server.ssl.key-store-password=your_keystore_password
   server.ssl.key-alias=your_certificate_alias
#

Make sure to replace keystore.jks, your_keystore_password, and your_certificate_alias with appropriate values.

  1. Restart your Spring Boot application, and it should now be accessible over HTTPS on port 8443.

Note: If you are using Docker, make sure to expose port 8443 in your Dockerfile or when running the container.

Now, clients can connect to your backend using https://<ip>:8443. However, since you are using a self-signed certificate, clients may see warnings about an untrusted certificate. To avoid these warnings, you can obtain a valid SSL certificate from a trusted CA.

Additionally, if you want to redirect all HTTP requests to HTTPS automatically, you can add the following configuration:

#
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.requiresChannel()
                .anyRequest()
                .requiresSecure();
    }
}
#

With this configuration, any HTTP request will be automatically redirected to HTTPS.

Remember to secure the keystore file and its password properly, as it contains sensitive information.

idle hedge
#

It highly depends on what you consider safe environment, many systems communicate using HTTP internally and some proxy does SSL offloading for them

#

The project I am working on right now is running inside OpenShift (Redhat kubernetes), internally the pods communicate using HTTP, SSL is done by openshift itself

crimson plaza
idle hedge
#

Inside openshift with limited access -> likely secure
Inside company network where every computer can run wireshark and listen in -> not secure

crimson plaza
#

So I should secure it then?

idle hedge
#

If it is the latter case I would say yes, even if you consider the environment technically internal it can be compromised.
But certificates and keys have expiration date, so you should have some process for renewing them

crimson plaza
idle hedge
crimson plaza
#

I think I will just generate one which is valid for one year

#

where can I generate certs?

idle hedge
#

openssh ?

#

I mean, the thing is, the client has to trust your certificate

#

So it should be signed by an authority

unique onyx
#

That will be the easiest way to do SSL on your own machine

#

I'd say to not secure your spring app itself

#

It adds complications and doesn't buy you much

#

There are exceptions to that statement, but I don't think you are in one of those cases

crimson plaza
#

So that I opened my HTTP port of my container and then secure every connection to it via Nginx Proxy Manager is fine?

unique onyx
#

Yes

#

Because the http port on your container isn't exposed to the wider internet

#

Basically, set up nginix to do http

#

Run certbot, and it will move you to https

#

Then you're golden

crimson plaza
#

it only secures it if you use the domain afaik

unique onyx
#

Just 80 and 443

#

And 8080 can be running locally

#

But I also can't think of anything horrid that would happen. Just people can get MITM'ed if they go directly to your ip

#

Which is unlikely

crimson plaza
unique onyx
#

What is nginix proxy manager

#

Vs nginix

#

So I would expect something like an ec2 machine with a public up that exposes 80 and 443

crimson plaza
#

THATS how it’s set up

unique onyx
#

And then some containers on that machine

crimson plaza
#

Yep

unique onyx
#

But I would expect nginix and the containers to be on the same machine

#

(they don't have to be, but I would expect it)

crimson plaza
#

Different container but same machine

unique onyx
#

Okay so wait

#

That's dumb

#

Why does nginix go out to the wider internet

#

Just to get back to the same machine

#

Why not localhost:8080

#

Or 0.0.0.0:8080

crimson plaza
#

Should I change that?

unique onyx
#

Try it

crimson plaza
#

Ok 1s

unique onyx
#

If that works, then you don't need to expose 8080 on the public ip

#

And then it's gucci

crimson plaza
#

And if I dont expose 8080...Not even localhost could open a connection

unique onyx
#

Fuckin docker

#

You can expose 8080 of one container to another container in a docker compose or whatevrr

#

But, tbh, it's a lot less of a PITA to just use a platform as a service

#

Which does SSL for you on a free tier

#

Like render, railway, heroku, etc

crimson plaza
#

But I would have to buy a new service...Thats not nice

unique onyx
#

Free tier

#

But whatever

#

I'll look up how to use compose for this later if I remember

crimson plaza
#

ok thx

twin wadiBOT
#

我是一个基于深度学习的对话模型,使用了自然语言处理和人工智能技术来进行对话。

#

不好意思,我是GPT-3,一个由OpenAI开发的人工智能语言模型。目前还没有GPT-4存在。有什么我可以帮助你的吗?

twin wadiBOT
#

@crimson plaza

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

unique onyx
#

no clue

#

also i havent looked anything up yet

twin wadiBOT
#

@crimson plaza

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

crimson plaza
unique onyx
#

you get what you pay for, yknow

crimson plaza
unique onyx
#

I think links is the thing though

crimson plaza
#

You mean I should Link the nginx proxy manager container with my backend container and it should Reroute everythng to my docker?

unique onyx
#

yeah so you don't have any extra ports exposed to the wider internet

#

and you don't hop over the internet to get to your local site

#

for context, the one site I run that uses a physical machine + nginix is this

#

and i got most of the instructions from the repo I forked from

#

and in that there is no docker involved, so its a bit simpler