raphw / byte-buddy

Runtime code generation for the Java virtual machine.
https://bytebuddy.net
Apache License 2.0
6.29k stars 807 forks source link

Update NamedPipe handling to allow callback to Service Accounts #1616

Closed FelixMarxIBM closed 7 months ago

FelixMarxIBM commented 7 months ago

While testing attachment via byte-buddy on Windows, we noticed that the NamedPipe is not able to report back the current state if the attachment was started from a service account. This is possible with the normal attach-tools.jar so I investigated what the difference is and it turns out that the hotspot attachment uses named pipes with a SecurityDescriptor. See VirtualMachineImpl.c how that is done. This PR does the same thing in JNA and in our test the attachment works afterwards when started from a service account against a JVM started from a user.

VirtualMachineImpl.c:

    // Custom Security Descriptor is required here to "get" Medium Integrity Level.
    // In order to allow Medium Integrity Level clients to open
    // and use a NamedPipe created by an High Integrity Level process.
    TCHAR *szSD = TEXT("D:")                  // Discretionary ACL
                  TEXT("(A;OICI;GRGW;;;WD)")  // Allow read/write to Everybody
                  TEXT("(A;OICI;GA;;;SY)")    // Allow full control to System
                  TEXT("(A;OICI;GA;;;BA)");   // Allow full control to Administrators
FelixMarxIBM commented 7 months ago

@raphw should I create an Issue for that or is a PR enough?

raphw commented 7 months ago

Thanks, I come across windows so rarely, great you could contribute this! I'll merge it obce the checks complete.

FelixMarxIBM commented 7 months ago

Hi @raphw I saw that the build failed here with the error

Error:  /home/runner/work/byte-buddy/byte-buddy/byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java:1083: @return tag should be present and have description. [JavadocMethod]

I'll quickly create a follow up PR to fix that at #1621

FelixMarxIBM commented 7 months ago

Hi @raphw I think the milestone is wrong here and should be 1.14.14, not 1.12.14