Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d266a86
fix(api): harden readiness, login throttling, audit and resource owne…
claude Nov 27, 2026
ddad587
fix(web): block every readiness path, honour the upload limit, flush …
claude Nov 27, 2026
a5c980d
fix(operator): rcon Secret adoption, backup Job names, OCI layer caps…
claude Nov 27, 2026
b4b92e6
fix(agent,gameproto): archive hard links, gzip integrity, Minecraft t…
claude Nov 27, 2026
d6afd9f
fix(telemetry,gp-module): cap k8s versions per report, package only m…
claude Nov 27, 2026
b39afec
fix(ci): check design-export paths after applying the patch
claude Nov 27, 2026
cdb9c4c
fix(images): make the FiveM, Farming Simulator 25 and ETS2 images run
claude Nov 27, 2026
9f263aa
docs(changelog): add the audit fixes entry
claude Nov 27, 2026
17597d1
fix(api): take the argon2 slot before building the dummy hash
claude Nov 27, 2026
32aad76
fix(api): lint findings in the audit and ownership changes
claude Nov 27, 2026
b9569ea
test(agent): cover the gzip trailer and hard link target checks
claude Nov 27, 2026
a1c179a
fix(api): keep the login file to the invalid-credentials message
claude Nov 27, 2026
207ddd2
fix: address review on the audit fixes
claude Nov 27, 2026
80942ec
fix(api): close response bodies in the busy tests
claude Nov 27, 2026
8e78fd8
fix: close review gaps in the audit fixes
claude Nov 27, 2026
f8e92e1
fix(telemetry-receiver): cap the folded k8s other share at 100%
claude Nov 27, 2026
65152d5
fix(operator): use the user's RCON password config field
claude Nov 27, 2026
d8799d6
chore: bump sftp to include GameplanePanel/sftp#7
claude Nov 27, 2026
acc1420
chore: merge master into fix/security-bug-audit-2026-11-27
claude Nov 27, 2026
c0d9776
test(bundlefetch): cover negative layer sizes, the module bundle tota…
claude Nov 27, 2026
69ca74f
test(bundlefetch): store the template blob in the bundle-total test
claude Nov 27, 2026
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
8 changes: 5 additions & 3 deletions .github/workflows/design-export.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
working-directory: gameplane
run: |
git add -A assets/design-export telemetry-receiver/design-export
git diff --cached --binary > "$RUNNER_TEMP/design-export.patch"
git diff --cached --binary --no-renames > "$RUNNER_TEMP/design-export.patch"
if [ -s "$RUNNER_TEMP/design-export.patch" ]; then
git diff --cached --stat
echo "changed=true" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -126,13 +126,15 @@ jobs:
exit 0
fi
# The patch comes from a run of the PR's own script: push nothing outside the export folders.
outside=$(git apply --numstat "$RUNNER_TEMP/design-export.patch" | cut -f3 |
# Check what the applied patch staged, not the patch's own path list: a rename lists
# only its destination there, so it could delete any file outside the export folders.
git apply --index "$RUNNER_TEMP/design-export.patch"
outside=$(git diff --cached --name-only --no-renames |
grep -vE '^(assets/design-export|telemetry-receiver/design-export)/' || true)
if [ -n "$outside" ]; then
echo "::error::The export patch touches files outside the export folders: $outside"
exit 1
fi
git apply --index "$RUNNER_TEMP/design-export.patch"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -s -q -m "design: regenerate the design export"
Expand Down
45 changes: 45 additions & 0 deletions agent/internal/archive/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ func (x *extractor) mkdir(dst string, mode fs.FileMode) error {
return err
}
_ = unix.Close(fd)
delete(x.files, dst)
x.dirs[dst] = mode
return nil
}
Expand Down Expand Up @@ -604,6 +605,9 @@ func (x *extractor) symlink(dst, target string) error {
if err != nil {
return fmt.Errorf("create symlink: %w", err)
}
// The name now holds a symlink: a later hard link must not reuse the
// regular file recorded earlier under the same name.
delete(x.files, dst)
return nil
}

Expand Down Expand Up @@ -644,6 +648,13 @@ func (x *extractor) hardlink(dst, rawTarget string, lay layout) error {
}
defer func() { _ = unix.Close(pfd) }()
tbase := path.Base(td)
var st unix.Stat_t
if err := unix.Fstatat(tfd, tbase, &st, unix.AT_SYMLINK_NOFOLLOW); err != nil {
return fmt.Errorf("hard link target %q is not a regular file: %w", rawTarget, err)
}
if st.Mode&unix.S_IFMT != unix.S_IFREG {
return fmt.Errorf("hard link target %q is not a regular file", rawTarget)
}
err = unix.Linkat(tfd, tbase, pfd, base, 0)
if errors.Is(err, unix.EEXIST) {
if err := unix.Unlinkat(pfd, base, 0); err != nil {
Expand Down Expand Up @@ -756,6 +767,22 @@ func (s *tarStream) next() (rawEntry, error) {
for {
h, err := s.tr.Next()
if errors.Is(err, io.EOF) {
// Read the gzip stream to its end so the CRC32 and size
// trailer are verified, and refuse non-zero trailing data.
// The drain is capped: zero runs compress about 1000:1, so an
// unbounded drain would let a small upload cost gigabytes of
// decompression before extraction even starts.
var zc zeroChecker
n, derr := io.Copy(&zc, io.LimitReader(s.gz, maxTarTrailerBytes+1))
if derr != nil {
return rawEntry{}, fmt.Errorf("read archive: %w", derr)
}
if n > maxTarTrailerBytes {
return rawEntry{}, fmt.Errorf("read archive: more than %d bytes after tar end marker", maxTarTrailerBytes)
}
if zc.dirty {
return rawEntry{}, errors.New("read archive: unexpected data after tar end marker")
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
return rawEntry{}, io.EOF
}
if err != nil {
Expand Down Expand Up @@ -785,6 +812,24 @@ func (s *tarStream) next() (rawEntry, error) {
return e, nil
}

// maxTarTrailerBytes caps the zero padding accepted after the tar end
// marker. tar writers pad to their record size (10 KiB by default); 1 MiB
// leaves room for large blocking factors.
const maxTarTrailerBytes = 1 << 20

// zeroChecker discards writes and records whether any byte was non-zero.
type zeroChecker struct{ dirty bool }

func (z *zeroChecker) Write(p []byte) (int, error) {
for _, b := range p {
if b != 0 {
z.dirty = true
break
}
}
return len(p), nil
}

func (s *tarStream) body() (io.Reader, error) {
return s.tr, nil
}
Expand Down
132 changes: 132 additions & 0 deletions agent/internal/archive/unpack_integrity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package archive

import (
"archive/tar"
"bytes"
"compress/gzip"
"io/fs"
"os"
"path"
"path/filepath"
"strings"
"testing"

"golang.org/x/sys/unix"
)

func TestUnpackHardLinkToReplacedSymlinkRefused(t *testing.T) {
ents := []tarEnt{
{name: "d/f", body: "x"},
{name: "d/f", typ: tar.TypeSymlink, link: "../x"},
{name: "top", typ: tar.TypeLink, link: "d/f"},
}
_, _, err := unpackTar(t, ents, UnpackOptions{})
if err == nil {
t.Fatal("Unpack accepted a hard link to a name replaced by a symlink")
}
// symlink() forgets the replaced regular file, so the hard link is
// refused by the x.files lookup; the Fstatat check is a second guard.
if msg := err.Error(); !strings.Contains(msg, "not yet extracted") && !strings.Contains(msg, "not a regular file") {
t.Fatalf("error %q did not come from the hard link check", err)
}
}

func TestUnpackDirOverRegularFileRefused(t *testing.T) {
ents := []tarEnt{
{name: "f", body: "x"},
{name: "f", typ: tar.TypeDir},
}
if _, _, err := unpackTar(t, ents, UnpackOptions{}); err == nil {
t.Fatal("Unpack accepted a directory entry over a regular file")
}
}

func TestUnpackTarGzBadCRCRefused(t *testing.T) {
data := makeTarGzBytes(t, []tarEnt{{name: "f", body: "hello"}})
data[len(data)-8] ^= 0xff
_, err := Unpack(writeArchive(t, data), t.TempDir(), UnpackOptions{Format: "tar.gz", MaxBytes: 1 << 20})
if err == nil {
t.Fatal("Unpack accepted an archive with a bad gzip CRC")
}
}

func TestUnpackTarGzMissingTrailerRefused(t *testing.T) {
data := makeTarGzBytes(t, []tarEnt{{name: "f", body: "hello"}})
data = data[:len(data)-8]
_, err := Unpack(writeArchive(t, data), t.TempDir(), UnpackOptions{Format: "tar.gz", MaxBytes: 1 << 20})
if err == nil {
t.Fatal("Unpack accepted an archive with a missing gzip trailer")
}
}

// tarGzWithTrailer builds a tar.gz whose gzip stream carries extra bytes
// after the tar end marker.
func tarGzWithTrailer(t *testing.T, trailer []byte) []byte {
t.Helper()
var tarBuf bytes.Buffer
tw := tar.NewWriter(&tarBuf)
if err := tw.WriteHeader(&tar.Header{Name: "f", Typeflag: tar.TypeReg, Mode: 0o644, Size: 5}); err != nil {
t.Fatal(err)
}
if _, err := tw.Write([]byte("hello")); err != nil {
t.Fatal(err)
}
if err := tw.Close(); err != nil {
t.Fatal(err)
}
var out bytes.Buffer
gz := gzip.NewWriter(&out)
if _, err := gz.Write(append(tarBuf.Bytes(), trailer...)); err != nil {
t.Fatal(err)
}
if err := gz.Close(); err != nil {
t.Fatal(err)
}
return out.Bytes()
}

func TestUnpackTarGzTrailingDataRefused(t *testing.T) {
data := tarGzWithTrailer(t, []byte("junk after the end marker"))
_, err := Unpack(writeArchive(t, data), t.TempDir(), UnpackOptions{Format: "tar.gz", MaxBytes: 1 << 20})
if err == nil || !strings.Contains(err.Error(), "unexpected data after tar end marker") {
t.Fatalf("err = %v, want trailing data refusal", err)
}
}

func TestUnpackTarGzZeroPaddingAccepted(t *testing.T) {
data := tarGzWithTrailer(t, make([]byte, 4096))
if _, err := Unpack(writeArchive(t, data), t.TempDir(), UnpackOptions{Format: "tar.gz", MaxBytes: 1 << 20}); err != nil {
t.Fatalf("Unpack refused zero padding after the end marker: %v", err)
}
}

// The x.files bookkeeping normally keeps a hard link off anything but a
// regular file; this checks the on-disk guard behind it on its own.
func TestHardlinkRefusesNonRegularTarget(t *testing.T) {
root := t.TempDir()
vol := filepath.Join(root, "volumes", plainVolume)
if err := os.MkdirAll(vol, 0o755); err != nil {
t.Fatal(err)
}
if err := os.Symlink("/etc/passwd", filepath.Join(vol, "s")); err != nil {
t.Fatal(err)
}
fd, err := unix.Open(root, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC, 0)
if err != nil {
t.Fatal(err)
}
defer func() { _ = unix.Close(fd) }()
x := &extractor{rootFD: fd, max: 1 << 20, files: map[string]int64{path.Join("volumes", plainVolume, "s"): 0}, dirs: map[string]fs.FileMode{}}
err = x.hardlink(path.Join("volumes", plainVolume, "top"), "s", layout{plain: true})
if err == nil || !strings.Contains(err.Error(), "not a regular file") {
t.Fatalf("err = %v, want not a regular file", err)
}
}

func TestUnpackTarGzOversizedPaddingRefused(t *testing.T) {
data := tarGzWithTrailer(t, make([]byte, maxTarTrailerBytes+1024))
_, err := Unpack(writeArchive(t, data), t.TempDir(), UnpackOptions{Format: "tar.gz", MaxBytes: 1 << 20})
if err == nil || !strings.Contains(err.Error(), "after tar end marker") {
t.Fatalf("err = %v, want oversized padding refusal", err)
}
}
1 change: 1 addition & 0 deletions agent/specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ All endpoints on the `--addr` control mux, except `/healthz`, return `401 Unauth
- **Partial uploads never linger, and never destroy an existing file**: `files.savePart` writes to a temp file in the destination directory and renames it over the final name only once the copy succeeds. A save that fails after the temp file is opened — a source read error, an `io.ErrUnexpectedEOF` from a truncated multipart body, or an over-the-limit part — removes only the temp file, so a client abort mid-upload can't leave a half-written file where a later `/files/read` or `/files/download` would serve it as complete, and can't delete a file that already existed at that name. `/files/stream` follows the same temp-and-rename rule, including resumed uploads.
- **Symlink confinement on upload**: `files.savePart` confines the upload destination the same way as other file operations: an existing symlink at the destination name (pointing inside the root, outside it, or dangling) is rejected with HTTP 400 (`errLinkTraversal`, which wraps `errPathOutOfRoot`), leaving the symlink and its target untouched. Regular (non-symlink) files are overwritten by a successful upload through an atomic `renameat` in the same directory descriptor.
- **Extracted mod files stay world-readable**: `mods.moduleFileMode` is `0o644`, not a tighter `0o600`, because the mods volume is shared with the game container, which runs as whatever uid its image needs — a different uid than the agent's own. At `0o600` the game process couldn't read its own mods. This is the rationale behind the `.golangci.yml` gosec G302 exclusion scoped to `agent/internal/mods/mods.go`.
- **Uploaded backup archives are checked end to end**: the archive worker (`archive.Unpack`, spec 041) reads a tar.gz to its gzip trailer, so a bad CRC32 or size, a missing trailer, or non-zero data after the tar end marker refuses the archive; zero padding after the end marker is accepted up to 1 MiB (`maxTarTrailerBytes`), so trailing padding cannot cost more decompression than that. A hard link entry must name an already extracted regular file: a name later replaced by a symlink or directory is forgotten, and the on-disk target is checked with `fstatat` before `linkat`.
- **Resource usage is in-pod**: The `usage` package reads from `/proc` or cgroups; no external metrics pipeline required. Cgroup mode is a fallback for older clusters; proc mode (default in production) requires the operator to set `ShareProcessNamespace: true`.
- **Module capabilities drive commands**: Game-specific commands (players, quiesce, lifecycle, status, actions) read their config from `--capabilities` (JSON unmarshaled into `caps.Spec`). New games using the supported command protocols require no agent code change. Player-list format parsers and the read-only Minecraft Java operator-file reader are built-in protocol adapters.
- **Minecraft Java operator identities:** the built-in `ops.json` protocol reader is enabled only for the trusted game identifier `minecraft-java` and an agent data root. Player snapshots advertise `capabilities.operators` even when RCON is disabled; other moderation remains template-driven. Reads reuse the file browser's descriptor-relative confinement, reject symlinks and non-regular files, and are capped at 1 MiB. Only names and UUIDs leave the agent, not permission levels or player-limit overrides.
Expand Down
7 changes: 7 additions & 0 deletions api/cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func mountHealthRoutes(r chi.Router, store *db.Store) {
})
pingSlot := make(chan struct{}, 1)
ready := func(w http.ResponseWriter, req *http.Request) {
// Kubelet probes reach the API directly and never carry proxy headers;
// every ingress or proxy hop adds one. Refuse proxied requests so
// public traffic cannot take the readiness slot.
if req.Header.Get("X-Forwarded-For") != "" || req.Header.Get("Forwarded") != "" {
http.NotFound(w, req)
return
}
select {
case pingSlot <- struct{}{}:
defer func() { <-pingSlot }()
Expand Down
36 changes: 36 additions & 0 deletions api/cmd/health_forwarded_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/go-chi/chi/v5"

"github.com/GameplanePanel/gameplane/api/internal/db"
)

func TestReadinessRefusesProxiedRequests(t *testing.T) {
store, err := db.Open(t.Context(), "sqlite", ":memory:")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = store.Close() })
r := chi.NewRouter()
mountHealthRoutes(r, store)

for _, header := range []string{"X-Forwarded-For", "Forwarded"} {
req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/readyz", nil)
req.Header.Set(header, "203.0.113.7")
rr := httptest.NewRecorder()
r.ServeHTTP(rr, req)
if rr.Code != http.StatusNotFound {
t.Fatalf("%s: status=%d, want 404", header, rr.Code)
}
}
rr := httptest.NewRecorder()
r.ServeHTTP(rr, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/readyz", nil))
if rr.Code != http.StatusOK {
t.Fatalf("direct probe: status=%d, want 200", rr.Code)
}
}
4 changes: 4 additions & 0 deletions api/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ func main() {
r.Use(requestTimeout(60 * time.Second))
r.Use(bodyLimit(1 << 20)) // 1 MiB default; upload proxy raises its own ceiling
r.Use(audit.Middleware(auditor))
// Unrouted requests (unknown paths, wrong methods) are not audited. Set
// before any Mount/Route: chi subrouters inherit these handlers.
r.NotFound(audit.NotFound)
r.MethodNotAllowed(audit.MethodNotAllowed)

mountHealthRoutes(r, store)
// Prometheus metrics are served by the separate metrics listener below,
Expand Down
Loading
Loading