Skip to content

RFC: Ownership and permissions issues when building non-root support but running as root #8608

@scabrero

Description

@scabrero

When sssd is built with --with-sssd-user=sssd and runs as sssd user, new logs and db files are owned by sssd:sssd with mode 600:

# ls -l /var/log/sssd/sssd.log
-rw-------. 1 sssd sssd   424 abr 15 16:34 sssd.log

If someone wants to run as root again, the recommended way is to override the service unit file like:

[Service]
User=root
Group=root
SupplementaryGroups=sssd

But the daemon will not start due to permission issues opening log / db files:

sssd[7220]: Could not open file [/var/log/sssd/sssd.log]. Error: [13][Permission denied]
[sssd] [ldb] (0x0020): Failed to connect to '/var/lib/sss/db/cache_xxxxxx.ldb' with backend 'tdb': Unable to open tdb '/var/lib/sss/db/cache_xxxxxx.ldb': Permission denied

The reason is that the ExecStartPre statements in the service unit chown /var/lib/sss/db/*.ldb and /var/log/sssd/*.log* to sssd:sssd but the mode remains 600. Removing the existent files will allow the service to start, but only once.

To better support this scenario I propose:

  1. To fix the mode of new files, update the default umask to grant group permissions when non-root support is built:
 /* Default secure umask */
+#ifdef SSSD_NON_ROOT_USER
+#define SSS_DFL_UMASK 0117
+#else
 #define SSS_DFL_UMASK 0177
+#endif

 /* Secure mask with executable bit */
+#ifdef SSSD_NON_ROOT_USER
+#define SSS_DFL_X_UMASK 0007
+#else
 #define SSS_DFL_X_UMASK 0077
+#endif

With this change, new logs and db files will be created with mode 0660 and new directories with 0770, always granting sssd group access regardless running as root or sssd.

  1. To fix the mode of existent files (when upgrading from < 2.10), add more ExecStartPre to chmod g+rw the necessary paths.

  2. To fix the ownership of new files:

  • Change the ExecStartPre to only chgrp sssd instead of chown sssd:sssd. Avoids the ownership "dance" between root and sssd.
  • Either:
    • Set the setgid bit in the relevant directories so new files are always owned by sssd group, assuming the parent directory is owned by sssd group.
    • Or set User=root in the override file but keep Group=sssd. New files will be owned by root:sssd. No need to add sssd supplementary group. I would prefer this one.

What do you think about these changes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions