Skip to content

Commit 2d7836a

Browse files
dpaasman00jriguera
authored andcommitted
[cmd/opampsupervisor] Conditionally use TLS config (open-telemetry#35363)
**Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> Fixes an issue where TLS would be used despite the opamp server using `ws` or `http` protocols. Before a TLS config would always get created, causing the connection to always use TLS settings. This change first checks which protocol we're using before creating a TLS config. **Link to tracking Issue:** <Issue number if applicable> Fixes open-telemetry#35283 **Testing:** <Describe what testing was performed and which tests were added.> Removed `tls.insecure_skip_verify: true` from e2e test configs which were using `ws` protocol since they are no longer needed. **Documentation:** <Describe the documentation added.>
1 parent 5c75f28 commit 2d7836a

8 files changed

+39
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: opampsupervisor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Only use TLS config when connecting to OpAMP server if using `wss` or `https` protocols.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35283]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

cmd/opampsupervisor/supervisor/supervisor.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ package supervisor
66
import (
77
"bytes"
88
"context"
9+
"crypto/tls"
910
_ "embed"
1011
"errors"
1112
"fmt"
1213
"net"
1314
"net/http"
15+
"net/url"
1416
"os"
1517
"path/filepath"
1618
"sort"
@@ -366,9 +368,17 @@ func (s *Supervisor) startOpAMP() error {
366368
func (s *Supervisor) startOpAMPClient() error {
367369
s.opampClient = client.NewWebSocket(newLoggerFromZap(s.logger))
368370

369-
tlsConfig, err := s.config.Server.TLSSetting.LoadTLSConfig(context.Background())
371+
// determine if we need to load a TLS config or not
372+
var tlsConfig *tls.Config
373+
parsedURL, err := url.Parse(s.config.Server.Endpoint)
370374
if err != nil {
371-
return err
375+
return fmt.Errorf("parse server endpoint: %w", err)
376+
}
377+
if parsedURL.Scheme == "wss" || parsedURL.Scheme == "https" {
378+
tlsConfig, err = s.config.Server.TLSSetting.LoadTLSConfig(context.Background())
379+
if err != nil {
380+
return err
381+
}
372382
}
373383

374384
s.logger.Debug("Connecting to OpAMP server...", zap.String("endpoint", s.config.Server.Endpoint), zap.Any("headers", s.config.Server.Headers))

cmd/opampsupervisor/testdata/supervisor/supervisor_accepts_conn.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
server:
22
endpoint: ws://{{.url}}/v1/opamp
3-
tls:
4-
insecure: true
53

64
capabilities:
75
reports_effective_config: true

cmd/opampsupervisor/testdata/supervisor/supervisor_agent_description.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
server:
22
endpoint: ws://{{.url}}/v1/opamp
3-
tls:
4-
insecure: true
53

64
capabilities:
75
reports_effective_config: true

cmd/opampsupervisor/testdata/supervisor/supervisor_basic.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
server:
22
endpoint: ws://{{.url}}/v1/opamp
3-
tls:
4-
insecure: true
53

64
capabilities:
75
reports_effective_config: true

cmd/opampsupervisor/testdata/supervisor/supervisor_healthcheck_port.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
server:
22
endpoint: ws://{{.url}}/v1/opamp
3-
tls:
4-
insecure: true
53

64
capabilities:
75
reports_effective_config: true

cmd/opampsupervisor/testdata/supervisor/supervisor_nocap.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
server:
22
endpoint: ws://{{.url}}/v1/opamp
3-
tls:
4-
insecure: true
53

64
capabilities:
75
reports_effective_config: false

cmd/opampsupervisor/testdata/supervisor/supervisor_persistence.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
server:
22
endpoint: ws://{{.url}}/v1/opamp
3-
tls:
4-
insecure: true
53

64
capabilities:
75
reports_effective_config: true

0 commit comments

Comments
 (0)