Skip to content

Read minimum TLS version from env var - #142

Merged
dkwon17 merged 6 commits into
mainfrom
tls
Nov 10, 2026
Merged

dkwon17 merged 6 commits into
mainfrom
tls

Conversation

@dkwon17

@dkwon17 dkwon17 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

The exec image will read the minimum TLS version from an environment variable and apply it to the server.

What issues does this PR fix or reference?

https://redhat.atlassian.net/browse/WTO-353?search_id=ecd2f8bd-0ab7-4924-9d77-6cef1d370be1&referrer=quick-find&xpis=eyJicmlkZ2UiOiJxdWlja0ZpbmQiLCJpZCI6IjE3OTIxODI4OTc4MTIiLCJzb3VyY2UiOiJqaXJhLXNvZnR3YXJlIn0%3D

Is it tested? How?

Please refer to redhat-developer/web-terminal-operator#203

Signed-off-by: David Kwon <dakwon@redhat.com>
@dkwon17
dkwon17 requested a review from ibuziuk as a code owner October 16, 2026 20:57
@codecov-commenter

codecov-commenter commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.17%. Comparing base (91ac8c8) to head (89f1acd).

Files with missing lines Patch % Lines
main.go 0.00% 1 Missing ⚠️
pkg/config/config.go 66.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #142      +/-   ##
==========================================
+ Coverage   64.47%   65.17%   +0.69%     
==========================================
  Files          15       16       +1     
  Lines         563      580      +17     
==========================================
+ Hits          363      378      +15     
- Misses        180      182       +2     
  Partials       20       20              
Flag Coverage Δ
unit-tests 65.17% <88.23%> (+0.69%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
tls.go 100.00% <100.00%> (ø)
main.go 0.00% <0.00%> (ø)
pkg/config/config.go 59.59% <66.66%> (+0.22%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread main.go Outdated
if config.TLSMinVersion == "" {
return nil
}
minVersion, err := strconv.ParseUint(config.TLSMinVersion, 10, 16)

@rohanKanojia rohanKanojia Oct 19, 2026 •

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 allow only known TLS versions here? ParseUint(..., 10, 16) accepts any uint16.

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.

In my latest commit, I updated this so that the TLS version is parsed by VersionName() from crypto/tls

Comment thread main.go Outdated
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

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.

Returning nil hands the decision to Go’s runtime default environment. Would an explicit &tls.Config{MinVersion: tls.VersionTLS12} work for both the unset and invalid cases? The behaviour would be the same today, but it wouldn’t depend on the environment.

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.

IMHO I prefer to leave this as is in case TLS 1.2 becomes deprecated, WDYT?

Move tls related logic to tls.go

Signed-off-by: David Kwon <dakwon@redhat.com>
Comment thread tls_test.go Outdated
)

func TestBuildTLSConfig_EmptyVersion(t *testing.T) {
logrus.SetOutput(io.Discard)

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.

These tests set config.TLSMinVersion and the global logrus output without restoring them, which could leak into other tests in main. Maybe add a t.Cleanup to reset both?

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 second thought, These tests could be converted into a table driven test, WDYT?

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.

Sounds good, updated in my latest commit

Comment thread tls_test.go Outdated
)

func TestBuildTLSConfig_EmptyVersion(t *testing.T) {
logrus.SetOutput(io.Discard)

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 second thought, These tests could be converted into a table driven test, WDYT?

Comment thread tls.go Outdated
return nil
}
name := tls.VersionName(uint16(minVersion))
if strings.HasPrefix(name, "0x") {

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.

nit, tls.VersionName(768) returns "SSLv3" rather than a 0x… string, so TLS_MIN_VERSION=768 would pass this check and log “Setting TLS min version to SSLv3”, even though crypto/tls doesn’t support SSLv3. Would an explicit allowlist work here?

switch v := uint16(minVersion); v {
case tls.VersionTLS10, tls.VersionTLS11, tls.VersionTLS12, tls.VersionTLS13:
    logrus.Infof("Setting TLS min version to %s", tls.VersionName(v))
    return &tls.Config{MinVersion: v}
default:
    logrus.Warnf("Unsupported TLS min version %q, using Go default", config.TLSMinVersion)
    return nil
}

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 initially wanted to avoid hardcoding TLS versions in case TLS 1.4 is adopted, but that seems like that would be quite far into the future. Anyways, I've updated the code to only accept TLS 1.0 - 1.3

Comment thread pkg/config/config.go
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

… test functions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: David Kwon <dakwon@redhat.com>
Comment thread Makefile
# 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.

Comment thread README.md
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 |

Update build/Dockerfile to default to amd64, pass in TARGETARCH to make compile

Signed-off-by: David Kwon <dakwon@redhat.com>
Signed-off-by: David Kwon <dakwon@redhat.com>
@dkwon17
dkwon17 merged commit eca2171 into main Nov 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants