unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd service in container.
@ 2022-08-23 17:31 Arun Isaac
  2022-08-23 17:33 ` [bug#57363] [PATCH] shepherd: Set #o640 permissions for log file of " Arun Isaac
  2022-08-26 14:48 ` [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd " Maxime Devos
  0 siblings, 2 replies; 7+ messages in thread
From: Arun Isaac @ 2022-08-23 17:31 UTC (permalink / raw)
  To: 57363; +Cc: Arun Isaac, Ludovic Courtès

When a shepherd service is run using make-forkexec-constructor, the log file
has #o640 permissions. This is set in the shepherd source code.
=> https://git.savannah.gnu.org/cgit/shepherd.git/tree/modules/shepherd/service.scm?h=v0.9.1#n987

However, when a shepherd service is run using
make-forkexec-constructor/container, the log file has #o644 permissions. This
patch corrects that.

CCing Ludo since they wrote the code adjacent to this patch.

Thanks!

Arun Isaac (1):
  shepherd: Set #o640 permissions for log file of service in container.

 gnu/build/shepherd.scm | 2 ++
 1 file changed, 2 insertions(+)

-- 
2.37.1





^ permalink raw reply	[flat|nested] 7+ messages in thread

* [bug#57363] [PATCH] shepherd: Set #o640 permissions for log file of service in container.
  2022-08-23 17:31 [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd service in container Arun Isaac
@ 2022-08-23 17:33 ` Arun Isaac
  2022-08-26 14:48 ` [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd " Maxime Devos
  1 sibling, 0 replies; 7+ messages in thread
From: Arun Isaac @ 2022-08-23 17:33 UTC (permalink / raw)
  To: 57363; +Cc: Arun Isaac, Ludovic Courtès

* gnu/build/shepherd.scm (make-forkexec-constructor/container): Set #o640
permissions for log file.
---
 gnu/build/shepherd.scm | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gnu/build/shepherd.scm b/gnu/build/shepherd.scm
index f4caefce3c..c7ba73967f 100644
--- a/gnu/build/shepherd.scm
+++ b/gnu/build/shepherd.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2017, 2018, 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2020 Mathieu Othacehe <othacehe@gnu.org>
 ;;; Copyright © 2022 Leo Nikkilä <hello@lnikki.la>
+;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -187,6 +188,7 @@ (define mounts
       ;; Create LOG-FILE so we can map it in the container.
       (unless (file-exists? log-file)
         (call-with-output-file log-file (const #t))
+        (chmod log-file #o640)
         (when user
           (let ((pw (getpwnam user)))
             (chown log-file (passwd:uid pw) (passwd:gid pw))))))
-- 
2.37.1





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd service in container.
  2022-08-23 17:31 [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd service in container Arun Isaac
  2022-08-23 17:33 ` [bug#57363] [PATCH] shepherd: Set #o640 permissions for log file of " Arun Isaac
@ 2022-08-26 14:48 ` Maxime Devos
  2022-08-29 19:15   ` Arun Isaac
  2022-08-29 19:15   ` [bug#57363] [PATCH v2] shepherd: Set #o640 permissions for log file of " Arun Isaac
  1 sibling, 2 replies; 7+ messages in thread
From: Maxime Devos @ 2022-08-26 14:48 UTC (permalink / raw)
  To: Arun Isaac, 57363; +Cc: Ludovic Courtès


[-- Attachment #1.1.1: Type: text/plain, Size: 825 bytes --]

On 23-08-2022 19:31, Arun Isaac wrote:

> However, when a shepherd service is run using
> make-forkexec-constructor/container, the log file has #o644 permissions. This
> patch corrects that.

There is a small window during which the log file has overly-wide 
permissions, which IIUC makes the log openable when it shouldn't, which 
could later be exploited (after the daemon has been running for a while) 
to extract anything secret written to the log by the service.

Try using (close (open log-file (logior O_CREAT O_APPEND O_CLOEXEC) 
#o600)) instead, that should make things atomic.

I do not know if clearing the log file is desired -- if so, remove 
O_APPEND, if not, keep O_APPEND.

Maybe O_RDONLY or O_WRONLY or O_RDWR needs to be added to make the call 
to 'open' succeed.

Greetings,
Maxime


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd service in container.
  2022-08-26 14:48 ` [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd " Maxime Devos
@ 2022-08-29 19:15   ` Arun Isaac
  2022-08-29 19:15   ` [bug#57363] [PATCH v2] shepherd: Set #o640 permissions for log file of " Arun Isaac
  1 sibling, 0 replies; 7+ messages in thread
From: Arun Isaac @ 2022-08-29 19:15 UTC (permalink / raw)
  To: Maxime Devos, 57363; +Cc: Ludovic Courtès


Hi Maxime,

> There is a small window during which the log file has overly-wide 
> permissions, which IIUC makes the log openable when it shouldn't, which 
> could later be exploited (after the daemon has been running for a while) 
> to extract anything secret written to the log by the service.

True, thanks for catching that!

> Try using (close (open log-file (logior O_CREAT O_APPEND O_CLOEXEC) 
> #o600)) instead, that should make things atomic.

Done. An updated patch follows.

> I do not know if clearing the log file is desired -- if so, remove 
> O_APPEND, if not, keep O_APPEND.

I don't think clearing the log file is desired. Append is good, I
think. Users wouldn't want their log files overwritten everytime their
system is restarted.

Regards,
Arun




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [bug#57363] [PATCH v2] shepherd: Set #o640 permissions for log file of service in container.
  2022-08-26 14:48 ` [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd " Maxime Devos
  2022-08-29 19:15   ` Arun Isaac
@ 2022-08-29 19:15   ` Arun Isaac
  2022-09-02  9:21     ` Ludovic Courtès
  1 sibling, 1 reply; 7+ messages in thread
From: Arun Isaac @ 2022-08-29 19:15 UTC (permalink / raw)
  To: Maxime Devos, Arun Isaac, 57363; +Cc: Ludovic Courtès

* gnu/build/shepherd.scm (make-forkexec-constructor/container): Set #o640
permissions for log file.
---
 gnu/build/shepherd.scm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gnu/build/shepherd.scm b/gnu/build/shepherd.scm
index f4caefce3c..9d9bfcfbc0 100644
--- a/gnu/build/shepherd.scm
+++ b/gnu/build/shepherd.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2017, 2018, 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2020 Mathieu Othacehe <othacehe@gnu.org>
 ;;; Copyright © 2022 Leo Nikkilä <hello@lnikki.la>
+;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -186,7 +187,7 @@ (define mounts
     (when log-file
       ;; Create LOG-FILE so we can map it in the container.
       (unless (file-exists? log-file)
-        (call-with-output-file log-file (const #t))
+        (close (open log-file (logior O_CREAT O_APPEND O_CLOEXEC) #o640))
         (when user
           (let ((pw (getpwnam user)))
             (chown log-file (passwd:uid pw) (passwd:gid pw))))))
-- 
2.37.1





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [bug#57363] [PATCH v2] shepherd: Set #o640 permissions for log file of service in container.
  2022-08-29 19:15   ` [bug#57363] [PATCH v2] shepherd: Set #o640 permissions for log file of " Arun Isaac
@ 2022-09-02  9:21     ` Ludovic Courtès
  2022-09-02 11:20       ` bug#57363: " Arun Isaac
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2022-09-02  9:21 UTC (permalink / raw)
  To: Arun Isaac; +Cc: 57363, Maxime Devos

Hi,

Arun Isaac <arunisaac@systemreboot.net> skribis:

> * gnu/build/shepherd.scm (make-forkexec-constructor/container): Set #o640
> permissions for log file.

LGTM!

However, note that ‘make-forkexec-constructor/container’ is now
deprecated in favor of (guix least-authority); apparently PageKite and
Jami are the only real users left.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#57363: [PATCH v2] shepherd: Set #o640 permissions for log file of service in container.
  2022-09-02  9:21     ` Ludovic Courtès
@ 2022-09-02 11:20       ` Arun Isaac
  0 siblings, 0 replies; 7+ messages in thread
From: Arun Isaac @ 2022-09-02 11:20 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 57363-done, Maxime Devos


>> * gnu/build/shepherd.scm (make-forkexec-constructor/container): Set #o640
>> permissions for log file.
>
> LGTM!

Thanks, pushed!

> However, note that ‘make-forkexec-constructor/container’ is now
> deprecated in favor of (guix least-authority); apparently PageKite and
> Jami are the only real users left.

Ah, I didn't know. I've been making extensive use of
make-forkexec-constructor/container in guix-forge and all my
services. Time to switch!




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-09-02 11:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-23 17:31 [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd service in container Arun Isaac
2022-08-23 17:33 ` [bug#57363] [PATCH] shepherd: Set #o640 permissions for log file of " Arun Isaac
2022-08-26 14:48 ` [bug#57363] [PATCH 0/1] Set #o640 permissions for log file of shepherd " Maxime Devos
2022-08-29 19:15   ` Arun Isaac
2022-08-29 19:15   ` [bug#57363] [PATCH v2] shepherd: Set #o640 permissions for log file of " Arun Isaac
2022-09-02  9:21     ` Ludovic Courtès
2022-09-02 11:20       ` bug#57363: " Arun Isaac

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).