Commit Graph

22 Commits (6bc0475e8916b360e1f39f28f1eedcd0148298e9)

Author SHA1 Message Date
Dustin f51e0fe2a9 r/samba-dc: Enable auto-restart for samba.service
Setting `RestartSec` is not enough to enable auto-restart; the `Restart`
option is also required, as it defaults to `no`.
2024-08-09 08:11:39 -05:00
Dustin ed22f6311c r/samba-dc: Auto restart samba
Although it's rare, sometimes Samba crashes or fails to start.  When
this happens, restarting it is almost always enough to get it working
again.  Since all sorts of authentication problems can occur if one of
the domain controllers is down, it's probably best to just have systemd
automatically restart _samba.service_ if it ever stops for any reason.
2024-07-03 10:30:20 -05:00
Dustin f334363aab r/samba-dc: sysvolsync: Remove winbind cache file
The `net cache flush` command does not seem to always work to clear the
identity mapping cache used by winbind.  Explicitly moving the file
does, though.
2023-10-28 09:56:44 -05:00
Dustin 3e70600691 r/samba-dc: sysvolsync: Fix running on fresh DC
On a new DC, the `idmap.ldb` file does not yet exist the first time
`sysvolsync` runs.  This causes a syntax error in the condition that
checks the modification timestamp of the file.
2023-10-28 09:52:24 -05:00
Dustin 5bffdc68a2 r/samba-dc: sysvolsync: Use system DNS server
Forcing the PDC lookup to use localhost as the DNS server does not work
when first adding a new domain controller, as the `sysvolsync` script
runs before Samba starts.  There isn't much advantage to using the local
DNS server over the system-defined server anyway.
2023-10-27 17:55:44 -05:00
Dustin d26de78b3d r/samba-dc: Rotate KDC log weekly
The Samba KDC log file seems to grow rather quickly sometimes, outpacing
the monthly rotation policy.  Let's rotate it weekly and keep 4
historical versions.
2023-05-23 08:31:58 -05:00
Dustin ad9fb6798e samba-dc: Omit tls cafile setting
The `tls cafile` setting in `smb.conf` is not necessary.  It is used for
verifying peer certificates for mutual TLS authentication, not to
specify the intermediate certificate authority chain like I thought.

The setting cannot simply be left out, though.  If it is not specified,
Samba will attempt to load a file from a built-in default path, which
will fail, causing the server to crash.  This is avoided by setting the
value to the empty string.
2023-05-10 08:28:49 -05:00
Dustin 5661910a21 samba-dc: Add sysvolsync script
Samba AD DC does not implement [DFS-R for replication of the SYSVOL][0]
contents.  This does not make much of a difference to me, since
the SYSVOL is really only used for Group Policy.  Windows machines may
log an error if they cannot access the (basically empty) GPO files, but
that's pretty much the only effect if the SYSVOL is in sync between
domain controllers.

Unfortunately, there is one side-effect of the missing DFS-R
functionality that does matter.  On domain controllers, all user,
computer, and group accounts need to have Unix UID/GID numbers mapped.
This is different than regular member machines, which only need UID/GID
numbers for users that will/are allowed to log into them.  LDAP entries
only have ID numbers mapped for the latter class of users, which does
not include machine accounts.  As a result, Samba falls back to
generating local ID numbers for the rest of the accounts.  Those ID
numbers are stored in a local database file,
`/var/lib/samba/private/idmap.ldb`.  It would seem that it wouldn't
actually matter if accounts have different ID numbers on different
domain controllers, but there are evidently [situations][1] where DCs
refuse to allocate ID numbers at all, which can cause authentication to
fail.  As such, the `idmap.ldb` file needs to be kept in sync.

If we're going to go through the effort of synchronizing `idmap.ldb`, we
might as well keep the SYSVOL in sync as well.  To that end, I've
written a script to synchronize both the SYSVOL contents and the
`idmap.ldb` file.  It performs a simple one-way synchronization using
`rsync` from the DC with the PDC emulator role, as discovered using DNS
SRV records.  To ensure the `idmap.ldb` file is in a consistent state,
it only copies the most recent backup file.  If the copied file differs
from the local one, the script stops Samba and restores the local
database from the backup.  It then flushes Samba's caches and restarts
the service.  Finally, it fixes the NT ACLs on the contents of the
SYSVOL.

Since the contents of the SYSVOL are owned by root, naturally the
synchronization process has to run as root as well.  To attempt to limit
the scope of control this would give the process, we use as much of the
systemd sandbox capabilities as possible.  Further, the SSH key pairs
the DCs use to authenticate to one another are restricted to only
running rsync.  As such, the `sysvolsync` script itself cannot run
`tdbbackup` to back up `idmap.ldb`.  To handle that, I've created a
systemd service and corresponding timer unit to run `tdbbackup`
periodically.

I considered for a long time how to best implement this process, and
although I chose this naïve implementation, I am not exactly happy with
it.  Since I do not fully understand *why* keeping
the `idmap.ldb` file in sync is necessary, there are undoubtedly cases
where blindly copying it from the PDC emulator is not correct.  There
are definitely cases where the contents of the SYSVOL can be updated on
a DC besides the PDC emulator, but again, we should not run into them
because we don't really use the SYSVOL at all.  In the end, I think this
solution is good enough for our needs, without being so complicated

[0]: https://wiki.samba.org/index.php?title=SysVol_replication_(DFS-R)&oldid=18120
[1]: https://lists.samba.org/archive/samba/2021-November/238370.html
2022-12-22 18:55:07 -06:00
Dustin 8965ede50a r/samba-dc: Remove winbindd restorecon workaround
This work-around is no longer necessary as the default Fedora policy now
covers the Samba DC daemon.  It never really worked correctly, anyway,
because Samba doesn't start `winbindd` fast enough for the
`/run/samba/winbindd` directory to be created before systemd spawns the
`restorecon` process, so it would usually fail to start the service the
first time after a reboot.
2022-08-22 20:32:07 -05:00
Dustin 24228953b0 r/samba-dc: Configure logrotate for KDC
The KDC service, as managed by Samba, continuously logs to two files
that need to be rotated.  The upstream configuration for logrotate only
manages one of these files, and does not correctly signal the service
after rotating, as it expects the service to be managed by systemd
instead of Samba.  As such, we need to adjust the configuration to
handle both files and send SIGHUP directly to the process.
2022-04-24 11:37:13 -05:00
Dustin 948079dafa r/samba-dc: Configure samba logging
Send logs to the systemd journal for easier viewing and disable logging
to a file.  Also, the `samba_dc_log_level` variable can control the log
level (0-10, 0 being off, 10 being insane debugging).
2021-11-07 16:18:51 -06:00
Dustin 7bb1eb677e r/samba-dc: Use rfc2307 on all DCs
I honestly don't remember why the `use rfc2307` setting was only enabled
on the first DC.  All DCs seem to need this setting in order to use the
UID/GID numbers from the directory, instead of using auto-generated
numbers.
2021-10-31 21:07:49 -05:00
Dustin cb92f47b4d roles/samba: Manage LDAP TLS certificates
This commit adds tasks to the *samba-dc* role to install TLS
certificates for the Samba LDAP server, and configures Samba to use
them.
2019-03-22 09:31:19 -05:00
Dustin 93598145b6 roles/samba-dc: Support configuring TLS
In order to enable LDAPS/STARTTLS support in Samba, the `tls enabled`
option must be set to `yes` and the `tls keyfile` and `tls certfile`
options must be set to the path of the private key and certificate
files, respectively, that Samba will use. The `samba_tls_enabled`,
`samba_tls_keyfile`, and `samb_tls_certfile` Ansible variables can be
used to control these values.
2018-05-28 15:24:34 -05:00
Dustin 984628cbbc roles/samba-dc: Fix typo in host principal name
The service principal name added to `/etc/krb5.keytab` had a trailing
`}` character because of a typo in the Ansible task. This resulted in
GSSAPI authentication failing because server processes could not find
the host key in the key table.
2018-04-08 10:50:51 -05:00
Dustin 5a91cb731a samba-dc: Configure samba4 winbind
The *samba-dc* role now configures `winbindd` on domain controllers to
support identity mapping on the local machine. This will allow domain
users to log into the domain controller itself, e.g. via SSH.

The Fedora packaging of *samba4* still has some warts. Specifically, it
does not have a proper SELinux policy, so some work-arounds need to be
put into place in order for confined processes to communicate with
winbind.
2018-03-11 18:16:17 -05:00
Dustin efbb563670 roles/samba-dc: Conditionally configure BIND9_DLZ
This commit adjusts the tasks in the *samba-dc* role to use a
conditional include to restrict tasks relating to the BIND9_DLZ plugin
only to hosts that are configured to use it.
2018-02-19 22:46:27 -06:00
Dustin 03ef6a402a roles/samba: Add some management tools
The *bind-utils* package contains `dig` and `nsupdate`, which are used
to query and manage DNS records.

The *cyrus-sasl-gssapi* package contains the GSSAPI plugin for
SASL-aware applications, including `ldapsearch`.

The *ldb-tools* package contains `ldbsearch` and other tools for
directly using Samba database files.
2018-02-18 13:14:35 -06:00
Dustin f458a46e3f roles/samba-dc: Additional BIND SELinux contexts
The `/var/lib/samba/bind-dns` directory contains files that are
hard-linked to files in the `/var/lib/samba/private` directory. All
paths for a file must have the same context, or `restorecon` will
effectively "toggle" the labels each time it is run.
2018-02-18 13:10:31 -06:00
Dustin 94154a9f2b roles/samba-dc: Correct restorecon path
Evidently, some files in `/var/lib/samba` match multiple file context
rules. Thus, when running `restorecon` against the entire
`/var/lib/samba` directory, files in the `bind-dns` subdirectory may end
up with the wrong label. To work around this issue, `restorecon` is now
run only on that subdirectory to ensure the correct labels are applied.

This is likely to cause problems when a full filesystem relabel is
scheduled.
2018-02-18 10:09:57 -06:00
Dustin cb7c36d65a roles/samba-dc: Support joining existing domain
The *samba-dc* role now supports joining an existing Active Directory
domain as an additional domain controller. The `samba_is_first_dc` variable
controls whether the machine will be provisioned with a new domain (when
true) or added to an existing domain (when false).

Joining an existing domain naturally requires credentials of a user with
permission to add a new DC, the `samba_dc_join_username` and
`samba_dc_join_password` variables can be used to specify them.
Alternatively, if these variables are not defined, then the process will
attempt to use Kerberos credentials. This would require playbooks to
make a ticket-granting-ticket available somehow, such as by executing
`kinit` prior to applying the *samba-dc* role.
2018-01-29 15:11:07 -06:00
Dustin 42ce2434ad roles/samba-dc: Deploy a Samba AD DC
The *samba-dc* role installs Samba on the managed node and configures it
as an Active Directory Domain controller. A custom module,
`samba_domain` handles the provisioning using `samba-tool domain
provision` in an idempotent way.
2018-01-29 15:07:15 -06:00