2021-10-29 12:57:33 +01:00
|
|
|
let
|
|
|
|
dbDomain = "example.org";
|
|
|
|
dbSuffix = "dc=example,dc=org";
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2021-10-29 12:57:33 +01:00
|
|
|
ldapRootUser = "admin";
|
|
|
|
ldapRootPassword = "foobar";
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2021-10-29 12:57:33 +01:00
|
|
|
testUser = "alice";
|
|
|
|
in import ./make-test-python.nix ({pkgs, ...}: {
|
|
|
|
name = "sssd-ldap";
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2021-10-29 12:57:33 +01:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ bbigras ];
|
|
|
|
};
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine = { pkgs, ... }: {
|
2021-10-29 12:57:33 +01:00
|
|
|
services.openldap = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
children = {
|
|
|
|
"cn=schema".includes = [
|
|
|
|
"${pkgs.openldap}/etc/schema/core.ldif"
|
|
|
|
"${pkgs.openldap}/etc/schema/cosine.ldif"
|
|
|
|
"${pkgs.openldap}/etc/schema/inetorgperson.ldif"
|
|
|
|
"${pkgs.openldap}/etc/schema/nis.ldif"
|
|
|
|
];
|
|
|
|
"olcDatabase={1}mdb" = {
|
|
|
|
attrs = {
|
|
|
|
objectClass = [ "olcDatabaseConfig" "olcMdbConfig" ];
|
|
|
|
olcDatabase = "{1}mdb";
|
2022-08-18 10:34:20 +01:00
|
|
|
olcDbDirectory = "/var/lib/openldap/db";
|
2021-10-29 12:57:33 +01:00
|
|
|
olcSuffix = dbSuffix;
|
|
|
|
olcRootDN = "cn=${ldapRootUser},${dbSuffix}";
|
|
|
|
olcRootPW = ldapRootPassword;
|
2020-09-27 23:23:31 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-10-29 12:57:33 +01:00
|
|
|
};
|
|
|
|
declarativeContents = {
|
|
|
|
${dbSuffix} = ''
|
|
|
|
dn: ${dbSuffix}
|
|
|
|
objectClass: top
|
|
|
|
objectClass: dcObject
|
|
|
|
objectClass: organization
|
|
|
|
o: ${dbDomain}
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2021-10-29 12:57:33 +01:00
|
|
|
dn: ou=posix,${dbSuffix}
|
|
|
|
objectClass: top
|
|
|
|
objectClass: organizationalUnit
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2021-10-29 12:57:33 +01:00
|
|
|
dn: ou=accounts,ou=posix,${dbSuffix}
|
|
|
|
objectClass: top
|
|
|
|
objectClass: organizationalUnit
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2021-10-29 12:57:33 +01:00
|
|
|
dn: uid=${testUser},ou=accounts,ou=posix,${dbSuffix}
|
|
|
|
objectClass: person
|
|
|
|
objectClass: posixAccount
|
|
|
|
# userPassword: somePasswordHash
|
|
|
|
homeDirectory: /home/${testUser}
|
|
|
|
uidNumber: 1234
|
|
|
|
gidNumber: 1234
|
|
|
|
cn: ""
|
|
|
|
sn: ""
|
|
|
|
'';
|
2020-09-01 06:03:20 +01:00
|
|
|
};
|
2021-10-29 12:57:33 +01:00
|
|
|
};
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2021-10-29 12:57:33 +01:00
|
|
|
services.sssd = {
|
|
|
|
enable = true;
|
2022-08-18 10:37:43 +01:00
|
|
|
# just for testing purposes, don't put this into the Nix store in production!
|
|
|
|
environmentFile = "${pkgs.writeText "ldap-root" "LDAP_BIND_PW=${ldapRootPassword}"}";
|
2021-10-29 12:57:33 +01:00
|
|
|
config = ''
|
|
|
|
[sssd]
|
|
|
|
config_file_version = 2
|
|
|
|
services = nss, pam, sudo
|
|
|
|
domains = ${dbDomain}
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2021-10-29 12:57:33 +01:00
|
|
|
[domain/${dbDomain}]
|
|
|
|
auth_provider = ldap
|
|
|
|
id_provider = ldap
|
|
|
|
ldap_uri = ldap://127.0.0.1:389
|
|
|
|
ldap_search_base = ${dbSuffix}
|
|
|
|
ldap_default_bind_dn = cn=${ldapRootUser},${dbSuffix}
|
|
|
|
ldap_default_authtok_type = password
|
2022-08-18 10:37:43 +01:00
|
|
|
ldap_default_authtok = $LDAP_BIND_PW
|
2021-10-29 12:57:33 +01:00
|
|
|
'';
|
2020-09-01 06:03:20 +01:00
|
|
|
};
|
2021-10-29 12:57:33 +01:00
|
|
|
};
|
2020-09-01 06:03:20 +01:00
|
|
|
|
2021-10-29 12:57:33 +01:00
|
|
|
testScript = ''
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("openldap.service")
|
|
|
|
machine.wait_for_unit("sssd.service")
|
2022-10-09 14:18:11 +01:00
|
|
|
result = machine.execute("getent passwd ${testUser}")
|
|
|
|
if result[0] == 0:
|
|
|
|
assert "${testUser}" in result[1]
|
|
|
|
else:
|
|
|
|
machine.wait_for_console_text("Backend is online")
|
|
|
|
machine.succeed("getent passwd ${testUser}")
|
2021-10-29 12:57:33 +01:00
|
|
|
'';
|
|
|
|
})
|