Skip to content

Commit

Permalink
Configure Samba for Kerberos authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
bersace committed May 16, 2024
1 parent a340a99 commit 86784f9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
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

0 comments on commit 86784f9

Please sign in to comment.