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