# SSL/TLS for multi-container project

**URL:** <https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188>\
**Category:** Product support\
**Tags:** raspberrypi4\
**Created:** [January 12, 2021, 7:08pm UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188 "2021-01-12T19:08:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [January 12, 2021, 7:08pm UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/1 "2021-01-12T19:08:18Z")

</div>

I’m using an RPi4 with Mosquitto, Node-Red, Influxdb, and Grafana to create a quick and easy way to deploy an IoT Gateway with a built-in dashboard.

I’ve successfully got each section running and passing data by using the [Balena-sense](https://github.com/balenalabs/balena-sense) project as a reference and adding the [Balena-Node-Red](https://github.com/balenalabs/balena-node-red). My next step is to ensure that each section is properly secured and I plan to enable TLS for all 4 containers.

I want to create the certificates on the first boot and store them in the persistent data. I will also need to download them to my pc in order to connect as a client to the MQTT broker.

Unfortunately, I have minimal experience using LetsEncrypt or similar services and have never used them on Balena. Is there a recommended method for creating the Certificates?

Thanks.

---

<div class="post-metadata">

**Author:** ![anujdeshpande](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/anujdeshpande/32/3155_2.png) [@anujdeshpande](https://forums.balena.io/u/anujdeshpande)\
**Post date:** [January 13, 2021, 7:03am UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/4 "2021-01-13T07:03:07Z")

</div>

Interesting approach! I was reading how to do this, and found a detailed guide here - [https://www.digitalocean.com/community/tutorials/how-to-secure-a-containerized-node-js-application-with-nginx-let-s-encrypt-and-docker-compose](https://www.digitalocean.com/community/tutorials/how-to-secure-a-containerized-node-js-application-with-nginx-let-s-encrypt-and-docker-compose)

Are you also using the public URL feature for balenaCloud along with this? Or is this just for internal communication between services?

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [January 13, 2021, 9:23am UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/6 "2021-01-13T09:23:31Z")

</div>

Thanks for the link. I’ll give it a shot.

Currently, I am not using the public URL feature but I intend to use it in the future to give me remote access to the Grafana dashboard and the Node-Red interface. Are there any other steps needed to secure it for the public URL?

Thanks

---

<div class="post-metadata">

**Author:** ![sradevski](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/sradevski/32/1609_2.png) [@sradevski](https://forums.balena.io/u/sradevski)\
**Post date:** [January 13, 2021, 12:06pm UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/7 "2021-01-13T12:06:36Z")

</div>

Hey there, you can see an example repo here: [https://github.com/balena-io-playground/balena-nginx](https://github.com/balena-io-playground/balena-nginx) on how to generate a certificate and use nginx as a reverse proxy. Aside from generating a certificate for your domain, you’ll need to protect your services using some form of authentication, as the public URL is public (as the name suggest :)) by default and we don’t provide any sort of authorization out of the box.

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [January 13, 2021, 12:19pm UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/8 "2021-01-13T12:19:36Z")

</div>

Thanks for the message. I’ll take a look at that repo.

For adding TLS for purely internal services - e.g without having the public URL turned on - will I need to use a domain name or can I use the IP address of the device?

I’m trying to make this as scale-able as possible so I don’t want to have to use a different domain name for each device.

I currently have set up the password authentication for both Node-Red and Grafana, and am in the process of ensuring that Influxdb is also secured by password.

---

<div class="post-metadata">

**Author:** ![sradevski](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/sradevski/32/1609_2.png) [@sradevski](https://forums.balena.io/u/sradevski)\
**Post date:** [January 13, 2021, 12:32pm UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/9 "2021-01-13T12:32:15Z")

</div>

What’s the reason for you needing a certificate for the internal services? If you need that, you can potentially create self-signed certificates, not sure if that would work for you though. You can check the let’s encrypt documentation and the repo I linked for more information, that should be a good start to figure out how to do start, please reach out if you’re still stuck 🙂

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [January 13, 2021, 12:50pm UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/10 "2021-01-13T12:50:55Z")

</div>

I will look into creating self signed certificates, as well as creating them with the cert bot and a domain. I am not 100% sure if I will need the public URL on, so self signed may be the best option. I am only using them to ensure that my services are encrypted and secure, as the devices may be used on non-secure networks.

Thanks for pointing me in the right direction. 🙂

---

<div class="post-metadata">

**Author:** ![sinegar](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@sinegar](https://forums.balena.io/u/sinegar)\
**Post date:** [January 13, 2021, 11:51pm UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/12 "2021-01-13T23:51:48Z")

</div>

You might want to consider traefik. Here is an example for balena: [https://github.com/klutchell/balena-traefik](https://github.com/klutchell/balena-traefik)

For internal certs you will need DNS let’s encrypt verification.

Another (more dynamic) traefik config example (it has other dependencies - e.g. hashi vault for secret management): [https://github.com/izer-xyz/beast/blob/main/proxZ/traefik.yml.tpl](https://github.com/izer-xyz/beast/blob/main/proxZ/traefik.yml.tpl)

---

<div class="post-metadata">

**Author:** ![Razikus](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@Razikus](https://forums.balena.io/u/Razikus)\
**Post date:** [January 14, 2021, 12:28am UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/13 "2021-01-14T00:28:03Z")

</div>

+1 for traefik, best proxy ever

This is our basic setup for this

> <https://gist.github.com/Razikus/a078a6fa9663526396edbdc6827f159f>

---

<div class="post-metadata">

**Author:** ![GregorR](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@GregorR](https://forums.balena.io/u/GregorR)\
**Post date:** [January 14, 2021, 10:50am UTC](https://forums.balena.io/t/ssl-tls-for-multi-container-project/233188/15 "2021-01-14T10:50:31Z")

</div>

Thanks for the replies, I’ve seen Traefik before but haven’t used it personally. I’ll give it a try as well.

Cheers.
