Workspace with Traefik, OAuth2, and TLS
This guide explains how to deploy the workspace container with the Traefik reverse proxy, OAuth2 authentication and TLS/HTTPS support for secure multi-user deployments.
Prerequisites
- Docker Engine v27 or later
- Docker Compose v2.x
- Sufficient system resources (at least 1GB RAM per workspace instance)
- Valid TLS certificates (production) or self-signed certificates (testing)
- A domain name pointing to the server (production) or localhost (testing)
Design
The docker-compose.yml file sets up:
- Traefik reverse proxy with TLS termination (ports 80, 443) and an automatic HTTP to HTTPS redirect
- Keycloak identity provider, served under
/auth - OAuth2 authentication through traefik-forward-auth
- the DTaaS web client
- Workspace containers for each user (user1, user2) behind authentication, using the workspace image
- Two Docker networks,
dtaas-frontendanddtaas-users, which separate the frontend services from the user workspaces
Initial Configuration
Follow the steps in configuration.md
to create a suitable configuration.
Create Workspace Files
Every deployment option needs user directories for the workspace files.
Create them for the USERNAME1 and USERNAME2 values set in
config/.env.
Start Services
To start all services with TLS:
This:
- starts the Traefik reverse proxy with TLS on ports 80 (HTTP → HTTPS redirect) and 443 (HTTPS)
- starts Keycloak and the DTaaS web client
- starts the traefik-forward-auth service for OAuth2 authentication
- starts the workspace instances for user1 and user2, protected by authentication
Accessing Workspaces
Once all services are running, open the workspaces through Traefik over HTTPS:
User Workspace (workspace)
- VNC Desktop:
https://intocps.org/user1/tools/vnc?path=user1%2Ftools%2Fvnc%2Fwebsockify - VS Code:
https://intocps.org/user1/tools/vscode - Jupyter Notebook:
https://intocps.org/user1 - Jupyter Lab:
https://intocps.org/user1/lab
Service Discovery
The workspace has a /services endpoint that returns a JSON list of
the available services, so frontend applications can discover them.
Example: Get the service list for user1
Response:
The endpoint values are filled in with the username from the
MAIN_USER environment variable. For user1, this variable is set from
USERNAME1 in config/.env.
Authentication Flow
- The user opens a workspace URL.
- Traefik forwards the request to traefik-forward-auth.
- If the user is not authenticated, they are redirected to the OAuth2 provider.
- The user logs in with the OAuth2 provider.
- The provider redirects back with an authorisation code.
- traefik-forward-auth exchanges the code for a token and creates a session.
- The user is redirected to the original URL and gains access.
Stopping Services
To stop all services:
To stop and remove volumes:
Customisation
Adding More Users
To add more workspace instances, add a new service in
docker-compose.yml:
Add the USERNAME3 variable to config/.env:
Add a Forward Auth rule for user3 to config/forward-auth-conf:
The username and email must match the workspace user.
Create the user's directory:
Bring up the user workspace:
Troubleshooting
Certificate Issues
Problem: "NET::ERR_CERT_INVALID" in the browser
Solutions:
- Verify that the certificate files exist in the
./certs/directory - Check the certificate file permissions
- Ensure that
config/tls.ymlreferences the correct certificate paths - For self-signed certificates, add a security exception in the browser
OAuth2 Issues
Problem: Redirect loop after OAuth2 login
Solutions:
- Verify that the OAuth2 callback URL matches
https://intocps.org/_oauth - Check that the
SERVER_DNSenvironment variable is set correctly - Ensure that
SERVER_DNSis correct (COOKIE_DOMAINis derived from it) - Verify that the OAuth2 application is approved and active
Port Conflicts
Problem: Ports 80 or 443 already in use
Solutions:
- Check for other services:
sudo netstat -tlnp | grep -E ':(80|443)' - Stop conflicting services
- Or change the port mappings in the compose file (not recommended for production)