Skip to content

Commit 05b363f

Browse files
committed
Delete partially working: user, window resizing
1 parent 919e165 commit 05b363f

File tree

7 files changed

+49
-532
lines changed

7 files changed

+49
-532
lines changed

cmd/api/api/exec.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ var upgrader = websocket.Upgrader{
3030
type ExecRequest struct {
3131
Command []string `json:"command"`
3232
TTY bool `json:"tty"`
33-
User string `json:"user,omitempty"`
34-
UID int32 `json:"uid,omitempty"`
3533
Env map[string]string `json:"env,omitempty"`
3634
Cwd string `json:"cwd,omitempty"`
3735
Timeout int32 `json:"timeout,omitempty"` // seconds
@@ -111,8 +109,6 @@ func (s *ApiService) ExecHandler(w http.ResponseWriter, r *http.Request) {
111109
"subject", subject,
112110
"command", execReq.Command,
113111
"tty", execReq.TTY,
114-
"user", execReq.User,
115-
"uid", execReq.UID,
116112
"cwd", execReq.Cwd,
117113
"timeout", execReq.Timeout,
118114
)
@@ -127,8 +123,6 @@ func (s *ApiService) ExecHandler(w http.ResponseWriter, r *http.Request) {
127123
Stdout: wsConn,
128124
Stderr: wsConn,
129125
TTY: execReq.TTY,
130-
User: execReq.User,
131-
UID: execReq.UID,
132126
Env: execReq.Env,
133127
Cwd: execReq.Cwd,
134128
Timeout: execReq.Timeout,

cmd/api/api/exec_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -182,29 +182,6 @@ func TestExecInstanceNonTTY(t *testing.T) {
182182
t.Logf("Command output: %q", outStr)
183183
require.Contains(t, outStr, "root", "whoami should return root user")
184184

185-
// Test another command to verify filesystem access and container context
186-
// We should see /docker-entrypoint.sh which is standard in nginx:alpine image
187-
t.Log("Testing exec command: ls /docker-entrypoint.sh")
188-
stdout = outputBuffer{}
189-
stderr = outputBuffer{}
190-
191-
t.Log("Calling ExecIntoInstance for ls command...")
192-
exit, err = exec.ExecIntoInstance(ctx(), actualInst.VsockSocket, exec.ExecOptions{
193-
Command: []string{"/bin/sh", "-c", "ls -la /docker-entrypoint.sh"},
194-
Stdin: nil,
195-
Stdout: &stdout,
196-
Stderr: &stderr,
197-
TTY: false,
198-
})
199-
t.Logf("ExecIntoInstance returned: err=%v, exit=%v", err, exit)
200-
201-
require.NoError(t, err, "ls command should succeed")
202-
require.Equal(t, 0, exit.Code, "ls should exit with code 0")
203-
204-
outStr = stdout.String()
205-
t.Logf("ls output: %q", outStr)
206-
require.Contains(t, outStr, "docker-entrypoint.sh", "should see docker-entrypoint.sh file")
207-
208185
// Cleanup
209186
t.Log("Cleaning up instance...")
210187
delResp, err := svc.DeleteInstance(ctx(), oapi.DeleteInstanceRequestObject{

lib/exec/README.md

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ Container (chroot /overlay/newroot)
3030
{
3131
"command": ["bash", "-c", "whoami"],
3232
"tty": true,
33-
"user": "www-data", // optional: username to run as
34-
"uid": 1000, // optional: UID to run as (overrides user)
3533
"env": { // optional: environment variables
3634
"FOO": "bar"
3735
},
@@ -56,10 +54,8 @@ Container (chroot /overlay/newroot)
5654
gRPC streaming RPC with protobuf messages:
5755

5856
**Request (client → server):**
59-
- `ExecStart`: Command, TTY flag, user/UID, environment variables, working directory, timeout
57+
- `ExecStart`: Command, TTY flag, environment variables, working directory, timeout
6058
- `stdin`: Input data bytes
61-
- `WindowSize`: Terminal resize events (TTY mode)
62-
- `Signal`: Send Unix signal to process (SIGINT, SIGTERM, SIGKILL, etc.)
6359

6460
**Response (server → client):**
6561
- `stdout`: Output data bytes
@@ -117,10 +113,6 @@ export HYPEMAN_TOKEN="your-jwt-token"
117113
./bin/hypeman-exec <instance-id> /bin/sh
118114
./bin/hypeman-exec -it <instance-id> /bin/sh
119115

120-
# Run as specific user
121-
./bin/hypeman-exec --user www-data <instance-id> whoami
122-
./bin/hypeman-exec --uid 1000 <instance-id> whoami
123-
124116
# With environment variables
125117
./bin/hypeman-exec --env FOO=bar --env BAZ=qux <instance-id> env
126118
./bin/hypeman-exec -e FOO=bar -e BAZ=qux <instance-id> env
@@ -132,17 +124,14 @@ export HYPEMAN_TOKEN="your-jwt-token"
132124
./bin/hypeman-exec --timeout 30 <instance-id> /long-running-script.sh
133125

134126
# Combined options
135-
./bin/hypeman-exec --user www-data --cwd /app --env ENV=prod \
136-
<instance-id> php artisan migrate
127+
./bin/hypeman-exec --cwd /app --env ENV=prod <instance-id> php artisan migrate
137128
```
138129

139130
### Options
140131

141132
- `-it`: Interactive mode with TTY (auto-detected if stdin/stdout are terminals)
142133
- `--token`: JWT token (or use `HYPEMAN_TOKEN` env var)
143134
- `--api-url`: API server URL (default: `http://localhost:8080`)
144-
- `--user`: Username to run command as
145-
- `--uid`: UID to run command as (overrides `--user`)
146135
- `--env` / `-e`: Environment variable (KEY=VALUE, can be repeated)
147136
- `--cwd`: Working directory
148137
- `--timeout`: Execution timeout in seconds (0 = no timeout)
@@ -188,24 +177,10 @@ The guest agent logs are written to the VM console log (accessible via `/var/lib
188177
```
189178
[exec-agent] listening on vsock port 2222
190179
[exec-agent] new exec stream
191-
[exec-agent] exec: command=[bash -c whoami] tty=true user=www-data uid=0 cwd=/app timeout=30
180+
[exec-agent] exec: command=[bash -c whoami] tty=true cwd=/app timeout=30
192181
[exec-agent] command finished with exit code: 0
193182
```
194183

195-
## Signal Support
196-
197-
The protocol supports sending Unix signals to running processes:
198-
199-
- `SIGHUP` (1): Hangup
200-
- `SIGINT` (2): Interrupt (Ctrl-C)
201-
- `SIGQUIT` (3): Quit
202-
- `SIGKILL` (9): Kill (cannot be caught)
203-
- `SIGTERM` (15): Terminate
204-
- `SIGSTOP` (19): Stop process
205-
- `SIGCONT` (18): Continue process
206-
207-
Signals can be sent via the WebSocket stream (implementation detail for advanced clients).
208-
209184
## Timeout Behavior
210185

211186
When a timeout is specified:
@@ -214,21 +189,11 @@ When a timeout is specified:
214189
- The exit code will be `124` (GNU timeout convention)
215190
- Timeout is enforced in the guest, so network issues won't cause false timeouts
216191

217-
## PTY Signal Handling & Architecture
218-
219-
For TTY mode (interactive shells), **the exec-agent runs inside the container namespace** - this is critical for proper signal handling:
220-
221-
### Why This Matters
222-
When the PTY and shell are in the same namespace, Ctrl+C (byte `0x03`) is correctly interpreted as SIGINT and delivered to the process. Running exec-agent in initrd namespace and using chroot for commands creates a namespace boundary that breaks signal handling.
223-
224-
### Implementation
225-
The init script (`lib/system/init_script.go`):
226-
1. Copies exec-agent into `/overlay/newroot/usr/local/bin/`
227-
2. Bind-mounts `/dev/pts` so PTY devices are accessible in container
228-
3. Runs exec-agent with `chroot /overlay/newroot`
192+
## Architecture
229193

230-
This ensures:
231-
- Ctrl+C, Ctrl+Z, and other terminal control sequences work correctly
232-
- PTY and process share the same namespace
233-
- No chroot wrapper needed when executing commands (agent is already in container)
194+
**exec-agent runs inside the container namespace**:
195+
- Init script copies agent binary into `/overlay/newroot/usr/local/bin/`
196+
- Bind-mounts `/dev/pts` so PTY devices are accessible
197+
- Runs agent with `chroot /overlay/newroot`
198+
- Commands execute directly (no chroot wrapper needed)
234199

lib/exec/client.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ type ExecOptions struct {
2424
Stdout io.Writer
2525
Stderr io.Writer
2626
TTY bool
27-
User string // Username to run as (optional)
28-
UID int32 // UID to run as (optional, overrides User)
2927
Env map[string]string // Environment variables
3028
Cwd string // Working directory (optional)
3129
Timeout int32 // Execution timeout in seconds (0 = no timeout)
@@ -87,8 +85,6 @@ func ExecIntoInstance(ctx context.Context, vsockSocketPath string, opts ExecOpti
8785
Start: &ExecStart{
8886
Command: opts.Command,
8987
Tty: opts.TTY,
90-
User: opts.User,
91-
Uid: opts.UID,
9288
Env: opts.Env,
9389
Cwd: opts.Cwd,
9490
TimeoutSeconds: opts.Timeout,

0 commit comments

Comments
 (0)