journal-brief icon indicating copy to clipboard operation
journal-brief copied to clipboard

no error message if executed with insufficient permissions

Open Zugschlus opened this issue 2 years ago • 2 comments

Hi,

when invoking journal-brief as a user that is not allowed to access the journal, I see in strace that journal-brief tries to open a file in /run/log/journal, resulting in EACCES.

However, no error message is given to the user and journal-brief behaves as if the log was empty.

Please consider giving a useful error message.

Greetings Marc

Zugschlus avatar Jun 13 '22 10:06 Zugschlus

The only way I can think to address this is to check that reader.has_runtime_files() or reader.has_persistent_files() (or that expression raises AttributeError). This check could go in cli/main.py, after the SelectiveReader is instantiated.

Want to code it up?

twaugh avatar Jun 15 '22 11:06 twaugh

I am not very fluent in Python and Exceptions, but how about this:

--- main.py     2022-06-30 11:59:12.353018261 +0200
+++ /usr/lib/python3/dist-packages/journal_brief/cli/main.py    2022-06-30 12:09:52.021287490 +0200
@@ -294,6 +294,8 @@
                                  log_level=self.log_level,
                                  inclusions=inclusions,
                                  explicit_inclusions=explicit_inclusions)
+        if not reader.has_runtime_files() and not reader.has_persistent_files():
+            raise PermissionError('Journal reader has neither runtime nor persistent files. Insufficient access rights of calling user?')
         with LatestJournalEntries(cursor_file=self.cursor_file,
                                   reader=reader,
                                   dry_run=self.args.dry_run,
@@ -323,6 +325,9 @@
     except IOError as ex:
         sys.stderr.write("{0}: {1}\n".format(PACKAGE, ex))
         sys.exit(1)
+    except PermissionError as ex:
+        sys.stderr.write("{0}: {1}\n".format(PACKAGE, ex))
+        sys.exit(1)
     except ConfigError:
         sys.exit(1)

Zugschlus avatar Jun 30 '22 10:06 Zugschlus