GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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) #407

New issue
Copy link
New issue
Copy link
Closed
Closed
Add TLS tracing support to netty (portion of JVM based languages)#407
Copy link
Assignees
ddelnano
Labels
area/datacollectorIssues related to Stirling (datacollector)kind/featureNew feature or requestpriority/important-soonMust be staffed and worked on either currently, or very soon, ideally in time for the next release.triage/acceptedIndicates an issue or PR is ready to be actively worked on.
Milestone
2022-Q3

Description

@ddelnano
ddelnano
opened on Feb 22, 2022
Issue body actions

Is 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.

Activity

  1. oazizi000 commented on Feb 23, 2022

    @oazizi000
    oazizi000
    on Feb 23, 2022
    Contributor
    More actions

    @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.

  2. ddelnano commented on Feb 23, 2022

    @ddelnano
    ddelnano
    on Feb 23, 2022
    MemberAuthor
    More actions

    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)
    
  3. ddelnano commented on Mar 4, 2022

    @ddelnano
    ddelnano
    on Mar 4, 2022
    MemberAuthor
    More actions

    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.

  4. copybaranaut
    added a commit that references this issue on Mar 19, 2022

    Update thriftmux container to work with mtls

    ed77a68
  5. normanmaurer
    added a commit that references this issue on Jun 3, 2022

    Add SSL.bioSetFd method to JNI code to support Pixie integration (#731)

    4141ffe
  6. chrisvest
    added 2 commits that reference this issue on Jun 10, 2022

    Update SslHandler to set bio fd member to facilitate openssl tracing …

    bc085b0

    Update SslHandler to set bio fd member to facilitate openssl tracing …

    23e89e1
  7. oazizi000
    added
    kind/featureNew feature or request
    area/datacollectorIssues related to Stirling (datacollector)
    on Jun 15, 2022
  8. zasgar
    added this to the 2022-Q3 milestone on Jun 16, 2022
  9. zasgar
    assigned
    ddelnano
    on Jun 16, 2022
  10. zasgar
    added
    triage/acceptedIndicates an issue or PR is ready to be actively worked on.
    priority/important-soonMust be staffed and worked on either currently, or very soon, ideally in time for the next release.
    on Jun 16, 2022
  11. raidyue
    added a commit that references this issue on Jul 8, 2022

    Update SslHandler to set bio fd member to facilitate openssl tracing …

    672547c
  12. franz1981
    added a commit that references this issue on Aug 22, 2022

    Update SslHandler to set bio fd member to facilitate openssl tracing …

    41db6e8
  13. copybaranaut
    added a commit that references this issue on Aug 24, 2022

    Upgrade finagle to version that includes tls tracing compatible netty…

    e577064
  14. copybaranaut
    added 2 commits that reference this issue on Oct 1, 2022

    Remove byteman from thriftmux container

    c0d8ebb

    Implement changes to get finagle tls tracing working.

    86b3c31
  15. ddelnano commented on Oct 5, 2022

    @ddelnano
    ddelnano
    on Oct 5, 2022
    MemberAuthor
    More actions

    This is finally implemented with 86b3c31 being merged 🥳

    The following changes were needed in order to complete this:

    • Integrate mux parser into stirling #367 -- initial support for mux protocol tracing (this was spread over more PRs, but this was the final one)
    • Update thriftmux test container to support tls via a command line flag #413 -- updated thriftmux docker image used during testing to support listening on tls
    • Enhance openssl tracing to fallback to function pointers when dlsym fails #428 -- implemented a way to determine netty's openssl version library by calling a function removed from a shared object's .dynsym
    • Fix thriftmux container from 22.04 upgrade #464 -- upgraded finagle to a version that included upstreamed netty changes (Update SslHandler to set bio fd member to facilitate openssl tracing (Pixie integration) netty/netty#12438, Add SSL.bioSetFd method to JNI code to support Pixie integration netty/netty-tcnative#731)
    • Ensure TraceMode::OnNewerKernel doesn't cause older kernels to fail to load BPF programs due to instruction length #603 -- fixed a bug that prevented mux protocol tracing to be enabled on newer kernels
    • Enable mux tracing on newer kernels (>= 5.2) #605 -- enabled mux traffic tracing (non tls) for newer kernels. Previously this needed runtime configuration to enable.
    • Remove byteman from thriftmux container #606 -- this removed a temporary workaround until stirling could handle netty's dynamic file name.

    It will be available in the next Pixie release (which should come later this week).

  16. ddelnano
    closed this as completedon Oct 5, 2022
  17. ddelnano commented on Oct 17, 2022

    @ddelnano
    ddelnano
    on Oct 17, 2022
    MemberAuthor
    More actions

    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:

    1. 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
    
    1. 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.
    2. 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.

  18. ddelnano commented on Oct 23, 2022

    @ddelnano
    ddelnano
    on Oct 23, 2022
    MemberAuthor
    More actions

    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).

  19. entlein
    added 4 commits that reference this issue on Jun 2, 2026

    Update thriftmux container to work with mtls

    710b290

    Upgrade finagle to version that includes tls tracing compatible netty…

    b20c607

    Remove byteman from thriftmux container

    1a72aeb

    Implement changes to get finagle tls tracing working.

    c785ca5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ddelnano
    ddelnano

Labels

area/datacollectorIssues related to Stirling (datacollector)kind/featureNew feature or requestpriority/important-soonMust be staffed and worked on either currently, or very soon, ideally in time for the next release.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

    Milestone

    • 2022-Q3

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.