|
| 1 | +--- |
| 2 | +title: Custom SSL certificates |
| 3 | +description: Use your own SSL certificate to use Memgraph Lab with HTTPS protocol. |
| 4 | +--- |
| 5 | + |
| 6 | +## Instantiating Memgraph Lab with Custom SSL Certificate |
| 7 | + |
| 8 | +Memgraph Lab supports using custom SSL certificates, ensuring secure communication over HTTPS. To set up |
| 9 | +SSL on Memgraph Lab you will need to configure a Dockerfile using a valid SSL certificate. |
| 10 | + |
| 11 | +### Options for Generating SSL Certificates |
| 12 | + |
| 13 | +You have several options for generating SSL certificates: |
| 14 | + |
| 15 | +#### OpenSSL |
| 16 | +OpenSSL is a widely used tool for generating SSL certificates. You can create a self-signed certificate using the following commands: |
| 17 | + |
| 18 | +1. Generate a private key: |
| 19 | + ```bash |
| 20 | + openssl genrsa -out key.pem 2048 |
| 21 | + ``` |
| 22 | + |
| 23 | +2. Generate a self-signed certificate: |
| 24 | + ```bash |
| 25 | + openssl req -new -x509 -key key.pem -out cert.pem -days 365 |
| 26 | + ``` |
| 27 | + |
| 28 | +However, this option has an expiration date and is not signed by a publicly trusted |
| 29 | +[certificate authority](https://en.wikipedia.org/wiki/Certificate_authority), which means |
| 30 | +you will most likely receive a security warning from your browser while using it. |
| 31 | + |
| 32 | +#### Let's Encrypt |
| 33 | +[Let's Encrypt](https://letsencrypt.org/) is a free, automated, and open certificate authority |
| 34 | +that provides SSL certificates. You can use tools like Certbot to obtain and install certificates. |
| 35 | +To use Let's Encrypt: |
| 36 | + |
| 37 | +1. Install Certbot. |
| 38 | +2. Run Certbot to obtain your certificates: |
| 39 | + ```bash |
| 40 | + sudo certbot certonly --standalone -d yourdomain.com |
| 41 | + ``` |
| 42 | + |
| 43 | +This will generate your SSL certificate and key, typically located in |
| 44 | +`/etc/letsencrypt/live/yourdomain.com/`. |
| 45 | + |
| 46 | +### Dockerfile setup |
| 47 | + |
| 48 | +To run Memgraph Lab with custom SSL certificates, you need to create a |
| 49 | +Dockerfile that specifies how to build the Docker image with your certificates. |
| 50 | + |
| 51 | +You will need to set the `SSL_CERT_PATH` and `SSL_KEY_PATH` environment variables |
| 52 | +to override the default `./ssl/` path used by Lab running in the container to |
| 53 | +determine the SSL certificate location. After that, you should copy your certificates |
| 54 | +(located in the `ssl` folder at the same location as your `Dockerfile`, for example) |
| 55 | +into the container at the specified path. |
| 56 | + |
| 57 | +#### Example Dockerfile |
| 58 | +```docker |
| 59 | +FROM memgraph/lab:latest |
| 60 | +
|
| 61 | +# Environment variables |
| 62 | +ENV SSL_IS_ENABLED=true |
| 63 | +ENV SSL_CERT_PATH=./myssl/cert.pem |
| 64 | +ENV SSL_KEY_PATH=./myssl/key.pem |
| 65 | +
|
| 66 | +# COPY source_on_your_machine destination_in_container |
| 67 | +COPY ssl/ ./myssl/ |
| 68 | +
|
| 69 | +EXPOSE 3000 |
| 70 | +``` |
| 71 | + |
| 72 | +#### Building and Running the Docker Container |
| 73 | + |
| 74 | +1. **Create the SSL Directory**: Make sure your SSL certificate and key are placed |
| 75 | +in a directory specified as `COPY` source in your Dockerfile. |
| 76 | + |
| 77 | +2. **Build the Docker Image**: Run the following command to build your Docker image: |
| 78 | + `docker build -t memgraph-lab-ssl .` |
| 79 | + |
| 80 | +3. **Run the Docker Container**: Start the container using the following command: |
| 81 | + `docker run -p 3000:3000 memgraph-lab-ssl` |
| 82 | + |
| 83 | +4. **Access Memgraph Lab**: You can now access Memgraph Lab in your web browser at |
| 84 | +`https://localhost:3000`. Ensure to configure your browser to trust the self-signed |
| 85 | +certificate if you are using one. |
0 commit comments