客製化政策

客製化政策

我想以root身分執行logstash以允許它讀取所有日誌(授予它存取每個日誌的權限是非常煩人的)。然而,我不希望它在我的伺服器上瘋狂運行,我考慮過將它限制在 SELinux 下。
我看到的選項是:

  • 為logstash 建立一個全新的標籤。這也意味著為logstash設定檔、logstash可執行檔和函式庫等建立標籤。
  • 使用為另一個進程設計的標籤來執行logstash。我密切關注,clogd_t因為它log的名稱中有它,我找不到任何可疑的寫入權限sudo sesearch --allow -s clogd_t | grep clogd_t | less -p write
  • 放棄並將其作為不受約束的根進程運行

這是正常的事嗎?

如果有必要的話,我使用的是 CentOS 6.7

答案1

我寧願制定自訂策略,因為它更清晰,並且可以讓您控制正在發生的事情。

客製化政策

據我了解,它是一個基於 java 的守護進程,您將運行它,因此使其作為system_u:system_r:logstash_t.然後,您需要向logstash_t 網域授予(唯讀?)對所有日誌檔案的存取權限,並最終授予logstash 運行可能需要的任何其他權限。

使用 refpolicy 接口,我們有類似的東西:

policy_module(logstash, 1.0)

# define the entry point and the domain
type logstash_exec_t
init_daemon_domain(logstash_t, logstash_exec_t)

然後logstash守護程式需要能夠讀取日誌檔:

logging_search_all_logs(logstash_t)
logging_getattr_all_logs(logstash_t)
logging_read_all_logs(logstash_t)

這應該可以完成大部分工作,然後您需要添加其餘的工作。

重複使用的政策

對於第二點,我不確定為什麼您沒有獲得 sesearch 報告的任何寫入權限,但如果您查看來源:

# clogd.te
storage_raw_read_fixed_disk(clogd_t)
storage_raw_write_fixed_disk(clogd_t)

# storage.te 
########################################
## <summary>
##      Allow the caller to directly write to a fixed disk.
##      This is extremely dangerous as it can bypass the
##      SELinux protections for filesystem objects, and
##      should only be used by trusted domains.
## </summary>
## <param name="domain">
##      <summary>
##      Domain allowed access.
##      </summary>
## </param>
#
interface(`storage_raw_write_fixed_disk',`
# and the rest of the stuff here...

這並不是人們真正想要的日誌監控工具。您可能會找到適合與第二個解決方案一起使用的東西,只需確保您沒有獲得額外的不需要的權限,因為這違背了在 selinux 中運行進程的整個目的。

希望能幫助你。

相關內容