From: Diego Nicola Barbato <dnbarbato@posteo.de>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 40405-done@debbugs.gnu.org
Subject: bug#40405: System log files are world readable
Date: Tue, 28 Apr 2020 15:11:47 +0200 [thread overview]
Message-ID: <87y2qfhi0c.fsf@GlaDOS.home> (raw)
In-Reply-To: <878sinthh4.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Wed, 22 Apr 2020 22:04:23 +0200")
[-- Attachment #1: Type: text/plain, Size: 1679 bytes --]
Hi,
Ludovic Courtès <ludo@gnu.org> writes:
> Hi,
>
> Ludovic Courtès <ludo@gnu.org> skribis:
>
>> Diego Nicola Barbato <dnbarbato@posteo.de> skribis:
>>
>>>From 43c9ded791ce5b480504ce3528ee34578168f90e Mon Sep 17 00:00:00 2001
>>> From: Diego Nicola Barbato <dnbarbato@posteo.de>
>>> Date: Tue, 7 Apr 2020 13:58:28 +0200
>>> Subject: [PATCH 1/2] service: Create log files as non-world-readable.
>>>
>>> * modules/shepherd/service.scm (exec-command): Create log-file with file
>>> permissions #o640.
>>
>> [...]
>>
>>>From e491436967a912e6e7372f582b3bf5c9784b8209 Mon Sep 17 00:00:00 2001
>>> From: Diego Nicola Barbato <dnbarbato@posteo.de>
>>> Date: Tue, 7 Apr 2020 13:38:47 +0200
>>> Subject: [PATCH 2/2] service: Add #:file-creation-mask to
>>> 'make-forkexec-constructor'.
>>>
>>> * modules/shepherd/service.scm (exec-command): Add #:file-creation-mask
>>> parameter and honor it.
>>> (fork+exec-command): Add #:file-creation-mask parameter and pass it to
>>> exec-command.
>>> (make-forkexec-constructor): Add #:file-creation-mask parameter and pass it
>>> to fork+exec-command.
>>> * doc/shepherd.texi (Service De- and Constructors): Adjust accordingly.
>>
>> I went ahead and pushed these two patches.
>
> These patches are in Shepherd 0.8.0, which was pushed in Guix master
> commit e3358a831e7d5d9e8dc614340e49ea5aeb11a7ff, so we’re done!
Great! Now we can simplify the 'start' method of
'syslogd-service-type'.
I did eventually write a test script, which I've attached in case we
want to add it to the Shepherd. I'm sorry it took so long that I missed
the new Shepherd release.
Regards,
Diego
[-- Attachment #2: 0001-tests-Test-file-creation-mask-option-of-make-forkexe.patch --]
[-- Type: text/x-patch, Size: 3229 bytes --]
From 2e7a0795b3a7080376238ab604c50d2c180f8730 Mon Sep 17 00:00:00 2001
From: Diego Nicola Barbato <dnbarbato@posteo.de>
Date: Mon, 27 Apr 2020 16:57:36 +0200
Subject: [PATCH] tests: Test #:file-creation-mask option of
'make-forkexec-constructor'.
* tests/file-creation-mask.sh: New file.
---
tests/file-creation-mask.sh | 79 +++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
create mode 100644 tests/file-creation-mask.sh
diff --git a/tests/file-creation-mask.sh b/tests/file-creation-mask.sh
new file mode 100644
index 0000000..9f5f10a
--- /dev/null
+++ b/tests/file-creation-mask.sh
@@ -0,0 +1,79 @@
+# GNU Shepherd --- Test the #:file-creation-mask option of 'make-forkexec-constructor'.
+# Copyright © 2020 Diego N. Barbato <dnbarbato@posteo.de>
+#
+# This file is part of the GNU Shepherd.
+#
+# The GNU Shepherd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# The GNU Shepherd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
+
+shepherd --version
+herd --version
+
+socket="t-socket-$$"
+conf="t-conf-$$"
+log="t-log-$$"
+pid="t-pid-$$"
+service_log="t-service-log-$$"
+service_new_file="t-service-new-file-$$"
+
+herd="herd -s $socket"
+
+trap "cat $log || true;
+ rm -f $socket $conf $log $service_log $service_new_file;
+ test -f $pid && kill \`cat $pid\` || true; rm -f $pid" EXIT
+
+function wait_for_file
+{
+ i=0
+ while ! test -f "$1" && test $i -lt 20
+ do
+ sleep 0.3
+ i=`expr $i + 1`
+ done
+ test -f "$1"
+}
+
+cat > "$conf"<<EOF
+(define %command
+ '("$SHELL" "-c" "touch $PWD/$service_new_file; echo foo"))
+
+(register-services
+ (make <service>
+ #:provides '(test)
+ #:start (make-forkexec-constructor %command
+ #:log-file "$PWD/$service_log"
+ ;; Set the umask such that file
+ ;; permissions are #o600.
+ #:file-creation-mask #o177)
+ #:stop (make-kill-destructor)
+ #:respawn? #f))
+EOF
+
+rm -f "$pid"
+shepherd -I -s "$socket" -c "$conf" -l "$log" --pid="$pid" &
+
+# Wait till it's ready.
+wait_for_file "$pid"
+
+# Start the service.
+$herd start test
+
+# Make sure the log file is created with the right permissions independently
+# of the value of #:file-creation-mask.
+wait_for_file "$service_log"
+test `stat -c %a "$service_log"` -eq 640
+
+# Make sure the service creates files with the right permissions as determined
+# by the value of #:file-creation-mask.
+wait_for_file "$service_new_file"
+test `stat -c %a "$service_new_file"` -eq 600
--
2.26.0
next prev parent reply other threads:[~2020-04-28 13:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-03 13:19 bug#40405: System log files are world readable Diego Nicola Barbato
2020-04-03 13:34 ` Diego Nicola Barbato
2020-04-05 22:12 ` Ludovic Courtès
2020-04-06 22:07 ` Ludovic Courtès
2020-04-07 0:49 ` Bengt Richter
2020-04-07 7:30 ` Ludovic Courtès
2020-04-08 12:32 ` Diego Nicola Barbato
2020-04-08 19:49 ` Ludovic Courtès
2020-04-19 14:28 ` Ludovic Courtès
2020-04-22 20:04 ` Ludovic Courtès
2020-04-28 13:11 ` Diego Nicola Barbato [this message]
2020-04-28 20:57 ` Ludovic Courtès
2020-04-29 10:02 ` Diego Nicola Barbato
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y2qfhi0c.fsf@GlaDOS.home \
--to=dnbarbato@posteo.de \
--cc=40405-done@debbugs.gnu.org \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).