Skip to content

Commit d412238

Browse files
authored
Implement SCRAM-SHA-256 for server authentication (PG14) (#76)
* Implement SCRAM-SHA-256 * test it * trace * move to community for auth * hmm
1 parent 7782933 commit d412238

File tree

8 files changed

+494
-12
lines changed

8 files changed

+494
-12
lines changed

.circleci/config.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ jobs:
1212
- image: cimg/rust:1.58.1
1313
environment:
1414
RUST_LOG: info
15-
- image: cimg/postgres:14.0
16-
auth:
17-
username: mydockerhub-user
18-
password: $DOCKERHUB_PASSWORD
15+
- image: postgres:14
16+
# auth:
17+
# username: mydockerhub-user
18+
# password: $DOCKERHUB_PASSWORD
1919
environment:
2020
POSTGRES_USER: postgres
2121
POSTGRES_DB: postgres
22+
POSTGRES_PASSWORD: postgres
23+
POSTGRES_HOST_AUTH_METHOD: scram-sha-256
2224
# Add steps to the job
2325
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
2426
steps:

.circleci/run_tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function start_pgcat() {
1212
}
1313

1414
# Setup the database with shards and user
15-
psql -e -h 127.0.0.1 -p 5432 -U postgres -f tests/sharding/query_routing_setup.sql
15+
PGPASSWORD=postgres psql -e -h 127.0.0.1 -p 5432 -U postgres -f tests/sharding/query_routing_setup.sql
1616
PGPASSWORD=sharding_user pgbench -h 127.0.0.1 -U sharding_user shard0 -i
1717
PGPASSWORD=sharding_user pgbench -h 127.0.0.1 -U sharding_user shard1 -i
1818
PGPASSWORD=sharding_user pgbench -h 127.0.0.1 -U sharding_user shard2 -i
@@ -72,7 +72,7 @@ psql -h 127.0.0.1 -p 6432 -d pgbouncer -c "SET client_encoding TO 'utf8'" > /dev
7272
(! psql -e -h 127.0.0.1 -p 6432 -d random_db -c 'SHOW STATS' > /dev/null)
7373

7474
# Start PgCat in debug to demonstrate failover better
75-
start_pgcat "debug"
75+
start_pgcat "trace"
7676

7777
# Add latency to the replica at port 5433 slightly above the healthcheck timeout
7878
toxiproxy-cli toxic add -t latency -a latency=300 postgres_replica

Cargo.lock

+82-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pgcat"
3-
version = "0.1.0-beta2"
3+
version = "0.2.0-beta1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -25,3 +25,7 @@ log = "0.4"
2525
arc-swap = "1"
2626
env_logger = "0.9"
2727
parking_lot = "0.11"
28+
hmac = "0.12"
29+
sha2 = "0.10"
30+
base64 = "0.13"
31+
stringprep = "0.1"

src/constants.rs

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ pub const CANCEL_REQUEST_CODE: i32 = 80877102;
1414
// AuthenticationMD5Password
1515
pub const MD5_ENCRYPTED_PASSWORD: i32 = 5;
1616

17+
// SASL
18+
pub const SASL: i32 = 10;
19+
pub const SASL_CONTINUE: i32 = 11;
20+
pub const SASL_FINAL: i32 = 12;
21+
pub const SCRAM_SHA_256: &str = "SCRAM-SHA-256";
22+
pub const NONCE_LENGTH: usize = 24;
23+
1724
// AuthenticationOk
1825
pub const AUTHENTICATION_SUCCESSFUL: i32 = 0;
1926

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ mod errors;
5454
mod messages;
5555
mod pool;
5656
mod query_router;
57+
mod scram;
5758
mod server;
5859
mod sharding;
5960
mod stats;

0 commit comments

Comments
 (0)