GeezerVison is showing github.com — Add TLS tracing support to netty (portion of JVM based languages) · Issue #407 · pixie-io/pixie
Add TLS tracing support to netty (portion of JVM based languages) #407DescriptionIs your feature request related to a problem? Please describe.
Projects like finagle uses netty for TLS (specifically netty-tcnative in finagle's case). Netty is a popular open source library so this should allow TLS tracing for any JVM based application using netty-tcnative.
Describe the solution you'd like
- netty TLS tracing should allow tracing encrypted mux connections
- netty TLS tracing should have feature parity with the existing openssl tracing
I'm happy to contribute my own time for this solution so I'm looking for any guidance on the "Additional context" section below (assuming the Pixie team is happy to accept this contribution).
Describe alternatives you've considered
N/A
Additional context
netty-tcnative has a few options for how it implements its tls: statically linked boringssl, statically linked openssl or a dynamically linked openssl. The pom.xml files in those directories explain how the compilation happens in more detail.
For the services I'm interested in instrumenting, they use the statically linked boringssl option. These services work by depending on finagle-netty4, which ultimately uses the aforementioned option. This was determined by inspecting the main application jar's Manifest file:
grep netty META-INF/MANIFEST.MF | grep native
libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar li
Looking inside the libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar jar, you will find that it has it's own shared library file. This shared object contains the expected SSL_write and SSL_read symbols used by Pixie's openssl tracing:
$ objdump --syms META-INF/native/libnetty_tcnative_linux_x86_64.so | grep SSL_write
00000000000249b0 l F .text 0000000000000040 netty_internal_tcnative_SSL_writeToSSL
0000000000034920 l F .text 000000000000015a SSL_write
ddelnano[7]smf1-cyz-26-sr1[mesos.prod.slave] netty4-tcnative $ objdump --syms META-INF/native/libnetty_tcnative_linux_x86_64.so | grep SSL_read
0000000000024970 l F .text 0000000000000040 netty_internal_tcnative_SSL_readFromSSL
0000000000036890 l F .text 00000000000000ff SSL_read
After looking at Pixie's openssl demo, I realized that in order to set another uprobe for this shared library we need to find the object file path. Since each service is bundled with its own shared library, I'm not sure how this would be determined.
In order to better understand this, I used pmap on a running service to see where the shared library existed. Unfortunately this didn't reveal the file path that the object file exists at.
$ sudo pmap 106762 | grep netty
ddelnano 512704 0.0 0.0 112824 2268 pts/0 S+ 15:59 0:00 grep --color=auto 106762
00007f1de2fb7000 2188K r-x-- libnetty_tcnative_linux_x86_648014508084024950371.so (deleted)
00007f1de31da000 2048K ----- libnetty_tcnative_linux_x86_648014508084024950371.so (deleted)
00007f1de33da000 72K r---- libnetty_tcnative_linux_x86_648014508084024950371.so (deleted)
00007f1de33ec000 4K rw--- libnetty_tcnative_linux_x86_648014508084024950371.so (deleted)
00007f1e8c4d9000 64K r-x-- libnetty_transport_native_epoll_x86_6416087313860959783777.so (deleted)
00007f1e8c4e9000 2044K ----- libnetty_transport_native_epoll_x86_6416087313860959783777.so (deleted)
00007f1e8c6e8000 8K rw--- libnetty_transport_native_epoll_x86_6416087313860959783777.so (deleted)
The next way I tried to determine this was through straceing the application to see where that file path exists as the JVM loads it. I was able to see the following open syscalls that indicate that the file existed for a short period of time under /tmp.
[tw-mbp-ddelnano netty-tcnative (main)]% grep tcnative ~/Desktop/netty_tcnative_strace.txt
[pid 89513] stat("/usr/local/relay-proxee/libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar", {st_mode=S_IFREG|0755, st_size=4022473, ...}) = 0
[pid 89513] stat("/usr/local/relay-proxee/libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar", <unfinished ...>
[pid 89513] open("/usr/local/relay-proxee/libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar", O_RDONLY <unfinished ...>
[pid 89513] <... read resumed>"-tcnative-boringssl-static/pom.p"..., 128) = 128
[pid 89513] stat("/usr/local/relay-proxee/libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar", <unfinished ...>
[pid 89513] stat("/usr/local/relay-proxee/libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar", <unfinished ...>
[pid 89513] access("/usr/local/relay-proxee/libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar", R_OK <unfinished ...>
[pid 89513] stat("/usr/local/relay-proxee/libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar", <unfinished ...>
[pid 89513] stat("/usr/local/relay-proxee/libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar", <unfinished ...>
[pid 89870] stat("/usr/lib/jvm/java-11-twitter/lib/libnetty_tcnative_linux_x86_64_fedora.so", <unfinished ...>
[pid 89870] stat("/usr/java/packages/lib/libnetty_tcnative_linux_x86_64_fedora.so", <unfinished ...>
[pid 89870] stat("/usr/lib64/libnetty_tcnative_linux_x86_64_fedora.so", <unfinished ...>
[pid 89870] stat("/lib64/libnetty_tcnative_linux_x86_64_fedora.so", 0x7fc6b8fa1aa0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/lib/libnetty_tcnative_linux_x86_64_fedora.so", 0x7fc6b8fa1aa0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/usr/lib/libnetty_tcnative_linux_x86_64_fedora.so", 0x7fc6b8fa1aa0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/usr/lib/jvm/java-11-twitter/lib/libnetty_tcnative_linux_x86_64_fedora.so", 0x7fc6b8fa38a0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/usr/java/packages/lib/libnetty_tcnative_linux_x86_64_fedora.so", 0x7fc6b8fa38a0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/usr/lib64/libnetty_tcnative_linux_x86_64_fedora.so", 0x7fc6b8fa38a0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/lib64/libnetty_tcnative_linux_x86_64_fedora.so", 0x7fc6b8fa38a0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/lib/libnetty_tcnative_linux_x86_64_fedora.so", 0x7fc6b8fa38a0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/usr/lib/libnetty_tcnative_linux_x86_64_fedora.so", 0x7fc6b8fa38a0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/usr/local/relay-proxee/libs/netty-tcnative-boringssl-static-2.0.35.Final.jar", <unfinished ...>
[pid 89870] stat("/usr/lib/jvm/java-11-twitter/lib/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/usr/java/packages/lib/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/usr/lib64/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/lib64/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/lib/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/usr/lib/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/usr/lib/jvm/java-11-twitter/lib/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/usr/java/packages/lib/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/usr/lib64/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/lib64/libnetty_tcnative_linux_x86_64.so", <unfinished ...>
[pid 89870] stat("/lib/libnetty_tcnative_linux_x86_64.so", 0x7fc6b8fa38a0) = -1 ENOENT (No such file or directory)
[pid 89870] stat("/usr/lib/libnetty_tcnative_linux_x86_64.so", 0x7fc6b8fa38a0) = -1 ENOENT (No such file or directory)
[pid 89870] open("/tmp/libnetty_tcnative_linux_x86_644671207194557745034.so", O_WRONLY|O_CREAT|O_EXCL, 0600 <unfinished ...>
[pid 89870] stat("/usr/local/relay-proxee/libs/3rdparty.jvm.io.netty.netty4-tcnative-boringssl-static-0.jar", <unfinished ...>
[pid 89870] open("/tmp/libnetty_tcnative_linux_x86_644671207194557745034.so", O_WRONLY|O_CREAT|O_TRUNC, 0666 <unfinished ...>
[pid 89870] write(1125, "_tcnative_SSL_getTimeout\0netty_i"..., 8192) = 8192
[pid 89870] write(1125, "ds\0netty_internal_tcnative_Nativ"..., 8192) = 8192
[pid 89870] stat("/tmp/libnetty_tcnative_linux_x86_644671207194557745034.so", {st_mode=S_IFREG|0600, st_size=2644109, ...}) = 0
[pid 89870] lstat("/tmp/libnetty_tcnative_linux_x86_644671207194557745034.so", {st_mode=S_IFREG|0600, st_size=2644109, ...}) = 0
[pid 89870] open("/tmp/libnetty_tcnative_linux_x86_644671207194557745034.so", O_RDONLY) = 1125
[pid 89870] open("/tmp/libnetty_tcnative_linux_x86_644671207194557745034.so", O_RDONLY|O_CLOEXEC) = 1125
[pid 89870] unlink("/tmp/libnetty_tcnative_linux_x86_644671207194557745034.so") = 0
This seemed to indicate that the java application created a file at /tmp/libnetty_tcnative_linux_x86_644671207194557745034.so. It makes me think that the JVM manages these files as part of System.loadLibrary, although I wasn't able to find more information about this. After the shared library is created, it is later removed by unlink so it seems they exist for a short duration.
Implementing this support will require having a deeper understanding of how the JVM handles shared object files that are bundled within a given jar. Activityoazizi000 commented on Feb 23, 2022 @ddelnano This is great. In a general sense, if we get this to work, we could even think of this as generally supporting statically linked boringssl. That'll end up covering some of netty and anything else that uses boringssl.
As an initial version, we could focus on boringssl instances that have symbols in the binary (which your example appears to have). Binaries where the symbols are stripped get a bit harder, but we can then look into options for detecting where those functions are.
Finally, regarding the path of the so file: Have you tried looking at the /proc/<pid>/maps? That usually has the full path of the shared library you're looking for. And we already have code for scanning that inside of Stirling. ddelnano commented on Feb 23, 2022 Generally supporting boringssl sounds great and I'd be happy to include that as part of this scope. I wasn't sure how portable this would be between how different applications link the same library since my understanding of ELF, linking, etc is somewhat limited.
Binaries where the symbols are stripped get a bit harder, but we can then look into options for detecting where those functions are.
I didn't realize that was possible to do. What's the general idea for how that would work?
Have you tried looking at the /proc//maps?
I did not, but that seems to point out the same /tmp directory file that was removed 🤔
$ sudo cat /proc/106762/maps | grep tcnative
7f1de2fb7000-7f1de31da000 r-xp 00000000 fd:02 13796 /tmp/libnetty_tcnative_linux_x86_648014508084024950371.so (deleted)
7f1de31da000-7f1de33da000 ---p 00223000 fd:02 13796 /tmp/libnetty_tcnative_linux_x86_648014508084024950371.so (deleted)
7f1de33da000-7f1de33ec000 r--p 00223000 fd:02 13796 /tmp/libnetty_tcnative_linux_x86_648014508084024950371.so (deleted)
7f1de33ec000-7f1de33ed000 rw-p 00235000 fd:02 13796 /tmp/libnetty_tcnative_linux_x86_648014508084024950371.so (deleted)
ddelnano commented on Mar 4, 2022 Since my last comment, we've determined that netty is responsible for deleting the netty-tcnative shared library and for creating it at a random filepath. The former is something we can disable through a netty flag.
The latter is something we need to solve for, however, in order to unblock testing I've created a thriftmux image that uses byteman to inject JVM bytecode to 'patch' netty's dynamic filepath generation for the netty-tcnative library only (code diff). This is something we need to solve for in order to productionize netty tls tracing, but will unblock us from moving forward with prototyping this.
With the change linked above, the library is loaded at a well known file path and is not deleted
/ # pmap 1 | grep tcnative
00007f64c5790000 2192K r-xp /tmp/libnetty_tcnative_linux_x86.so
00007f64c59b4000 2048K ---p /tmp/libnetty_tcnative_linux_x86.so
00007f64c5bb4000 80K rw-p /tmp/libnetty_tcnative_linux_x86.so
With the library issues sorted, I'm now starting to work on implementing an acceptance test for tracing finagle mtls (netty tls) applications (adding additional test cases to openssl_trace_bpf_test.cc. ddelnano commented on Oct 5, 2022 This is finally implemented with 86b3c31 being merged 🥳
The following changes were needed in order to complete this:
It will be available in the next Pixie release (which should come later this week). ddelnano commented on Oct 17, 2022 The past week I tried to run a netty application on a pixie cluster deployed on minikube and I realized there are a few remaining issues to work through. These are all related to the slight differences between pixie's acceptance test environment and the containerized version that runs in production:
- The PEM docker image is missing the
libcrypt1 package, which leads to RawFptrManager issues with libnetty_tcnative.so. This is seen in the error log I noticed below (slack)
W20221017 16:24:23.614436 468593 uprobe_manager.cc:559] Attaching OpenSSL uprobes on dynamic library failed for PID 458961: Internal : Failed to dlopen so file: /host/var/lib/docker/overlay2/029d19d314b31df1be18148ac37e7888ffdc8f123e785f479900eb203045f515/merged/tmp/libnetty_tcnative_linux_x86.so, libcrypt.so.1: cannot open shared object file: No such file or directory
- The
RawFptrManager code is still disabled as a fallback. This needs to be enabled in order for netty TLS tracing to work out of the box.
- Pixie uses a different upid discovery mechanism in prod vs in its acceptance testing (slack). The prod mechanism doesn't work for netty's case and needs to be more deeply investigated
The full details of how I discovered these issues can be seen in this slack thread. ddelnano commented on Oct 23, 2022 After debugging this more, 3 was due to running the netty application outside of k8s (which causes Pixie to ignore the process). I've created #632 for fixing item 1, and I'll follow up with enabling the RawFptrManager by default soon (item 2).
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|