Repository navigation
Conversation
grpc-okhttp's channelz support (Utils.getSocketOptions, reached from the client and server transports' getStats()) calls getKeepAlive(), getOOBInline(), getReuseAddress() and getTrafficClass(), and only catches SocketException (logging Level.SEVERE on catch). Returning false / 0 instead of throwing UnsupportedOperationException lets channelz socket queries succeed cleanly on UDS transports.
d139f41 to
f00f22a
Compare
|
Good day @kannanjgithub ! Eric recommended that I ask you to review this. Would you have a moment to look? Thanks! |
| * {@code adb shell run-as} can connect as the app itself). The server does not yet expose peer | ||
| * identity, so serve nothing that anyone with debugging access (or, on the older tiers, another app |
There was a problem hiding this comment.
LocalSocket.getPeerCredentials() gives us uid/pid/gid for free on accepted sockets. Is there a plan (or a tracking issue) to expose them, for example as the remote SocketAddress or a transport attribute? Then an interceptor could do uid == Process.myUid() || uid == SHELL_UID. That would close the gap for ABSTRACT on Android < 9 or targetSdk ≤ 27, where other apps can connect. A follow-up is fine, but a TODO or issue link here would help.
There was a problem hiding this comment.
Yes! I do have code that exposes the peer creds via TRANSPORT_ATTR_REMOTE_ADDR but I'm saving it for a follow up PR since this one is already quite large and the new public API surface is likely to be controversial. I added a TODO for now.
Add the server-side counterpart to UdsChannelBuilder, delegating
reflectively to OkHttpServerBuilder with a package-private
SocketAddress and ServerSocketFactory backed by LocalServerSocket. No
changes to grpc-okhttp or grpc-core are needed. Like UdsChannelBuilder,
only UdsServerBuilder.forPath(String, Namespace) is public and
`@ExperimentalApi` pending a fully vetted UDS public API.
This commit only supports Namespace.ABSTRACT (all LocalServerSocket
itself supports); filesystem sockets and peer-UID authorization may
follow in separate commits. The SELinux reachability tiers documented in
UdsServerBuilder's Javadoc come from AOSP system/sepolicy/private/
{domain.te,app.te,mls} and were verified with SELinux enforcing across
a server/client targetSdk 27 vs. 33 matrix at API 33, adbd (uid 2000),
and cross-app at API 24.
Tested on-device via :grpc-android:connectedDebugAndroidTest against
AOSP emulators at API 24 (minSdk), 26, and 33.
- Report peer SO_PEERCRED via package-private UdsPeerSocketAddress on UdsSocket.Accepted.getRemoteSocketAddress() for Channelz and logs. - Add TODO on UdsServerBuilder for exposing peer credentials publicly.
UdsChannelInteropTest.runTest() put assertEquals inside its try block and caught ExecutionException and InterruptedException without failing, turning setUp/tearDown failures in TestCallable into false passes. Let exceptions propagate to JUnit instead.
UdsChannelInteropTest and TesterActivity previously proxied a raw LocalServerSocket through UdsTcpEndpointConnector to a TCP server because grpc-android had no UDS server. Running both directly against an in-process UdsServerBuilder removes UdsTcpEndpointConnector and gives UdsServerBuilder coverage across the interop matrix on Firebase Test Lab
:grpc-android now has instrumentation tests under src/androidTest that require a real Android kernel and were only compiled in presubmit. Run grpc-android's debug androidTest APK on Firebase Test Lab across multiple devices alongside grpc-binder.
Add MediumPhone.arm API 33 (matching grpc-android's targetSdkVersion and local verification) to the grpc-android Firebase Test Lab matrix.
f00f22a to
08369be
Compare
Our team uses the okhttp server in our Android apps so our debug/test APIs can be called from an
adb-connected host. But TCP/IP has an access-control problem: Android's app sandbox does not generally restrict traffic to localhost, so any installed app holding the normalINTERNETpermission can connect and call sensitive APIs whenever the server app is listening.Unix domain sockets in Linux' abstract namespace avoid this while remaining reachable via
adb forward tcp:PORT localabstract:NAMEeven on unrooteduserbuilds. On Android 9+ (when the hosting app targets API 28+), SELinux's per-app categories block other apps from connecting to the abstract socket, limiting reachability to the app itself, anadb-authorized host (adbd), and privileged system processes. Listening in the file system restricts access to same-uid even on older Android versions, and prevents access via adbd on unrooted devices.This PR adds only one new public API:
UdsServerBuilder, counterpart to the existingUdsChannelBuilderstopgap.Suggested review order:
UdsServerBuilder,UdsSocketAddressUdsServerSocketFactory,UdsServerSocket,UdsListeningSocket,UdsAbstractListeningSocket,UdsFilesystemListeningSocketUdsSocket,UdsSocketFactory