8000 fix: resolve `vmsan create --connect` failing with HTTP 500 by angelorc · Pull Request #32 · angelorc/vmsan · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion agent/shell/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log/slog"
"net/http"
"path/filepath"
"strings"

"github.com/gorilla/websocket"
)
Expand Down Expand Up @@ -81,7 +82,11 @@ func (h *Handler) handleNewSession(w http.ResponseWriter, r *http.Request) {
if err.Error() == "max sessions reached" {
http.Error(w, `{"error":"too many concurrent sessions"}`, http.StatusTooManyRequests)
} else {
http.Error(w, `{"error":"internal error"}`, http.StatusInternalServerError)
h.logger.Error("shell.session.create_failed", "shell", shell, "user", runAs, "error", err)
// Sanitize: only include the first line to avoid leaking stack traces.
msg := strings.SplitN(err.Error(), "\n", 2)[0]
encoded, _ := json.Marshal(msg)
http.Error(w, `{"error":`+string(encoded)+`}`, http.StatusInternalServerError)
}
return
}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/jailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ export class Jailer {
);
}

// Fix /home/ubuntu ownership so the ubuntu user (uid 1000) can access
// their home directory. Some base rootfs images ship /home/ubuntu owned
// by root:root which causes EACCES when the agent runs commands as ubuntu.
const ubuntuHome = join(tmpMount, "home", "ubuntu");
if (existsSync(ubuntuHome)) {
execSync(`sudo chown 1000:1000 "${ubuntuHome}"`, { stdio: "pipe" });
}

execSync(`sudo umount "${tmpMount}"`, { stdio: "pipe" });
} catch {
// Mount point may already be unmounted or directory removed
Expand Down
15 changes: 15 additions & 0 deletions src/lib/shell/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ export class ShellSession {
});
});

this.ws.on("unexpected-response", (_req, res) => {
const maxBytes = 4096;
let body = "";
res.on("data", (chunk: Buffer) => {
if (body.length < maxBytes) {
body += chunk.toString().slice(0, maxBytes - body.length);
}
});
res.on("end", () => {
cleanup();
const detail = body.trim() || "no response body";
reject(new Error(`Shell connection failed (HTTP ${res.statusCode}): ${detail}`));
});
});

this.ws.on("error", (err) => {
cleanup();
reject(err);
Expand Down
0