Skip to content

Commit dba23bc

Browse files
author
CommanderKeynes
committed
Add tests for LDAP
1 parent 7876624 commit dba23bc

File tree

9 files changed

+233
-24
lines changed

9 files changed

+233
-24
lines changed

.circleci/glauth.cfg

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#################
2+
# glauth.conf
3+
4+
#################
5+
# General configuration.
6+
debug = true
7+
8+
[ldap]
9+
enabled = true
10+
# run on a non privileged port
11+
listen = "0.0.0.0:3893"
12+
tls = false
13+
14+
[ldaps]
15+
enabled = false
16+
#################
17+
# Tracing section controls the tracer configuration
18+
[tracing]
19+
# if enabled is set to false, a no-op tracer will be used
20+
enabled = true
21+
# if both grpcEndpoint and httpEndpoint are unset, the default stdout provider will be used
22+
# TODO add allowGRPCInsecure: right now grpc otlp is using the WithInsecure flag so traffic
23+
# will always go without verifying server certificates
24+
# grpcEndpoint = "otlp.monitoring.io:4317"
25+
# httpEndpoint = "http://otlp.monitoring.io:4318"
26+
#################
27+
# The backend section controls the data store.
28+
[backend]
29+
datastore = "config"
30+
baseDN = "dc=example,dc=com"
31+
nameformat = "cn"
32+
groupformat = "ou"
33+
34+
# If you are using a client that requires reading the root DSE first
35+
# such as SSSD
36+
# anonymousdse = true
37+
38+
## Configure dn format to use structures like
39+
## "uid=serviceuser,cn=svcaccts,$BASEDN" instead of "cn=serviceuser,ou=svcaccts,$BASEDN"
40+
## to help ease migrations from other LDAP systems
41+
# nameformat = "uid"
42+
# groupformat = "cn"
43+
44+
## Configure ssh-key attribute name, default is 'sshPublicKey'
45+
# sshkeyattr = "ipaSshPubKey"
46+
47+
[behaviors]
48+
# Ignore all capabilities restrictions, for instance allowing every user to perform a search
49+
IgnoreCapabilities = false
50+
# Enable a "fail2ban" type backoff mechanism temporarily banning repeated failed login attempts
51+
LimitFailedBinds = true
52+
# How many failed login attempts are allowed before a ban is imposed
53+
NumberOfFailedBinds = 3
54+
# How long (in seconds) is the window for failed login attempts
55+
PeriodOfFailedBinds = 10
56+
# How long (in seconds) is the ban duration
57+
BlockFailedBindsFor = 60
58+
# Clean learnt IP addresses every N seconds
59+
PruneSourceTableEvery = 600
60+
# Clean learnt IP addresses not seen in N seconds
61+
PruneSourcesOlderThan = 600
62+
63+
#################
64+
# The users section contains a hardcoded list of valid users.
65+
# to create a passSHA256: echo -n "mysecret" | openssl dgst -sha256
66+
[[users]]
67+
name = "admin_user"
68+
uidnumber = 5001
69+
primarygroup = 5501
70+
mail = "admin_user@example.com"
71+
passsha256 = "6478579e37aff45f013e14eeb30b3cc56c72ccdc310123bcdf53e0333e3f416a" # dogood
72+
[[users.customattributes]]
73+
employeetype = ["Intern", "Temp"]
74+
employeenumber = [12345, 54321]
75+
[[users.capabilities]]
76+
action = "search"
77+
object = "dc=example,dc=com"
78+
79+
# This user record shows all of the possible fields available
80+
[[users]]
81+
name = "sharding_user"
82+
givenname="John"
83+
sn="Doe"
84+
mail = "sharding_user@example.com"
85+
uidnumber = 5002
86+
primarygroup = 5501
87+
loginShell = "/bin/sh"
88+
homeDir = "/root"
89+
passsha256 = "6478579e37aff45f013e14eeb30b3cc56c72ccdc310123bcdf53e0333e3f416a" # dogood
90+
sshkeys = ["ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEA3UKCEllO2IZXgqNygiVb+dDLJJwVw3AJwV34t2jzR+/tUNVeJ9XddKpYQektNHsFmY93lJw5QDSbeH/mAC4KPoUM47EriINKEelRbyG4hC/ko/e2JWqEclPS9LP7GtqGmscXXo4JFkqnKw4TIRD52XI9n1syYM9Y8rJ88fjC/Lpn+01AB0paLVIfppJU35t0Ho9doHAEfEvcQA6tcm7FLJUvklAxc8WUbdziczbRV40KzDroIkXAZRjX7vXXhh/p7XBYnA0GO8oTa2VY4dTQSeDAUJSUxbzevbL0ll9Gi1uYaTDQyE5gbn2NfJSqq0OYA+3eyGtIVjFYZgi+txSuhw== rsa-key-20160209"]
91+
passappsha256 = [
92+
"c32255dbf6fd6b64883ec8801f793bccfa2a860f2b1ae1315cd95cdac1338efa", # TestAppPw1
93+
"c9853d5f2599e90497e9f8cc671bd2022b0fb5d1bd7cfff92f079e8f8f02b8d3", # TestAppPw2
94+
"4939efa7c87095dacb5e7e8b8cfb3a660fa1f5edcc9108f6d7ec20ea4d6b3a88", # TestAppPw3
95+
]
96+
97+
#################
98+
# The groups section contains a hardcoded list of valid users.
99+
[[groups]]
100+
name = "superheros"
101+
gidnumber = 5501
102+
103+
[[groups]]
104+
name = "svcaccts"
105+
gidnumber = 5502
106+
107+
[[groups]]
108+
name = "vpn"
109+
gidnumber = 5503
110+
includegroups = [ 5501 ]
111+

.circleci/pgcat.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ tls_private_key = ".circleci/server.key"
4949
# Connecting to that database allows running commands like `SHOW POOLS`, `SHOW DATABASES`, etc..
5050
admin_username = "admin_user"
5151
admin_password = "admin_pass"
52-
admin_auth_type = "md5"
5352

5453
# pool
5554
# configs are structured as pool.<pool_name>
@@ -99,7 +98,6 @@ sharding_function = "pg_bigint_hash"
9998
[pools.sharded_db.users.0]
10099
username = "sharding_user"
101100
password = "sharding_user"
102-
auth_type = "md5"
103101
# Maximum number of server connections that can be established for this user
104102
# The maximum number of connection from a single Pgcat process to any database in the cluster
105103
# is the sum of pool_size across all users.
@@ -109,7 +107,6 @@ statement_timeout = 0
109107
[pools.sharded_db.users.1]
110108
username = "other_user"
111109
password = "other_user"
112-
auth_type = "md5"
113110
pool_size = 21
114111
statement_timeout = 30000
115112

@@ -150,7 +147,6 @@ prepared_statements_cache_size = 500
150147
[pools.simple_db.users.0]
151148
username = "simple_user"
152149
password = "simple_user"
153-
auth_type = "md5"
154150
pool_size = 5
155151
statement_timeout = 30000
156152

.circleci/pgcat_ldap.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
[general]
3+
host = "0.0.0.0"
4+
port = 6432
5+
admin_username = "admin_user"
6+
admin_password = ""
7+
admin_auth_type = "ldap"
8+
admin_auth_ldapurl = "ldap://127.0.0.1:3893"
9+
admin_auth_ldapsuffix = "@example.com"
10+
11+
[pools.sharded_db.users.0]
12+
username = "sharding_user"
13+
password = "sharding_user"
14+
auth_type = "ldap"
15+
auth_ldapurl = "ldap://127.0.0.1:3893"
16+
auth_ldapsuffix = "@example.com"
17+
pool_size = 10
18+
min_pool_size = 1
19+
pool_mode = "transaction"
20+
21+
[pools.sharded_db.shards.0]
22+
servers = [
23+
[ "127.0.0.1", 5432, "primary" ],
24+
]
25+
database = "shard0"

.circleci/pgcat_trust.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
[general]
3-
43
host = "0.0.0.0"
54
port = 6432
65
admin_username = "admin_user"

pgcat.minimal.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@
55

66
host = "0.0.0.0"
77
port = 6433
8-
admin_username = "jdoe"
8+
admin_username = "pgcat"
99
admin_password = "pgcat"
10-
admin_auth_type = "ldap"
11-
admin_auth_ldapurl = "ldap://127.0.0.1:3893"
12-
admin_auth_ldapsuffix = "@example.com"
1310

1411
[pools.pgml.users.0]
15-
username = "jdoe"
12+
username = "postgres"
1613
password = "postgres"
17-
auth_type = "ldap"
18-
auth_ldapurl = "ldap://127.0.0.1:3893"
19-
auth_ldapsuffix = "@example.com"
2014
pool_size = 10
2115
min_pool_size = 1
2216
pool_mode = "transaction"

pgcat.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ verify_server_certificate = false
7676
admin_username = "admin_user"
7777
# Password to access the virtual administrative database
7878
admin_password = "admin_pass"
79-
admin_auth_type = "md5"
8079

8180
# Default plugins that are configured on all pools.
8281
[plugins]
@@ -275,8 +274,6 @@ result = [
275274
# if `server_username` is not set.
276275
username = "sharding_user"
277276

278-
auth_type = "md5"
279-
280277
# PostgreSQL password used to authenticate the user and connect to the server
281278
# if `server_password` is not set.
282279
password = "sharding_user"
@@ -302,7 +299,6 @@ statement_timeout = 0
302299
[pools.sharded_db.users.1]
303300
username = "other_user"
304301
password = "other_user"
305-
auth_type = "md5"
306302
pool_size = 21
307303
statement_timeout = 15000
308304
connect_timeout = 1000
@@ -341,7 +337,6 @@ sharding_function = "pg_bigint_hash"
341337
[pools.simple_db.users.0]
342338
username = "simple_user"
343339
password = "simple_user"
344-
auth_type = "md5"
345340
pool_size = 5
346341
min_pool_size = 3
347342
server_lifetime = 60000

src/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ impl Address {
208208
pub struct User {
209209
pub username: String,
210210
pub password: Option<String>,
211+
212+
#[serde(default = "User::default_auth_type")]
211213
pub auth_type: String,
212214
pub auth_ldapsuffix: Option<String>,
213215
pub auth_ldapurl: Option<String>,
@@ -245,6 +247,10 @@ impl Default for User {
245247
}
246248

247249
impl User {
250+
pub fn default_auth_type() -> String {
251+
"md5".into()
252+
}
253+
248254
fn validate(&self) -> Result<(), Error> {
249255
if let Some(min_pool_size) = self.min_pool_size {
250256
if min_pool_size > self.pool_size {
@@ -339,7 +345,10 @@ pub struct General {
339345

340346
pub admin_username: String,
341347
pub admin_password: String,
348+
349+
#[serde(default = "General::default_admin_auth_type")]
342350
pub admin_auth_type: String,
351+
343352
pub admin_auth_ldapurl: Option<String>,
344353
pub admin_auth_ldapsuffix: Option<String>,
345354

@@ -357,6 +366,10 @@ impl General {
357366
"0.0.0.0".into()
358367
}
359368

369+
pub fn default_admin_auth_type() -> String {
370+
"md5".into()
371+
}
372+
360373
pub fn default_port() -> u16 {
361374
5432
362375
}

tests/docker/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ RUN apt-get update && apt-get install llvm-11 psmisc postgresql-contrib postgres
66
RUN cargo install cargo-binutils rustfilt
77
RUN rustup component add llvm-tools-preview
88
RUN sudo gem install bundler
9+
RUN wget -O /usr/bin/glauth https://github.com/glauth/glauth/releases/download/v2.3.2/glauth-linux-amd64
10+
RUN chmod +x /usr/bin/glauth
911
RUN wget -O toxiproxy-2.4.0.deb https://github.com/Shopify/toxiproxy/releases/download/v2.4.0/toxiproxy_2.4.0_linux_$(dpkg --print-architecture).deb && \
1012
sudo dpkg -i toxiproxy-2.4.0.deb
1113
RUN wget -O go1.21.3.linux-$(dpkg --print-architecture).tar.gz https://go.dev/dl/go1.21.3.linux-$(dpkg --print-architecture).tar.gz && \

0 commit comments

Comments
 (0)