太长了;博士

太长了;博士

如何授予somegroup读取系统日志的只读权限? (我使用的是 Debian10 buster)。

$ journalctl  
Hint: You are currently not seeing messages from other users and the system.
      Users in the 'systemd-journal' group can see all messages. Pass -q to
      turn off this notice.
No journal files were opened due to insufficient permissions.

我知道我可以将用户添加到systemd-journal组中,但如何授予组读取权限?

答案1

太长了;博士

创建以下文件:

# /etc/tmpfiles.d/somegroup_journal.conf
#Type  Path                           Mode User Group Age Argument
a+     /run/log/journal               -    -    -     -   d:group:somegroup:r-x
a+     /run/log/journal               -    -    -     -   group:somegroup:r-x
a+     /run/log/journal/%m            -    -    -     -   d:group:somegroup:r-x
a+     /run/log/journal/%m            -    -    -     -   group:somegroup:r-x
a+     /run/log/journal/%m/*.journal* -    -    -     -   d:group:somegroup:r--
a+     /run/log/journal/%m/*.journal* -    -    -     -   group:somegroup:r--

如何弄清楚:

男人systemd-journald.service(8)具有以下内容:

其他用户和组可以通过文件系统访问控制列表 (ACL) 被授予对日志文件的访问权限。发行版和管理员可以选择使用如下命令向“wheel”和“adm”系统组的所有成员授予读取访问权限:

# setfacl -Rnm g:wheel:rx,d:g:wheel:rx,g:adm:rx,d:g:adm:rx /var/log/journal/

虽然这听起来很完美,但这个例子很触及/var/log/journal/,但是日志控制优先顺序/run/log/journal/如下所示以下来源:

if (laccess("/run/log/journal", F_OK) >= 0)
        dir = "/run/log/journal";
else
        dir = "/var/log/journal";

/* If we are in any of the groups listed in the journal ACLs,
 * then all is good, too. Let's enumerate all groups from the
 * default ACL of the directory, which generally should allow
 * access to most journal files too. */
r = acl_search_groups(dir, &g);

/run挂载为tmpfs,因此以下 ACL 规则可能不会持续存在:

# setfacl -Rnm g:somegroup:rx,d:g:somegroup:rx /run/log/journal/

要使其持续存在,请配置用于生成/run/log/journal.浏览还有一些来源, 我们发现tmpfiles.d/systemd.conf.m4

z /run/log/journal 2755 root systemd-journal - -
Z /run/log/journal/%m ~2750 systemd-journal - -
m4_ifdef(`HAVE_ACL',`
a+ /run/log/journal/%m - - - - d:group:adm:r-x
a+ /run/log/journal/%m - - - - group:adm:r-x
a+ /run/log/journal/%m/*.journal* - - - - d:group:adm:r--
')'m4_dnl

这表明需要在 中添加 ACL 规则tmpfiles.d。上述文件的编译版本可在本地找到/usr/lib/tmpfiles.d/systemd.conf。将该示例与 man 结合起来tmpfiles.d(5)提供一些详细信息以帮助创建可行的解决方案。

创建以下文件:

# /etc/tmpfiles.d/somegroup_journal.conf
#Type  Path                           Mode User Group Age Argument
a+     /run/log/journal               -    -    -     -   d:group:somegroup:r-x
a+     /run/log/journal               -    -    -     -   group:somegroup:r-x
a+     /run/log/journal/%m            -    -    -     -   d:group:somegroup:r-x
a+     /run/log/journal/%m            -    -    -     -   group:somegroup:r-x
a+     /run/log/journal/%m/*.journal* -    -    -     -   d:group:somegroup:r--
a+     /run/log/journal/%m/*.journal* -    -    -     -   group:somegroup:r--

快速测试加上重新启动确认这有效!

相关内容