#50448 ticket 50297 - prefix deployment -selinux +uid
Closed 3 years ago by spichugi. Opened 4 years ago by tbordaz.
tbordaz/389-ds-base ticket_50297  into  master

file modified
+22 -2
@@ -511,8 +511,28 @@ 

  schemadir=/$PACKAGE_NAME/schema

  

  # default user, group

- defaultuser=dirsrv

- defaultgroup=dirsrv

+ AC_MSG_CHECKING(for --with-username)

+ AC_ARG_WITH([username],

+    AS_HELP_STRING([--with-username=USERNAME],

+                   [Name of the user running the instances])

+ )

+ if test -n "$with_username"; then

+   AC_MSG_RESULT([$with_username])

+   defaultuser=$with_username

+ else

+   defaultuser=dirsrv

+ fi

+ AC_MSG_CHECKING(for --with-groupname)

+ AC_ARG_WITH([groupname],

+    AS_HELP_STRING([--with-groupname=GROUPNAME],

+                   [Group of the user running the instances])

+ )

+ if test -n "$with_groupname"; then

+   AC_MSG_RESULT([$with_groupname])

+   defaultgroup=$with_groupname

+ else

+   defaultgroup=dirsrv

+ fi

  

  AC_MSG_CHECKING(for --with-perldir)

  AC_ARG_WITH([perldir],

@@ -45,8 +45,8 @@ 

  tmpfiles_d = @tmpfiles_d@

  

  ; These values can be altered in an installation of ds

- user = dirsrv

- group = dirsrv

+ user = @defaultuser@

+ group = @defaultgroup@

  root_dn = cn=Directory Manager

  

  schema_dir = @instconfigdir@/slapd-{instance_name}/schema

@@ -69,7 +69,8 @@ 

      ensure_list_str,

      format_cmd_list,

      selinux_present,

-     selinux_label_port)

+     selinux_label_port,

+     get_user_is_root)

  from lib389.paths import Paths

  from lib389.nss_ssl import NssSsl

  from lib389.tasks import BackupTask, RestoreTask
@@ -840,6 +841,9 @@ 

          slapd_options.verify()

          slapd = slapd_options.collect()

  

+         if not slapd['user'] == 'root':

+             general['selinux'] = False

+ 

          # In order to work by "default" for tests, we need to create a backend.

          backends = []

          if self.creation_suffix is not None:
@@ -1595,7 +1599,7 @@ 

          self.config.set('nsslapd-security', 'on')

          self.use_ldaps_uri()

  

-         if selinux_present():

+         if selinux_present() and get_user_is_root():

              selinux_label_port(self.sslport)

  

          if self.ds_paths.perl_enabled:

@@ -193,6 +193,10 @@ 

      """

      status = False

  

+     if not shutil.which("semanage"):

+         log.error('semanage command not found, will not relabel ports.' )

+         return status

+ 

      try:

          import selinux

          if selinux.is_selinux_enabled():

Bug Description:
On prefix build, the defaultuser/defaultgroup is set to dirsrv.
While the installed build belongs to the local user.

By default selinux is True in general option. Selinux should be true
only if if the instance['user'] = 'root'.

Fix Description:
Define defaultuser/defaultgroup as local user if in prefix deployment.
Set selinux=False if the user is not root

https://pagure.io/389-ds-base/issue/50297

Reviewed by: Mark Reynolds

Platforms tested: F28

Flag Day: no

Doc impact: no

I'm worried about this here, because this will cause the obs build service to put the prefix user to abuild instead of dirsrv. Should this instead default to dirsrv and you override it with "--prefixuser=..." at ./configure instead?

Otherwise everything else looks pretty good to me!

Okay, second comment: This is not the right place: we should be checking if current running user == root, in utils.py: selinux_present(), and only if root is true, do we continue to check. We also need to check that semanage is present in the selinux_present function as well to work with setups that do not have that but are running as root

rebased onto 6b08e590c23673f5bf39a2b42efa9a22d7447145

4 years ago

rebased onto 38b49c07d3fb1f50d8d8b7725d12bb25605d2f89

4 years ago

Should this be a debug message? This check is above where we are doing other selinux checks, should this be moved lower in the function? I'm not sure, just asking...

Yes should be a debug message, otherwise the rest looks reasonable, thanks for the changes @tbordaz :) I'll leave @mreynolds to give his approval.

rebased onto 495207017f0996d5a71065b0f7997fea2b0cf663

4 years ago

Indeed it is a debug message as the command will succeed but the command will not label the port (because policycoreutils-python-utils is not installed)

selinux_present is called to decide if the port needs to be labeled or not.
This requires both semanage to be installed and selinux to be enabled. I think we can do the test the over way around the important step being the status=True if both conditions are tested.

Wouldn't be shutil.which('semanage') sufficient here?

rebased onto 4ce1364fe607ccea24511125713efa69b4c4a904

4 years ago

rebased onto 15790cbdc0ba8e61134f5b8e015e00d40bd13110

4 years ago

rebased onto ae3368505597beece8555b6cc5659e99b25f4f58

4 years ago

rebased onto bb62303

4 years ago

@firstyear , @mhonek any additional concern on that PR ?

Not really, but it probably needs a rebase and update :)

Argh, this fell in cracks, sorry for that... I think this actually worked well for me. But yeah, rebase and some aligning is probably necessary now.

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/3506

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago