Skip to content

GSSAPI/Kerberos auth #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Configure Samba for Kerberos authentication
  • Loading branch information
bersace committed May 16, 2024
commit 86784f9e23d376adcba4911ebe472429de12edf0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist/
docker-compose.override.yml
# test/conftest.py creates .env files
.env
test/samba.keytab
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ services:
environment:
REALM: bridoulou.fr
ADMIN_PASS: 1Ntegral
DNS_BACKEND: "NONE"
volumes:
- ./test/fixtures/samba/kerberos.sh:/docker-entrypoint-init.d/00-kerberos.sh
- ./test:/test # Use to export keytab in kerberos.sh
- ./test/fixtures/samba/nominal.sh:/docker-entrypoint-init.d/95-nominal.sh
- ./test/fixtures/samba/extra.sh:/docker-entrypoint-init.d/96-extra.sh
hostname: samba1
domainname: ldap2pg.docker
labels:
com.dnsdock.alias: samba1.ldap2pg.docker
command: [-d=1]
command: [-d=3]

postgres:
image: postgres:${PGVERSION-16}-alpine
Expand Down
4 changes: 4 additions & 0 deletions ldaprc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ TLS_REQCERT allow
NETWORK_TIMEOUT 5
TIMEOUT 5
REFERRALS off
SASL_AUTHCID Administrator
# Disable canonicalization which trigger Kerberos SPN ldap/172.X.Y.Z instead of ldap/samba1.ldap2pg.docker.
# With canonicalisation, GSSAPI fails with "Server not found in Kerberos database".
SASL_NOCANON on
21 changes: 21 additions & 0 deletions test/fixtures/samba/kerberos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -x
samba-tool spn add ldap/samba1.ldap2pg.docker SAMBA1$
samba-tool spn add ldap/localhost SAMBA1$
samba-tool spn add ldap/localhost.localdomain SAMBA1$

# Get Gateway (field 3) from default route (destination is 0.0.0.0).
gateway_hex="$(grep -E '^\w+\s+00000000' /proc/net/route | cut -f 3)"
gateway_bytes=( # IP is little endian.
$((16#${gateway_hex:6:2}))
$((16#${gateway_hex:4:2}))
$((16#${gateway_hex:2:2}))
$((16#${gateway_hex:0:2}))
)
printf -v gateway "%d.%d.%d.%d" "${gateway_bytes[@]}"

samba-tool spn add "ldap/$gateway" SAMBA1$
samba-tool spn list SAMBA1$
samba-tool domain exportkeytab /test/samba.keytab --principal=Administrator
chown -v "$(stat -c %u:%g "${BASH_SOURCE[0]}")" /test/samba.keytab
17 changes: 17 additions & 0 deletions test/krb5.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[libdefaults]
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
rdns = false
default_realm = BRIDOULOU.FR
default_keytab_name = FILE:test/samba.keytab

[realms]
BRIDOULOU.FR = {
kdc = samba1.ldap2pg.docker
admin_server = samba1.ldap2pg.docker
}

[domain_realm]
.ldap2pg.docker = BRIDOULOU.FR
ldap2pg.docker = BRIDOULOU.FR