Невозможно использовать docker кеш из-за SELINUX - PullRequest
0 голосов
/ 27 марта 2020

Я пытаюсь создать том кеша для моего docker образа (мой хост - RedHat 7.7, образ основан на Ubuntu: bioni c):

docker run -v /tmp/cache:/cache:z --entrypoint true --name cache image-dev
docker run --rm --volumes-from cache image-dev

К сожалению, я не могу использовать файлы, которые были кэшированы.

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/cache/pip/wheels/c6/8c/80/527c233e7cb169f828b7168ebeab0fc5206d09b0fa133472fb/mysqlclient-1.4.6-cp36-cp36m-linux_x86_64.whl'
Consider using the `--user` option or check the permissions.

Я заметил, что когда я отключаю SE LINUX, все работает нормально.

Я пытался исследовать его, используя:

ausearch -m avc -ts recent | audit2allow

#============= container_t ==============

#!!!! This avc is a constraint violation.  You would need to modify the attributes of either the source or target types to allow this access.
#Constraint rule: 
#   mlsconstrain file { ioctl read lock execute execute_no_trans } ((h1 dom h2 -Fail-)  or (t1 != mcs_constrained_type -Fail-) ); Constraint DENIED
mlsconstrain file { write setattr append unlink link rename } ((h1 dom h2 -Fail-)  or (t1 != mcs_constrained_type -Fail-) ); Constraint DENIED
mlsconstrain file { create relabelto } ((h1 dom h2 -Fail-)  and (l2 eq h2)  or (t1 != mcs_constrained_type -Fail-) ); Constraint DENIED
mlsconstrain file { relabelfrom } ((h1 dom h2 -Fail-)  or (t1 != mcs_constrained_type -Fail-) ); Constraint DENIED

#   Possible cause is the source level (s0:c46,c613) and target level (s0:c241,c588) are different.
allow container_t container_file_t:file { ioctl read };

И я создал собственную политику SE Linux policy container_cache.te и загрузил ее в систему:

policy_module(container_cache, 1.0)
require {
    type container_t;
    type container_file_t;
}
allow container_t container_file_t:file { ioctl read read lock execute execute_no_trans write setattr append unlink link rename create relabelto relabelfrom };

К сожалению, это не помогло.

Кто-нибудь знает, как это исправить без отключения SE Linux?

1 Ответ

0 голосов
/ 30 марта 2020

Ответом на этот вопрос являются разные метки MCS / MLS для каждого контейнера. Эти метки могут быть установлены с помощью флага, например:

--security-opt label=level:s0:c100,c200

Дополнительная информация о https://docs.docker.com/engine/reference/run/#security -конфигурации

...