Skip to content

Commit 8b94af6

Browse files
alexey-tikhonovpbrezina
authored andcommitted
MONITOR: validate value of 'user' option.
Only 'root' and SSSD_USER are valid values. Reviewed-by: Iker Pedrosa <[email protected]> Reviewed-by: Pavel Březina <[email protected]>
1 parent 9bf55bf commit 8b94af6

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ test-authtok
115115
.pytest_cache
116116
__pycache__
117117
.venv
118+
src/man/sssd_user_name.include
118119

119120
# multihost tests
120121
!src/tests/multihost/sssd

src/man/Makefile.am

+2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ SUFFIXES = .1.xml .1 .3.xml .3 .5.xml .5 .8.xml .8
127127
$(XSLTPROC) -o $@ $(XSLTPROC_FLAGS) $(DOCBOOK_XSLT) $<
128128

129129
.5.xml.5:
130+
@echo -n $(SSSD_USER) > $(dir $<)/sssd_user_name.include
130131
$(XMLLINT) $(XMLLINT_FLAGS) $<
131132
$(XSLTPROC) -o $@ $(XSLTPROC_FLAGS) $(DOCBOOK_XSLT) $<
133+
@rm -f $(dir $<)/sssd_user_name.include
132134

133135
.8.xml.8:
134136
$(XMLLINT) $(XMLLINT_FLAGS) $<

src/man/sssd.conf.5.xml

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DocBook V4.4//EN"
3-
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
3+
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
4+
[
5+
<!ENTITY sssd_user_name SYSTEM "sssd_user_name.include">
6+
]>
47
<reference>
58
<title>SSSD Manual pages</title>
69
<refentry>
@@ -409,20 +412,23 @@
409412
The user to drop the privileges to where
410413
appropriate to avoid running as the
411414
root user.
412-
<phrase condition="have_systemd">
413-
This option does not work when running socket-activated
414-
services, as the user set up to run the processes is
415-
set up during compilation time.
415+
Currently the only supported value is '&sssd_user_name;'.
416+
</para>
416417

417-
The way to override the systemd unit files is by creating
418-
the appropriate files in /etc/systemd/system/.
418+
<para condition="have_systemd">
419+
This option does not work when running socket-activated
420+
services, as the user set up to run the processes is
421+
set up during compilation time.
419422

420-
Keep in mind that any change in the socket user, group or
421-
permissions may result in a non-usable SSSD. The same may
422-
occur in case of changes of the user running the NSS
423-
responder.
424-
</phrase>
423+
The way to override the systemd unit files is by creating
424+
the appropriate files in /etc/systemd/system/.
425+
426+
Keep in mind that any change in the socket user, group or
427+
permissions may result in a non-usable SSSD. The same may
428+
occur in case of changes of the user running the NSS
429+
responder.
425430
</para>
431+
426432
<para>
427433
Default: not set, process will run as root
428434
</para>

src/monitor/monitor.c

+19-11
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,13 @@ static char *check_services(char **services)
825825

826826
static int get_service_user(struct mt_ctx *ctx)
827827
{
828+
errno_t ret = EOK;
829+
830+
ctx->uid = 0;
831+
ctx->gid = 0;
832+
828833
#ifdef SSSD_NON_ROOT_USER
829-
errno_t ret;
830-
char *user_str;
834+
char *user_str = NULL;
831835

832836
ret = confdb_get_string(ctx->cdb, ctx, CONFDB_MONITOR_CONF_ENTRY,
833837
CONFDB_MONITOR_USER_RUNAS,
@@ -837,18 +841,22 @@ static int get_service_user(struct mt_ctx *ctx)
837841
return ret;
838842
}
839843

840-
ret = sss_user_by_name_or_uid(user_str, &ctx->uid, &ctx->gid);
841-
talloc_free(user_str);
842-
if (ret != EOK) {
843-
DEBUG(SSSDBG_FATAL_FAILURE, "Failed to set allowed UIDs.\n");
844-
return ret;
844+
if (strcmp(user_str, SSSD_USER) == 0) {
845+
sss_sssd_user_uid_and_gid(&ctx->uid, &ctx->gid);
846+
} else if (strcmp(user_str, "root") != 0) {
847+
DEBUG(SSSDBG_FATAL_FAILURE,
848+
"Unsupported value '%s' of config option '%s'! Only 'root' or '"
849+
SSSD_USER"' are supported.\n",
850+
user_str, CONFDB_MONITOR_USER_RUNAS);
851+
sss_log(SSS_LOG_CRIT, "Unsupported value of config option '%s'!",
852+
CONFDB_MONITOR_USER_RUNAS);
853+
ret = ERR_INVALID_CONFIG;
845854
}
846-
#else
847-
ctx->uid = 0;
848-
ctx->gid = 0;
855+
856+
talloc_free(user_str);
849857
#endif
850858

851-
return EOK;
859+
return ret;
852860
}
853861

854862
static int get_monitor_config(struct mt_ctx *ctx)

0 commit comments

Comments
 (0)