[go: up one dir, main page]

HTTP 502 error when trying to access HTTPS server running within workspace

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

MR: Pending

Description

As a user, I want to access ports opened within a workspace so that I can test services running on the workspace.

  • Current behavior:

When I run a http server within the workspace I can connect to it by opening the workspace URL and replace the port with the port of the http server. I will see whatever is served by the http server (Hello workspace! in the example below).

When I run a https server (with a self-signed certificate) though I get a 502 Bad Gateway error.

  • Expected behavior:

The page served by the https server should be shown also for https and even for self-signed certificates (as during development self-signed certificates are often used).

  • Steps to reproduce:
  1. Create a workspace
  2. Create a self-signed certificate
gitlab-workspaces@workspace-...:/projects/test$ mkdir -p "$PWD/certificate"
gitlab-workspaces@workspace-...:/projects/test$ export TLS_KEY="$PWD/certificate/tls.key"
gitlab-workspaces@workspace-...:/projects/test$ export TLS_CERT="$PWD/certificate/tls.crt"
gitlab-workspaces@workspace-...:/projects/test$ openssl req -x509 -newkey rsa:4096 -days 365 -nodes -out "$TLS_CERT" -keyout "$TLS_KEY" -subj '/CN=localhost'
  1. Start a https server with the created certificate (e.g. using nodejs)

package.json

{
    "name": "test",
    "version": "1.0.0",
    "description": "test case to repdoruce workspace behaviour",
    "dependencies": {
        "express": "^5.1.0"
    }
}

test.js (working)

const http = require('http')
const express = require('express')
const { readFileSync } = require('fs')

const app = express()
app.get('/', (_req, res) => {
    res.send('Hello workspace!')
})
const server = http.createServer(app)
server.listen(8080, '0.0.0.0')

test.js (not working)

const https = require('https')
const express = require('express')
const { readFileSync } = require('fs')

const app = express()
app.get('/', (_req, res) => {
    res.send('Hello workspace!')
})
const server = https.createServer({
  key: readFileSync(process.env.TLS_KEY),
  cert: readFileSync(process.env.TLS_CERT)
}, app)
server.listen(8080, '0.0.0.0')
gitlab-workspaces@workspace-...:/projects/test$ node test.js
  • Additional information:

.devfile.yaml

schemaVersion: 2.2.0
variables:
  registry-root: registry.gitlab.com
components:
  - name: tooling-container
    attributes:
      gl/inject-editor: true
    container:
      image: "{{registry-root}}/gitlab-org/workspaces/gitlab-workspaces-docs/nodejs:22.13.1-ubuntu-24.04"
      memoryRequest: 1024M
      memoryLimit: 4096M
      cpuRequest: 1000m
      cpuLimit: 2000m
      endpoints:
        - name: http-8080
          targetPort: 8080

Acceptance criteria

  • Ports are forwarded also for https
  • Self-signed certificates are supported
Edited by 🤖 GitLab Bot 🤖