Add functions to set passwords without sending them in plain text

Offen
#139 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
postgresql, python
Bereich
databases

Rechercherichtung

Start with the Connection class of PyGreSQL and the libpq wrapper it calls, since the proposed methods sit on top of PQencryptPasswordConn() and PQchangePassword(). Check how the libpq version is detected so the code can fall back to encrypting locally and sending ALTER USER on older libpq. Decide whether DB and pgdb get the methods too. Done means encrypt_password() and change_password() exist with tests that run against a PostgreSQL server and cover both the libpq 17+ path and the fallback.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

enhancement

To set a password with SQL, it is usually sent in plain text (ALTER ROLE ... PASSWORD '...'), so it can end up in the server log or in pg_stat_activity. libpq has functions that encrypt the password on the client:

  • PQencryptPasswordConn() (libpq 10) returns the encrypted password, using the algorithm from the server setting password_encryption (normally SCRAM-SHA-256), or a given algorithm.
  • PQchangePassword() (libpq 17) encrypts the password and sends the ALTER USER command.

psycopg2 has encrypt_password(), psycopg 3 has both functions at the pq level. PostgreSQL 18 and 19 warn about MD5 passwords, so this helps with moving to SCRAM.

I plan to add Connection.encrypt_password(password, user, algorithm=None) and Connection.change_password(user, password), maybe also in DB and pgdb. change_password() would use PQchangePassword() with libpq 17 or newer, and otherwise encrypt the password and send ALTER USER with the escaped user name and encrypted password. User name and password are encoded with the client encoding.

Vorherrschende Sprache
Python
Sterne
48
Forks
22
Ø Merge
12 Min.
Gemergte PRs (30 T.)
28

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Keine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus PyGreSQL/PyGreSQL

Alle Issues in PyGreSQL/PyGreSQL

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.