Ste*_*art 4 debian systemd journalctl systemd-journald
如何授予只读权限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.
Run Code Online (Sandbox Code Playgroud)
我知道我可以将用户添加到systemd-journal组中,但是如何授予组读取权限?
创建以下文件:
# /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--
Run Code Online (Sandbox Code Playgroud)
man systemd-journald.service(8)有以下内容:
可以通过文件系统访问控制列表 (ACL) 授予其他用户和组访问日志文件的权限。发行版和管理员可以选择使用如下命令向“wheel”和“adm”系统组的所有成员授予读取访问权限:
Run Code Online (Sandbox Code Playgroud)# setfacl -Rnm g:wheel:rx,d:g:wheel:rx,g:adm:rx,d:g:adm:rx /var/log/journal/
虽然这听起来很完美,示例接触/var/log/journal/,但journalctl优先排序/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 Code Online (Sandbox Code Playgroud)
/run挂载为tmpfs,因此以下 ACL 规则可能不会持续存在:
# setfacl -Rnm g:somegroup:rx,d:g:somegroup:rx /run/log/journal/
Run Code Online (Sandbox Code Playgroud)
要使其持久化,请配置用于生成/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
Run Code Online (Sandbox Code Playgroud)
这表明需要将 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--
Run Code Online (Sandbox Code Playgroud)
快速测试加上重新启动确认这是有效的!
| 归档时间: |
|
| 查看次数: |
2475 次 |
| 最近记录: |