Advertise SCRAM-SHA-256-PLUS only on TLS connections (like postgres)

Aperta
#477 0 commenti 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
42/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
postgresql, rust

Direzione di ricerca

Start with src/api/auth/sasl.rs, src/api/mod.rs, and src/tokio/server.rs to trace how TLS state reaches authentication and how mechanisms are advertised and dispatched. Then inspect ScramServerAuth::on_client_first_message_with_secret and the changes from #476. Done means SCRAM-SHA-256-PLUS is offered and accepted only over TLS, and the y gs2 flag is rejected only on TLS when a certificate is configured.

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

Descrizione

Problem

ScramAuth advertises SCRAM-SHA-256-PLUS whenever a certificate is configured, regardless of whether the connection is actually over TLS (rebuild_supported_mechanisms builds a static list). Channel binding is only possible over TLS, so advertising -PLUS on a plaintext connection is wrong:

  • An RFC-correct client that supports channel binding and sees -PLUS offered MUST use the p= gs2 flag (RFC 5802 §6) — but it cannot compute tls-server-end-point data without TLS. Postgres avoids this trap by never offering -PLUS on non-TLS connections:

    // auth-scram.c, scram_get_mechanisms
    /*
     * ... Channel binding is only supported with SSL.
     */
    if (port->ssl_in_use)
        appendStringInfoString(buf, SCRAM_SHA_256_PLUS_NAME);
    
  • Interaction with #476: the gs2-flag checks added there are static — a y flag is rejected whenever a certificate is configured, even on non-TLS connections, where y (or n) is the only option a client has. Postgres rejects y only when ssl_in_use. After this change both the advertisement and the gs2 checks should key off the connection's TLS state, not just certificate configuration.

Scope

  1. Advertise per connection: offer SCRAM-SHA-256-PLUS only when the connection is secure.
  2. Reject -PLUS selection on non-TLS connections in the mechanism dispatch (postgres does this in scram_init: channel binding cannot be performed without SSL).
  3. Make the gs2-flag checks connection-aware: y should be rejected only when the connection is over TLS and a certificate is configured.

API feasibility — what exists today vs what's missing

The TLS state is available and accurate at auth time:

  • negotiate_tls (src/tokio/server.rs) builds DefaultClient::new(addr, true) right after the TLS handshake and false for plain connections, before the startup/auth flow.
  • ClientInfo::is_secure() (src/api/mod.rs) exposes it.
  • Both AuthMechanism::begin(client) and AuthMechanism::next(client, msg) receive the client, so ScramMechanism/SaslMechanism can see it.

Two public surfaces currently can't use it:

  1. SaslMechanismFactory::sasl_mechanism_names(&self) takes no client — the advertised list (src/api/auth/sasl.rs, SaslMechanism::begin) and the dispatch match are connection-blind. Needs either a client-aware variant (e.g. sasl_mechanism_names_for(&self, client: &dyn ClientInfo) with a default impl) or a signature change.
  2. The gs2-flag checks from #476 live in ScramServerAuth::on_client_first_message_with_secret, which has no connection context. Connection-aware enforcement needs state plumbed in — e.g. a setter on the per-connection clone (set_channel_binding_supported(bool)) or a parameter on the method. Low-level users (greptimedb) own the socket and know the TLS state, so either works for them.

So: feasible without restructuring — TLS info reaches the mechanism layer today; only the two surfaces above need extending.

Sketch

  • ScramAuth: filter -PLUS from the advertised names and from the accepted-mechanism check when !client.is_secure().
  • Handler layer sets the channel-binding capability on the per-connection ScramServerAuth clone from client.is_secure(); low-level default stays strict (strict when a certificate is configured), documented.
Lingua principale
Rust
Stelle
805
Fork
88
Merge medio
1g 7h
PR unite (30g)
10

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 sunng87/pgwire

Tutte le issue di sunng87/pgwire

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.