asyx 0.3.0 → 0.3.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/README.md +110 -335
- package/package.json +1 -1
- package/src/commands/mqtt.js +7 -7
- package/src/commands/setup.js +23 -2
- package/src/commands/sts.js +4 -4
- package/src/commands/tunnel.js +4 -4
- package/src/lib/device.js +39 -6
package/README.md
CHANGED
|
@@ -1,376 +1,151 @@
|
|
|
1
1
|
# Asyx CLI
|
|
2
2
|
|
|
3
|
-
Secure tunnels
|
|
3
|
+
Secure, device-bound tunnels for HTTP, TCP, and UDP. The CLI handles device auth, JWT refresh, and resilient control-plane connectivity so you can expose local services without managing relay infrastructure.
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> Beta access is invitation-only while we scale capacity.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
---
|
|
8
8
|
|
|
9
|
+
## 0. Install & Update
|
|
9
10
|
```bash
|
|
10
|
-
npm install -g asyx
|
|
11
|
+
npm install -g asyx # install
|
|
12
|
+
npm update -g asyx # upgrade
|
|
13
|
+
npm uninstall -g asyx # remove
|
|
11
14
|
```
|
|
15
|
+
- Node.js 18.17+ recommended. Prefer `npx asyx <cmd>` if you cannot install globally.
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
- Installs the `asyx` binary globally so it is available in your `PATH`.
|
|
15
|
-
- Prefer `npx asyx <cmd>` if you cannot install globally.
|
|
16
|
-
|
|
17
|
-
### Updating / Removing
|
|
17
|
+
---
|
|
18
18
|
|
|
19
|
+
## 1. Set up the device (once per host)
|
|
19
20
|
```bash
|
|
20
|
-
|
|
21
|
-
npm uninstall -g asyx
|
|
21
|
+
asyx setup
|
|
22
22
|
```
|
|
23
|
+
- Opens a browser for passwordless approval and lets you choose `<subdomain>.tunnel.asyx.ai`.
|
|
24
|
+
- Provisions a device certificate and client ID under `~/.asyx/certs/<clientId>/`.
|
|
25
|
+
- Hardware fingerprint is hashed locally; raw attributes never leave the device.
|
|
26
|
+
- Certificates are single-device; run `asyx setup` on each host.
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
1. **Authorize the client**
|
|
28
|
-
```bash
|
|
29
|
-
asyx setup
|
|
30
|
-
```
|
|
31
|
-
- **Opens your default browser** to complete device authorization—you'll need to approve the connection in your browser.
|
|
32
|
-
- Completes CLI registration on the Asyx website after passwordless magic-link authentication.
|
|
33
|
-
- Lets you pick a personal `<subdomain>.tunnel.asyx.ai` address (fixed for now; choose carefully) that is covered by the Asyx-managed wildcard TLS certificate.
|
|
34
|
-
- Provisions an Asyx-issued client certificate and unique client identifier (stored under `~/.asyx/certs/<clientId>/`).
|
|
35
|
-
- Captures a minimal hardware fingerprint, hashes it locally (SHA-256 with public salt), and shares only the hash so the Asyx backend can verify the CLI is on the authorized device.
|
|
36
|
-
- Certificates are single-device: copying them to another machine fails policy checks, so re-run `asyx setup` on every host.
|
|
28
|
+
---
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Want to share your Minecraft server with friends? It's literally one command:
|
|
30
|
+
## 2. Open tunnels
|
|
31
|
+
All tunnels are loopback-only. The CLI never binds your app port; it forwards to your existing listener. Public port comes from your tenant’s 10-port block (auto-assigned unless you request one with `--external-port`).
|
|
41
32
|
|
|
33
|
+
### HTTP
|
|
42
34
|
```bash
|
|
43
|
-
|
|
44
|
-
# 2. Run this:
|
|
45
|
-
asyx tunnel --minecraft
|
|
46
|
-
|
|
47
|
-
# 3. Share the hostname shown (e.g., example.tunnel.asyx.ai)
|
|
48
|
-
# Your friends connect using just the hostname—no port needed!
|
|
35
|
+
asyx tunnel --http --port 3000
|
|
49
36
|
```
|
|
37
|
+
- Forwards HTTP traffic to `127.0.0.1:3000`.
|
|
38
|
+
- Forward-only proxy; automatic JWT refresh.
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
2. **Open a tunnel**
|
|
54
|
-
|
|
55
|
-
**HTTP tunnel:**
|
|
56
|
-
```bash
|
|
57
|
-
asyx tunnel --http --port 3000
|
|
58
|
-
```
|
|
59
|
-
- Creates a forward-only HTTP tunnel bound to your issued client ID.
|
|
60
|
-
- Automatically refreshes JWTs over the Asyx messaging pipeline and keeps the session alive while traffic is flowing.
|
|
61
|
-
|
|
62
|
-
**Minecraft tunnel (easiest way to share your server):**
|
|
63
|
-
```bash
|
|
64
|
-
asyx tunnel --minecraft
|
|
65
|
-
```
|
|
66
|
-
- **One command** to expose your local Minecraft server to the internet.
|
|
67
|
-
- Automatically configures port 25565 (override with `--port` if needed).
|
|
68
|
-
- Creates an SRV record so players can connect using just the hostname—**no port number needed**.
|
|
69
|
-
- **Example**: Run `asyx tunnel --minecraft`, then share `example.tunnel.asyx.ai` with your friends. They connect in Minecraft using just that hostname.
|
|
70
|
-
- Optional `--name` flag for a custom subdomain (e.g., `--name my-server` → `my-server.example.tunnel.asyx.ai`).
|
|
71
|
-
- That's it! No firewall rules, no port forwarding, no DNS configuration.
|
|
72
|
-
|
|
73
|
-
**TCP tunnel (for other services):**
|
|
74
|
-
```bash
|
|
75
|
-
asyx tunnel --tcp --port <localPort> [--name <service>]
|
|
76
|
-
```
|
|
77
|
-
- Creates a TCP tunnel for raw TCP connections (e.g., game servers, databases, SSH).
|
|
78
|
-
- `--port`: Local target port on `127.0.0.1` (e.g., `25565` for Minecraft on `127.0.0.1:25565`).
|
|
79
|
-
- `--name`: Optional service name; if provided, creates a CNAME alias `<name>.<subdomain>.tunnel.asyx.ai`; otherwise only `host:port` form is used.
|
|
80
|
-
- The CLI prints the assignment: `fqdn:publicPort` (alias if `--name` provided, otherwise `host:port`).
|
|
81
|
-
- Uses Asyx binary framing over WebSocket (no user action needed; handled automatically).
|
|
82
|
-
- The relay URL in assignments uses `/tcp` endpoint (configured automatically).
|
|
83
|
-
|
|
84
|
-
**UDP tunnel (for UDP-based services):**
|
|
85
|
-
```bash
|
|
86
|
-
asyx tunnel --udp --port 9000 # Coordinator assigns public port
|
|
87
|
-
asyx tunnel --udp --port 9000 --external-port 10010 # Request a specific port in your block
|
|
88
|
-
```
|
|
89
|
-
- Creates a UDP tunnel for UDP-based services (e.g., game servers, real-time applications).
|
|
90
|
-
- `--port`: Your local app's UDP listening port (required).
|
|
91
|
-
- `--external-port`: Optional public port assignment; must be inside your tenant's 10-port block; otherwise the request is rejected.
|
|
92
|
-
- Targets are loopback-only; the CLI and relay enforce this automatically.
|
|
93
|
-
- CLI never binds your app's port; it uses an ephemeral socket and forwards to your existing local server.
|
|
94
|
-
- Output shows both FQDN and `FQDN:publicPort`. Point your external client at that public endpoint; traffic is forwarded to your local app on loopback.
|
|
95
|
-
- Uses secure binary framing over WebSocket (`udpWs-v1`) for efficient UDP datagram forwarding.
|
|
96
|
-
- Reuses the same MQTT/JWT control plane as TCP; no extra setup needed.
|
|
97
|
-
|
|
98
|
-
3. **Clean up (optional)**
|
|
99
|
-
```bash
|
|
100
|
-
rm -rf ~/.asyx/certs/<clientId>
|
|
101
|
-
```
|
|
102
|
-
Removes local device material; re-run `asyx setup` afterwards to restore access.
|
|
103
|
-
|
|
104
|
-
## What's New in v0.3.0
|
|
105
|
-
|
|
106
|
-
### UDP Tunnels
|
|
107
|
-
|
|
108
|
-
Support for UDP tunnels alongside HTTP and TCP:
|
|
109
|
-
- **Same command shape as TCP**: `--port` is your app's local port; optional `--external-port` requests a specific public port from your assigned block.
|
|
110
|
-
- **Loopback-only targets**: Targets are loopback-only; the CLI and relay enforce this automatically.
|
|
111
|
-
- **CLI never binds your app's port**: It forwards to your existing local server using an ephemeral socket.
|
|
112
|
-
- **Production-ready**: Full backend infrastructure is complete and validated.
|
|
113
|
-
|
|
114
|
-
### Enhanced Protocol Support
|
|
115
|
-
|
|
116
|
-
The CLI now supports HTTP, TCP, and UDP tunnels, giving you flexibility to expose any type of service through Asyx's secure relay infrastructure.
|
|
117
|
-
|
|
118
|
-
> **Note**: Version 0.3.0 is currently in development and will be published once the full feature set is complete and validated. The backend infrastructure is production-ready, and we're finalizing the remaining components before public release.
|
|
119
|
-
|
|
120
|
-
## What's New in v0.2.3
|
|
121
|
-
|
|
122
|
-
- **Minecraft tunnels made easy**: New `--minecraft` verb—just run `asyx tunnel --minecraft` and share your server instantly. No port numbers, no configuration, no hassle.
|
|
123
|
-
- **SRV record support**: Minecraft clients automatically discover the correct port via DNS SRV records—players just enter the hostname.
|
|
124
|
-
- **TCP tunnel support**: Expose raw TCP services (game servers, databases, SSH) with `asyx tunnel --tcp --port <n>`
|
|
125
|
-
- **Asyx binary framing**: Automatic protocol handling for multi-stream TCP tunneling
|
|
126
|
-
- **Coordinator-based assignments**: TCP tunnels use the same assignment system as HTTP tunnels; no additional configuration needed
|
|
127
|
-
- **Service aliases**: Optional `--name` flag for friendly service names (when aliases are provisioned)
|
|
128
|
-
|
|
129
|
-
## Why Asyx
|
|
130
|
-
|
|
131
|
-
- **Device-bound identity** – Every `setup` run issues a unique certificate and uuLID. Asyx backend policies reject duplicate usage, preventing credential theft or relocation.
|
|
132
|
-
- **Hardware attestation without PII** – The CLI derives a hashed hardware fingerprint locally using the safe `hw-fingerprint` fields; raw hardware attributes never leave the device.
|
|
133
|
-
- **Resilient control plane** – Automatic JWT refresh via the background messaging queue, bounded reconnects, and observable logging (`ASYX_DEBUG=1`) keep tunnels stable during long soaks.
|
|
134
|
-
- **Zero manual relay config** – Asyx backend assignments route traffic for you; no hostnames, firewall poking, or manual DNS updates required.
|
|
135
|
-
- **Multi-protocol support** – HTTP, TCP, and UDP tunnels share the same assignment system; choose the protocol that fits your service.
|
|
136
|
-
- **Secure proxy architecture** – Forward-only mode avoids local port binding conflicts and keeps user services isolated from the CLI process.
|
|
137
|
-
- **Observability-first UX** – Friendly error messages, deterministic exit codes, and optional debug traces make support straightforward.
|
|
138
|
-
- **Future-ready auth** – Today's magic-link flow will extend to tunnel sharing with Asyx Quickpass, delivering passwordless approvals for downstream users.
|
|
139
|
-
|
|
140
|
-
## Command Reference
|
|
141
|
-
|
|
142
|
-
```bash
|
|
143
|
-
asyx setup # Provision device certificate and client identity
|
|
144
|
-
asyx tunnel --http --port <n> # Start HTTP tunnel for local port <n>
|
|
145
|
-
asyx tunnel --minecraft # Start Minecraft tunnel (easiest way!)
|
|
146
|
-
asyx tunnel --minecraft --name <svc> # Start Minecraft tunnel with custom name
|
|
147
|
-
asyx tunnel --tcp --port <n> [--name <service>] # Start TCP tunnel for local port <n>
|
|
148
|
-
asyx tunnel --udp --port <n> [--external-port <p>] # Start UDP tunnel for local port <n> (v0.3.0+)
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
Use `asyx help` or `asyx <command> --help` for details.
|
|
152
|
-
|
|
153
|
-
## Logging
|
|
154
|
-
|
|
155
|
-
Control CLI verbosity with the `ASYX_LOG_LEVEL` environment variable:
|
|
156
|
-
|
|
157
|
-
```
|
|
158
|
-
# Levels (case-insensitive): error, warn, info, debug
|
|
159
|
-
# Default: info
|
|
160
|
-
ASYX_LOG_LEVEL=warn asyx tunnel --http --port 3000 # quiet mode: only warnings/errors
|
|
161
|
-
ASYX_LOG_LEVEL=debug asyx tunnel --http --port 3000 # full verbosity for engineering
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
- Invalid values fall back to `info`.
|
|
165
|
-
- Structured logs (JSON) are emitted to stdout/stderr; by default, debug is suppressed.
|
|
166
|
-
- User-facing banners remain visible regardless of log level.
|
|
167
|
-
|
|
168
|
-
## Heartbeat Behavior
|
|
169
|
-
|
|
170
|
-
The CLI manages heartbeats automatically to keep idle sessions stable without user tuning.
|
|
171
|
-
|
|
172
|
-
- Heartbeats pause whenever HTTP traffic is flowing and resume only when idle.
|
|
173
|
-
- Intervals are controlled server-side to prevent abuse and excessive reconnects.
|
|
174
|
-
- Heartbeat stops when the tunnel exits or errors.
|
|
175
|
-
- Use `ASYX_DEBUG=1` if you need to trace heartbeat activity for support purposes.
|
|
176
|
-
|
|
177
|
-
## Security Groups
|
|
178
|
-
|
|
179
|
-
### HTTP Tunnels with `--secgroup`
|
|
180
|
-
|
|
181
|
-
HTTP tunnels support per-guest authentication via Asyx Quickpass security groups. When you specify `--secgroup <slug>`, the tunnel enforces access control so only authorized guests (with valid Quickpass cookies) can access your service.
|
|
182
|
-
|
|
183
|
-
### TCP Tunnels
|
|
184
|
-
|
|
185
|
-
TCP tunnels in v4.1 do not enforce per-guest authentication. Access is owner-only via JWT validation; guests connecting to the public port are anonymous (no per-connection auth). TCP tunnels honor relay-level limits:
|
|
186
|
-
|
|
187
|
-
**Minecraft Tunnels (v0.2.3+):**
|
|
188
|
-
|
|
189
|
-
The `--minecraft` verb makes sharing your Minecraft server incredibly simple:
|
|
190
|
-
|
|
40
|
+
### TCP
|
|
191
41
|
```bash
|
|
192
|
-
|
|
193
|
-
asyx tunnel --minecraft
|
|
194
|
-
|
|
195
|
-
# Share the hostname with friends (no port needed!)
|
|
196
|
-
# Example: example.tunnel.asyx.ai
|
|
42
|
+
asyx tunnel --tcp --port <targetPort> [--name <alias>] [--external-port <publicPort>]
|
|
197
43
|
```
|
|
44
|
+
- For raw TCP services (databases, SSH, games).
|
|
45
|
+
- `--port`: local app port on loopback.
|
|
46
|
+
- `--name` (optional): CNAME alias `<name>.<subdomain>.tunnel.asyx.ai`; otherwise use `fqdn:publicPort`.
|
|
47
|
+
- `--external-port` (optional): must be inside your tenant block; otherwise rejected.
|
|
48
|
+
- Uses tcpWs transport; guests connect with native TCP on the public port.
|
|
198
49
|
|
|
199
|
-
|
|
200
|
-
- Asyx automatically provisions an SRV record (`_minecraft._tcp.<host>`) that tells Minecraft clients which port to use
|
|
201
|
-
- Players enter just the hostname in the Minecraft launcher—no port number required
|
|
202
|
-
- The Minecraft launcher automatically discovers the port via the SRV record
|
|
203
|
-
|
|
204
|
-
**With a custom name:**
|
|
50
|
+
### UDP
|
|
205
51
|
```bash
|
|
206
|
-
asyx tunnel --
|
|
207
|
-
# Share: my-server.example.tunnel.asyx.ai
|
|
52
|
+
asyx tunnel --udp --port <targetPort> [--external-port <publicPort>]
|
|
208
53
|
```
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
-
|
|
212
|
-
- **
|
|
213
|
-
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
- **Best-effort design**: SRV provisioning failures don't block tunnel creation; the tunnel still works with `hostname:port` format.
|
|
218
|
-
- **No default alias**: CNAME aliases are only created if you provide `--name`.
|
|
219
|
-
- **Connection limits**: Maximum concurrent connections per lease
|
|
220
|
-
- **Rate limits**: Bandwidth and connection rate throttling
|
|
221
|
-
- **Idle timeouts**: Automatic connection closure after inactivity
|
|
222
|
-
|
|
223
|
-
Future TCP guard/securing features are planned but out of scope for v4.1.
|
|
224
|
-
|
|
225
|
-
## UDP Tunnels
|
|
226
|
-
|
|
227
|
-
UDP tunnels allow you to expose UDP-based services (game servers, real-time applications, custom protocols) through Asyx's secure relay infrastructure.
|
|
228
|
-
|
|
229
|
-
### Quick Start (UDP)
|
|
230
|
-
|
|
54
|
+
- For UDP services (games, realtime apps).
|
|
55
|
+
- `--port`: local app port on loopback.
|
|
56
|
+
- `--external-port`: optional request within your tenant block.
|
|
57
|
+
- CLI uses an **ephemeral** socket; it never claims your service port. Forwards to your app.
|
|
58
|
+
- Loopback-only is enforced by CLI and relay.
|
|
59
|
+
- Uses udpWs transport; guests send native UDP to the public port.
|
|
60
|
+
|
|
61
|
+
### Minecraft (shortcut)
|
|
231
62
|
```bash
|
|
232
|
-
|
|
233
|
-
npm install -g asyx
|
|
234
|
-
|
|
235
|
-
# Run a UDP app locally on 127.0.0.1:9000, then:
|
|
236
|
-
asyx tunnel --udp --port 9000 # Coordinator assigns public port
|
|
237
|
-
asyx tunnel --udp --port 9000 --external-port 10010 # Request a specific port in your block
|
|
63
|
+
asyx tunnel --minecraft [--port <localPort>] [--name <alias>]
|
|
238
64
|
```
|
|
65
|
+
- One command to share a Minecraft server (defaults to 25565).
|
|
66
|
+
- SRV record created so players use the hostname only (no port needed).
|
|
239
67
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
- `--port <targetPort>` (required): Your local app's UDP listening port.
|
|
245
|
-
- `--external-port <publicPort>` (optional): Must be inside your tenant's 10-port block; otherwise the request is rejected.
|
|
68
|
+
After a tunnel opens, the CLI prints:
|
|
69
|
+
- `fqdn` and `fqdn:publicPort` for guests.
|
|
70
|
+
- Target shown as `tcp://127.0.0.1:<port>` or `udp://127.0.0.1:<port>` so you know your app keeps the port.
|
|
246
71
|
|
|
247
|
-
|
|
72
|
+
---
|
|
248
73
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
### Behavior Guarantees
|
|
252
|
-
|
|
253
|
-
- **Loopback only**: Targets are loopback-only; the CLI and relay enforce this automatically.
|
|
254
|
-
- **Your app keeps the port**: The CLI binds an ephemeral socket and forwards to your app's port; you don't stop or move your server.
|
|
255
|
-
- **Refresh/renewal**: Leases refresh automatically (same pattern as TCP).
|
|
256
|
-
- **Errors you may see**:
|
|
257
|
-
- `UDP_EXTERNAL_PORT_OUT_OF_BLOCK`: The requested `--external-port` is outside your tenant's assigned port block.
|
|
258
|
-
- `UDP_RELAY_UNAVAILABLE`: The relay isn't reachable or the WebSocket connection failed.
|
|
259
|
-
|
|
260
|
-
### Minimal Examples
|
|
261
|
-
|
|
262
|
-
Forward a local game server on 25565:
|
|
74
|
+
## 3. Command quick reference
|
|
263
75
|
```bash
|
|
264
|
-
asyx
|
|
76
|
+
asyx setup # Provision device cert & client ID
|
|
77
|
+
asyx tunnel --http --port <n> # HTTP tunnel
|
|
78
|
+
asyx tunnel --tcp --port <n> [--name <alias>] [--external-port <p>]
|
|
79
|
+
asyx tunnel --udp --port <n> [--external-port <p>]
|
|
80
|
+
asyx tunnel --minecraft [--port <n>] [--name <alias>]
|
|
265
81
|
```
|
|
266
|
-
|
|
267
|
-
|
|
82
|
+
- Targets are loopback-only; non-loopback hosts are rejected.
|
|
83
|
+
- `--external-port` must be inside your assigned block; omit to auto-assign blockStart.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 4. Protocol details (high level)
|
|
88
|
+
- **Transport**: TCP/UDP tunnels use WebSocket to the relay (tcpWs/udpWs); guests see native TCP/UDP on the public port.
|
|
89
|
+
- **Assignments**: Coordinator returns `fqdn`, `publicPort`, `relayUrl`, and JWT. CLI validates JWT via JWKS before connecting.
|
|
90
|
+
- **Aliases & SRV**: TCP can create CNAME aliases via `--name`; Minecraft auto-provisions SRV so players use the hostname only.
|
|
91
|
+
- **Loopback-only**: CLI validates; relay enforces at admission/binding. Targets must resolve to loopback.
|
|
92
|
+
- **Owner-only auth**: HTTP can use Quickpass groups; TCP/UDP are owner-authenticated via JWT (no per-guest auth in v4.1).
|
|
93
|
+
|
|
94
|
+
### Quickpass (HTTP guest access control)
|
|
95
|
+
- Passwordless guest access: invite guests into a **security group** and run `asyx tunnel --http --port <n> --secgroup <slug>`.
|
|
96
|
+
- Relay-enforced: guests must present a valid Quickpass cookie; unauthorized requests are rejected at the relay (no app changes).
|
|
97
|
+
- Perfect for sharing dashboards/dev tools without opening them publicly; no VPN, no basic auth.
|
|
98
|
+
- Zero extra infra: no DNS edits, no reverse proxies; the relay does the policy check.
|
|
99
|
+
- Coming extensions: the same flow will back future sharing for TCP/UDP when per-guest auth is added.
|
|
100
|
+
- TCP/UDP today remain owner-only via JWT (no per-guest auth in v4.1).
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 5. Logging
|
|
105
|
+
Set verbosity with `ASYX_LOG_LEVEL` (`error|warn|info|debug`, default `info`):
|
|
268
106
|
```bash
|
|
269
|
-
asyx tunnel --
|
|
107
|
+
ASYX_LOG_LEVEL=debug asyx tunnel --tcp --port 25565
|
|
270
108
|
```
|
|
109
|
+
Structured logs go to stdout/stderr; user banners remain.
|
|
271
110
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
### TCP Tunnel Issues
|
|
275
|
-
|
|
276
|
-
**Alias unavailable:**
|
|
277
|
-
- If the Coordinator returns a warning that an alias is unavailable, use the `fqdn:publicPort` format shown in the CLI output.
|
|
278
|
-
- This is normal during validation phases; `host:port` always works.
|
|
279
|
-
|
|
280
|
-
**Local service not accessible:**
|
|
281
|
-
- Ensure your local service is running on `127.0.0.1:<port>` on the CLI machine.
|
|
282
|
-
- The tunnel forwards connections from the relay to `127.0.0.1:<localPort>`.
|
|
283
|
-
|
|
284
|
-
**Connection timeouts:**
|
|
285
|
-
- If external connections to `fqdn:publicPort` time out, check firewall/port exposure at the relay.
|
|
286
|
-
- The relay must have the `publicPort` open in its security group/firewall rules.
|
|
287
|
-
- Verify the relay is operational and the TCP tunnel is active (check CLI logs).
|
|
288
|
-
|
|
289
|
-
### UDP Tunnel Issues
|
|
290
|
-
|
|
291
|
-
**UDP_EXTERNAL_PORT_OUT_OF_BLOCK:**
|
|
292
|
-
- The requested `--external-port` is outside your tenant's assigned 10-port block.
|
|
293
|
-
- Check your tenant's port block assignment and use a port within that range.
|
|
294
|
-
- If you don't specify `--external-port`, the Coordinator automatically assigns an available port.
|
|
295
|
-
|
|
296
|
-
**UDP_RELAY_UNAVAILABLE:**
|
|
297
|
-
- The relay isn't reachable or the WebSocket connection failed.
|
|
298
|
-
- Check network connectivity and verify the relay is operational.
|
|
299
|
-
- Review CLI logs for connection errors or WebSocket handshake failures.
|
|
300
|
-
|
|
301
|
-
**Local service not receiving packets:**
|
|
302
|
-
- Ensure your local UDP service is running and listening on `127.0.0.1:<port>` (or the `--target-host` you specified).
|
|
303
|
-
- The CLI uses an ephemeral socket and forwards to your app's port; your app must be listening before starting the tunnel.
|
|
304
|
-
- Verify the tunnel is active and the WebSocket connection is established (check CLI output for "UDP tunnel active").
|
|
305
|
-
|
|
306
|
-
**Packets not reaching the relay:**
|
|
307
|
-
- Verify the relay's security group allows UDP traffic on the assigned port range (typically 10000-32000).
|
|
308
|
-
- Check if the relay host has a local firewall (e.g., UFW) that might be blocking UDP traffic.
|
|
309
|
-
- Ensure both AWS Security Group and host-level firewall rules allow UDP on the public port.
|
|
310
|
-
|
|
311
|
-
### MQTT Connection Issues (Windows)
|
|
312
|
-
|
|
313
|
-
If you experience issues where the CLI connects but never receives `open_ack` messages (especially on Windows after running `asyx setup` without OpenSSL), the private key may be in PKCS#8 format which Node's TLS stack on Windows rejects.
|
|
314
|
-
|
|
315
|
-
**Solution**: Rerun `asyx setup` to regenerate keys in the correct format. The CLI will automatically convert existing PKCS#8 keys to PKCS#1 format (required for Windows TLS compatibility).
|
|
316
|
-
|
|
317
|
-
**Manual workaround** (if you cannot rerun setup):
|
|
318
|
-
```javascript
|
|
319
|
-
const crypto = require('crypto');
|
|
320
|
-
const fs = require('fs');
|
|
321
|
-
const keyPath = '~/.asyx/certs/<clientId>/private.pem.key';
|
|
322
|
-
|
|
323
|
-
const keyPem = fs.readFileSync(keyPath, 'utf8');
|
|
324
|
-
const privateKey = crypto.createPrivateKey({ key: keyPem, format: 'pem' });
|
|
325
|
-
const pkcs1Pem = privateKey.export({ type: 'pkcs1', format: 'pem' });
|
|
326
|
-
fs.writeFileSync(keyPath, pkcs1Pem, { mode: 0o600 });
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
This issue is fixed in version 0.1.2+ where keys are automatically generated in PKCS#1 format for Windows compatibility.
|
|
330
|
-
|
|
331
|
-
## Security
|
|
332
|
-
|
|
333
|
-
Asyx tunnels are designed with security-first principles to protect both your local services and the tunnel infrastructure. Every active tunnel operates with **per-tunnel cryptographic isolation**, short-lived JWT credentials, and in-band credential refresh to achieve zero-downtime, zero-trust operation.
|
|
334
|
-
|
|
335
|
-
### Zero Public Exposure
|
|
336
|
-
- **Local services remain private**: Your services never expose ports directly to the internet. All traffic flows through Asyx's cloud-managed relay infrastructure with TLS encryption end-to-end.
|
|
337
|
-
- **No manual firewall rules**: The tunnel architecture eliminates the need to open ports or configure NAT, reducing attack surface.
|
|
111
|
+
---
|
|
338
112
|
|
|
339
|
-
|
|
340
|
-
-
|
|
341
|
-
-
|
|
342
|
-
-
|
|
113
|
+
## 6. Behavior notes
|
|
114
|
+
- Short-lived JWTs with in-band refresh; tunnels stay up without reconnecting.
|
|
115
|
+
- MQTT/JWT control plane is shared across HTTP/TCP/UDP.
|
|
116
|
+
- CLI never binds your app port (TCP/UDP); it forwards to it.
|
|
117
|
+
- Loopback-only enforcement at both CLI and relay.
|
|
118
|
+
- Idle/heartbeat handled automatically; no tuning needed.
|
|
343
119
|
|
|
344
|
-
|
|
345
|
-
- **Unique per-device credentials**: Each `asyx setup` run provisions a unique device certificate and client identifier. Certificates cannot be copied or reused on other machines—policy checks reject duplicate usage.
|
|
346
|
-
- **Hardware attestation without PII**: The CLI derives a hashed hardware fingerprint locally using safe, non-sensitive attributes. Raw hardware data never leaves your device; only a SHA-256 hash (with public salt) is shared for device verification.
|
|
347
|
-
- **Web-based pairing**: CLI installation and pairing occur over HTTPS, binding user identity and device fingerprint to tenant ownership.
|
|
120
|
+
---
|
|
348
121
|
|
|
349
|
-
|
|
350
|
-
- **
|
|
351
|
-
- **
|
|
352
|
-
- **
|
|
353
|
-
- **
|
|
122
|
+
## 7. Why Asyx
|
|
123
|
+
- **Device-bound identity**: Each `setup` issues a unique cert + uuLID per host; backend rejects duplicates to prevent credential reuse.
|
|
124
|
+
- **Hardware attestation without PII**: Fingerprint is hashed locally from safe fields; raw hardware data never leaves the device.
|
|
125
|
+
- **Resilient control plane**: In-band JWT refresh, bounded reconnects, and structured logs (`ASYX_LOG_LEVEL`, `ASYX_DEBUG`) keep long sessions stable.
|
|
126
|
+
- **Zero manual relay config**: Assignments route traffic for you—no DNS edits, firewall poking, or relay setup.
|
|
127
|
+
- **Multi-protocol, one system**: HTTP, TCP, and UDP share the same assignment/JWT/MQTT fabric; pick the protocol that fits your service.
|
|
128
|
+
- **Secure proxy architecture**: Forward-only; avoids local port conflicts and isolates your app from the CLI process.
|
|
129
|
+
- **Observability-first UX**: Clear errors, deterministic exits, optional debug traces.
|
|
130
|
+
- **Future-ready auth**: Today’s magic-link flow extends to sharing via Asyx Quickpass (passwordless downstream approvals).
|
|
354
131
|
|
|
355
|
-
|
|
356
|
-
- **Cryptographic presence monitoring**: Only active relays can receive new assignments, preventing stale routing and unauthorized access.
|
|
357
|
-
- **Event-driven orchestration**: Verifiable routing for DNS assignment, relay control, and session lifecycle via secure cloud events.
|
|
358
|
-
- **Session-level audit trail**: Token issuance (JTI), timestamps, and validation context are logged for complete traceability.
|
|
359
|
-
- **Dynamic access control**: Tunnels can be reassigned or closed in real time based on usage patterns or detected anomalies.
|
|
132
|
+
---
|
|
360
133
|
|
|
361
|
-
|
|
362
|
-
- **
|
|
363
|
-
- **
|
|
364
|
-
- **
|
|
134
|
+
## 7. Troubleshooting (quick)
|
|
135
|
+
- **External port rejected**: ensure `--external-port` is inside your 10-port block.
|
|
136
|
+
- **Relay unavailable**: check network/WSS reachability; see logs for `...RELAY_UNAVAILABLE`.
|
|
137
|
+
- **No traffic to app**: confirm your service is listening on `127.0.0.1:<port>` and the tunnel is active; for UDP ensure the WS is still connected.
|
|
138
|
+
- **Windows MQTT handshake issues**: rerun `asyx setup` to regenerate keys (PKCS#1).
|
|
365
139
|
|
|
366
|
-
|
|
367
|
-
- **Open-source CLI**: The CLI client is open source, allowing independent audit and transparency, reinforcing trust and security posture.
|
|
368
|
-
- **Comprehensive telemetry**: Structured logs for authentication, policy, and reauth events form a complete trust graph for security analysis.
|
|
140
|
+
---
|
|
369
141
|
|
|
370
|
-
|
|
371
|
-
-
|
|
372
|
-
-
|
|
142
|
+
## 8. Security (brief)
|
|
143
|
+
- Device-bound identity per host; hardware fingerprint hashed locally.
|
|
144
|
+
- Mutual TLS to control plane; RS256 JWTs validated via JWKS.
|
|
145
|
+
- Forward-only proxy: your app remains isolated; no direct inbound to your host.
|
|
146
|
+
- Report issues: [security@asyx.ai](mailto:security@asyx.ai) (no public issues for security).
|
|
373
147
|
|
|
374
|
-
|
|
148
|
+
---
|
|
375
149
|
|
|
376
|
-
|
|
150
|
+
## 9. License
|
|
151
|
+
[Apache-2.0](./LICENSE)
|
package/package.json
CHANGED
package/src/commands/mqtt.js
CHANGED
|
@@ -2,11 +2,9 @@ import { constants as fsConstants } from 'node:fs';
|
|
|
2
2
|
import { access } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { AsyxMqttClient, controlWildcard, controlOpen, controlClose, controlStatus } from "@asyx/mqtt-client";
|
|
5
|
-
import { loadOrCreateClientId } from "../lib/device.js";
|
|
5
|
+
import { loadOrCreateClientId, getDeviceJsonPath } from "../lib/device.js";
|
|
6
6
|
import { getSharedTransport } from "../lib/shared-transport.js";
|
|
7
7
|
|
|
8
|
-
const DEVICE_JSON_PATH = join(process.env.HOME ?? '', '.asyx', 'device.json');
|
|
9
|
-
|
|
10
8
|
export default async function mqtt() {
|
|
11
9
|
// Dev-only command gating
|
|
12
10
|
const isDev = process.env.NODE_ENV === 'dev';
|
|
@@ -15,8 +13,9 @@ export default async function mqtt() {
|
|
|
15
13
|
process.exit(2);
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
// Device credential guard
|
|
19
|
-
|
|
16
|
+
// Device credential guard - use same path resolution as device.js
|
|
17
|
+
const deviceJsonPath = getDeviceJsonPath();
|
|
18
|
+
await access(deviceJsonPath, fsConstants.F_OK).catch(() => {
|
|
20
19
|
console.error('This command is for dev use only. Missing ~/.asyx/device.json');
|
|
21
20
|
process.exit(2);
|
|
22
21
|
});
|
|
@@ -138,8 +137,9 @@ async function connect() {
|
|
|
138
137
|
const { readFile } = await import('node:fs/promises');
|
|
139
138
|
const { join: pathJoin } = await import('node:path');
|
|
140
139
|
|
|
141
|
-
|
|
142
|
-
const
|
|
140
|
+
// Use same path resolution as device.js for consistency
|
|
141
|
+
const deviceJsonPath = getDeviceJsonPath();
|
|
142
|
+
const devJson = await readFile(deviceJsonPath, "utf8");
|
|
143
143
|
const dev = JSON.parse(devJson);
|
|
144
144
|
const clientId = dev.clientId;
|
|
145
145
|
const cli = new AsyxMqttClient(t, { clientId });
|
package/src/commands/setup.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import crypto from 'node:crypto';
|
|
6
6
|
import { ensureKeyAndCsr } from '../lib/csr.js';
|
|
7
|
-
import { loadOrCreateClientId } from '../lib/device.js';
|
|
7
|
+
import { loadOrCreateClientId, resetClientId } from '../lib/device.js';
|
|
8
8
|
|
|
9
9
|
const CONSOLE_URL = process.env.ASYX_CONSOLE_URL || 'https://www.asyx.ai/console/tunnel';
|
|
10
10
|
const STS_URL = process.env.ASYX_STS_URL || 'https://www.asyx.ai/www/sts';
|
|
@@ -19,7 +19,28 @@ function isJsonResponse(res) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export default async function cmdSetup(argv = process.argv.slice(2)) {
|
|
22
|
-
|
|
22
|
+
let clientId = loadOrCreateClientId();
|
|
23
|
+
|
|
24
|
+
// Check if there are existing certs that might belong to another user
|
|
25
|
+
// On Windows, multiple users can share the same home directory structure,
|
|
26
|
+
// so we automatically regenerate clientId if existing certs are found
|
|
27
|
+
const certsDir = path.join(os.homedir(), '.asyx', 'certs', clientId);
|
|
28
|
+
try {
|
|
29
|
+
const manifestPath = path.join(certsDir, 'manifest.json');
|
|
30
|
+
if (await fs.access(manifestPath).then(() => true).catch(() => false)) {
|
|
31
|
+
// Existing certs found - regenerate clientId to avoid subdomain mismatch
|
|
32
|
+
// This fixes the Windows multi-user issue where another user's clientId
|
|
33
|
+
// would be reused, causing subdomain mismatch
|
|
34
|
+
console.log(`⚠️ Found existing setup for clientId ${clientId}`);
|
|
35
|
+
console.log(`🔄 Regenerating clientId to ensure correct subdomain assignment...\n`);
|
|
36
|
+
resetClientId();
|
|
37
|
+
clientId = loadOrCreateClientId();
|
|
38
|
+
console.log(` New clientId: ${clientId}\n`);
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
// No existing certs, proceed normally
|
|
42
|
+
}
|
|
43
|
+
|
|
23
44
|
if (!/^cli_[A-F0-9]{12}$/.test(clientId)) {
|
|
24
45
|
console.error('Invalid clientId format (expected cli_[A-F0-9]{12})');
|
|
25
46
|
process.exit(2);
|
package/src/commands/sts.js
CHANGED
|
@@ -6,14 +6,14 @@ import fssync from 'node:fs';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import os from 'node:os';
|
|
8
8
|
import { ensureKeyAndCsr } from '../lib/csr.js';
|
|
9
|
-
import { loadOrCreateClientId } from '../lib/device.js';
|
|
9
|
+
import { loadOrCreateClientId, getDeviceJsonPath } from '../lib/device.js';
|
|
10
10
|
|
|
11
11
|
const STS_URL = process.env.ASYX_STS_URL || 'https://www.asyx.ai/www/sts';
|
|
12
|
-
const DEVICE_JSON_PATH = join(process.env.HOME ?? '', '.asyx', 'device.json');
|
|
13
12
|
|
|
14
13
|
export default async function cmdSts(argv = process.argv.slice(2)) {
|
|
15
|
-
// Device credential guard
|
|
16
|
-
|
|
14
|
+
// Device credential guard - use same path resolution as device.js
|
|
15
|
+
const deviceJsonPath = getDeviceJsonPath();
|
|
16
|
+
await access(deviceJsonPath, fsConstants.F_OK).catch(() => {
|
|
17
17
|
console.error('This command is for dev use only. Missing ~/.asyx/device.json');
|
|
18
18
|
process.exit(2);
|
|
19
19
|
});
|
package/src/commands/tunnel.js
CHANGED
|
@@ -9,8 +9,7 @@ import crypto from "node:crypto";
|
|
|
9
9
|
import logger from "../lib/logger.js";
|
|
10
10
|
import { dispatch as dispatchEvt } from "../mqtt/events/index.js";
|
|
11
11
|
import { MessageIngress } from "../mqtt/ingress.js";
|
|
12
|
-
|
|
13
|
-
const DEVICE_JSON_PATH = join(process.env.HOME ?? '', '.asyx', 'device.json');
|
|
12
|
+
import { getDeviceJsonPath } from "../lib/device.js";
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* QPA-CLI-09: Publish refresh request with ECONNRESET error handling.
|
|
@@ -78,8 +77,9 @@ export async function publishRefreshRequestWithErrorHandling(
|
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
export default async function tunnel(args = []) {
|
|
81
|
-
// Device credential guard
|
|
82
|
-
|
|
80
|
+
// Device credential guard - use same path resolution as device.js
|
|
81
|
+
const deviceJsonPath = getDeviceJsonPath();
|
|
82
|
+
await access(deviceJsonPath, fsConstants.F_OK).catch(() => {
|
|
83
83
|
console.error('This command is for dev use only. Missing ~/.asyx/device.json');
|
|
84
84
|
process.exit(2);
|
|
85
85
|
});
|
package/src/lib/device.js
CHANGED
|
@@ -1,18 +1,51 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as fs from "fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import crypto from "node:crypto";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
function resolveConfigDir() {
|
|
7
|
+
// Allow explicit override (useful for Windows/packaged builds)
|
|
8
|
+
if (process.env.ASYX_CONFIG_DIR && process.env.ASYX_CONFIG_DIR.trim()) {
|
|
9
|
+
return process.env.ASYX_CONFIG_DIR.trim();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Standard resolution via os.homedir()
|
|
13
|
+
const home = homedir();
|
|
14
|
+
if (home) return join(home, ".asyx");
|
|
15
|
+
|
|
16
|
+
// Defensive fallbacks for Windows in case os.homedir() cannot resolve
|
|
17
|
+
if (process.env.USERPROFILE) return join(process.env.USERPROFILE, ".asyx");
|
|
18
|
+
if (process.env.HOMEDRIVE && process.env.HOMEPATH) {
|
|
19
|
+
return join(`${process.env.HOMEDRIVE}${process.env.HOMEPATH}`, ".asyx");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
throw new Error("Unable to determine Asyx config directory (missing home directory)");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const DIR = resolveConfigDir();
|
|
7
26
|
const FILE = join(DIR, "device.json");
|
|
8
27
|
|
|
9
28
|
export function loadOrCreateClientId() {
|
|
10
|
-
if (!existsSync(DIR)) mkdirSync(DIR, { recursive: true });
|
|
11
|
-
if (existsSync(FILE)) {
|
|
12
|
-
const raw = JSON.parse(readFileSync(FILE, "utf8"));
|
|
29
|
+
if (!fs.existsSync(DIR)) fs.mkdirSync(DIR, { recursive: true });
|
|
30
|
+
if (fs.existsSync(FILE)) {
|
|
31
|
+
const raw = JSON.parse(fs.readFileSync(FILE, "utf8"));
|
|
13
32
|
if (raw?.clientId) return raw.clientId;
|
|
14
33
|
}
|
|
15
34
|
const clientId = "cli_" + crypto.randomUUID().replace(/-/g, "").slice(0, 12).toUpperCase();
|
|
16
|
-
writeFileSync(FILE, JSON.stringify({ clientId }, null, 2));
|
|
35
|
+
fs.writeFileSync(FILE, JSON.stringify({ clientId }, null, 2));
|
|
17
36
|
return clientId;
|
|
18
37
|
}
|
|
38
|
+
|
|
39
|
+
export function resetClientId() {
|
|
40
|
+
if (fs.existsSync(FILE)) {
|
|
41
|
+
fs.writeFileSync(FILE, JSON.stringify({}, null, 2));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get the path to device.json using the same resolution logic as loadOrCreateClientId
|
|
47
|
+
* This ensures consistent path resolution across all commands (tunnel, setup, etc.)
|
|
48
|
+
*/
|
|
49
|
+
export function getDeviceJsonPath() {
|
|
50
|
+
return FILE;
|
|
51
|
+
}
|