2015-02-11 56 views
2

因此,我們有一個需要apparmor配置文件(客戶端授權)的django應用程序。它運行在位於/opt/fact-virtual-environment的Python虛擬環境中。應用程序本身安裝到/usr/share/fact在apparmor配置文件中加載Django應用程序的設置

以下是我的個人資料,到目前爲止(內置大多是用AA-genprof工具):

# Last Modified: Tue Jan 20 09:25:09 2015 
#include <tunables/global> 

/usr/bin/fact flags=(audit) { 
    #include <abstractions/apache2-common> 
    #include <abstractions/base> 
    #include <abstractions/bash> 


    capability setgid, 
    capability sys_resource, 

    /usr/local/lib/python2.7/dist-packages/**/ rm, 
    /usr/local/lib/python2.7/dist-packages/** rm, 
    /usr/local/lib/python2.7/site-packages/**/ rm, 
    /usr/local/lib/python2.7/site-packages/** rm, 
    /etc/apparmor.d/** r, 
    #/usr/lib/python2.7/**[^/] r, 

    /usr/bin/sudo Ux, 

    #/usr/bin/strace ux, 
    /bin/bash rix, 
    /bin/dash rix, 
    /bin/uname rix, 
    /dev/tty rw, 
    /etc/default/locale r, 
    #/etc/nsswitch.conf r, 
    #/etc/group r, 
    #/etc/passwd r, 
    /etc/environment r, 
    /etc/login.defs r, 
    /etc/lsb-release r, 
    /etc/fact/fact.ini r, 
    /etc/python2.7/sitecustomize.py r, 
    /etc/security/pam_env.conf r, 
    /lib{,32,64}/** mr, 
    /opt/fact-virtual-environment/**/ mr, 
    /opt/fact-virtual-environment/lib/python2.7/**/ mr, 
    /opt/fact-virtual-environment/lib/python2.7/** mr, 
    /opt/fact-virtual-environment/bin/python rix, 
    /run/utmp rk, 
    /sbin/ldconfig rix, 
    /sbin/ldconfig.real rix, 
    /usr/bin/fact rix, 
    /usr/lib{,32,64}/** mr, 
    /usr/share/fact/**/ r, 
    /usr/share/fact/** r, 
    /usr/share/pyshared/** r, 
    /usr/share/pyshared/**/ r, 
} 

...和/usr/bin/fact命令是一個簡單的包裝:

#!/bin/bash 

## This script is for running the 'fact' command on staging/prod, it sudos to 
## the 'fact' user before executing /opt/fact/bin/fact 

## It is installed as '/usr/bin/fact' 

PYTHONPATH=/usr/share/fact 
PYTHON_BIN=/opt/fact-virtual-environment/bin/python 
DJANGO_SETTINGS_MODULE=fact.settings.staging 

if [ "$USER" != "fact" ]; 
then 
    sudo -u fact $0 $*; 
else 
    PYTHONPATH=${PYTHONPATH} DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE} ${PYTHON_BIN} -m fact.managecommand $*; 
fi 

我已經啓用了很多讀取權限,我知道我不需要,比如在調試嘗試中設置的整個/usr/local/lib/*。一些令我感到非常震驚的事情是,當我運行service apparmor reload(或重新啓動)時,我的配置文件似乎不會重新加載。我似乎得到不同的結果,如果我重新啓動服務與aa-complain usr.bin.fact其次aa-enforce usr.bin.fact

現在,當我運行我的命令,並檢查系統日誌,我看到以下內容:

Feb 11 15:08:48 spiffy kernel: [1228245.774660] type=1400 audit(1423620528.359:14142): apparmor="DENIED" operation="open" parent=12884 profile="/usr/bin/fact" name="/usr/local/lib/python2.7/site-packages/" pid=12885 comm="python" requested_mask="r" denied_mask="r" fsuid=111 ouid=0 
Feb 11 15:08:48 spiffy kernel: [1228245.774855] type=1400 audit(1423620528.359:14143): apparmor="DENIED" operation="open" parent=12884 profile="/usr/bin/fact" name="/usr/local/lib/python2.7/dist-packages/" pid=12885 comm="python" requested_mask="r" denied_mask="r" fsuid=111 ouid=0 
Feb 11 15:08:48 spiffy kernel: [1228245.775829] type=1400 audit(1423620528.359:14144): apparmor="DENIED" operation="open" parent=12884 profile="/usr/bin/fact" name="/usr/local/lib/python2.7/dist-packages/" pid=12885 comm="python" requested_mask="r" denied_mask="r" fsuid=111 ouid=0 

..和我的Python應用程序barfs:

$ fact 
Traceback (most recent call last): 
    File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main 
    "__main__", fname, loader, pkg_name) 
    File "/usr/lib/python2.7/runpy.py", line 72, in _run_code 
    exec code in run_globals 
    File "/usr/share/fact/fact/managecommand.py", line 6, in <module> 
    execute_from_command_line(sys.argv) 
    File "/opt/fact-virtual-environment/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line 
    utility.execute() 
    File "/opt/fact-virtual-environment/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute 
    settings.INSTALLED_APPS 
    File "/opt/fact-virtual-environment/local/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__ 
    self._setup(name) 
    File "/opt/fact-virtual-environment/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup 
    self._wrapped = Settings(settings_module) 
    File "/opt/fact-virtual-environment/local/lib/python2.7/site-packages/django/conf/__init__.py", line 98, in __init__ 
    % (self.SETTINGS_MODULE, e) 
ImportError: Could not import settings 'fact.settings.staging' (Is it on sys.path? Is there an import error in the settings file?): cannot import name current_app 

,設置文件,它在尋找是位於/usr/share/fact/fact/settings/staging.py

我完全不能混淆爲什麼我不能讓這個應用程序運行在其apparmor配置文件。配置文件中的設置應該允許它。這是怎麼回事?

回答

1

全部否認正在尋找這個特定的目錄:/usr/local/lib/python2.7/dist-packages/

您的個人資料包括這個目錄中的一些孩子:

/usr/local/lib/python2.7/dist-packages/**/ rm, 
/usr/local/lib/python2.7/dist-packages/** rm, 
/usr/local/lib/python2.7/site-packages/**/ rm, 
/usr/local/lib/python2.7/site-packages/** rm, 

但不包括此特定的目錄。因此,添加到您的個人資料,重新加載配置文件,然後再試一次:

/usr/local/lib/python2.7/dist-packages/ r, 

的AppArmor使用後/以確定如果管理員打算讓越來越目錄列表與允許讀取的文件。

感謝

2

您的個人資料丟失權限讀取目錄 /usr/local/lib/python2.7/site-packages/

,你將需要添加 在/ usr/local/lib目錄/python2.7/site-packages/ r,

您當前的配置文件允許訪問/usr/local/lib/python2.7/site-packages/下的所有權限,但不能實際訪問目錄本身

相關問題