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
44 changes: 44 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Dependabot version updates for the sftp module.
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
time: "03:00"
commit-message:
prefix: "chore(deps)"
include: "scope"
open-pull-requests-limit: 5
groups:
sftp-minor-patch:
update-types: ["minor", "patch"]

- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
time: "03:00"
commit-message:
prefix: "chore(deps)"
include: "scope"
open-pull-requests-limit: 5
groups:
sftp-docker-minor-patch:
update-types: ["minor", "patch"]

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
time: "03:00"
commit-message:
prefix: "chore(deps)"
include: "scope"
open-pull-requests-limit: 5
groups:
actions-minor-patch:
update-types: ["minor", "patch"]
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# CI: the shared Gameplane workflow for split components (lint with Gameplane's
# .golangci.yml and .hadolint.yaml, race tests on amd64 and arm64 with the
# .testcoverage.yml gate, govulncheck, image build). Pinned by SHA.
name: ci

on:
pull_request:
push:
branches: [main]
schedule:
- cron: "17 4 * * 1" # weekly, so govulncheck sees new advisories
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
ci:
uses: GameplanePanel/Gameplane/.github/workflows/go-component.yaml@783aefb67b0744eaf8d0ee51cb10d94ae9739fd6 # master
with:
# This repo is the sftp/ submodule in Gameplane; the Dockerfile copies sftp/...
path: sftp
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/sftp
coverage/
11 changes: 11 additions & 0 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Coverage threshold gate for the sftp module.
# Enforced in CI by Gameplane's shared go-component.yaml workflow (go-test-coverage/v2).
# The scaffold only has run(); main() is process wiring. Ratchet up as the
# SSH server, API client and virtual file system land (spec 040 T020-T029).
profile: coverage/unit.out
github-action-output: false

threshold:
file: 0
package: 0
total: 70
22 changes: 22 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# sftp — AI assistant guide

This repository holds the optional SFTP endpoint for game server files (spec 040 in Gameplane). It is a split component of [GameplanePanel/Gameplane](https://github.com/GameplanePanel/Gameplane), checked out there as the `sftp/` submodule. It never reads game volumes itself: every login and file operation goes to the Gameplane API as the signed-in user. What it does and its contracts: [`specs.md`](specs.md).

## How it fits into Gameplane

- **Own Go module**, not part of Gameplane's `go.work`. Build and test from this repository's root: `go build ./...` (inside a Gameplane checkout, prefix `GOWORK=off`).
- **CI** is `.github/workflows/ci.yaml`, a thin caller of Gameplane's shared [`go-component.yaml`](https://github.com/GameplanePanel/Gameplane/blob/master/.github/workflows/go-component.yaml), pinned by SHA: lint with Gameplane's root `.golangci.yml` and `.hadolint.yaml` (no copy here), race tests on amd64 and arm64 with the `.testcoverage.yml` gate, govulncheck, and an image build. Dependabot runs in this repository.
- **Images** `sftp` (`Dockerfile`, built by `make image-sftp`) are built and published from the Gameplane repository root: the Dockerfiles copy `sftp/...` from that build context.
- **Callers live in Gameplane:** paths such as `operator/`, `api/`, `charts/`, `docs/` and `web/` in `specs.md` and code comments refer to that repository.
- **Shipping a change:** PR to `main` here → after it merges, bump the `sftp` pointer in Gameplane (`git -C sftp checkout <merged sha on main>`, `git add sftp`) in a Gameplane PR. A user-visible change gets its `changelog/unreleased/` entry in that Gameplane PR.

## Rules

Gameplane's [`AGENTS.md`](https://github.com/GameplanePanel/Gameplane/blob/master/AGENTS.md) core rules apply here. The ones that matter most in this repository:

- **CI verifies:** locally only compile checks (`go build ./...`); never run test or lint suites locally.
- **Fix, don't silence:** no `//nolint` and no per-repository `.golangci.yml`; `_test.go` files are exempt from `errcheck`/`gosec`/`unparam` through the shared config.
- **Go errors:** wrap with `%w`.
- **Tests:** never delete or weaken a test without the maintainer's explicit sign-off; fix the code.
- **Git:** signed commits (`git commit -s`), conventional prefixes (`feat:`, `fix:`, `chore:`, `docs:` …), one branch per unit of work, never amend pushed commits; delete the branch after merge.
- **Docs:** keep `specs.md` in step with behaviour changes in the same PR.
22 changes: 22 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# sftp — AI assistant guide

This repository holds the optional SFTP endpoint for game server files (spec 040 in Gameplane). It is a split component of [GameplanePanel/Gameplane](https://github.com/GameplanePanel/Gameplane), checked out there as the `sftp/` submodule. It never reads game volumes itself: every login and file operation goes to the Gameplane API as the signed-in user. What it does and its contracts: [`specs.md`](specs.md).

## How it fits into Gameplane

- **Own Go module**, not part of Gameplane's `go.work`. Build and test from this repository's root: `go build ./...` (inside a Gameplane checkout, prefix `GOWORK=off`).
- **CI** is `.github/workflows/ci.yaml`, a thin caller of Gameplane's shared [`go-component.yaml`](https://github.com/GameplanePanel/Gameplane/blob/master/.github/workflows/go-component.yaml), pinned by SHA: lint with Gameplane's root `.golangci.yml` and `.hadolint.yaml` (no copy here), race tests on amd64 and arm64 with the `.testcoverage.yml` gate, govulncheck, and an image build. Dependabot runs in this repository.
- **Images** `sftp` (`Dockerfile`, built by `make image-sftp`) are built and published from the Gameplane repository root: the Dockerfiles copy `sftp/...` from that build context.
- **Callers live in Gameplane:** paths such as `operator/`, `api/`, `charts/`, `docs/` and `web/` in `specs.md` and code comments refer to that repository.
- **Shipping a change:** PR to `main` here → after it merges, bump the `sftp` pointer in Gameplane (`git -C sftp checkout <merged sha on main>`, `git add sftp`) in a Gameplane PR. A user-visible change gets its `changelog/unreleased/` entry in that Gameplane PR.

## Rules

Gameplane's [`AGENTS.md`](https://github.com/GameplanePanel/Gameplane/blob/master/AGENTS.md) core rules apply here. The ones that matter most in this repository:

- **CI verifies:** locally only compile checks (`go build ./...`); never run test or lint suites locally.
- **Fix, don't silence:** no `//nolint` and no per-repository `.golangci.yml`; `_test.go` files are exempt from `errcheck`/`gosec`/`unparam` through the shared config.
- **Go errors:** wrap with `%w`.
- **Tests:** never delete or weaken a test without the maintainer's explicit sign-off; fix the code.
- **Git:** signed commits (`git commit -s`), conventional prefixes (`feat:`, `fix:`, `chore:`, `docs:` …), one branch per unit of work, never amend pushed commits; delete the branch after merge.
- **Docs:** keep `specs.md` in step with behaviour changes in the same PR.
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM --platform=$BUILDPLATFORM golang:1.27-alpine AS build
WORKDIR /src

COPY sftp/go.mod sftp/go.sum* ./sftp/
WORKDIR /src/sftp
RUN go mod download

WORKDIR /src
COPY sftp/ ./sftp/
WORKDIR /src/sftp

ARG VERSION=dev
# Cross-compile on the build host ($BUILDPLATFORM above) rather than under
# QEMU emulation: multi-arch release builds of the arm64 image were slow
# enough to hit the release job timeout.
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build \
-trimpath \
-ldflags="-s -w -X main.Version=${VERSION}" \
-o /out/sftp .

FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=build /out/sftp /sftp
USER 65532:65532
# SFTP listens on 2222 by default (Helm sftp.port); the Service maps it.
EXPOSE 2222
ENTRYPOINT ["/sftp"]
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# sftp

> This repository is checked out as the `sftp/` submodule of [GameplanePanel/Gameplane](https://github.com/GameplanePanel/Gameplane). Paths such as `docs/`, `operator/`, `api/`, `charts/` and `web/` below refer to that repository.

The **sftp** component [optional] is Gameplane's SFTP endpoint for game server files. Each cluster can run one. A user connects with any SFTP client (FileZilla, WinSCP, `sftp`) using an SSH key or a generated SFTP password from their Gameplane profile, and sees one folder per game server they may access. Logging in as `<user>+<server>` opens one server directly.

The server holds no permissions and mounts no volumes: every login and file operation is sent to the Gameplane API as that user, so roles, ownership, per-cluster grants and the audit log apply exactly as in the dashboard Files tab.

Status: the server runs (`sftp serve`). The design is spec 040 (`specs/040-sftp-access/` in Gameplane).

## Running

```sh
sftp serve \
--host-key /etc/sftp/hostkeys \
--api-url https://gameplane-api.gameplane.svc:8080 \
--service-token-file /etc/sftp/service-token
```

Every flag has a `GAMEPLANE_SFTP_*` environment variable; the flag wins. Required: `--host-key` (a key file or a directory of keys, kept stable so clients can verify it), `--api-url`, `--service-token-file`. Optional: `--listen` (`:2222`), `--ca-file`, `--idle-timeout` (`15m`), `--max-sessions-per-user` (`4`), `--max-preauth-connections` (`64`, connections still authenticating; more are closed at once), `--max-transfers-per-user` (`8`), `--default-namespace` (`gameplane-games`, must match the API), `--metrics-addr` (`:9102`, empty disables). `sftp version` prints the build version. The full contract is in [`specs.md`](specs.md).

Clients log in as `<user>` to see every server they may access, or as `<user>+<server>` (or `<user>+<namespace>/<server>`) to open one server directly. There is no shell, command execution or port forwarding. Dotfiles are hidden.

Gameplane builds and ships the image and the Helm chart (`sftp.enabled`). Lint, tests, coverage and govulncheck for this module run in this repository's own CI.
22 changes: 22 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module github.com/GameplanePanel/gameplane/sftp

go 1.27.0

require (
github.com/pkg/sftp v1.13.12
github.com/prometheus/client_golang v1.25.0
golang.org/x/crypto v0.59.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.3 // indirect
github.com/prometheus/common v0.72.0 // indirect
github.com/prometheus/procfs v0.22.0 // indirect
golang.org/x/sys v0.50.0 // indirect
google.golang.org/protobuf v1.36.12 // indirect
)
40 changes: 40 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ=
github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pkg/sftp v1.13.12 h1:Myhzy/ZzLPnCtE2F2WtDHsgs8RfgMnH2gfbHuCJhkMU=
github.com/pkg/sftp v1.13.12/go.mod h1:uNkH9roSXglNJqM+glJJi+TQXQUm0fXFWqCFmT8hsN0=
github.com/prometheus/client_golang v1.25.0 h1:cDtW1TcFsMi1RJc8khwCKB4VhzwV04aKqbYtNOXuiK0=
github.com/prometheus/client_golang v1.25.0/go.mod h1:j2X/4/kaQHLPnmyEU8zjmkndo1T317VpCIQEml8LTKk=
github.com/prometheus/client_model v0.6.3 h1:O0jaTVAYNxTHYInEPFJt5I3+sN8zqBtVMPTB1qyxiEo=
github.com/prometheus/client_model v0.6.3/go.mod h1:gpN5P9S7Rr6Yr92PiQ+Ixvhf6JZEkF1dnxsYL2aPBEM=
github.com/prometheus/common v0.72.0 h1:tAYsE+sPJxIncDAobm4H5aQjmox9ZxEIIqPbiffa8G4=
github.com/prometheus/common v0.72.0/go.mod h1:77NWqAQ2tXT7BIK40qjJdw5Acrsrg1TlHAnsQi3i6mk=
github.com/prometheus/procfs v0.22.0 h1:6q9+/JL9IKAPbCmBrv9n5O5Ty3NKnciV5X7YGw0oics=
github.com/prometheus/procfs v0.22.0/go.mod h1:CvmFr/GVhIjIvWJZW3tgkODBQMRIf0EyWMQLHCHab58=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/crypto v0.59.0 h1:xS2jhqYbzNrpvkWP2YTDf4TJwBy3ykR03i8vFDxEc7c=
golang.org/x/crypto v0.59.0/go.mod h1:veDyUwATGs3c+vN3VfTbzViMGXeTBk3WyhBOkn+F/4U=
golang.org/x/sys v0.50.0 h1:dkKZEFTEKaLr1sjhs0WiKqoi8Jj5nHbS3Njmx1UoMJs=
golang.org/x/sys v0.50.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.48.0 h1:G6UU1eiSB8nl3DzeUGt7Mg+2SctI8tPS6Z5/mBt6cOk=
golang.org/x/term v0.48.0/go.mod h1:BRDLHCZr2SUjIeBHHpRyQeC9xzSAVbzY2rvKgafnHf4=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
Loading