Skip to content
Snippets Groups Projects
Commit aacff4d9 authored by adecoa's avatar adecoa
Browse files

Fix ldap support to virtual desktop


Signed-off-by: default avatarendika <endika.aldecoa@ehu.eus>
parent 654fa5d4
Branches virtual-pc-ldap
No related tags found
1 merge request!137Virtual pc ldap suport
Pipeline #283 passed with stage
in 2 minutes and 37 seconds
This commit is part of merge request !137. Comments created here will be created in the context of that merge request.
...@@ -70,7 +70,7 @@ class VirtualPCCharm(CharmBase, InstallProgress): ...@@ -70,7 +70,7 @@ class VirtualPCCharm(CharmBase, InstallProgress):
self._stored.set_default() self._stored.set_default()
self.last_status_update = time.time() self.last_status_update = time.time()
self.state.set_default(ldap_installed=False) self._stored.set_default(ldap_installed=False)
# Basic hooks # Basic hooks
self.framework.observe(self.on.install, self._on_install) self.framework.observe(self.on.install, self._on_install)
...@@ -205,19 +205,17 @@ class VirtualPCCharm(CharmBase, InstallProgress): ...@@ -205,19 +205,17 @@ class VirtualPCCharm(CharmBase, InstallProgress):
def _ldap_integration(self, event): def _ldap_integration(self, event):
self.unit.status = MaintenanceStatus("Configuring Ldap autentication") self.unit.status = MaintenanceStatus("Configuring Ldap autentication")
_configure_ldap(event.params["ldap_host"], self._configure_ldap(event.params["ldap_host"], event.params["ldap_domain"], event.params["ldap_password"])
event.params["ldap_domain"], if not self._stored.ldap_installed:
event.params["ldap_password"])
if not self.state.ldap_installed:
install_apt(packages=["ldap-auth-client", "nscd"], install_apt(packages=["ldap-auth-client", "nscd"],
update=True, progress=self) update=True, progress=self)
# edit /etc/nsswitch.conf # edit /etc/nsswitch.conf
shell("sudo sed -E -i '/passwd|group/ !b; s/$/ ldap/' /etc/nsswitch.conf") shell("sudo sed -E -i '/passwd|group|shadow/ !b; s/$/ ldap/' /etc/nsswitch.conf")
# restart nscd # restart nscd
shell("sudo systemctl restart nscd") shell("sudo systemctl restart nscd")
#create a home directory when user login #create a home directory when user login
shell("echo session required pam_mkhomedir.so skel=/etc/skel umask=077 | sudo tee /etc/pam.d/common-session") shell("echo session required pam_mkhomedir.so skel=/etc/skel umask=077 | sudo tee /etc/pam.d/common-session")
self.state.ldap_installed = True self._stored.ldap_installed = True
else: else:
shell("dpkg-reconfigure -f noninteractive ldap-auth-client") shell("dpkg-reconfigure -f noninteractive ldap-auth-client")
self.unit.status = ActiveStatus("Ldap autentication configured") self.unit.status = ActiveStatus("Ldap autentication configured")
...@@ -232,18 +230,18 @@ class VirtualPCCharm(CharmBase, InstallProgress): ...@@ -232,18 +230,18 @@ class VirtualPCCharm(CharmBase, InstallProgress):
status_msg = "Ready" status_msg = "Ready"
return status_type(status_msg) return status_type(status_msg)
def _configure_ldap(host, domain, password): def _configure_ldap(self, host, domain, password):
#configure ldap-auth-config with debconf #configure ldap-auth-config with debconf
shell("echo ldap-auth-config ldap-auth-config/rootbindpw password {} | sudo debconf-set-selections".format(password)) shell("echo ldap-auth-config ldap-auth-config/rootbindpw password {} | sudo debconf-set-selections".format(password))
shell("echo ldap-auth-config ldap-auth-config/bindpw password {} | sudo debconf-set-selections".format(password)) shell("echo ldap-auth-config ldap-auth-config/bindpw password {} | sudo debconf-set-selections".format(password))
shell("echo ldap-auth-config ldap-auth-config/binddn string cn=admin,dc={},dc={} | sudo debconf-set-selections".format(domin.split("."))) shell("echo ldap-auth-config ldap-auth-config/binddn string cn=admin,dc={},dc={} | sudo debconf-set-selections".format(domain.split(".")[0],domain.split(".")[1]))
shell("echo ldap-auth-config ldap-auth-config/dblogin boolean false | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/dblogin boolean false | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/rootbinddn string cn=admin,dc={},dc={} | sudo debconf-set-selections".format(domin.split(".")) shell("echo ldap-auth-config ldap-auth-config/rootbinddn string cn=admin,dc={},dc={} | sudo debconf-set-selections".format(domain.split(".")[0],domain.split(".")[1]))
shell("echo ldap-auth-config ldap-auth-config/ldapns/ldap-server string ldap://{} | sudo debconf-set-selections".format(host)) shell("echo ldap-auth-config ldap-auth-config/ldapns/ldap-server string ldap://{} | sudo debconf-set-selections".format(host))
shell("echo ldap-auth-config ldap-auth-config/override boolean true | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/override boolean true | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/ldapns/ldap_version select 3 | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/ldapns/ldap_version select 3 | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/dbrootlogin boolean true | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/dbrootlogin boolean true | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/ldapns/base-dn string dc={},dc={} | sudo debconf-set-selections".format(domin.split(".")) shell("echo ldap-auth-config ldap-auth-config/ldapns/base-dn string dc={},dc={} | sudo debconf-set-selections".format(domain.split(".")[0],domain.split(".")[1]))
shell("echo ldap-auth-config ldap-auth-config/move-to-debconf boolean true | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/move-to-debconf boolean true | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/pam_password select clear | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/pam_password select clear | sudo debconf-set-selections")
......
...@@ -70,7 +70,7 @@ class VirtualPCCharm(CharmBase, InstallProgress): ...@@ -70,7 +70,7 @@ class VirtualPCCharm(CharmBase, InstallProgress):
self._stored.set_default() self._stored.set_default()
self.last_status_update = time.time() self.last_status_update = time.time()
self.state.set_default(ldap_installed=False) self._stored.set_default(ldap_installed=False)
# Basic hooks # Basic hooks
self.framework.observe(self.on.install, self._on_install) self.framework.observe(self.on.install, self._on_install)
...@@ -87,6 +87,7 @@ class VirtualPCCharm(CharmBase, InstallProgress): ...@@ -87,6 +87,7 @@ class VirtualPCCharm(CharmBase, InstallProgress):
self.framework.observe(self.on["remove-package"].action, self._remove_package) self.framework.observe(self.on["remove-package"].action, self._remove_package)
self.framework.observe(self.on["remove-snap"].action, self._remove_snap) self.framework.observe(self.on["remove-snap"].action, self._remove_snap)
self.framework.observe(self.on["update-system"].action, self._update_system) self.framework.observe(self.on["update-system"].action, self._update_system)
self.framework.observe(self.on["integrate-ldap"].action, self._ldap_integration)
# Relations hooks # Relations hooks
...@@ -204,19 +205,17 @@ class VirtualPCCharm(CharmBase, InstallProgress): ...@@ -204,19 +205,17 @@ class VirtualPCCharm(CharmBase, InstallProgress):
def _ldap_integration(self, event): def _ldap_integration(self, event):
self.unit.status = MaintenanceStatus("Configuring Ldap autentication") self.unit.status = MaintenanceStatus("Configuring Ldap autentication")
_configure_ldap(event.params["ldap_host"], self._configure_ldap(event.params["ldap_host"], event.params["ldap_domain"], event.params["ldap_password"])
event.params["ldap_domain"], if not self._stored.ldap_installed:
event.params["ldap_password"])
if not self.state.ldap_installed:
install_apt(packages=["ldap-auth-client", "nscd"], install_apt(packages=["ldap-auth-client", "nscd"],
update=True, progress=self) update=True, progress=self)
# edit /etc/nsswitch.conf # edit /etc/nsswitch.conf
shell("sudo sed -E -i '/passwd|group/ !b; s/$/ ldap/' /etc/nsswitch.conf") shell("sudo sed -E -i '/passwd|group|shadow/ !b; s/$/ ldap/' /etc/nsswitch.conf")
# restart nscd # restart nscd
shell("sudo systemctl restart nscd") shell("sudo systemctl restart nscd")
#create a home directory when user login #create a home directory when user login
shell("echo session required pam_mkhomedir.so skel=/etc/skel umask=077 | sudo tee /etc/pam.d/common-session") shell("echo session required pam_mkhomedir.so skel=/etc/skel umask=077 | sudo tee /etc/pam.d/common-session")
self.state.ldap_installed = True self._stored.ldap_installed = True
else: else:
shell("dpkg-reconfigure -f noninteractive ldap-auth-client") shell("dpkg-reconfigure -f noninteractive ldap-auth-client")
self.unit.status = ActiveStatus("Ldap autentication configured") self.unit.status = ActiveStatus("Ldap autentication configured")
...@@ -231,18 +230,18 @@ class VirtualPCCharm(CharmBase, InstallProgress): ...@@ -231,18 +230,18 @@ class VirtualPCCharm(CharmBase, InstallProgress):
status_msg = "Ready" status_msg = "Ready"
return status_type(status_msg) return status_type(status_msg)
def _configure_ldap(host, domain, password): def _configure_ldap(self, host, domain, password):
#configure ldap-auth-config with debconf #configure ldap-auth-config with debconf
shell("echo ldap-auth-config ldap-auth-config/rootbindpw password {} | sudo debconf-set-selections".format(password)) shell("echo ldap-auth-config ldap-auth-config/rootbindpw password {} | sudo debconf-set-selections".format(password))
shell("echo ldap-auth-config ldap-auth-config/bindpw password {} | sudo debconf-set-selections".format(password)) shell("echo ldap-auth-config ldap-auth-config/bindpw password {} | sudo debconf-set-selections".format(password))
shell("echo ldap-auth-config ldap-auth-config/binddn string cn=admin,dc={},dc={} | sudo debconf-set-selections".format(domin.split("."))) shell("echo ldap-auth-config ldap-auth-config/binddn string cn=admin,dc={},dc={} | sudo debconf-set-selections".format(domain.split(".")[0],domain.split(".")[1]))
shell("echo ldap-auth-config ldap-auth-config/dblogin boolean false | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/dblogin boolean false | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/rootbinddn string cn=admin,dc={},dc={} | sudo debconf-set-selections".format(domin.split(".")) shell("echo ldap-auth-config ldap-auth-config/rootbinddn string cn=admin,dc={},dc={} | sudo debconf-set-selections".format(domain.split(".")[0],domain.split(".")[1]))
shell("echo ldap-auth-config ldap-auth-config/ldapns/ldap-server string ldap://{} | sudo debconf-set-selections".format(host)) shell("echo ldap-auth-config ldap-auth-config/ldapns/ldap-server string ldap://{} | sudo debconf-set-selections".format(host))
shell("echo ldap-auth-config ldap-auth-config/override boolean true | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/override boolean true | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/ldapns/ldap_version select 3 | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/ldapns/ldap_version select 3 | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/dbrootlogin boolean true | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/dbrootlogin boolean true | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/ldapns/base-dn string dc={},dc={} | sudo debconf-set-selections".format(domin.split(".")) shell("echo ldap-auth-config ldap-auth-config/ldapns/base-dn string dc={},dc={} | sudo debconf-set-selections".format(domain.split(".")[0],domain.split(".")[1]))
shell("echo ldap-auth-config ldap-auth-config/move-to-debconf boolean true | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/move-to-debconf boolean true | sudo debconf-set-selections")
shell("echo ldap-auth-config ldap-auth-config/pam_password select clear | sudo debconf-set-selections") shell("echo ldap-auth-config ldap-auth-config/pam_password select clear | sudo debconf-set-selections")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment