Skip to content

Commit aed2190

Browse files
authored
Enable TLS tracing for applications using dynamically linked OpenSSL v3 (#1337)
Summary: Enable TLS tracing for applications using dynamically linked OpenSSL v3 Relevant Issues: #692 Type of change: /kind feature Test Plan: Existing tests provide the necessary coverage Changelog Message: ```release-note TLS tracing now supports applications using OpenSSL v3 ``` --------- Signed-off-by: Dom Del Nano <ddelnano@pixielabs.ai>
1 parent fa0d741 commit aed2190

4 files changed

Lines changed: 9 additions & 36 deletions

File tree

src/stirling/source_connectors/socket_tracer/BUILD.bazel

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,10 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
1616

17-
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
1817
load("//bazel:pl_build_system.bzl", "pl_cc_binary", "pl_cc_bpf_test", "pl_cc_library", "pl_cc_test")
1918

2019
package(default_visibility = ["//src/stirling:__subpackages__"])
2120

22-
# TODO(ddelnano): Remove once new tls tracing implementation is
23-
# the default and we are ready to enable tracing of openssl v3.
24-
bool_flag(
25-
name = "enable_openssl_v3_testing_flag",
26-
build_setting_default = False,
27-
)
28-
29-
config_setting(
30-
name = "enable_openssl_v3_testing",
31-
flag_values = {
32-
":enable_openssl_v3_testing_flag": "True",
33-
},
34-
)
35-
36-
enable_openssl_v3_tracing_defines = select({
37-
":enable_openssl_v3_testing": ["ENABLE_OPENSSL_V3_TRACING"],
38-
"//conditions:default": [],
39-
})
40-
4121
pl_cc_library(
4222
name = "cc_library",
4323
srcs = glob(
@@ -48,7 +28,6 @@ pl_cc_library(
4828
],
4929
),
5030
hdrs = glob(["*.h"]),
51-
defines = enable_openssl_v3_tracing_defines,
5231
deps = [
5332
"//src/common/exec:cc_library",
5433
"//src/common/grpcutils:cc_library",
@@ -455,7 +434,6 @@ pl_cc_bpf_test(
455434
name = "openssl_trace_bpf_test",
456435
timeout = "long",
457436
srcs = ["openssl_trace_bpf_test.cc"],
458-
defines = enable_openssl_v3_tracing_defines,
459437
flaky = True,
460438
shard_count = 2,
461439
tags = [

src/stirling/source_connectors/socket_tracer/openssl_trace_bpf_test.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,8 @@ typedef ::testing::Types<NginxOpenSSL_1_1_0_ContainerWrapper, NginxOpenSSL_1_1_1
166166
Node12_3_1ContainerWrapper, Node14_18_1AlpineContainerWrapper>
167167
OpenSSLServerImplementations;
168168

169-
// TODO(ddelnano): Remove once new tls tracing implementation is
170-
// the default and we are ready to enable tracing of openssl v3.
171-
#ifdef ENABLE_OPENSSL_V3_TRACING
172169
typedef ::testing::Types<NginxOpenSSL_1_1_1_ContainerWrapper, NginxOpenSSL_3_0_7_ContainerWrapper>
173170
OpenSSLServerNestedSyscallFDImplementations;
174-
#else
175-
typedef ::testing::Types<NginxOpenSSL_1_1_1_ContainerWrapper>
176-
OpenSSLServerNestedSyscallFDImplementations;
177-
#endif
178171

179172
template <typename T>
180173
using OpenSSLTraceTest = BaseOpenSSLTraceTest<T, false>;

src/stirling/source_connectors/socket_tracer/socket_trace_connector.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ DEFINE_uint64(max_body_bytes, gflags::Uint64FromEnv("PL_STIRLING_MAX_BODY_BYTES"
149149

150150
DEFINE_bool(
151151
access_tls_socket_fd_via_syscall,
152-
gflags::BoolFromEnv("PL_ACCESS_TLS_SOCKET_FD_VIA_SYSCALL", false),
152+
gflags::BoolFromEnv("PL_ACCESS_TLS_SOCKET_FD_VIA_SYSCALL", true),
153153
"If true, stirling will identify a socket's fd based on the underlying syscall (read, write, "
154154
"etc) while a user space tls function call occurs. When false, stirling attempts to access the "
155155
"socket fd by walking user space data structures which may be brittle.");

src/stirling/source_connectors/socket_tracer/uprobe_manager.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,17 @@ struct SSLLibMatcher {
285285
HostPathForPIDPathSearchType search_type;
286286
};
287287

288-
// TODO(ddelnano): Remove the ENABLE_OPENSSL_V3_TRACING ifdef once this
289-
// code this could should be enabled outside of test use cases
290288
static constexpr const auto kLibSSLMatchers = MakeArray<SSLLibMatcher>({
291289
SSLLibMatcher{
292290
.libssl = "libssl.so.1.1",
293291
.libcrypto = "libcrypto.so.1.1",
294292
.search_type = HostPathForPIDPathSearchType::kSearchTypeEndsWith,
295293
},
296-
#ifdef ENABLE_OPENSSL_V3_TRACING
297294
SSLLibMatcher{
298295
.libssl = "libssl.so.3",
299296
.libcrypto = "libcrypto.so.3",
300297
.search_type = HostPathForPIDPathSearchType::kSearchTypeEndsWith,
301298
},
302-
#endif
303299
SSLLibMatcher{
304300
.libssl = kLibNettyTcnativePrefix,
305301
.libcrypto = kLibNettyTcnativePrefix,
@@ -314,6 +310,12 @@ StatusOr<int> UProbeManager::AttachOpenSSLUProbesOnDynamicLib(uint32_t pid) {
314310
const auto libssl = ssl_library_match.libssl;
315311
const auto libcrypto = ssl_library_match.libcrypto;
316312

313+
// TODO(ddelnano): The legacy tls tracing implementation does not support OpenSSL v3.
314+
// Remove this once that implementation is removed in addition to the feature toggle.
315+
if (!FLAGS_access_tls_socket_fd_via_syscall && absl::EndsWith(libssl, "so.3")) {
316+
continue;
317+
}
318+
317319
const std::vector<std::string_view> lib_names = {libssl, libcrypto};
318320
const auto search_type = ssl_library_match.search_type;
319321

@@ -342,7 +344,7 @@ StatusOr<int> UProbeManager::AttachOpenSSLUProbesOnDynamicLib(uint32_t pid) {
342344
return error::Internal("libcrypto not found [path = $0]", container_libcrypto.string());
343345
}
344346

345-
if (!FLAGS_access_tls_socket_fd_via_syscall) {
347+
if (!FLAGS_access_tls_socket_fd_via_syscall || libssl == kLibNettyTcnativePrefix) {
346348
auto fptr_manager = std::make_unique<obj_tools::RawFptrManager>(container_libcrypto);
347349

348350
PX_RETURN_IF_ERROR(UpdateOpenSSLSymAddrs(fptr_manager.get(), container_libcrypto, pid));
@@ -359,7 +361,7 @@ StatusOr<int> UProbeManager::AttachOpenSSLUProbesOnDynamicLib(uint32_t pid) {
359361

360362
// TODO(ddelnano): Remove this conditional logic once the new tls tracing
361363
// implementation is the default.
362-
if (FLAGS_access_tls_socket_fd_via_syscall) {
364+
if (FLAGS_access_tls_socket_fd_via_syscall && libssl != kLibNettyTcnativePrefix) {
363365
spec.probe_fn = absl::Substitute("$0_syscall_fd_access", spec.probe_fn);
364366
}
365367
PX_RETURN_IF_ERROR(LogAndAttachUProbe(spec));

0 commit comments

Comments
 (0)