Debian
如何讓特定組具有對 systemd 日誌的讀取權限?
如何授予閱讀
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
組中,但是如何授予組讀取權限?
tl;博士
創建以下文件:
# /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--
如何弄清楚:
man 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/
,但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
掛載為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
這表明需要在
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--
快速測試加上重新啟動確認這是有效的!