Bash
以其他使用者身份在腳本中執行命令需要 10-15 秒才能執行
我啟動一個 bash 腳本(作為glassfish使用者從 java 同步),它作為另一個使用者啟動一個命令(比如說myUser):
#!/bin/bash echo myPassword | su -c "command" myUser &
當我從 bash shell 以 glassfish 使用者身份啟動此腳本時,該命令會立即執行。但是當我從 java 啟動這個腳本時,命令會在 10-15 秒後執行。
看起來像登錄安全超時?
我想知道這是否與SELINUX有關?這是啟動java程序(Glassfish)的命令行:
/usr/share/glassfish3/glassfish/bin/asadmin start-domain
下面是 asadmin 啟動腳本的 SELINUX 狀態:
$ ls -Z /usr/share/glassfish3/bin/asadmin -rwxr-xr-x. glassfish glassfish unconfined_u:object_r:bin_t:s0 /usr/share/glassfish3/bin/asadmin
我正在執行: - Centos 6.4 上的 GNU bash,版本 4.2.53(1)-release (x86_64-redhat-linux-gnu) - java 1.6.45 X86_64 和 Glassfish 3.1.2.2
更新:回應@larsks 評論
SeLinux 處於強制模式。該腳本在從 java執行時會生成以下審計日誌:
BEFORE THE COMMAND type=SERVICE_START msg=audit(1438862733.335:8932): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg=' comm="fprintd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success' type=USER_AVC msg=audit(1438862733.336:8933): pid=883 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 msg='avc: denied { send_msg } for msgtype=method_return dest=:1.2520 spid=16027 tpid=16026 scontext=system_u:system_r:fprintd_t:s0 tcontext=system_u:system_r:initrc_t:s0 tclass=dbus exe="/usr/bin/dbus-daemon" sauid=81 hostname=? addr=? terminal=?' HERE IS THE 10-15s WAIT type=USER_AUTH msg=audit(1438862758.408:8934): pid=16026 uid=1001 auid=4294967295 ses=4294967295 subj=system_u:system_r:initrc_t:s0 msg='op=PAM:authentication acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=? res=success' type=USER_ACCT msg=audit(1438862758.410:8935): pid=16026 uid=1001 auid=4294967295 ses=4294967295 subj=system_u:system_r:initrc_t:s0 msg='op=PAM:accounting acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=? res=success' type=CRED_ACQ msg=audit(1438862758.411:8936): pid=16026 uid=1001 auid=4294967295 ses=4294967295 subj=system_u:system_r:initrc_t:s0 msg='op=PAM:setcred acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=? res=success' type=USER_START msg=audit(1438862758.422:8937): pid=16026 uid=1001 auid=4294967295 ses=4294967295 subj=system_u:system_r:initrc_t:s0 msg='op=PAM:session_open acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=? res=success' type=USER_END msg=audit(1438862758.429:8938): pid=16026 uid=1001 auid=4294967295 ses=4294967295 subj=system_u:system_r:initrc_t:s0 msg='op=PAM:session_close acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=? res=success' type=CRED_DISP msg=audit(1438862758.429:8939): pid=16026 uid=1001 auid=4294967295 ses=4294967295 subj=system_u:system_r:initrc_t:s0 msg='op=PAM:setcred acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=? res=success' NOW THE COMMAND HAS BEEN EXECUTED
該腳本在從 bash執行時會生成以下審計日誌:
BEFORE THE COMMAND type=SERVICE_START msg=audit(1438863622.854:9013): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg=' comm="fprintd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success' type=USER_AUTH msg=audit(1438863622.877:9014): pid=16215 uid=1001 auid=0 ses=1116 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:authentication acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=pts/1 res=success' type=USER_ACCT msg=audit(1438863622.879:9015): pid=16215 uid=1001 auid=0 ses=1116 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:accounting acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=pts/1 res=success' type=CRED_ACQ msg=audit(1438863622.879:9016): pid=16215 uid=1001 auid=0 ses=1116 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:setcred acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=pts/1 res=success' type=USER_START msg=audit(1438863622.882:9017): pid=16215 uid=1001 auid=0 ses=1116 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:session_open acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=pts/1 res=success' type=USER_END msg=audit(1438863622.888:9018): pid=16215 uid=1001 auid=0 ses=1116 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:session_close acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=pts/1 res=success' type=CRED_DISP msg=audit(1438863622.888:9019): pid=16215 uid=1001 auid=0 ses=1116 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:setcred acct="administrator" exe="/usr/bin/su" hostname=? addr=? terminal=pts/1 res=success' NOW THE COMMAND HAS BEEN EXECUTED
如果您正在獲取 selinux AVC,則可以設置本地策略以允許使用該
audit2allow
工具執行該特定操作:# audit2allow -M local -a
這將創建一個策略 (
local.pp
),允許在您的審計日誌中導致 selinux 拒絕的任何內容。然後,您可以通過執行以下命令啟動此模組:# semodule -i local.pp
您可以在文件中看到原始碼
local.te
。您問題中的 AVC 將導致:
module local 1.0; require { type fprintd_t; type initrc_t; class dbus send_msg; } #============= fprintd_t ============== allow fprintd_t initrc_t:dbus send_msg;