sandcovery 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/sandcovery-docker.mjs +1 -1
- package/dist/cli/sandcovery-kubectl.mjs +1 -1
- package/dist/{handlers-B6NdmgQM.mjs → handlers-CpLa3dvg.mjs} +4 -2
- package/dist/{port-forwarder-DxnuUTsW.mjs → port-forwarder-DvSPr-Tg.mjs} +305 -42
- package/dist/{start-aOWo5B3M.mjs → start-D1LPu-aN.mjs} +2 -2
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $ as CurrentRedactedNames, $n as merge$1, $t as timeoutOrElse, An as exitInterrupt$1, Ar as toJson, At as interrupt$1, B as makeFilter, Bn as TaggedError, Br as isString, Bt as provide, C as decodeUnknownEffect, Cn as hasInterrupts, Cr as makePrimitive, Ct as fail$2, D as encodeSync, Dn as andThen, Dr as BaseProto, Dt as forever, E as decodeUnknownSync, Er as setStackTraceLimit, Et as fnUntraced, Fn as succeed, Fr as symbol$1, Ft as onExit$1, G as CurrentRedactedNames$1, Gn as of, Gr as identity, Gt as runPromise, H as optionalKey, Hn as seconds, Hr as constTrue, Ht as provideService, In as suspend$2, Ir as hasProperty, It as onExitPrimitive, J as redactUrl, Jn as isSuccess, Jt as succeed$1, K as empty$2, Kn as getSuccess, Kr as pipeArguments, Kt as runSync, Ln as sync, Lr as isNotNull, Lt as onInterrupt, M as isGreaterThan, Mn as exitZipRight, Mr as redact, Mt as mapError, Nn as fiberInterrupt, Nr as symbol, Nt as matchCauseEffect, O as fromJsonString, On as callback, Or as Class, Ot as forkIn, P as isMaxCodePoints, Pn as makeLatchUnsafe, Pr as random, Pt as onError, Q as unwrap, Qn as getOrUndefined$1, R as isSchemaError, Rn as TracerTimingEnabled$1, Rr as isNotNullish, Rt as orElseSucceed, S as decodeTo, Sn as done, Sr as isExit, St as ensuring$2, T as decodeUnknownResult, Tn as squash, Tr as getStackTraceLimit, Tt as flatMap, Ur as constVoid, V as optional, Vr as constFalse, Vt as provideContext, W as makeFormatterStandardSchemaV1, Wn as toSeconds, Wr as dual, Wt as runFork, X as toString, Xn as Reference, Xt as sync$1, Y as setAll$1, Yn as try_, Yt as suspend$3, Z as fromBody, Zn as Service$1, Zt as tap$1, _ as String$1, _n as close, _r as args, _t as catchIf, an as void_, at as remove, b as Unknown, bn as fail$3, br as exitFailCause, bt as contextWith, c as Json, cn as withParentSpan, cr as isSome, ct as fromSetCookie, dn as catchDone, dr as match, dt as as$1, en as tryPromise, er as exists$1, et as empty$3, fn as doneExitFromCause, fr as none, ft as asVoid, g as Record, gn as addFinalizerExit, gr as PipeInspectableProto, hn as addFinalizer, hr as Done, ht as catchCause, in as useSpan, ir as getOrNull, it as merge$2, jn as exitVoid, jr as format, jt as map, k as is$1, kr as NodeInspectSymbol, kt as gen, l as Literal, lr as liftThrowable, m as NullOr, mn as effect, mr as toArray, mt as callback$1, nn as uninterruptibleMask, nr as fromNullishOr, nt as fromRecordUnsafe, o as FiniteFromString, on as whileLoop, or as getOrUndefined, ot as set, p as NonEmptyString, pn as isDoneCause, pr as some, pt as cached, q as fromInput, qn as isFailure, qt as sleep, r as DateFromString, rn as updateContext, rr as getOrElse, rt as isRedactedName, s as Int, sn as withFiber$1, sr as isNone, st as setAll, t as ArraySchema, tn as try_$1, tr as flatMap$1, tt as fromInput$1, u as Literals, ur as map$1, ut as andThen$1, v as Struct, vn as forkUnsafe, vr as evaluate, vt as catchTag, w as decodeUnknownOption, wn as isTimeoutError, wr as withFiber, wt as failCause$1, xn as TimeoutError, xr as exitSucceed, y as Union, yn as makeUnsafe$1, yr as exitFail, yt as context, zn as DisablePropagation, zr as isPropertyKey, zt as promise } from "./Schema-CoX0a2_o.mjs";
|
|
2
|
-
import { C as enabledVariable, F as rerunArgv, I as valuesOf$1, O as flagOf, Q as CliFailure, R as ellipsis, S as writePrivateFile, U as escapeUnprintable, Y as isDigits, Z as isWordCharacter, _ as formatMoney, a as RELAY_PORT, at as holdCluster, c as onPath, ct as Clock, d as BIN, f as CLEARABLE, g as formatCount, h as counted, i as forwarderSocket, j as lastValue, m as PROBLEM_REPORT_MAX, n as attachForwarder, nt as Canceled, o as RELAY_SOURCE, q as consistsOf, rt as IDLE_MS, s as v7, st as noop, tt as usageFailure, u as shimsOf, v as formatPercent, x as withFileLock, y as version } from "./port-forwarder-
|
|
2
|
+
import { C as enabledVariable, F as rerunArgv, I as valuesOf$1, O as flagOf, Q as CliFailure, R as ellipsis, S as writePrivateFile, U as escapeUnprintable, Y as isDigits, Z as isWordCharacter, _ as formatMoney, a as RELAY_PORT, at as holdCluster, c as onPath, ct as Clock, d as BIN, f as CLEARABLE, g as formatCount, h as counted, i as forwarderSocket, j as lastValue, m as PROBLEM_REPORT_MAX, n as attachForwarder, nt as Canceled, o as RELAY_SOURCE, q as consistsOf, rt as IDLE_MS, s as v7, st as noop, tt as usageFailure, u as shimsOf, v as formatPercent, x as withFileLock, y as version } from "./port-forwarder-DvSPr-Tg.mjs";
|
|
3
3
|
import { A as NO_MARKUP_TERMS, C as AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD, D as ENTERPRISE_PLAN, E as CREDIT_PURCHASE_MIN_MICRO_USD, G as CiJobId, J as KeySecret, K as CredentialId, L as CreateSandboxRequest, M as thresholdBelowTopUp, N as ApiError, O as FREE_PLAN, Q as UsageShareId, R as Port, S as AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD, T as CREDIT_PURCHASE_MAX_MICRO_USD, V as ProviderSort, W as ApiKeyId, X as Provider, Y as ProcessId, Z as SandboxId, _ as KeyKind, a as USAGE_SHARE_FIGURES, b as CredentialFields, c as EstimateRequest, d as UsagePeriod, f as API_PREFIX, g as CreateKeyRequest, i as ShareToken, j as creditsAfterFeeMicroUsd, k as MICRO_USD_PER_DOLLAR, l as MONTH_TEXT, m as SANDCOVERY_ORIGIN, n as CreateUsageShareRequest, o as UsageShareFigure, p as LocalPath, q as KeyId, r as DEFAULT_SHARED_FIGURES, s as CalendarDay, t as Sandcovery, u as MonthlyCostQuery, v as SpendLimit, x as GitHubId, y as UpdateKeyRequest, z as SandboxStatus } from "./src-BqfeIyqj.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
@@ -16784,7 +16784,9 @@ const relayCommand = (tokenFile) => {
|
|
|
16784
16784
|
`$s python3 -c ${quoted(RELAY_SOURCE)} ${String(RELAY_PORT)} ${file}`
|
|
16785
16785
|
].join(" && ");
|
|
16786
16786
|
};
|
|
16787
|
-
const shownAddress = ({ host, port }) =>
|
|
16787
|
+
const shownAddress = ({ host, port, protocol }) => {
|
|
16788
|
+
return `${host.includes(":") ? `[${host}]` : host}:${String(port)}/${protocol}`;
|
|
16789
|
+
};
|
|
16788
16790
|
const unforwardedMessage = (entry) => entry.reason === "busy" ? `Can't forward ${shownAddress(entry)} to this computer. Another program here listens on it, so the port stays in the sandbox.` : `Can't forward ${shownAddress(entry)} to this computer. Only an administrator may listen on it here, so the port stays in the sandbox.`;
|
|
16789
16791
|
const forwarded = async ({ context, sandbox, sync }) => {
|
|
16790
16792
|
const { entry } = context;
|
|
@@ -10,6 +10,7 @@ import fs from "node:fs";
|
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import { text } from "node:stream/consumers";
|
|
12
12
|
import os from "node:os";
|
|
13
|
+
import dgram from "node:dgram";
|
|
13
14
|
// ../../node_modules/.pnpm/effect@4.1.1/node_modules/effect/dist/Clock.js
|
|
14
15
|
/**
|
|
15
16
|
* Context reference for the active time service in the environment.
|
|
@@ -1123,7 +1124,7 @@ const withFileLock = ({ bin, file, work }) => {
|
|
|
1123
1124
|
}), () => work, (own) => removeIf(lock, sameAs(own)));
|
|
1124
1125
|
};
|
|
1125
1126
|
// package.json
|
|
1126
|
-
var version = "0.6.
|
|
1127
|
+
var version = "0.6.2";
|
|
1127
1128
|
// ../format/src/display.ts
|
|
1128
1129
|
const LOCALE = "en-US";
|
|
1129
1130
|
const UTC = "UTC";
|
|
@@ -1165,6 +1166,15 @@ const monthName = new Intl.DateTimeFormat(LOCALE, {
|
|
|
1165
1166
|
timeZone: UTC
|
|
1166
1167
|
});
|
|
1167
1168
|
Array.from({ length: 12 }, (_, month) => monthName.format(Date.UTC(2e3, month)));
|
|
1169
|
+
new Intl.DateTimeFormat(LOCALE, {
|
|
1170
|
+
day: "numeric",
|
|
1171
|
+
hour: "2-digit",
|
|
1172
|
+
hourCycle: "h23",
|
|
1173
|
+
minute: "2-digit",
|
|
1174
|
+
month: "short",
|
|
1175
|
+
timeZone: "Asia/Seoul",
|
|
1176
|
+
year: "numeric"
|
|
1177
|
+
});
|
|
1168
1178
|
new Intl.DateTimeFormat(LOCALE, {
|
|
1169
1179
|
day: "numeric",
|
|
1170
1180
|
hour: "numeric",
|
|
@@ -4445,6 +4455,7 @@ const RELAY_TOKEN_HEADER = "x-sandcovery-relay-token";
|
|
|
4445
4455
|
const RELAY_SOURCE = String.raw`import base64
|
|
4446
4456
|
import hashlib
|
|
4447
4457
|
import hmac
|
|
4458
|
+
import ipaddress
|
|
4448
4459
|
import json
|
|
4449
4460
|
import os
|
|
4450
4461
|
import socket
|
|
@@ -4456,6 +4467,7 @@ GUID = b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
|
|
4456
4467
|
HEADER_LIMIT = 16384
|
|
4457
4468
|
CHUNK = 65536
|
|
4458
4469
|
KEEPALIVE_SECONDS = 30
|
|
4470
|
+
POLL_SECONDS = 1
|
|
4459
4471
|
TEXT, BINARY, CLOSE, PING, PONG = 1, 2, 8, 9, 10
|
|
4460
4472
|
EVENTS = [
|
|
4461
4473
|
"docker", "events", "--format", "{{.Actor.ID}}",
|
|
@@ -4463,6 +4475,14 @@ EVENTS = [
|
|
|
4463
4475
|
"--filter", "event=start",
|
|
4464
4476
|
"--filter", "event=die",
|
|
4465
4477
|
]
|
|
4478
|
+
INSPECT = "{{.Id}} {{.HostConfig.NetworkMode}} {{json .NetworkSettings.Ports}}"
|
|
4479
|
+
PROTOCOLS = {"tcp": ("0A", socket.SOCK_STREAM), "udp": ("07", socket.SOCK_DGRAM)}
|
|
4480
|
+
SERVED = {
|
|
4481
|
+
"0.0.0.0": ("0.0.0.0",),
|
|
4482
|
+
"127.0.0.1": ("127.0.0.1",),
|
|
4483
|
+
"::": ("::", "0.0.0.0"),
|
|
4484
|
+
"::1": ("::1",),
|
|
4485
|
+
}
|
|
4466
4486
|
|
|
4467
4487
|
|
|
4468
4488
|
def shut(sock, how=socket.SHUT_RDWR):
|
|
@@ -4596,29 +4616,159 @@ def pipe(peer, upstream):
|
|
|
4596
4616
|
pass
|
|
4597
4617
|
|
|
4598
4618
|
|
|
4599
|
-
def
|
|
4619
|
+
def send_datagrams(peer, upstream, finished):
|
|
4620
|
+
try:
|
|
4621
|
+
while True:
|
|
4622
|
+
try:
|
|
4623
|
+
data = upstream.recv(CHUNK)
|
|
4624
|
+
except ConnectionRefusedError:
|
|
4625
|
+
continue
|
|
4626
|
+
if finished.is_set():
|
|
4627
|
+
return
|
|
4628
|
+
peer.send(BINARY, data)
|
|
4629
|
+
except OSError:
|
|
4630
|
+
shut(peer.conn)
|
|
4631
|
+
|
|
4632
|
+
|
|
4633
|
+
def datagrams(peer, upstream):
|
|
4634
|
+
finished = threading.Event()
|
|
4635
|
+
with upstream:
|
|
4636
|
+
threading.Thread(
|
|
4637
|
+
target=send_datagrams, args=(peer, upstream, finished), daemon=True
|
|
4638
|
+
).start()
|
|
4639
|
+
try:
|
|
4640
|
+
while True:
|
|
4641
|
+
opcode, payload = peer.message()
|
|
4642
|
+
if opcode == CLOSE:
|
|
4643
|
+
return
|
|
4644
|
+
try:
|
|
4645
|
+
upstream.send(payload)
|
|
4646
|
+
except ConnectionRefusedError:
|
|
4647
|
+
pass
|
|
4648
|
+
finally:
|
|
4649
|
+
finished.set()
|
|
4650
|
+
shut(upstream)
|
|
4651
|
+
try:
|
|
4652
|
+
peer.send(CLOSE)
|
|
4653
|
+
except OSError:
|
|
4654
|
+
pass
|
|
4655
|
+
|
|
4656
|
+
|
|
4657
|
+
def sockets(kind):
|
|
4658
|
+
found = []
|
|
4659
|
+
for table in (kind, kind + "6"):
|
|
4660
|
+
try:
|
|
4661
|
+
with open("/proc/net/" + table) as file:
|
|
4662
|
+
rows = file.read().splitlines()[1:]
|
|
4663
|
+
except OSError:
|
|
4664
|
+
continue
|
|
4665
|
+
for row in rows:
|
|
4666
|
+
fields = row.split()
|
|
4667
|
+
if fields[3] != PROTOCOLS[kind][0]:
|
|
4668
|
+
continue
|
|
4669
|
+
hexed, port = fields[1].split(":")
|
|
4670
|
+
address = ipaddress.ip_address(
|
|
4671
|
+
b"".join(
|
|
4672
|
+
int(hexed[at:at + 8], 16).to_bytes(4, sys.byteorder)
|
|
4673
|
+
for at in range(0, len(hexed), 8)
|
|
4674
|
+
)
|
|
4675
|
+
)
|
|
4676
|
+
mapped = getattr(address, "ipv4_mapped", None)
|
|
4677
|
+
shown = str(address if mapped is None else mapped)
|
|
4678
|
+
found.append((shown, int(port, 16), "socket:[" + fields[9] + "]"))
|
|
4679
|
+
return found
|
|
4680
|
+
|
|
4681
|
+
|
|
4682
|
+
def dialed(kind, number):
|
|
4683
|
+
bound = {address for address, port, _ in sockets(kind) if port == number}
|
|
4684
|
+
only_ipv6 = bound & {"::", "::1"} and not bound & {"0.0.0.0", "127.0.0.1"}
|
|
4685
|
+
for address in ("::1", "127.0.0.1") if only_ipv6 else ("127.0.0.1", "::1"):
|
|
4686
|
+
family = socket.AF_INET6 if ":" in address else socket.AF_INET
|
|
4687
|
+
try:
|
|
4688
|
+
upstream = socket.socket(family, PROTOCOLS[kind][1])
|
|
4689
|
+
except OSError:
|
|
4690
|
+
continue
|
|
4691
|
+
try:
|
|
4692
|
+
upstream.connect((address, number))
|
|
4693
|
+
except OSError:
|
|
4694
|
+
upstream.close()
|
|
4695
|
+
continue
|
|
4696
|
+
return upstream
|
|
4697
|
+
return None
|
|
4698
|
+
|
|
4699
|
+
|
|
4700
|
+
def owned(hosted):
|
|
4701
|
+
links = set()
|
|
4702
|
+
for name in os.listdir("/proc"):
|
|
4703
|
+
if not name.isdigit():
|
|
4704
|
+
continue
|
|
4705
|
+
try:
|
|
4706
|
+
with open("/proc/" + name + "/cgroup") as file:
|
|
4707
|
+
groups = file.read()
|
|
4708
|
+
inside = any(ident in groups for ident in hosted)
|
|
4709
|
+
descriptors = os.listdir("/proc/" + name + "/fd") if inside else []
|
|
4710
|
+
except OSError:
|
|
4711
|
+
continue
|
|
4712
|
+
for descriptor in descriptors:
|
|
4713
|
+
try:
|
|
4714
|
+
links.add(os.readlink("/proc/" + name + "/fd/" + descriptor))
|
|
4715
|
+
except OSError:
|
|
4716
|
+
pass
|
|
4717
|
+
return links
|
|
4718
|
+
|
|
4719
|
+
|
|
4720
|
+
def listening(hosted):
|
|
4721
|
+
if not hosted:
|
|
4722
|
+
return []
|
|
4723
|
+
links = owned(hosted)
|
|
4724
|
+
found = {
|
|
4725
|
+
(host, port, kind)
|
|
4726
|
+
for kind in PROTOCOLS
|
|
4727
|
+
for address, port, link in sockets(kind)
|
|
4728
|
+
if link in links
|
|
4729
|
+
for host in SERVED.get(address, ())
|
|
4730
|
+
}
|
|
4731
|
+
return [
|
|
4732
|
+
{"host": host, "port": port, "protocol": kind}
|
|
4733
|
+
for host, port, kind in sorted(found)
|
|
4734
|
+
]
|
|
4735
|
+
|
|
4736
|
+
|
|
4737
|
+
def containers():
|
|
4600
4738
|
ids = subprocess.run(
|
|
4601
4739
|
["docker", "ps", "--quiet", "--no-trunc"], capture_output=True, text=True
|
|
4602
4740
|
).stdout.split()
|
|
4603
4741
|
if not ids:
|
|
4604
|
-
return "[]"
|
|
4742
|
+
return "[]", []
|
|
4605
4743
|
shown = subprocess.run(
|
|
4606
|
-
["docker", "inspect", "--format",
|
|
4744
|
+
["docker", "inspect", "--format", INSPECT, *ids],
|
|
4607
4745
|
capture_output=True,
|
|
4608
4746
|
text=True,
|
|
4609
4747
|
).stdout
|
|
4610
|
-
|
|
4748
|
+
rows = [row for row in (line.split(" ", 2) for line in shown.splitlines()) if len(row) == 3]
|
|
4749
|
+
ports = "[" + ",".join(row[2] for row in rows) + "]"
|
|
4750
|
+
return ports, [row[0] for row in rows if row[1] == "host"]
|
|
4611
4751
|
|
|
4612
4752
|
|
|
4613
4753
|
def events(peer, key):
|
|
4614
4754
|
accept(peer, key)
|
|
4615
4755
|
lock = threading.Lock()
|
|
4756
|
+
state = {"hosted": [], "listening": [], "ports": "[]"}
|
|
4616
4757
|
watcher = subprocess.Popen(EVENTS, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
|
4617
4758
|
|
|
4759
|
+
def send(tag):
|
|
4760
|
+
shown = (
|
|
4761
|
+
'{"listening":' + json.dumps(state["listening"])
|
|
4762
|
+
+ ',"ports":' + state["ports"]
|
|
4763
|
+
+ ',"tag":' + json.dumps(tag) + "}"
|
|
4764
|
+
)
|
|
4765
|
+
peer.send(TEXT, shown.encode())
|
|
4766
|
+
|
|
4618
4767
|
def snapshot(tag=None):
|
|
4619
4768
|
with lock:
|
|
4620
|
-
|
|
4621
|
-
|
|
4769
|
+
state["ports"], state["hosted"] = containers()
|
|
4770
|
+
state["listening"] = listening(state["hosted"])
|
|
4771
|
+
send(tag)
|
|
4622
4772
|
|
|
4623
4773
|
def watch():
|
|
4624
4774
|
try:
|
|
@@ -4628,8 +4778,20 @@ def events(peer, key):
|
|
|
4628
4778
|
pass
|
|
4629
4779
|
shut(peer.conn)
|
|
4630
4780
|
|
|
4781
|
+
def poll():
|
|
4782
|
+
try:
|
|
4783
|
+
while not peer.done.wait(POLL_SECONDS):
|
|
4784
|
+
with lock:
|
|
4785
|
+
found = listening(state["hosted"])
|
|
4786
|
+
if found != state["listening"]:
|
|
4787
|
+
state["listening"] = found
|
|
4788
|
+
send(None)
|
|
4789
|
+
except OSError:
|
|
4790
|
+
shut(peer.conn)
|
|
4791
|
+
|
|
4631
4792
|
try:
|
|
4632
4793
|
threading.Thread(target=watch, daemon=True).start()
|
|
4794
|
+
threading.Thread(target=poll, daemon=True).start()
|
|
4633
4795
|
snapshot()
|
|
4634
4796
|
while True:
|
|
4635
4797
|
opcode, payload = peer.message()
|
|
@@ -4660,16 +4822,17 @@ def handle(conn, token):
|
|
|
4660
4822
|
target = request[1].split("?")[0]
|
|
4661
4823
|
if target.endswith("/events"):
|
|
4662
4824
|
return events(peer, key)
|
|
4663
|
-
|
|
4664
|
-
|
|
4825
|
+
parts = target.rsplit("/", 2)
|
|
4826
|
+
kind, digits = parts[1:] if len(parts) == 3 else ("", "")
|
|
4827
|
+
known = kind in PROTOCOLS and digits.isascii() and digits.isdigit()
|
|
4828
|
+
number = int(digits) if known else 0
|
|
4665
4829
|
if not 0 < number < 65536:
|
|
4666
4830
|
return refuse(peer, "404 Not Found")
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
except OSError:
|
|
4831
|
+
upstream = dialed(kind, number)
|
|
4832
|
+
if upstream is None:
|
|
4670
4833
|
return refuse(peer, "502 Bad Gateway")
|
|
4671
4834
|
accept(peer, key)
|
|
4672
|
-
pipe(peer, upstream)
|
|
4835
|
+
(pipe if kind == "tcp" else datagrams)(peer, upstream)
|
|
4673
4836
|
except (EOFError, OSError, ValueError):
|
|
4674
4837
|
pass
|
|
4675
4838
|
finally:
|
|
@@ -4717,11 +4880,18 @@ const RETRY_MS = [
|
|
|
4717
4880
|
1e4,
|
|
4718
4881
|
3e4
|
|
4719
4882
|
];
|
|
4883
|
+
const UDP_IDLE_MS = 9e4;
|
|
4884
|
+
const QUEUED_DATAGRAMS = 256;
|
|
4720
4885
|
const ANY_IPV4 = "0.0.0.0";
|
|
4721
4886
|
const HIGHEST_PORT = 65535;
|
|
4722
|
-
const
|
|
4887
|
+
const PROTOCOLS = ["tcp", "udp"];
|
|
4888
|
+
const PublishedSchema = Struct({
|
|
4723
4889
|
host: String$1,
|
|
4724
4890
|
port: Number$1,
|
|
4891
|
+
protocol: Literals(PROTOCOLS)
|
|
4892
|
+
});
|
|
4893
|
+
const UnforwardedSchema = Struct({
|
|
4894
|
+
...PublishedSchema.fields,
|
|
4725
4895
|
reason: Literals(["busy", "denied"])
|
|
4726
4896
|
});
|
|
4727
4897
|
const decodeRequest = decodeUnknownOption(fromJsonString(Struct({
|
|
@@ -4736,6 +4906,7 @@ const decodeRequest = decodeUnknownOption(fromJsonString(Struct({
|
|
|
4736
4906
|
})));
|
|
4737
4907
|
const decodeReply = decodeUnknownOption(fromJsonString(Struct({ unforwarded: ArraySchema(UnforwardedSchema) })));
|
|
4738
4908
|
const SnapshotSchema = Struct({
|
|
4909
|
+
listening: ArraySchema(PublishedSchema),
|
|
4739
4910
|
ports: ArraySchema(NullOr(Record(String$1, NullOr(ArraySchema(Struct({
|
|
4740
4911
|
HostIp: String$1,
|
|
4741
4912
|
HostPort: String$1
|
|
@@ -4743,16 +4914,32 @@ const SnapshotSchema = Struct({
|
|
|
4743
4914
|
tag: NullOr(String$1)
|
|
4744
4915
|
});
|
|
4745
4916
|
const decodeSnapshot = decodeUnknownOption(fromJsonString(SnapshotSchema));
|
|
4746
|
-
const keyOf = ({ host, port }) => `${host} ${String(port)}`;
|
|
4917
|
+
const keyOf = ({ host, port, protocol }) => `${protocol} ${host} ${String(port)}`;
|
|
4747
4918
|
const isPort = (port) => Number.isInteger(port) && port > 0 && port <= HIGHEST_PORT;
|
|
4748
|
-
const
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
port
|
|
4753
|
-
|
|
4754
|
-
|
|
4919
|
+
const protocolOf = (target) => PROTOCOLS.find((protocol) => target.endsWith(`/${protocol}`));
|
|
4920
|
+
const publishedIn = (ports) => ports.flatMap((container) => Object.entries(container ?? {}).flatMap(([target, bindings]) => {
|
|
4921
|
+
const protocol = protocolOf(target);
|
|
4922
|
+
return protocol === void 0 ? [] : (bindings ?? []).flatMap(({ HostIp, HostPort }) => {
|
|
4923
|
+
const port = Number(HostPort);
|
|
4924
|
+
return isPort(port) ? [{
|
|
4925
|
+
host: HostIp === "" ? ANY_IPV4 : HostIp,
|
|
4926
|
+
port,
|
|
4927
|
+
protocol
|
|
4928
|
+
}] : [];
|
|
4929
|
+
});
|
|
4930
|
+
}));
|
|
4755
4931
|
const errorCode = (error) => error.code ?? "";
|
|
4932
|
+
const refusalOf = (published, error) => {
|
|
4933
|
+
const code = errorCode(error);
|
|
4934
|
+
if (code === "EADDRINUSE") return {
|
|
4935
|
+
...published,
|
|
4936
|
+
reason: "busy"
|
|
4937
|
+
};
|
|
4938
|
+
return code === "EACCES" ? {
|
|
4939
|
+
...published,
|
|
4940
|
+
reason: "denied"
|
|
4941
|
+
} : null;
|
|
4942
|
+
};
|
|
4756
4943
|
const cancel = (timer) => {
|
|
4757
4944
|
if (timer !== null) clearTimeout(timer);
|
|
4758
4945
|
return null;
|
|
@@ -4810,6 +4997,62 @@ const carry = (local, remote) => {
|
|
|
4810
4997
|
remote.close();
|
|
4811
4998
|
});
|
|
4812
4999
|
};
|
|
5000
|
+
const datagramsOf = ({ dial, port, socket }) => {
|
|
5001
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
5002
|
+
const end = (sender, session) => {
|
|
5003
|
+
if (sessions.get(sender) === session) sessions.delete(sender);
|
|
5004
|
+
clearTimeout(session.idle);
|
|
5005
|
+
session.remote?.close();
|
|
5006
|
+
};
|
|
5007
|
+
const opened = (sender, from) => {
|
|
5008
|
+
const session = {
|
|
5009
|
+
idle: setTimeout(() => {
|
|
5010
|
+
end(sender, session);
|
|
5011
|
+
}, UDP_IDLE_MS),
|
|
5012
|
+
queue: [],
|
|
5013
|
+
remote: null
|
|
5014
|
+
};
|
|
5015
|
+
const listen = (remote) => {
|
|
5016
|
+
if (sessions.get(sender) !== session) {
|
|
5017
|
+
remote.close();
|
|
5018
|
+
return;
|
|
5019
|
+
}
|
|
5020
|
+
session.remote = remote;
|
|
5021
|
+
remote.addEventListener("open", () => {
|
|
5022
|
+
for (const datagram of session.queue.splice(0)) remote.send(datagram);
|
|
5023
|
+
});
|
|
5024
|
+
remote.addEventListener("message", ({ data }) => {
|
|
5025
|
+
if (data instanceof ArrayBuffer) {
|
|
5026
|
+
session.idle.refresh();
|
|
5027
|
+
socket.send(new Uint8Array(data), from.port, from.address);
|
|
5028
|
+
}
|
|
5029
|
+
});
|
|
5030
|
+
remote.addEventListener("close", () => {
|
|
5031
|
+
end(sender, session);
|
|
5032
|
+
});
|
|
5033
|
+
};
|
|
5034
|
+
const connected = async () => {
|
|
5035
|
+
const outcome = await dial(`/udp/${String(port)}`, listen);
|
|
5036
|
+
if (outcome === null || outcome instanceof Error) end(sender, session);
|
|
5037
|
+
};
|
|
5038
|
+
sessions.set(sender, session);
|
|
5039
|
+
connected();
|
|
5040
|
+
return session;
|
|
5041
|
+
};
|
|
5042
|
+
socket.on("message", (datagram, from) => {
|
|
5043
|
+
const sender = `${from.address} ${String(from.port)}`;
|
|
5044
|
+
const session = sessions.get(sender) ?? opened(sender, from);
|
|
5045
|
+
const { remote } = session;
|
|
5046
|
+
session.idle.refresh();
|
|
5047
|
+
if (remote?.readyState === WebSocket.OPEN) {
|
|
5048
|
+
if (remote.bufferedAmount <= BUFFERED_LIMIT) remote.send(datagram);
|
|
5049
|
+
} else if (session.queue.length < QUEUED_DATAGRAMS) session.queue.push(datagram);
|
|
5050
|
+
});
|
|
5051
|
+
return { close: () => {
|
|
5052
|
+
for (const [sender, session] of sessions) end(sender, session);
|
|
5053
|
+
socket.close();
|
|
5054
|
+
} };
|
|
5055
|
+
};
|
|
4813
5056
|
const forwarderSocket = (settingsFile) => socketOf({
|
|
4814
5057
|
name: "docker-ports",
|
|
4815
5058
|
settingsFile
|
|
@@ -4845,7 +5088,7 @@ const forwardPorts = async (socketPath) => {
|
|
|
4845
5088
|
};
|
|
4846
5089
|
const listener = net.createServer({ allowHalfOpen: true });
|
|
4847
5090
|
const release = () => {
|
|
4848
|
-
for (const
|
|
5091
|
+
for (const listening of state.bound.values()) listening.close();
|
|
4849
5092
|
state.bound.clear();
|
|
4850
5093
|
state.notices.clear();
|
|
4851
5094
|
state.latest = null;
|
|
@@ -4909,15 +5152,18 @@ const forwardPorts = async (socketPath) => {
|
|
|
4909
5152
|
throw error;
|
|
4910
5153
|
}
|
|
4911
5154
|
};
|
|
5155
|
+
const dial = async (target, listen) => {
|
|
5156
|
+
const { attachment } = state;
|
|
5157
|
+
return attachment === null ? null : await attempted(attachment, target, listen);
|
|
5158
|
+
};
|
|
4912
5159
|
const tunnel = async (local, port) => {
|
|
4913
5160
|
local.on("error", noop);
|
|
4914
|
-
const
|
|
4915
|
-
const outcome = attachment === null ? null : await attempted(attachment, `/tcp/${String(port)}`, (remote) => {
|
|
5161
|
+
const outcome = await dial(`/tcp/${String(port)}`, (remote) => {
|
|
4916
5162
|
carry(local, remote);
|
|
4917
5163
|
});
|
|
4918
5164
|
if (outcome === null || outcome instanceof Error) local.destroy();
|
|
4919
5165
|
};
|
|
4920
|
-
const
|
|
5166
|
+
const listenTcp = async (published) => {
|
|
4921
5167
|
const { host, port } = published;
|
|
4922
5168
|
const server = net.createServer({
|
|
4923
5169
|
allowHalfOpen: true,
|
|
@@ -4927,18 +5173,7 @@ const forwardPorts = async (socketPath) => {
|
|
|
4927
5173
|
});
|
|
4928
5174
|
const { promise, resolve } = Promise.withResolvers();
|
|
4929
5175
|
server.once("error", (error) => {
|
|
4930
|
-
|
|
4931
|
-
if (code === "EADDRINUSE") resolve({
|
|
4932
|
-
host,
|
|
4933
|
-
port,
|
|
4934
|
-
reason: "busy"
|
|
4935
|
-
});
|
|
4936
|
-
else if (code === "EACCES") resolve({
|
|
4937
|
-
host,
|
|
4938
|
-
port,
|
|
4939
|
-
reason: "denied"
|
|
4940
|
-
});
|
|
4941
|
-
else resolve(null);
|
|
5176
|
+
resolve(refusalOf(published, error));
|
|
4942
5177
|
});
|
|
4943
5178
|
server.listen({
|
|
4944
5179
|
host,
|
|
@@ -4951,10 +5186,38 @@ const forwardPorts = async (socketPath) => {
|
|
|
4951
5186
|
});
|
|
4952
5187
|
return await promise;
|
|
4953
5188
|
};
|
|
5189
|
+
const listenUdp = async (published) => {
|
|
5190
|
+
const { host, port } = published;
|
|
5191
|
+
const ipv6 = host.includes(":");
|
|
5192
|
+
const socket = dgram.createSocket({
|
|
5193
|
+
ipv6Only: ipv6,
|
|
5194
|
+
type: ipv6 ? "udp6" : "udp4"
|
|
5195
|
+
});
|
|
5196
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
5197
|
+
socket.once("error", (error) => {
|
|
5198
|
+
socket.close();
|
|
5199
|
+
resolve(refusalOf(published, error));
|
|
5200
|
+
});
|
|
5201
|
+
socket.bind({
|
|
5202
|
+
address: host,
|
|
5203
|
+
port
|
|
5204
|
+
}, () => {
|
|
5205
|
+
socket.removeAllListeners("error");
|
|
5206
|
+
socket.on("error", noop);
|
|
5207
|
+
state.bound.set(keyOf(published), datagramsOf({
|
|
5208
|
+
dial,
|
|
5209
|
+
port,
|
|
5210
|
+
socket
|
|
5211
|
+
}));
|
|
5212
|
+
resolve(null);
|
|
5213
|
+
});
|
|
5214
|
+
return await promise;
|
|
5215
|
+
};
|
|
5216
|
+
const bind = async (published) => published.protocol === "udp" ? await listenUdp(published) : await listenTcp(published);
|
|
4954
5217
|
const apply = async (published) => {
|
|
4955
5218
|
const wanted = new Map(published.map((entry) => [keyOf(entry), entry]));
|
|
4956
|
-
for (const [key,
|
|
4957
|
-
|
|
5219
|
+
for (const [key, listening] of state.bound) if (!wanted.has(key)) {
|
|
5220
|
+
listening.close();
|
|
4958
5221
|
state.bound.delete(key);
|
|
4959
5222
|
}
|
|
4960
5223
|
for (const key of state.notices.keys()) if (!wanted.has(key)) state.notices.delete(key);
|
|
@@ -4978,9 +5241,9 @@ const forwardPorts = async (socketPath) => {
|
|
|
4978
5241
|
for (const tag of next.tags) state.syncs.get(tag)?.();
|
|
4979
5242
|
await applyLatest();
|
|
4980
5243
|
};
|
|
4981
|
-
const received = ({ ports, tag }) => {
|
|
5244
|
+
const received = ({ listening, ports, tag }) => {
|
|
4982
5245
|
state.latest = {
|
|
4983
|
-
published: publishedIn(ports),
|
|
5246
|
+
published: [...publishedIn(ports), ...listening.filter(({ port }) => isPort(port))],
|
|
4984
5247
|
tags: [...state.latest?.tags ?? [], ...tag === null ? [] : [tag]]
|
|
4985
5248
|
};
|
|
4986
5249
|
applyLatest();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Br as isString, E as decodeUnknownSync, Ir as hasProperty, Jn as isSuccess, O as fromJsonString, V as optional, Yn as try_, _ as String$1, c as Json, g as Record, n as Boolean, or as getOrUndefined, qn as isFailure, v as Struct, w as decodeUnknownOption } from "./Schema-CoX0a2_o.mjs";
|
|
2
|
-
import { $ as exitCodeOf, A as isOptionValue, B as plainPrefix, C as enabledVariable, D as closest, E as productVariable, F as rerunArgv, G as remoteLine, H as theme, J as isDigit, K as remoteText, L as clearLine, M as parseFailure, N as parseLeaf, O as flagOf, P as readOptionToken, Q as CliFailure, R as ellipsis, S as writePrivateFile, T as modeOf, U as escapeUnprintable, V as spinnerFrame, W as remoteCell, X as isUpper, Z as isWordCharacter, b as configDirectory, d as BIN, et as statusOf$1, it as IDLE_WATCHER_ENV, j as lastValue, k as isOptionToken, l as setupDropIns, nt as Canceled, ot as watchIdle, p as CLI, q as consistsOf, r as forwardPorts, st as noop, t as FORWARDER_ENV, tt as usageFailure, w as guidanceOn, y as version, z as glyph } from "./port-forwarder-
|
|
2
|
+
import { $ as exitCodeOf, A as isOptionValue, B as plainPrefix, C as enabledVariable, D as closest, E as productVariable, F as rerunArgv, G as remoteLine, H as theme, J as isDigit, K as remoteText, L as clearLine, M as parseFailure, N as parseLeaf, O as flagOf, P as readOptionToken, Q as CliFailure, R as ellipsis, S as writePrivateFile, T as modeOf, U as escapeUnprintable, V as spinnerFrame, W as remoteCell, X as isUpper, Z as isWordCharacter, b as configDirectory, d as BIN, et as statusOf$1, it as IDLE_WATCHER_ENV, j as lastValue, k as isOptionToken, l as setupDropIns, nt as Canceled, ot as watchIdle, p as CLI, q as consistsOf, r as forwardPorts, st as noop, t as FORWARDER_ENV, tt as usageFailure, w as guidanceOn, y as version, z as glyph } from "./port-forwarder-DvSPr-Tg.mjs";
|
|
3
3
|
import { m as SANDCOVERY_ORIGIN } from "./src-BqfeIyqj.mjs";
|
|
4
4
|
import { n as sendTelemetry$1, t as loopbackOrigin } from "./telemetry-DBPKT8Ap.mjs";
|
|
5
5
|
import "./posthog-project-CdWw_ofg.mjs";
|
|
@@ -1340,7 +1340,7 @@ const runCommand = async ({ invocation, session }) => {
|
|
|
1340
1340
|
try {
|
|
1341
1341
|
const local = LOCAL_COMMANDS.get(key);
|
|
1342
1342
|
if (local !== void 0) return await local(context);
|
|
1343
|
-
const { HANDLERS } = await import("./handlers-
|
|
1343
|
+
const { HANDLERS } = await import("./handlers-CpLa3dvg.mjs");
|
|
1344
1344
|
const handler = HANDLERS.get(key);
|
|
1345
1345
|
if (handler === void 0) throw internalFailure(invocation.path);
|
|
1346
1346
|
return await handler(context);
|