Skip to content

Docker container running an Active Directory Domain Controller with Samba4.

Notifications You must be signed in to change notification settings

laztrav/docker-samba-ad-dc

 
 

Repository files navigation

Docker container demonstrating Samba's Active Directory Domain Controller (AD DC) support

This repository is unmaintained. Check if one of the forks are up to date.

Run these commands to build, start and stop the container

# build samba AD image
docker build -t samba-ad-dc .
# run samba AD image with autogenerated passwords
docker run --privileged -v ${PWD}/samba:/var/lib/samba  -e "SAMBA_DOMAIN=SAMDOM" -e "SAMBA_REALM=SAMDOM.EXAMPLE.COM" --name dc1 --dns 127.0.0.1 -d samba-ad-dc
# run samba AD image with predefined passwords without mounting the samba volume
docker run -e "SAMBA_DOMAIN=SAMDOM" -e "SAMBA_REALM=SAMDOM.EXAMPLE.COM" -e "ROOT_PASSWORD=Opoh6quoo5lu" -e "SAMBA_ADMIN_PASSWORD=Yi1se@i^h0" --name dc1 --dns 127.0.0.1 -d samba-ad-dc
# stop and remove samba AD image
docker stop dc1 && docker rm dc1
# remove local samba 
sudo rm -rf samba

You can of course change the domain and realm to your liking.

You get the IP-address of the running machine by issuing docker inspect dc1 | grep IPAddress and the root user's password as well as other passwords by running docker logs dc1 2>&1 | head -3. You should then be able to log in with SSH.

One fast check to see that Kerberos talks with Samba:

ssh [email protected]
root@1779834e202b:~# kinit [email protected]
Password for [email protected]:
Warning: Your password will expire in 41 days on Thu Jul 10 19:36:55 2014
root@1779834e202b:~# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: [email protected]

Valid starting     Expires            Service principal
05/29/14 19:45:53  05/30/14 05:45:53  krbtgt/[email protected]
        renew until 05/30/14 19:45:43

LDAP search within the container:

ldapsearch -b "DC=samdom,DC=example,DC=com" "(&(objectClass=user)(name=administrator))"

Edit custom.sh to add custom logic executed at the and of supervisord.

Redmine client

Now you can test Redmine ldap login to the host.

docker run --name redmine -d sameersbn/redmine:latest
REDMINE_IP=$(docker inspect redmine | grep IPAddres | awk -F'"' '{print $4}')
xdg-open "http://${REDMINE_IP}/auth_sources/new"

Refresh the browser until the login page shows. Login with both username and password as admin. Fill the form with these credentials:

Name: samdom
Host: *samba_ad_dc_ip*
Port: 389 [ ] LDAPS
Account: Administrator@smbdc1
Password: *samba_admin_password_here*
Base DN: CN=Users,DC=samdom,DC=example,DC=com
LDAP filter:
Timeout (in seconds):

On-the-fly user creation [X]
Attributes:
    Login attribute: sAMAccountName
    Firstname attribute: givenName
    Lastname attribute: sn
    Email attribute: userPrincipalName

Now log out and log in with the samba administrator credentials (username: administrator, password: check with docker log dc1)

Windows client

This is a nice guide to join your Windows 7 client to the DC. Just make sure to have your Docker container as the primary DNS server for Windows.

LDAP explorers

I used JXplorer to explore the LDAP-schema. To log in you need to input something like this: JXplorer example

Testing UNIX login with sssd

root@e936157c0bc1:~# getent passwd Administrator
administrator:*:935000500:935000513:Administrator:/:
root@e936157c0bc1:~# getent group "Domain Users"
domain users:*:935000513:administrator
root@e936157c0bc1:~# ssh Administrator@localhost
Administrator@localhost's password:
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.14.4-1-ARCH x86_64)

Resources

I followed the guide on Samba's wiki pages https://wiki.samba.org/index.php/Samba_AD_DC_HOWTO

Port usage: https://wiki.samba.org/index.php/Samba_port_usage

Port forwarding command

If you want the DC to be reachable through the host's IP you can start the container with this command:

docker run --privileged -p 53:53 -p 53:53/udp -p 88:88 -p 88:88/udp -p 135:135 -p 137:137/udp -p 138:138/udp -p 139:139 -p 389:389 -p 389:389/udp -p 445:445 -p 464:464 -p 464:464/udp -p 636:636 -p 3268:3268 -p 3269:3269 -p 1024:1024 -p 1025:1025 -p 1026:1026 -p 1027:1027 -p 1028:1028 -p 1029:1029 -p 1030:1030 -p 1031:1031 -p 1032:1032 -p 1033:1033 -p 1034:1034 -p 1035:1035 -p 1036:1036 -p 1037:1037 -p 1038:1038 -p 1039:1039 -p 1040:1040 -p 1041:1041 -p 1042:1042 -p 1043:1043 -p 1044:1044 -v ${HOME}/dockervolumes/samba:/var/lib/samba  -e "SAMBA_DOMAIN=samdom" -e "SAMBA_REALM=samdom.example.com" -e "SAMBA_HOST_IP=$(hostname --all-ip-addresses |cut -f 1 -d' ')" --name samdom --dns 127.0.0.1 -d samba-ad-dc

The problem is that the port range 1024 and upwards are used for dynamic RPC-calls, luckily Samba goes through them in order, so the first 20 or so should suffice for testing purposes. Windows complains otherwise that "The RPC server is unavailable". It's also possible to eliminate long command line parameters by using $(for port in $(seq 135 139); do echo -n "-p $port:$port "; done;) instead.

TODO

  • xattr and acl support for docker containers
  • NTP support
  • Try to join other Samba4 servers with a Samba4 DC
  • How to implement redundancy and fail-safes?
  • Verify that Bind9 Dynamically Loadable Zones (DLZ) work
  • Can this be used for UNIX logins as well?
  • Probably a lot more to make this robust enough for production use
  • Fix rare BIND9 startup problems. Failed to connect to /var/lib/samba/private/dns/sam.ldb.

About

Docker container running an Active Directory Domain Controller with Samba4.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%