An authfile change made during server startup is never applied

Aperta Adatta ai principianti
#632 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
83/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Inizia con UserIndex.LoadUsers, loadUserIndex e addWatchEvents in share/settings/users.go. L’issue include una riproduzione deterministica della modifica persa durante l’avvio; eseguila nel package share/settings per confermare il comportamento. Il lavoro è concluso quando viene caricata una modifica effettuata tra la lettura iniziale e la configurazione del watcher e la riproduzione ha esito positivo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

UserIndex.LoadUsers (share/settings/users.go) reads the authfile
(loadUserIndex) and only then starts watching its directory (addWatchEvents). If
the file changes between the read and watcher.Add, no event is ever delivered for
that change. The server keeps the users it read at startup until the file changes
again. The 1-second reconcile ticker only compares symlink targets, so it doesn't
catch a plain rename or write.

This matters wherever the authfile and the server are managed together: a
config-management run or a Kubernetes rollout that updates the authfile while the
server is restarting leaves the server enforcing stale users and passwords,
indefinitely.

In our test, the server restarted, read the authfile at startup, and the file was
atomically replaced moments later, before LoadUsers returned. For the next
120 s the server kept refusing the new file's users and accepting the old file's.

Reproduction

A test in share/settings that runs LoadUsers's two steps with the change between
them. It fails every time:

package settings

import (
	"os"
	"path/filepath"
	"testing"
	"time"

	"github.com/jpillora/chisel/share/cio"
)

func TestAuthfileChangeDuringStartupIsMissed(t *testing.T) {
	dir := t.TempDir()
	path := filepath.Join(dir, "users.json")
	os.WriteFile(path, []byte(`{"old:pw": [""]}`), 0644)
	u := NewUserIndex(cio.NewLogger("test"))
	u.configFile = path
	if err := u.loadUserIndex(); err != nil { // step 1 of LoadUsers
		t.Fatal(err)
	}
	tmp := filepath.Join(dir, "tmp")
	os.WriteFile(tmp, []byte(`{"new:pw": [""]}`), 0644)
	os.Rename(tmp, path) // the change lands here
	if err := u.addWatchEvents(); err != nil { // step 2 of LoadUsers
		t.Fatal(err)
	}
	time.Sleep(3 * time.Second)
	if _, ok := u.Get("new"); !ok {
		t.Errorf("authfile changed during startup was never applied: users still %v", u.inner)
	}
}
--- FAIL: TestAuthfileChangeDuringStartupIsMissed (3.00s)
    authfile changed during startup was never applied: users still map[old:0x...]

A fix: start the watch before the first read, or reload once more right after the
watch is set up.

Notes

  • Found at 5ee6c74 with an Antithesis test that rewrites the authfile under a running server while clients log in and open tunnels.
  • Related: TASKS.md #2 (watcher misses rename/truncate updates) is fixed; this startup
    window remains. GitHub #298 and #493 (both open) report authfile changes
    not being picked up, without a root cause; this race is one possible cause.
Lingua principale
Go
Stelle
16.8k
Fork
1.6k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jpillora/chisel

Tutte le issue di jpillora/chisel

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.