Repository navigation
Conversation
ADB_RELAY_HOSTS of .env (<host>:<first>-<last>, comma separated) starts adb-relay, the nginx of stf-proxy in the network of the host, which relays the port ranges of the devices of the device hosts for adb connect of STF. zebrunner.sh writes configuration/adb-relay/relay-hosts.conf from it, skips invalid entries, overlapping ranges and ranges with a port of MCloud, and runs compose with the profile adb-relay; stop, down and shutdown always include the profile. The e2e device drops proxy_port and server_proxy_port. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ADB_RELAY_HOSTS takes <host>:<port> entries, a device host in several of them: the remote debug port of every Android device (min_port + 1) is the documented default. A range is still relayed, with a warning that it also makes the screens of the devices public (min_port, no sign-in of their own). A port of an earlier entry is skipped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ADB_RELAY=true makes adb-relay read the Android devices of STF every ADB_RELAY_SYNC_SECONDS (STF_TOKEN of variables.env, stf-proxy on the port of the host) and relay the remote debug port of every present device of AGENT_HOSTS (connectPort, the screen port + 1 of an older STF), never the screen ports, in ADB_RELAY_PORTS only; a port of two devices, of MCloud or of ADB_RELAY_HOSTS is skipped and logged. nginx reloads gracefully only when the servers change. The sync is configuration/adb-relay/adb-relay.sh with awk programs in the nginx image (no new image, no jq there). zebrunner.sh starts adb-relay also in the auto mode and checks its settings; ADB_RELAY_HOSTS stays a fixed list in addition. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
adb-relay runs on the network of the host: instead of all the secrets of variables.env it gets configuration/adb-relay/stf-token, which ./zebrunner.sh setup, start and restart write from STF_TOKEN in place (mode 600, empty without the auto mode, ignored by git, removed by shutdown). The relay reads it on every sync and logs when the STF API answers again after an error. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The auto mode relays the remote debug port of every Android device of STF of AGENT_HOSTS, present or not (the device host refuses the port of an absent one): the servers of nginx change only when a device is added, removed or moved, so nginx reloads almost never. present is no longer read from the API. A port of two devices (e.g. a stale registration and a new device) is skipped for both and logged with their serials and the fix. ADB_RELAY_SYNC_SECONDS defaults to 300; README explains why the relay polls STF. Also fixes a broken sentence of the README. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When the device hosts (mcloud-agent) are in a private LAN and only the MCloud server is public, the screens, the tests, ZeroMQ and the storage already go through the server. The remote debug of STF (
adb connect <host>:<port>) does not: the port is a device port on the device host, and the users cannot reach it.adb-relayrelays the remote debug ports through the server. In the recommended auto mode it needs no manual list.How
Auto mode (recommended):
ADB_RELAY=trueADB_RELAY_SYNC_SECONDS(default 300),adb-relayreadsGET /api/v1/devices?fields=serial,platform,display.url,screenPort,connectPortwithSTF_TOKENofvariables.env, the token the grid uses.variables.envand its other secrets../zebrunner.sh setup,startandrestartcopy onlySTF_TOKENintoconfiguration/adb-relay/stf-token:umask 077and kept at mode 600 (protect_filescovers it too, and gives it back to the folder owner aftersudo);shutdown../zebrunner.sh startorrestart, not a recreate. It logs when the STF API answers again after an error./d/<host>/part ofdisplay.url) is inAGENT_HOSTS, to the same port of that host.presentis no longer requested from the API.connectPortwhen STF has it (the parallel STF change, needed forconnect_portof mcloud-agent).screenPortor the last segment ofdisplay.url.ADB_RELAY_PORTS=<first>-<last>(optional) limits the relay to the range opened in the firewall.AGENT_HOSTS, ports outsideADB_RELAY_PORTS, ports of MCloud or ofADB_RELAY_HOSTS, and a port of two devices (both are skipped; usually a stale registration plus a new device with the same port). The log names both serials and the fix: remove the gone device in STF (Settings, Devices) or changeconnect_portin mcloud-agent. iOS devices are ignored.nginx -tfirst, thenSIGHUP, which is graceful, so open adb sessions go on (checked in the docker test). Ifnginx -tfails, the previous servers are kept.Why polling
ADB_RELAY_SYNC_SECONDS(300 s), or at once after./zebrunner.sh restartordocker restart adb-relay(the relay syncs when it starts).How it reaches the STF API
stf-proxyon127.0.0.1:${STF_PORT}with the scheme ofSTF_URL. That scheme matches the stf-proxy listener in a normal setup and in Zebrunner CE.curl -kskips the certificate check: the certificate is issued for the public name, not for the loopback address.Implementation choice
nginx:${TAG_NGINX}withentrypoint: ["bash", "/opt/adb-relay/adb-relay.sh"].execs the official entrypoint as before.curl,bash,mawkand thenjsCLI, but nojq,pythonor perl JSON module.configuration/adb-relay/devices.awk); the relay decisions are inrelay.awk. I chose awk over njs for these reasons:make teston the CI and developer machines without docker (macOS bash 3.2 with BSD awk, Linux with mawk).fields=keeps the answer small, and the reader handles escapes, nesting,nullvalues and pretty-printed or one-line JSON.AGENT_HOSTSmatch plus a character-class check.listen <port> so_keepalive=on; proxy_pass <host>:$server_port;, with a per-serverresolver(from/etc/resolv.conf) for hosts given by name.ADB_RELAY_HOSTS: a fixed list, as beforeADB_RELAY, or in addition to it:<host>:<port>entries (a range is accepted, with the warning that it also exposes the screens).zebrunner.shwritesrelay-hosts.conffrom it; these ports win over auto-mode devices with the same port.zebrunner.shadb-relayprofile whenADB_RELAY=trueorADB_RELAY_HOSTShas a valid entry.stop,downandshutdownalways pass the profile.ADB_RELAY(true/false),ADB_RELAY_PORTSandADB_RELAY_SYNC_SECONDS.STF_TOKENor an emptyAGENT_HOSTS.configuration/adb-relay/stf-tokenonsetup,startandrestart.setupkeeps theADB_RELAY*settings of the previous setup.README
ADB_RELAY=true,ADB_RELAY_PORTSfor the firewall,REMOTE_CONNECT_HOSTof mcloud-agent,connect_portof mcloud-agent optional..envrows, Firewall and Services rows, the security note, and troubleshooting (the relay log lists the relayed and skipped devices, plus the meaning of API errors).Configuration
.env:ADB_RELAY=true,ADB_RELAY_PORTS=7400-7999(the range opened in the firewall), andAGENT_HOSTS.STF_TOKENinvariables.envmust be set (the grid needs it too). Then run./zebrunner.sh restart.REMOTE_CONNECT_HOSTto the public name of MCloud. mcloud-agent passes it to mcloud-device, so STF showsadb connect <mcloud>:<port>. Optionally setconnect_portper device; it needs the STF withconnectPort.ADB_RELAY_PORTSin the server firewall for the users.This PR pairs with mcloud-device
REMOTE_CONNECT_HOST, the mcloud-agent settings (REMOTE_CONNECT_HOST,connect_port) and zebrunner/stffeat/fixed-connect-port.Security
lib/units/device/plugins/connect.tsand the processor) listens only while a user is using the device. It accepts only that user's adb keys (STF Settings, ADB keys), and STF asks that user about an unknown key.min_port) has no authentication of its own. The auto mode never relays it. A manual range would make it public, so the range triggers a warning and the README says to put a range only behind a firewall that allows the users' networks.Tests
make lint: ok. The new scripts and awk files are linted, anddocker compose configruns with and without the profile.make test(macOS, bash 3.2, BSD awk): ok, 362 checks.tests/adb_relay_test.sh:screenPort/connectPort, pretty-printed, escapes) and of a newer one (with them,display: null, iOS);connectPort, and the screen port is never relayed;AGENT_HOSTS(whole-name match only), ports outsideADB_RELAY_PORTS, MCloud and manual ports (single and ranges), and the same port of two devices are skipped for both (including a stale registration plus a new device), with both serials and the fix in the reason;tests/zebrunner_test.sh(auto mode section):ADB_RELAY=yesandfalsedo not;ADB_RELAY*settings;ADB_RELAY_SYNC_SECONDSis 300;ADB_RELAY_PORTSandADB_RELAY_SYNC_SECONDSwarn, as do an emptySTF_TOKENorAGENT_HOSTS;docker compose configpasses the settings toadb-relay;stf-tokenholds only the token (quotes stripped), mode 600, updated in place onstart(same inode, mode restored), recreated byrestart, empty withADB_RELAY=false, given back to the folder owner aftersudo, removed byshutdown.tests/adb_relay_docker_test.sh(inDOCKER_TESTS): ok, 33 checks in about 40 s on Docker Desktop (the test setsADB_RELAY_SYNC_SECONDS=2). All the containers and networks it creates are removed.ADB_RELAY_HOSTSentry.connectPort), the manual port, and an absent device. The device host refuses the absent device's port, which the relay logs as 502.AGENT_HOSTSand a port outsideADB_RELAY_PORTS.stf-token. A refused token is logged and the devices are kept; the correct token, written in place, is picked up on the next sync without a restart.variables.envis not mounted into the relay.ADB_RELAY=false) works without a sync.make docker:tests/adb_relay_docker_test.shpasses.tests/compose_test.shstops at the pull because the pinnedTAG_STF=3.1andTAG_SELENIUM_HUB=3.1are not published on public.ecr.aws; this is not caused by this PR. With published beta images, its relay section passed on the first commit.