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
4 changes: 2 additions & 2 deletions scripts/dev-fleet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ inpanel curl -sS -m 40 -D "$STATE/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mi
-H 'Content-Type: application/json' \
-d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" '{setupToken:$t, ceremonyId:$c, totpCode:$code}')"
grep -q '^HTTP/[0-9.]* 200' "$STATE/setup.hdr" || die "FinishSetup failed: $(head -1 "$STATE/setup.hdr")"
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$STATE/setup.hdr" | tr -d '\r')
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$STATE/setup.hdr" | tr -d '\r')
[ -n "$COOKIE" ] || die "FinishSetup set no session cookie"
api AuthService/Me | jq -e '.admin.id' >/dev/null || die "the session cookie does not work"
say "panel up, first admin created"
Expand Down Expand Up @@ -247,7 +247,7 @@ say "three nodes online (de1, nl1, fi1), a Hysteria2 inbound on each (UDP 4433,

# ---------------------------------------------------------------- the owner's session for the token script, and the token
umask 077
( printf 'MG_ADMIN_URL=%s\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\nMG_NETNS=%s\n' "$ADMIN" "${COOKIE#__Host-sid=}" "$TOTP_SECRET" mgdf-panel >"$STATE/owner.env" )
( printf 'MG_ADMIN_URL=%s\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\nMG_NETNS=%s\n' "$ADMIN" "${COOKIE#*=}" "$TOTP_SECRET" mgdf-panel >"$STATE/owner.env" )
echo
say "admin URL: $ADMIN/ (loopback inside the namespace mgdf-panel: reach it with ip netns exec mgdf-panel <command>)"
if [ -z "$MCP_E2E" ]; then
Expand Down
4 changes: 2 additions & 2 deletions scripts/e2e-wsl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ curl -sS -m 40 -D "$WORK/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mistgate.ad
-H 'Content-Type: application/json' \
-d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" '{setupToken:$t, ceremonyId:$c, totpCode:$code}')"
grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "FinishSetup failed: $(head -1 "$WORK/setup.hdr")"
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
[ -n "$COOKIE" ] || die "FinishSetup set no session cookie"
SECRETS+=("${COOKIE#*=}")
TOTP_LAST=$(($(date +%s) / 30)) STEPUP_UNTIL=$(($(date +%s) + 280)) # the sign-in just proved a factor: step-up is open for 5 minutes
Expand Down Expand Up @@ -1597,7 +1597,7 @@ if [ -n "${HOLD:-}" ]; then
[ -z "$EDGE" ] || die "--hold is for the VPS edition"
( umask 077
printf 'MG_ADMIN_URL=%s/\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\nMG_NETNS=%s\n' \
"$ADMIN" "${COOKIE#__Host-sid=}" "$TOTP_SECRET" "${MG_E2E_NS:-}" >"$WORK/owner.env" )
"$ADMIN" "${COOKIE#*=}" "$TOTP_SECRET" "${MG_E2E_NS:-}" >"$WORK/owner.env" )
step "12. holding: the test panel stays up until Ctrl-C"
say "admin $ADMIN/ (in network namespace ${MG_E2E_NS:-none}), owner session and authenticator secret in $WORK/owner.env"
say "make an MCP token (from another shell): bash scripts/e2e/mcp-token.sh $WORK/owner.env"
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e/bridge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ start_panel() {
-H 'Content-Type: application/json' -d "$(jq -nc --arg t "$token" --arg c "$ceremony" --arg code "$(totp_code)" \
'{setupToken:$t,ceremonyId:$c,totpCode:$code}')"
grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "first-admin setup failed"
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
[ -n "$COOKIE" ] || die "no session cookie"
OWNER_STEP=$(($(date +%s) / 30))
OWNER_STEPUP_UNTIL=$(api AuthService/Me | jq -r '.stepUpUntilUnix // 0')
Expand Down
6 changes: 3 additions & 3 deletions scripts/e2e/censor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ inpanel curl -skS -m 30 -D "$WORK/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mi
-H 'Content-Type: application/json' -d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" \
'{setupToken:$t,ceremonyId:$c,totpCode:$code}')"
grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "first-admin setup failed"
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
[ -n "$COOKIE" ] || die "first-admin setup did not set a session cookie"
ME=$(api AuthService/Me)
jq -e '.admin.id' <<<"$ME" >/dev/null || die "the owner session does not work"
Expand Down Expand Up @@ -440,10 +440,10 @@ python3 "$WORK/vless_to_xray.py" "$WORK/vless.uri" 10809 "$WORK/xray-op-b.json"
chmod 600 "$WORK/xray-op-a.json" "$WORK/xray-op-b.json"

# Mint the same admin-profile token a separate MCP client receives from the panel owner.
inpanel env MG_ADMIN_URL="$ADMIN" MG_OWNER_COOKIE="${COOKIE#__Host-sid=}" MG_TOTP_SECRET="$TOTP_SECRET" \
inpanel env MG_ADMIN_URL="$ADMIN" MG_OWNER_COOKIE="${COOKIE#*=}" MG_TOTP_SECRET="$TOTP_SECRET" \
"$BIN/mcptoken" -profile admin -name censor-sim >"$MCP_TOKEN" 2>"$WORK/mcptoken.log" || die "could not mint the lab MCP token"
OWNER_STEP=$(( $(date +%s) / 30 ))
printf 'MG_ADMIN_URL=%s\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\n' "$ADMIN" "${COOKIE#__Host-sid=}" "$TOTP_SECRET" >>"$MCP_SECRETS"
printf 'MG_ADMIN_URL=%s\nMG_OWNER_COOKIE=%s\nMG_TOTP_SECRET=%s\n' "$ADMIN" "${COOKIE#*=}" "$TOTP_SECRET" >>"$MCP_SECRETS"
chmod 600 "$MCP_TOKEN" "$MCP_SECRETS"
say "profiles, owner settings and alice's test subscription are ready"

Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e/edge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ PY
-H 'Content-Type: application/json' \
-d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" '{setupToken:$t, ceremonyId:$c, totpCode:$code}')"
grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "FinishSetup failed: $(head -1 "$WORK/setup.hdr")"
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
[ -n "$COOKIE" ] || die "FinishSetup set no session cookie"
SECRETS+=("${COOKIE#*=}")
TOTP_LAST=$(($(date +%s) / 30)) STEPUP_UNTIL=$(($(date +%s) + 280))
Expand Down
12 changes: 10 additions & 2 deletions scripts/e2e/mcpe2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func (e *env) rpc(cookie, bearer, svc, method string, body any) (int, map[string
req, _ := http.NewRequest("POST", e.admin+"api/mistgate.admin.v1."+svc+"/"+method, bytes.NewReader(b))
req.Header.Set("Content-Type", "application/json")
if cookie != "" {
req.Header.Set("Cookie", "__Host-sid="+cookie)
req.Header.Set("Cookie", cookieName(e.admin)+"="+cookie)
}
if bearer != "" {
req.Header.Set("Authorization", "Bearer "+bearer)
Expand Down Expand Up @@ -650,7 +650,7 @@ func (e *env) signup(setupToken string) error {
return fmt.Errorf("FinishSetup %d", resp.StatusCode)
}
for _, c := range resp.Cookies() {
if c.Name == "__Host-sid" {
if c.Name == cookieName(e.admin) {
e.cookie = c.Value
}
}
Expand Down Expand Up @@ -1306,3 +1306,11 @@ func (e *env) leaks() {
}
e.check(fmt.Sprintf("no secret in the panel log (%d bytes)", len(log)), len(lhit) == 0, "leaked: %v", lhit)
}

// cookieName is the session cookie of the admin listener: __Host-sid over HTTPS, sid on the plain-HTTP admin listener.
func cookieName(admin string) string {
if strings.HasPrefix(admin, "http://") {
return "sid"
}
return "__Host-sid"
}
10 changes: 9 additions & 1 deletion scripts/e2e/mcptoken/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *client) rpc(svc, method string, body any) (int, map[string]any) {
b, _ := json.Marshal(body)
req, _ := http.NewRequest("POST", c.admin+"api/mistgate.admin.v1."+svc+"/"+method, bytes.NewReader(b))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Cookie", "__Host-sid="+c.cookie)
req.Header.Set("Cookie", cookieName(c.admin)+"="+c.cookie)
resp, err := hc.Do(req)
if err != nil {
fail(err.Error())
Expand Down Expand Up @@ -123,3 +123,11 @@ func fail(msg string) {
fmt.Fprintln(os.Stderr, "mcptoken:", msg)
os.Exit(1)
}

// cookieName is the session cookie of the admin listener: __Host-sid over HTTPS, sid on the plain-HTTP admin listener.
func cookieName(admin string) string {
if strings.HasPrefix(admin, "http://") {
return "sid"
}
return "__Host-sid"
}
2 changes: 1 addition & 1 deletion scripts/e2e/probe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ inpanel curl -skS -m 30 -D "$WORK/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mi
-H 'Content-Type: application/json' -d "$(jq -nc --arg t "$SETUP_TOKEN" --arg c "$CEREMONY" --arg code "$(totp_code)" \
'{setupToken:$t,ceremonyId:$c,totpCode:$code}')"
grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "first-admin setup failed"
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
[ -n "$COOKIE" ] || die "first-admin setup did not set a session cookie"
ME=$(api AuthService/Me)
jq -e '.admin.id' <<<"$ME" >/dev/null || die "the owner session does not work"
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e/sni443.sh
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ start_panel() {
-H 'Content-Type: application/json' -d "$(jq -nc --arg t "$token" --arg c "$ceremony" --arg code "$(totp_code)" \
'{setupToken:$t,ceremonyId:$c,totpCode:$code}')"
grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "first-admin setup failed"
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
[ -n "$COOKIE" ] || die "no session cookie"
OWNER_STEP=$(($(date +%s) / 30))
OWNER_STEPUP_UNTIL=$(api AuthService/Me | jq -r '.stepUpUntilUnix // 0')
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e/trusttunnel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ tt_hold() {
MG_OWNER_COOKIE=%s
MG_TOTP_SECRET=%s
MG_NETNS=%s
' "$ADMIN" "${COOKIE#__Host-sid=}" "$TOTP_SECRET" "${MG_E2E_NS:-}" >"$WORK/owner.env" )
' "$ADMIN" "${COOKIE#*=}" "$TOTP_SECRET" "${MG_E2E_NS:-}" >"$WORK/owner.env" )
say "the settings of both: $WORK/tt-dev.env; the admin API is $ADMIN, the owner session of this panel in $WORK/owner.env (0600). To switch a person off while a connection is open: POST <admin>/api/mistgate.admin.v1.UserService/SetUsersEnabled {"userIds":[TT_ALICE_USER_ID],"enabled":false} with the owner cookie and a fresh authenticator code of MG_TOTP_SECRET (a step-up, as the stand does in E5)"
trap 'exit 0' INT TERM
FINISHED=1
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ stage_seed() {
curl -sS -m 40 -D "$WORK/setup.hdr" -o /dev/null -X POST "$ADMIN/api/mistgate.admin.v1.AuthService/FinishSetup" -H 'Content-Type: application/json' \
-d "$(jq -nc --arg t "$token" --arg c "$ceremony" --arg code "$(fresh_totp)" '{setupToken:$t, ceremonyId:$c, totpCode:$code}')"
grep -q '^HTTP/[0-9.]* 200' "$WORK/setup.hdr" || die "FinishSetup failed"
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(__Host-sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
COOKIE=$(sed -n 's/^[Ss]et-[Cc]ookie: \(\(__Host-\)\{0,1\}sid=[^;]*\).*/\1/p' "$WORK/setup.hdr" | tr -d '\r')
STEPUP_UNTIL=$(($(date +%s) + 280))
save_state COOKIE
ok "old panel up, owner created (password + authenticator code), signed in"
Expand Down
Loading