Repository navigation
Read minimum TLS version from env var #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
59d3982
4ff1ce3
c1a77b9
f563f89
a94c811
89f1acd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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`. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a new section in the readme for this: |
||
|
|
||
| | Rule | Purpose | | ||
| | --- | --- | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in my latest commit |
||
|
|
@@ -195,6 +203,7 @@ func ResetConfigForTest() { | |
| PodSelector = "" | ||
| UseTLS = false | ||
| UseBearerToken = false | ||
| TLSMinVersion = "" | ||
| defaultURLValue = ":4444" | ||
| defaultAuthenticatedUserID = "\x00" | ||
| defaultPodSelector = "" | ||
|
|
||
| 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} | ||
| } |
| 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) | ||
| } | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On main,
ARCHis unset, soGOARCHis empty and Go builds for the host. With this default, make compile always producesamd64, andbuild/Dockerfileruns it without passingARCH. Suggest passingARG TARGETARCHthrough the Dockerfile.There was a problem hiding this comment.
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.