From 59d3982f3c6e2e77203cd83b178194f56379de20 Mon Sep 17 00:00:00 2001 From: David Kwon Date: Wed, 14 Oct 2026 14:59:13 -0400 Subject: [PATCH 1/5] Read minimum TLS version from env var Signed-off-by: David Kwon --- Makefile | 1 + README.md | 1 + main.go | 16 ++++++++++++++++ pkg/config/config.go | 8 ++++++++ 4 files changed, 26 insertions(+) diff --git a/Makefile b/Makefile index 75d83e9..c23db59 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ endif # Enable using Podman instead of Docker export DOCKER ?= podman export WEB_TERMINAL_EXEC_IMG ?= quay.io/wto/web-terminal-exec:next +export ARCH ?= amd64 ### fmt: Formats code using goimports diff --git a/README.md b/README.md index b5592ad..dc2761e 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ The Web Terminal Exec component is intended to only run within an OpenShift clus This repository contains a Makefile to simplify development of Web Terminal Exec. The following environment variables can be set to configure behavior: * `DOCKER`: configure container build tool to use for building container images. Default is `podman`. * `WEB_TERMINAL_EXEC_IMG`: Configure image name and tag for container builds. Default is `quay.io/wto/web-terminal-exec:next`. +* `ARCH`: Configure target architecture for the image build (e.g. `amd64`, `arm64`, `s390x`, `ppc64le`). Default is `amd64`. | Rule | Purpose | | --- | --- | diff --git a/main.go b/main.go index 2e407d5..b59f3b0 100644 --- a/main.go +++ b/main.go @@ -12,8 +12,10 @@ package main import ( + "crypto/tls" "net/http" "os" + "strconv" "github.com/redhat-developer/web-terminal-exec/pkg/activity" "github.com/redhat-developer/web-terminal-exec/pkg/config" @@ -54,8 +56,22 @@ func main() { ReadTimeout: constants.ServerReadTimeout, WriteTimeout: constants.ServerWriteTimeout, MaxHeaderBytes: constants.MaxHeaderBytes, + TLSConfig: buildTLSConfig(), } if err := server.ListenAndServeTLS(TLSCertFile, TLSKeyFile); err != nil { logrus.Errorf("Failed to start server with TLS enabled: %s", err) } } + +func buildTLSConfig() *tls.Config { + if config.TLSMinVersion == "" { + return nil + } + minVersion, err := strconv.ParseUint(config.TLSMinVersion, 10, 16) + if err != nil { + logrus.Warnf("Invalid TLS min version %q, using Go default", config.TLSMinVersion) + return nil + } + logrus.Infof("Setting TLS min version to %s", tls.VersionName(uint16(minVersion))) + return &tls.Config{MinVersion: uint16(minVersion)} +} diff --git a/pkg/config/config.go b/pkg/config/config.go index 326d78e..fc440e5 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -53,6 +53,11 @@ var ( // UseBearerToken (deprecated) kept for compatibility but if specified must have 'true' value UseBearerToken bool + + // TLSMinVersion is the minimum TLS version as a decimal uint16 + // (e.g. "771" for TLS 1.2, "772" for TLS 1.3). + // Set by the operator from the cluster APIServer TLS profile. + TLSMinVersion string ) const ( @@ -64,6 +69,7 @@ const ( devworkspaceIDEnvVar = "DEVWORKSPACE_ID" devworkspaceNameEnvVar = "DEVWORKSPACE_NAME" devworkspaceNamespaceEnvVar = "DEVWORKSPACE_NAMESPACE" + tlsMinVersionEnvVar = "TLS_MIN_VERSION" ) var ( @@ -125,6 +131,7 @@ func updateDefaultsFromEnv() error { DevWorkspaceName = os.Getenv(devworkspaceNameEnvVar) DevWorkspaceNamespace = os.Getenv(devworkspaceNamespaceEnvVar) DevWorkspaceID = os.Getenv(devworkspaceIDEnvVar) + TLSMinVersion = os.Getenv(tlsMinVersionEnvVar) if DevWorkspaceName == "" { return fmt.Errorf("environment variable %s must be set", devworkspaceNameEnvVar) } @@ -182,6 +189,7 @@ func printConfig() { logrus.Infof("==> Pod selector: %s", PodSelector) logrus.Infof("==> Idle timeout: %s", IdleTimeout) logrus.Infof("==> Stop retry period: %s", StopRetryPeriod) + logrus.Infof("==> TLS min version: %s", TLSMinVersion) } func ResetConfigForTest() { From 4ff1ce3f9cb39b65da23ca4de93cfe5573503dd8 Mon Sep 17 00:00:00 2001 From: David Kwon Date: Wed, 21 Oct 2026 14:02:16 -0400 Subject: [PATCH 2/5] Add logic to verify tls config version is vaild Move tls related logic to tls.go Signed-off-by: David Kwon --- Makefile | 2 +- main.go | 17 +--------------- tls.go | 39 +++++++++++++++++++++++++++++++++++++ tls_test.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 tls.go create mode 100644 tls_test.go diff --git a/Makefile b/Makefile index c23db59..779d324 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ compile: -asmflags all=-trimpath=/ \ -ldflags "-X $(GO_PACKAGE_PATH)/version.Commit=$(GIT_COMMIT_ID) \ -X $(GO_PACKAGE_PATH)/version.BuildTime=$(BUILD_TIME)" \ - main.go + . ### docker: Builds and pushes Web Terminal Exec image docker: docker-build docker-push diff --git a/main.go b/main.go index b59f3b0..b259d75 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ // -// Copyright (c) 2019-2025 Red Hat, Inc. +// Copyright (c) 2019-2026 Red Hat, Inc. // This program and the accompanying materials are made // available under the terms of the Eclipse Public License 2.0 // which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -12,10 +12,8 @@ package main import ( - "crypto/tls" "net/http" "os" - "strconv" "github.com/redhat-developer/web-terminal-exec/pkg/activity" "github.com/redhat-developer/web-terminal-exec/pkg/config" @@ -62,16 +60,3 @@ func main() { logrus.Errorf("Failed to start server with TLS enabled: %s", err) } } - -func buildTLSConfig() *tls.Config { - if config.TLSMinVersion == "" { - return nil - } - minVersion, err := strconv.ParseUint(config.TLSMinVersion, 10, 16) - if err != nil { - logrus.Warnf("Invalid TLS min version %q, using Go default", config.TLSMinVersion) - return nil - } - logrus.Infof("Setting TLS min version to %s", tls.VersionName(uint16(minVersion))) - return &tls.Config{MinVersion: uint16(minVersion)} -} diff --git a/tls.go b/tls.go new file mode 100644 index 0000000..d035a2f --- /dev/null +++ b/tls.go @@ -0,0 +1,39 @@ +// +// Copyright (c) 2019-2026 Red Hat, Inc. +// This program and the accompanying materials are made +// available under the terms of the Eclipse Public License 2.0 +// which is available at https://www.eclipse.org/legal/epl-2.0/ +// +// SPDX-License-Identifier: EPL-2.0 +// +// Contributors: +// Red Hat, Inc. - initial API and implementation + +package main + +import ( + "crypto/tls" + "strconv" + "strings" + + "github.com/redhat-developer/web-terminal-exec/pkg/config" + "github.com/sirupsen/logrus" +) + +func buildTLSConfig() *tls.Config { + if config.TLSMinVersion == "" { + return nil + } + minVersion, err := strconv.ParseUint(config.TLSMinVersion, 10, 16) + if err != nil { + logrus.Warnf("Invalid TLS min version %q, using Go default", config.TLSMinVersion) + return nil + } + name := tls.VersionName(uint16(minVersion)) + if strings.HasPrefix(name, "0x") { + logrus.Warnf("Unknown TLS version %q, ignoring", config.TLSMinVersion) + return nil + } + logrus.Infof("Setting TLS min version to %s", name) + return &tls.Config{MinVersion: uint16(minVersion)} +} diff --git a/tls_test.go b/tls_test.go new file mode 100644 index 0000000..c0f98a7 --- /dev/null +++ b/tls_test.go @@ -0,0 +1,56 @@ +// +// Copyright (c) 2019-2026 Red Hat, Inc. +// This program and the accompanying materials are made +// available under the terms of the Eclipse Public License 2.0 +// which is available at https://www.eclipse.org/legal/epl-2.0/ +// +// SPDX-License-Identifier: EPL-2.0 +// +// Contributors: +// Red Hat, Inc. - initial API and implementation + +package main + +import ( + "crypto/tls" + "io" + "testing" + + "github.com/redhat-developer/web-terminal-exec/pkg/config" + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" +) + +func TestBuildTLSConfig_EmptyVersion(t *testing.T) { + logrus.SetOutput(io.Discard) + config.TLSMinVersion = "" + assert.Nil(t, buildTLSConfig()) +} + +func TestBuildTLSConfig_ValidTLS12(t *testing.T) { + logrus.SetOutput(io.Discard) + config.TLSMinVersion = "771" + tlsConfig := buildTLSConfig() + assert.NotNil(t, tlsConfig) + assert.Equal(t, uint16(tls.VersionTLS12), tlsConfig.MinVersion) +} + +func TestBuildTLSConfig_ValidTLS13(t *testing.T) { + logrus.SetOutput(io.Discard) + config.TLSMinVersion = "772" + tlsConfig := buildTLSConfig() + assert.NotNil(t, tlsConfig) + assert.Equal(t, uint16(tls.VersionTLS13), tlsConfig.MinVersion) +} + +func TestBuildTLSConfig_InvalidString(t *testing.T) { + logrus.SetOutput(io.Discard) + config.TLSMinVersion = "not-a-number" + assert.Nil(t, buildTLSConfig()) +} + +func TestBuildTLSConfig_UnknownVersion(t *testing.T) { + logrus.SetOutput(io.Discard) + config.TLSMinVersion = "999" + assert.Nil(t, buildTLSConfig()) +} From c1a77b9d84b9fb80a4c5df1363eaac1b40da95a2 Mon Sep 17 00:00:00 2001 From: David Kwon Date: Mon, 2 Nov 2026 17:23:41 -0500 Subject: [PATCH 3/5] Reject SSLv3 and other unsupported TLS versions via allowlist, update test functions Co-Authored-By: Claude Opus 4.6 Signed-off-by: David Kwon --- pkg/config/config.go | 1 + tls.go | 18 ++++++--- tls_test.go | 96 +++++++++++++++++++++++++++++++------------- 3 files changed, 80 insertions(+), 35 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index fc440e5..2a7f8e0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -203,6 +203,7 @@ func ResetConfigForTest() { PodSelector = "" UseTLS = false UseBearerToken = false + TLSMinVersion = "" defaultURLValue = ":4444" defaultAuthenticatedUserID = "\x00" defaultPodSelector = "" diff --git a/tls.go b/tls.go index d035a2f..e4be9a7 100644 --- a/tls.go +++ b/tls.go @@ -14,12 +14,18 @@ package main import ( "crypto/tls" "strconv" - "strings" "github.com/redhat-developer/web-terminal-exec/pkg/config" "github.com/sirupsen/logrus" ) +var supportedTLSVersions = map[uint16]bool{ + tls.VersionTLS10: true, + tls.VersionTLS11: true, + tls.VersionTLS12: true, + tls.VersionTLS13: true, +} + func buildTLSConfig() *tls.Config { if config.TLSMinVersion == "" { return nil @@ -29,11 +35,11 @@ func buildTLSConfig() *tls.Config { logrus.Warnf("Invalid TLS min version %q, using Go default", config.TLSMinVersion) return nil } - name := tls.VersionName(uint16(minVersion)) - if strings.HasPrefix(name, "0x") { - logrus.Warnf("Unknown TLS version %q, ignoring", config.TLSMinVersion) + v := uint16(minVersion) + if !supportedTLSVersions[v] { + logrus.Warnf("Unsupported TLS version %q, ignoring", config.TLSMinVersion) return nil } - logrus.Infof("Setting TLS min version to %s", name) - return &tls.Config{MinVersion: uint16(minVersion)} + logrus.Infof("Setting TLS min version to %s", tls.VersionName(v)) + return &tls.Config{MinVersion: v} } diff --git a/tls_test.go b/tls_test.go index c0f98a7..b344c47 100644 --- a/tls_test.go +++ b/tls_test.go @@ -21,36 +21,74 @@ import ( "github.com/stretchr/testify/assert" ) -func TestBuildTLSConfig_EmptyVersion(t *testing.T) { - logrus.SetOutput(io.Discard) - config.TLSMinVersion = "" - assert.Nil(t, buildTLSConfig()) -} +func TestBuildTLSConfig(t *testing.T) { + tests := []struct { + name string + version string + wantNil bool + wantMinVer uint16 + }{ + { + name: "empty version returns nil", + version: "", + wantNil: true, + }, + { + name: "valid TLS 1.2", + version: "771", + wantMinVer: tls.VersionTLS12, + }, + { + name: "valid TLS 1.3", + version: "772", + wantMinVer: tls.VersionTLS13, + }, + { + name: "invalid non-numeric string returns nil", + version: "not-a-number", + wantNil: true, + }, + { + name: "valid TLS 1.0", + version: "769", + wantMinVer: tls.VersionTLS10, + }, + { + name: "valid TLS 1.1", + version: "770", + wantMinVer: tls.VersionTLS11, + }, + { + name: "SSLv3 is rejected", + version: "768", + wantNil: true, + }, + { + name: "unknown version returns nil", + version: "999", + wantNil: true, + }, + } -func TestBuildTLSConfig_ValidTLS12(t *testing.T) { - logrus.SetOutput(io.Discard) - config.TLSMinVersion = "771" - tlsConfig := buildTLSConfig() - assert.NotNil(t, tlsConfig) - assert.Equal(t, uint16(tls.VersionTLS12), tlsConfig.MinVersion) -} + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + origOutput := logrus.StandardLogger().Out + origVersion := config.TLSMinVersion + t.Cleanup(func() { + logrus.SetOutput(origOutput) + config.TLSMinVersion = origVersion + }) -func TestBuildTLSConfig_ValidTLS13(t *testing.T) { - logrus.SetOutput(io.Discard) - config.TLSMinVersion = "772" - tlsConfig := buildTLSConfig() - assert.NotNil(t, tlsConfig) - assert.Equal(t, uint16(tls.VersionTLS13), tlsConfig.MinVersion) -} - -func TestBuildTLSConfig_InvalidString(t *testing.T) { - logrus.SetOutput(io.Discard) - config.TLSMinVersion = "not-a-number" - assert.Nil(t, buildTLSConfig()) -} + logrus.SetOutput(io.Discard) + config.TLSMinVersion = tt.version -func TestBuildTLSConfig_UnknownVersion(t *testing.T) { - logrus.SetOutput(io.Discard) - config.TLSMinVersion = "999" - assert.Nil(t, buildTLSConfig()) + result := buildTLSConfig() + if tt.wantNil { + assert.Nil(t, result) + } else { + assert.NotNil(t, result) + assert.Equal(t, tt.wantMinVer, result.MinVersion) + } + }) + } } From f563f891809cd15811c4755bbc3ad97e9e3f093d Mon Sep 17 00:00:00 2001 From: David Kwon Date: Tue, 10 Nov 2026 11:03:37 -0500 Subject: [PATCH 4/5] Update readme to document "TLS_MIN_VERSION" Update build/Dockerfile to default to amd64, pass in TARGETARCH to make compile Signed-off-by: David Kwon --- README.md | 6 ++++++ build/Dockerfile | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dc2761e..868e7e2 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,12 @@ If a token is not provided or does not match what is expected, the server return Host:Port address for the Web Terminal Exec server. (default ":4444") ``` +## Environment variables +The following environment variables configure runtime behavior of the server: +| Variable | Description | Default | +|----------|-------------|---------| +| `TLS_MIN_VERSION` | Minimum TLS version as a decimal uint16 value. Supported values: `769` (TLS 1.0), `770` (TLS 1.1), `771` (TLS 1.2), `772` (TLS 1.3). | Go default | + ## Development The Web Terminal Exec component is intended to only run within an OpenShift cluster in the context of a Web Terminal Operator installation. To test builds of Web Terminal Exec in an OpenShift cluster, edit the web-terminal-exec DevWorkspaceTemplate created by the Web Terminal Operator to use the in-development image. Alternatively, individual Web Terminal instances can be edited to use a custom image for testing. Running locally or in isolation (i.e. without the Web Terminal Operator installed) is not currently supported. diff --git a/build/Dockerfile b/build/Dockerfile index 12a9957..b13024d 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,5 +1,6 @@ # https://access.redhat.com/containers/?tab=tags#/registry.access.redhat.com/ubi9/go-toolset FROM registry.access.redhat.com/ubi9/go-toolset:1.26.5-1784190466 AS builder +ARG TARGETARCH=amd64 ENV GOPATH=/go/ USER root WORKDIR /web-terminal-exec @@ -15,7 +16,7 @@ RUN go env GOPROXY && \ COPY . . # Compile Web Terminal Exec binary -RUN make compile +RUN make compile ARCH=${TARGETARCH} # https://access.redhat.com/containers/?tab=tags#/registry.access.redhat.com/ubi9-minimal FROM registry.access.redhat.com/ubi9/ubi-minimal:9.8-1784092902 From a94c811fd3412872814de34e911fd8d3f65089e8 Mon Sep 17 00:00:00 2001 From: David Kwon Date: Tue, 10 Nov 2026 11:13:17 -0500 Subject: [PATCH 5/5] Set arch for docker build Signed-off-by: David Kwon --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 779d324..7d0c9e3 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ docker: docker-build docker-push ### docker-build: Builds the Web Terminal Exec image docker-build: - $(DOCKER) build . -t ${WEB_TERMINAL_EXEC_IMG} -f build/Dockerfile + $(DOCKER) build . -t ${WEB_TERMINAL_EXEC_IMG} -f build/Dockerfile --build-arg TARGETARCH=$(ARCH) ### docker-push: Web Terminal Exec image docker-push: