Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On main, ARCH is unset, so GOARCH is empty and Go builds for the host. With this default, make compile always produces amd64, and build/Dockerfile runs it without passing ARCH. Suggest passing ARG TARGETARCH through the Dockerfile.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in the latest commits to use TARGETARCH in the build/Dockerfile.



### fmt: Formats code using goimports
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could TLS_MIN_VERSION be documented here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new section in the readme for this:

## 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 |


| Rule | Purpose |
| --- | --- |
Expand Down
3 changes: 2 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -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/
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -64,6 +69,7 @@ const (
devworkspaceIDEnvVar = "DEVWORKSPACE_ID"
devworkspaceNameEnvVar = "DEVWORKSPACE_NAME"
devworkspaceNamespaceEnvVar = "DEVWORKSPACE_NAMESPACE"
tlsMinVersionEnvVar = "TLS_MIN_VERSION"
)

var (
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add TLSMinVersion = "" to ResetConfigForTest()? Then the new field is cleared like the others.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in my latest commit

Expand All @@ -195,6 +203,7 @@ func ResetConfigForTest() {
PodSelector = ""
UseTLS = false
UseBearerToken = false
TLSMinVersion = ""
defaultURLValue = ":4444"
defaultAuthenticatedUserID = "\x00"
defaultPodSelector = ""
Expand Down
45 changes: 45 additions & 0 deletions tls.go
Original file line number Diff line number Diff line change
@@ -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}
}
94 changes: 94 additions & 0 deletions tls_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
Loading