diff --git a/Makefile b/Makefile index 75d83e9..7d0c9e3 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 @@ -76,14 +77,14 @@ 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 ### 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: diff --git a/README.md b/README.md index b5592ad..868e7e2 100644 --- a/README.md +++ b/README.md @@ -65,12 +65,19 @@ 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. 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/build/Dockerfile b/build/Dockerfile index 9499975..8d1b14d 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.10-1794208260 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-1794186349 diff --git a/main.go b/main.go index 2e407d5..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/ @@ -54,6 +54,7 @@ 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) diff --git a/pkg/config/config.go b/pkg/config/config.go index 326d78e..2a7f8e0 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() { @@ -195,6 +203,7 @@ func ResetConfigForTest() { PodSelector = "" UseTLS = false UseBearerToken = false + TLSMinVersion = "" defaultURLValue = ":4444" defaultAuthenticatedUserID = "\x00" defaultPodSelector = "" diff --git a/tls.go b/tls.go new file mode 100644 index 0000000..e4be9a7 --- /dev/null +++ b/tls.go @@ -0,0 +1,45 @@ +// +// 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" + + "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 + } + 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 + } + 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", tls.VersionName(v)) + return &tls.Config{MinVersion: v} +} diff --git a/tls_test.go b/tls_test.go new file mode 100644 index 0000000..b344c47 --- /dev/null +++ b/tls_test.go @@ -0,0 +1,94 @@ +// +// 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(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, + }, + } + + 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 + }) + + logrus.SetOutput(io.Discard) + config.TLSMinVersion = tt.version + + result := buildTLSConfig() + if tt.wantNil { + assert.Nil(t, result) + } else { + assert.NotNil(t, result) + assert.Equal(t, tt.wantMinVer, result.MinVersion) + } + }) + } +}