Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make config files permissions consistent. #6841

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/sssd.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ done
%attr(755,%{sssd_user},%{sssd_user}) %dir %{gpocachepath}
%attr(750,%{sssd_user},%{sssd_user}) %dir %{_var}/log/%{name}
%attr(700,%{sssd_user},%{sssd_user}) %dir %{_sysconfdir}/sssd
%attr(711,%{sssd_user},%{sssd_user}) %dir %{_sysconfdir}/sssd/conf.d
%attr(711,root,root) %dir %{_sysconfdir}/sssd/pki
%ghost %attr(0600,root,root) %config(noreplace) %{_sysconfdir}/sssd/sssd.conf
%attr(700,%{sssd_user},%{sssd_user}) %dir %{_sysconfdir}/sssd/conf.d
%attr(700,%{sssd_user},%{sssd_user}) %dir %{_sysconfdir}/sssd/pki
%ghost %attr(0600,%{sssd_user},%{sssd_user}) %config(noreplace) %{_sysconfdir}/sssd/sssd.conf
%dir %{_sysconfdir}/logrotate.d
%config(noreplace) %{_sysconfdir}/logrotate.d/sssd
%dir %{_sysconfdir}/rwtab.d
Expand Down
2 changes: 2 additions & 0 deletions src/man/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ ENUM_CONDS = ;without_ext_enumeration
endif
if SSSD_NON_ROOT_USER
SSSD_NON_ROOT_USER_CONDS = ;with_non_root_user_support
else
SSSD_NON_ROOT_USER_CONDS = ;without_non_root_user_support
endif


Expand Down
15 changes: 10 additions & 5 deletions src/man/sssd.conf.5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@
is only as a label for the section.
</para>

<para>
<filename>sssd.conf</filename> must be a regular file, owned by
root and only root may read from or write to the file.
<para condition="without_non_root_user_support">
<filename>sssd.conf</filename> must be a regular file that is owned,
readable, and writeable only by 'root'.
</para>
<para condition="with_non_root_user_support">
<filename>sssd.conf</filename> must be a regular file that is owned,
readable, and writeable by '&sssd_user_name;' user (if SSSD is configured
to run under 'root' then <filename>sssd.conf</filename> also
can be owned by 'root').
</para>
</refsect1>

Expand Down Expand Up @@ -92,8 +98,7 @@

<para>
The snippet files require the same owner and permissions
as <filename>sssd.conf</filename>. Which are by default
root:root and 0600.
as <filename>sssd.conf</filename>.
</para>
</refsect1>

Expand Down
3 changes: 1 addition & 2 deletions src/tests/multihost/alltests/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,7 @@ def test_0028_bz1723273(self, multihost, backupsssdconf):
result = sssctl_check.stdout_text.strip()
rm_dir = 'rm -rf /tmp/test'
multihost.client[0].run_command(rm_dir, raiseonerr=False)
assert 'File ownership and permissions check failed. Expected ' \
'root:root and 0600' in result and \
assert 'File ownership and permissions check failed' in result and \
sssctl_check.returncode == 1

@pytest.mark.tier1
Expand Down
21 changes: 2 additions & 19 deletions src/tools/sssctl/sssctl_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,15 @@ errno_t sssctl_config_check(struct sss_cmdline *cmdline,
config_path,
config_snippet_path);

if (ret == ERR_INI_OPEN_FAILED) {
PRINT("Failed to open %s\n", config_path);
if (ret != EOK) {
PRINT("Failed to read '%s': %s\n", config_path, sss_strerror(ret));
goto done;
}

if (!sss_ini_exists(init_data)) {
PRINT("File %1$s does not exist.\n", config_path);
}

if (ret == ERR_INI_INVALID_PERMISSION) {
PRINT("File ownership and permissions check failed. "
"Expected root:root and 0600.\n");
goto done;
}

if (ret == ERR_INI_PARSE_FAILED) {
PRINT("Failed to load configuration from %s.\n",
config_path);
goto done;
}

if (ret == ERR_INI_ADD_SNIPPETS_FAILED) {
PRINT("Error while reading configuration directory.\n");
goto done;
}

/* Used snippet files */
ra_success = sss_ini_get_ra_success_list(init_data);
num_ra_success = ref_array_len(ra_success);
Expand Down
37 changes: 29 additions & 8 deletions src/util/sss_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,39 @@ static int sss_ini_config_file_from_mem(struct sss_ini *self,

static int sss_ini_access_check(struct sss_ini *self)
{
uid_t uid = 0;
gid_t gid = 0;
int ret;

if (!self->main_config_exists) {
return EOK;
}

return ini_config_access_check(self->file,
INI_ACCESS_CHECK_MODE |
INI_ACCESS_CHECK_UID |
INI_ACCESS_CHECK_GID,
0, /* owned by root */
0, /* owned by root */
S_IRUSR, /* r**------ */
ALLPERMS & ~(S_IWUSR|S_IXUSR));
/* 'sssd:sssd' owned config is always fine */
sss_sssd_user_uid_and_gid(&uid, &gid);
ret = ini_config_access_check(self->file,
INI_ACCESS_CHECK_MODE |
INI_ACCESS_CHECK_UID |
INI_ACCESS_CHECK_GID,
uid, /* owned by SSSD_USER */
gid, /* owned by SSSD_USER */
S_IRUSR, /* r**------ */
ALLPERMS & ~(S_IWUSR|S_IXUSR));
if (ret != 0) {
/* if SSSD runs under 'root' then 'root:root' owned config is also fine */
if ((getuid() == 0) && (uid != 0)) {
ret = ini_config_access_check(self->file,
INI_ACCESS_CHECK_MODE |
INI_ACCESS_CHECK_UID |
INI_ACCESS_CHECK_GID,
0, /* owned by root */
0, /* owned by root */
S_IRUSR, /* r**------ */
ALLPERMS & ~(S_IWUSR|S_IXUSR));
}
}

return ret;
}


Expand Down