@@ -31,6 +31,7 @@ LDAP_KADMIN_DN="uid=kadmin,${LDAP_KRB_DN}"
31
31
LDAP_KADMIN_PW=" kadmintest"
32
32
LDAP_ADMIN_DN=" cn=admin,${LDAP_BASE_DN} "
33
33
LDAP_ADMIN_PW=" test"
34
+ KRB_BOB_PW=" bob@BOB@123"
34
35
KERBEROS_REALM=" $( echo " ${DOMAIN} " | tr " [:lower:]" " [:upper:]" ) "
35
36
export LC_ALL=C
36
37
export DEBIAN_FRONTEND=noninteractive
@@ -68,6 +69,7 @@ LDAP kadmin DN : ${LDAP_KADMIN_DN}
68
69
LDAP kadmin PW : ${LDAP_KADMIN_PW}
69
70
LDAP admin DN : ${LDAP_ADMIN_DN}
70
71
LDAP admin PW : ${LDAP_ADMIN_PW}
72
+ KRB bob PW : ${KRB_BOB_PW}
71
73
==============================================================================
72
74
EOF
73
75
@@ -326,6 +328,7 @@ echo "OK"
326
328
printf " Creating test user principals ... "
327
329
kadmin.local -q " addprinc -randkey -policy defaultpol alice" > /dev/null || die
328
330
kadmin.local -q " ktadd -k krb5.alice.keytab alice" > /dev/null || die
331
+ kadmin.local -q " addprinc -pw ${KRB_BOB_PW} -policy defaultpol bob" > /dev/null || die
329
332
kadmin.local -q " addprinc -randkey -policy defaultpol mallory" > /dev/null || die
330
333
kadmin.local -q " ktadd -k krb5.mallory.keytab mallory" > /dev/null || die
331
334
echo " OK"
@@ -416,6 +419,21 @@ server {
416
419
auth_gss_service_ccache /tmp/krb5cc_nginx;
417
420
}
418
421
422
+ location /fallback.php {
423
+ include snippets/fastcgi-php.conf;
424
+ fastcgi_pass unix:/run/php/php-fpm.sock;
425
+ auth_gss on;
426
+ auth_gss_realm ${KERBEROS_REALM} ;
427
+ auth_gss_keytab /etc/krb5.http.keytab;
428
+ auth_gss_service_name HTTP/${TEST_HOST_FQDN} ;
429
+ auth_gss_allow_basic_fallback on;
430
+ auth_gss_authorized_principal bob@${KERBEROS_REALM} ;
431
+ auth_gss_format_full on;
432
+ fastcgi_param HTTP_AUTHORIZATION "";
433
+ fastcgi_param KRB5CCNAME \$ krb5_cc_name;
434
+ auth_gss_service_ccache /tmp/krb5cc_nginx;
435
+ }
436
+
419
437
location /delegate.php {
420
438
include snippets/fastcgi-php.conf;
421
439
fastcgi_pass unix:/run/php/php-fpm.sock;
471
489
echo " OK"
472
490
473
491
492
+ printf " Writing fallback.php ... "
493
+ if ! cat << 'EOF ' > /var/www/kerberos/fallback.php
494
+ <?php
495
+ if (!isset($_SERVER["REMOTE_USER"]) || $_SERVER["REMOTE_USER"] == "") {
496
+ http_response_code(500);
497
+ echo("REMOTE_USER not set");
498
+ exit();
499
+ }
500
+ echo("Authenticated as " . $_SERVER["REMOTE_USER"]);
501
+ ?>
502
+ EOF
503
+ then
504
+ die
505
+ fi
506
+ echo " OK"
507
+
508
+
474
509
printf " Writing delegate.php ... "
475
510
if ! cat << EOF > /var/www/kerberos/delegate.php
476
511
<?php
@@ -581,6 +616,46 @@ test_path()
581
616
fi
582
617
}
583
618
619
+ test_basic ()
620
+ {
621
+ SUBURL=" $1 "
622
+ EXPECT1=" $2 "
623
+ EXPECT2=" $3 "
624
+
625
+ printf " curl %s, incorrect basic auth: http status (expect %s)=" " ${SUBURL} " " ${EXPECT1} "
626
+ rm -f " ${CURL_OUTPUT} "
627
+ CODE=" $( $CURL_NONEGOTIATE -u " bob:InVaLiD" -w " %{http_code}" " http://${TEST_HOST_FQDN} :8080/${SUBURL} " ) " || true
628
+ printf " %s ... " " ${CODE} "
629
+ if [ " $CODE " = " ${EXPECT1} " ]; then
630
+ echo " OK"
631
+ else
632
+ EX=1
633
+ echo " FAILED"
634
+ if [ -e " ${CURL_OUTPUT} " ]; then
635
+ echo " HTTP body:"
636
+ cat " ${CURL_OUTPUT} "
637
+ echo " "
638
+ fi
639
+ fi
640
+
641
+ printf " curl %s, basic auth: http status (expect %s)=" " ${SUBURL} " " ${EXPECT2} "
642
+ rm -f " ${CURL_OUTPUT} "
643
+ CODE=" $( $CURL_NONEGOTIATE -u " bob:${KRB_BOB_PW} " -w " %{http_code}" " http://${TEST_HOST_FQDN} :8080/${SUBURL} " ) " || true
644
+ printf " %s ... " " ${CODE} "
645
+ if [ " $CODE " = " ${EXPECT2} " ]; then
646
+ echo " OK"
647
+ else
648
+ EX=1
649
+ echo " FAILED"
650
+ if [ -e " ${CURL_OUTPUT} " ]; then
651
+ echo " HTTP body:"
652
+ cat " ${CURL_OUTPUT} "
653
+ echo " "
654
+ fi
655
+ fi
656
+
657
+ }
658
+
584
659
test_ldapwhoami ()
585
660
{
586
661
LDAP_EXPECTED=" dn:uid=${1} ,cn=gss-spnego,cn=auth"
@@ -606,6 +681,8 @@ test_ldapwhoami()
606
681
printf " Destroying Kerberos tickets ... "
607
682
kdestroy -q > /dev/null 2>&1 || true
608
683
echo " OK"
684
+ test_basic " fallback.php" 401 200
685
+ test_path " fallback.php" 401 401
609
686
test_path " noauth.php" 200 200
610
687
test_path " auth.php" 401 401
611
688
test_path " delegate.php" 401 401
619
696
EX=1
620
697
echo " FAILED"
621
698
fi
699
+ test_basic " fallback.php" 401 200
700
+ test_path " fallback.php" 401 403
622
701
test_path " noauth.php" 200 200
623
702
test_path " auth.php" 401 200
624
703
test_path " delegate.php" 401 200
@@ -634,6 +713,24 @@ else
634
713
EX=1
635
714
echo " FAILED"
636
715
fi
716
+ test_basic " fallback.php" 401 200
717
+ test_path " fallback.php" 401 403
718
+ test_path " noauth.php" 200 200
719
+ test_path " auth.php" 401 403
720
+ test_path " delegate.php" 401 403
721
+
722
+
723
+ echo " "
724
+ printf " Obtaining Kerberos ticket for bob ... "
725
+ kdestroy -q > /dev/null 2>&1 || true
726
+ if echo " ${KRB_BOB_PW} " | kinit bob > /dev/null 2>&1 ; then
727
+ echo " OK"
728
+ else
729
+ EX=1
730
+ echo " FAILED"
731
+ fi
732
+ test_basic " fallback.php" 401 200
733
+ test_path " fallback.php" 401 200
637
734
test_path " noauth.php" 200 200
638
735
test_path " auth.php" 401 403
639
736
test_path " delegate.php" 401 403
0 commit comments