fix(xcecli): assert own hostname as FROM_HOST at submission time (bug-1676, gitea #44)
JobSubmitRequest gains a FromHost field, populated in BuildJobRequest() via os.Hostname(). Matches how traditional batch schedulers report the submitting host, and sidesteps having the server derive it from the connection (which apiserver was doing via ctx.ClientIP() -- an IP not a hostname, and spoofable via X-Forwarded-For since this apiserver never configures gin's TrustedProxies). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AgYRU3zDTqNGV5Jk8aiKLg
This commit is contained in:
parent
590e2a726e
commit
4fad788430
3 changed files with 37 additions and 0 deletions
27
src/frontend/xcecli/cmd/jobs/submit_test.go
Normal file
27
src/frontend/xcecli/cmd/jobs/submit_test.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package jobs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// bug-1676: BuildJobRequest asserts our own hostname as FromHost rather than
|
||||
// leaving it for the server to derive from the connection (spoofable via
|
||||
// X-Forwarded-For, and only ever an IP, never a hostname).
|
||||
func TestBuildJobRequest_SetsFromHostToLocalHostname(t *testing.T) {
|
||||
js := NewJobSubmitter(nil)
|
||||
js.command = "sleep 1"
|
||||
|
||||
req, err := js.BuildJobRequest()
|
||||
if err != nil {
|
||||
t.Fatalf("BuildJobRequest: %v", err)
|
||||
}
|
||||
|
||||
wantHost, hostErr := os.Hostname()
|
||||
if hostErr != nil {
|
||||
t.Skipf("os.Hostname() unavailable in this environment: %v", hostErr)
|
||||
}
|
||||
if req.FromHost != wantHost {
|
||||
t.Errorf("FromHost = %q, want local hostname %q", req.FromHost, wantHost)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue