<div dir="ltr">Hi all,<div><br></div><div>I have been exploring using a service account with restricted permissions to add and enrol hosts, rather than using an administrative user. I based the account details on an earlier posting to this list (<a href="https://www.redhat.com/archives/freeipa-users/2016-January/msg00524.html">https://www.redhat.com/archives/freeipa-users/2016-January/msg00524.html</a>), but ran into a couple of things that I found odd:</div><div><br></div><div>1. The service account needs to be explicitly granted permission to read itself.</div><div><br></div><div>When a host was previously enrolled with FreeIPA and has run `ipa-client-install --uninstall`, a fresh `ipa-client-install` using a service user fails unless the host is manually deleted with `ipa host-del`, or the service user is explicitly granted permission to read itself.</div><div><br></div><div>Without either of the above, `ipa-client-install` fails with an error "Joining realm failed: RPC failed at server.  host with name "my.hostname.domain" already exists". On the server side, for some reason the service user tries to look itself up to check if it's got permissions to modify the host (which it does). It does not seem to have permissions to look itself up by default in the cn=sysaccounts,cn=etc tree, so the permission check fails, and throws the error above.</div><div><br></div><div>I'm granting the service account the following permission to work around this, but I'm a little confused as to why it's required:</div><div><div><font face="monospace">ipa permission-add 'Read Host Join User' --target=uid=my-join-user,cn=sysaccounts,cn=etc,dc=example,dc=com --right=read --right=search --right=compare --attrs='*'</font></div></div><div><br></div><div>Is that permission going to cause the service account to be able to do anything it shouldn't, or does it look okay?</div><div><br></div><div>2. The service account's password expiry must be set in a separate ldapmodify call</div><div><br></div><div>I tried to create the service account with a password that does not expire by setting "krbPasswordExpiration: 20380119031407Z" on the account when it is created, but it seems to be immediately overwritten. If I create the account in one ldapmodify call, and set the password expiration in a separate call, the expiration seems to stick. Is that expected, or am I setting the expiration incorrectly?</div><div><br></div><div>I've included the full set of commands I'm using the setup my service account for host enrolment, in case something I'm doing wrong is causing the above strangeness. I'm running FreeIPA 4.2.0 on CentOS 7.</div><div><br></div><div>I'd be keen for some feedback on this approach, and whether it's normal to have to use the workarounds above.</div><div><br></div><div>Thanks,</div><div>Nicholas.</div><div><br></div><div><div><font face="monospace">## Configure the account used by hosts to join the domain</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"># Authenticate so the ipa commands can run</font></div><div><font face="monospace">kinit admin</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"># (System account needs special permissions to read itself)</font></div><div><font face="monospace">ipa permission-add 'Read Host Join User' --target=uid=my-join-user,cn=sysaccounts,cn=etc,dc=example,dc=com --right=read --right=search --right=compare --attrs='*'</font></div><div><font face="monospace">ipa privilege-add 'Read Host Join User'</font></div><div><font face="monospace">ipa privilege-add-permission --permissions='Read Host Join User' 'Read Host Join User'</font></div><div><font face="monospace">ipa privilege-add 'Add Hosts'</font></div><div><font face="monospace">ipa privilege-add-permission --permissions='System: Add Hosts' 'Add Hosts'</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"># Role to assign to the system account, with permissions to enrol hosts, add hosts, and read itself</font></div><div><font face="monospace">ipa role-add --desc="Host Joining" 'Host Joining'</font></div><div><font face="monospace">ipa role-add-privilege --privileges='Host Enrollment' 'Host Joining'</font></div><div><font face="monospace">ipa role-add-privilege --privileges='Add Hosts' 'Host Joining'</font></div><div><font face="monospace">ipa role-add-privilege --privileges='Read Host Join User' 'Host Joining'</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"># Drop admin permissions</font></div><div><font face="monospace">kdestroy</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"># Create the system account in LDAP and add it to the new role</font></div><div><font face="monospace">cat <<LDIF_END | ldapmodify -x -D 'cn=Directory Manager' -W</font></div><div><font face="monospace">dn: uid=my-join-user,cn=sysaccounts,cn=etc,dc=example,dc=com</font></div><div><font face="monospace">changetype: add</font></div><div><font face="monospace">objectclass: account</font></div><div><font face="monospace">objectclass: simplesecurityobject</font></div><div><font face="monospace">objectclass: inetUser</font></div><div><font face="monospace">objectClass: krbprincipalaux</font></div><div><font face="monospace">objectClass: krbticketpolicyaux</font></div><div><font face="monospace">uid: my-join-user</font></div><div><font face="monospace">krbPrincipalName: <a href="mailto:my-join-user@EXAMPLE.COM">my-join-user@EXAMPLE.COM</a></font></div><div><font face="monospace">userPassword: averysecurepassword</font></div><div><font face="monospace">passwordExpirationTime: 20380119031407Z</font></div><div><font face="monospace">nsIdleTimeout: 0</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">dn: cn=Host Joining,cn=roles,cn=accounts,dc=example,dc=com</font></div><div><font face="monospace">changetype: modify</font></div><div><font face="monospace">add: member</font></div><div><font face="monospace">member: uid=my-join-user,cn=sysaccounts,cn=etc,dc=example,dc=com</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">LDIF_END</font></div><div><font face="monospace"># Ensure the join user's password does not expire. This must be set in a separate ldapmodify call or it gets overwritten</font></div><div><font face="monospace">cat <<LDIF_END | ldapmodify -x -D 'cn=Directory Manager' -W</font></div><div><font face="monospace">dn: uid=my-join-user,cn=sysaccounts,cn=etc,dc=example,dc=com</font></div><div><font face="monospace">changetype: modify</font></div><div><font face="monospace">replace: krbPasswordExpiration</font></div><div><font face="monospace">krbPasswordExpiration: 20380119031407Z</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">LDIF_END</font></div><div><font face="monospace"># NB: the trailing empty line after each entry is required in the above LDIFs</font></div></div></div>