Skip to content

Commit d2e9cc6

Browse files
committed
account PAM interface calls acct_mgmt function in handler
1 parent 880d0f7 commit d2e9cc6

File tree

2 files changed

+17
-44
lines changed

2 files changed

+17
-44
lines changed

pam-oidc/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,29 @@ impl PamServiceModule for PamCustom {
148148
}
149149

150150
fn chauthtok(_pamh: Pam, _flags: PamFlags, _args: Vec<String>) -> PamError {
151+
info!("chauthtok called.");
151152
PamError::SUCCESS
152153
}
153154

154155
fn open_session(_pamh: Pam, _flags: PamFlags, _args: Vec<String>) -> PamError {
156+
info!("open_session called.");
155157
PamError::SUCCESS
156158
}
157159

158160
fn close_session(_pamh: Pam, _flags: PamFlags, _args: Vec<String>) -> PamError {
161+
info!("close_session called.");
159162
PamError::SUCCESS
160163
}
161164

162165
fn setcred(_pamh: Pam, _flags: PamFlags, _args: Vec<String>) -> PamError {
166+
info!("setcred called.");
163167
PamError::SUCCESS
164168
}
165169

166170
fn acct_mgmt(_pamh: Pam, _flags: PamFlags, _args: Vec<String>) -> PamError {
171+
info!("acct_mgmt called.");
167172
PamError::SUCCESS
173+
// PamError::USER_UNKNOWN
168174
}
169175
}
170176

tests/test.sh

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,13 @@
11
#!/bin/bash
22

3-
# set -a && . .env && ./tests/test.sh mariadb && set +a
4-
# set -a && . .env && ./tests/test.sh percona && set +a
5-
6-
mariadb() {
7-
set -e
8-
ROOT_PASSWORD=simple
9-
docker rm -f database
10-
docker run --name database -de MYSQL_ROOT_PASSWORD=${ROOT_PASSWORD} mariadb:10.7 # does not work with latest and non-v1
11-
until docker exec -it database mysql -h 127.0.0.1 -uroot -p${ROOT_PASSWORD} -e "SELECT 1;" 1>/dev/null
12-
do
13-
echo waiting...
14-
sleep 5
15-
done
16-
docker exec -it database mysql -uroot -p${ROOT_PASSWORD} -e "INSTALL SONAME 'auth_pam_v1';"
17-
docker cp ./config/service_example database:/etc/pam.d/oidc
18-
docker cp ./pam-oidc/target/debug/libpam_oidc.so database:/lib/x86_64-linux-gnu/security/libpam_oidc.so
19-
docker exec -it database mkdir /etc/datajoint
20-
docker cp ./config/libpam_oidc.yaml database:/etc/datajoint/
21-
docker exec -it database mysql -uroot -p${ROOT_PASSWORD} -e "CREATE USER '${DJ_AUTH_USER}'@'%' IDENTIFIED VIA pam USING 'oidc';"
22-
docker exec -it database mysql -h 127.0.0.1 -u${DJ_AUTH_USER} -p${DJ_AUTH_PASSWORD} -e "SELECT 'delegated to oidc' as login;"
23-
docker exec -it database mysql -h 127.0.0.1 -u${DJ_AUTH_USER} -p${DJ_AUTH_PASSWORD} -e "SELECT 'delegated to oidc' as login;"
24-
docker exec -it database mysql -h 127.0.0.1 -u${DJ_AUTH_USER} -pdeny -e "SELECT 'delegated to oidc' as login;"
25-
}
26-
27-
percona() {
28-
set -e
29-
ROOT_PASSWORD=simple
30-
docker rm -f database
31-
docker run --name database -de MYSQL_ROOT_PASSWORD=${ROOT_PASSWORD} --entrypoint bash percona:8 -c "echo 'plugin_load_add = auth_pam.so' >> /etc/my.cnf && /docker-entrypoint.sh mysqld"
32-
until docker exec -it database mysql -h 127.0.0.1 -uroot -p${ROOT_PASSWORD} -e "SELECT 1;" 1>/dev/null
33-
do
34-
echo waiting...
35-
sleep 5
36-
done
37-
docker cp ./config/service_example database:/etc/pam.d/oidc
38-
docker cp ./pam-oidc/target/debug/libpam_oidc.so database:/usr/lib64/security/libpam_oidc.so
39-
docker exec -itu root database mkdir /etc/datajoint
40-
docker cp ./config/libpam_oidc.yaml database:/etc/datajoint/
41-
docker exec -it database mysql -uroot -p${ROOT_PASSWORD} -e "CREATE USER '${DJ_AUTH_USER}'@'%' IDENTIFIED WITH auth_pam AS 'oidc';"
42-
docker exec -it database mysql -h 127.0.0.1 -u${DJ_AUTH_USER} -p${DJ_AUTH_PASSWORD} -e "SELECT 'delegated to oidc' as login;"
43-
docker exec -it database mysql -h 127.0.0.1 -u${DJ_AUTH_USER} -p${DJ_AUTH_PASSWORD} -e "SELECT 'delegated to oidc' as login;"
44-
docker exec -it database mysql -h 127.0.0.1 -u${DJ_AUTH_USER} -pdeny -e "SELECT 'delegated to oidc' as login;"
45-
}
46-
3+
# Usage:
4+
# ./tests/test.sh '<demouser_password>'
5+
6+
docker compose up --build -d --wait percona
7+
docker compose exec percona mysql -hlocalhost -uroot -ppassword -e "CREATE USER 'demouser'@'%' IDENTIFIED WITH auth_pam AS 'oidc';"
8+
docker compose exec percona mysql -hlocalhost -uroot -ppassword -e "SHOW PLUGINS;" | grep auth_pam
9+
docker compose exec percona mysql -hlocalhost -udemouser -p"$1" -e "SELECT 1;" || echo "Failed to authenticate with real password"
10+
docker compose exec percona mysql -hlocalhost -udemouser -p'bogus_password' -e "SELECT 1;" || echo "Failed to authenticate for bogus password"
11+
sleep 3
12+
docker compose logs percona
13+
docker compose down

0 commit comments

Comments
 (0)