Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Concurrent token refresh can corrupt stored credentials (keychain key and nais-credentials.json.enc out of sync)

Aperta
#816 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
cli, security

Direzione di ricerca

Start with getOIDCUser and storeOIDCUser in internal/naisapi/auth/oidcuser.go, including the decryption and file-write paths. Reproduce with several nais alpha mcp serve processes after token expiry, then verify nais auth print-access-token. Done means concurrent refreshes preserve a matching keychain key and encrypted credentials file, with locked read-check-refresh-store behavior and an atomic file replacement.

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

Descrizione

getOIDCUser (internal/naisapi/auth/oidcuser.go:68) refreshes an expired token inside the process, with no lock across processes. storeOIDCUser (:75-105) does three things on every call:

  1. Generates a fresh random encryption key.
  2. Stores that key in the keychain (:98).
  3. Writes nais-credentials.json.enc with a non-atomic os.WriteFile (:163).

When two nais processes refresh at the same time, the keychain key and the file can end up written by different processes. Decryption then fails (:57-59, ErrNeedsOIDCLogin), and the user has to run nais login again. A torn read during the write has the same effect.

This happens in practice with several nais alpha mcp serve instances, one per AI agent session (navikt/cplt runs one per sandboxed session).

Suggested fix:

  • Take an exclusive file lock (for example flock on <configDir>/nais-credentials.lock) around the whole sequence: read, check validity, refresh, store.
  • After getting the lock, re-read the credentials, and skip the refresh if another process has already done it.
  • Write the file through a temp file and rename it into place.
  • Consider reusing the existing keychain key instead of rotating it on every refresh, so the key and the file can't drift apart.

Repro idea: let the access token expire, start N nais alpha mcp serve processes, and call one tool on each at the same time. Afterwards, check whether nais auth print-access-token still works.

Lingua principale
Go
Stelle
2
Fork
5
Merge medio
2h 55m
PR unite (30g)
30

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 nais/cli

Tutte le issue di nais/cli

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.