AWS에서 CentOS 6을 실행했는데 제가 본 것은 저를 당황하게 했습니다.
때때로 읽고 쓰는 능력을 잃는 s3fs
마운트가 있습니다 . /etc/fstab
나는 몇 달 동안 훌륭하게 작동한 cron 작업을 가지고 있습니다. 이는 매분마다 마운트가 좋은지 테스트하고 연결이 끊어지면 바로 공유할 것 umount
입니다 mount
. 마운트는 무부하 상태와 실제 부하 상태에서 더 자주 사라지는 경향이 있으므로 이는 훌륭한 솔루션이었습니다.
어떤 이유로 이것이 작동을 멈추고 이제 머신이 공유에서 읽기/쓰기를 할 수 없게 됩니다. 프로비저닝 후 부팅 시 머신이 가장 먼저 하는 일은 공유 umount
이기 때문입니다.mount
이제 읽으려고 할 때 발생하는 오류는 다음과 같습니다.
cp: cannot open `/app/canary.txt' for reading: Input/output error
나는 /var/log/messages
이것을 본다:
kernel: s3fs[3077]: segfault at e66000 ip 00007f833663d94e sp 00007ffc849c5b18
error 4 in libc-2.12.so[7f83365b4000+18a000]
이제 콘솔에서 루트로 똑같은 스크립트를 실행하면 완벽하게 작동합니다. 드라이브를 마운트 해제 및 마운트하고 작동 상태로 둡니다.
내 첫 번째 추측은 환경의 무언가가 차이를 유발하고 있다는 것이었기 때문에 source /root/.bash_profile
스크립트에 a를 추가했지만 소용이 없었습니다.
/etc/fstab의 줄은 괴물이지만, 여러 번의 미세 조정 시도 끝에 가장 잘 작동하는 줄은 다음과 같습니다.
ourbucket /app fuse.s3fs _netdev,allow_other,endpoint=us-west-2,url=https://s3-us-west-2.amazonaws.com,use_path_request_style,use_sse,gid=1001,umask=0007,use_cache=/srv/s3fs,retries=20,parallel_count=30,connect_timeout=30,readwrite_timeout=60,stat_cache_expire=86400,max_stat_cache_size=100000 0 0
cronfile의 모습은 다음과 같습니다.
* * * * * root /usr/bin/sudo /root/check_mount.sh
환경에 영향을 미칠 수 있다고 생각하여 sudo를 사용하거나 사용하지 않고 시도해 보았습니다.
나는 다양한 스크립트 변형을 시도했지만 이러한 명령의 대부분은 한 지점 또는 다른 지점에서 사용되었습니다. 어떤 유형을 사용하든 동일한 문제가 발생합니다 umount
.
\cp /app/canary.txt /tmp/canary.txt
retVal=$?
sleep 1
if [ ${retVal} -ne 0 ]; then
echo "Copy failed, trying to umount"
umount /app
echo "umount returned $?"
sleep 1
echo "Trying umount -f"
umount -f /app
echo "umount -f returned $?"
sleep 1
echo "Trying fusermount -u"
/usr/local/bin/fusermount -u /app
echo "fusermount returned $?"
sleep 1
echo "Trying to mount"
mount /app
echo "mount returned $?"
sleep 1
echo "Trying copy after mount"
\cp /app/canary.txt /tmp/canary.txt
fi
이 스크립트는 처음에 에 있었고 python
주요 부분은 에 포함되어 있었지만 os.system
방정식에서 이를 제거하고 싶었습니다. 동일한 문제를 제공하고 있었습니다.
답변1
내 완전한 솔루션은 다음과 같습니다.
먼저 audit.log를 시각적으로 감사했습니다. 올바른 것을 잡기 위해, 나는 audit2allow
정책과 유형 적용 규칙을 만들곤 했습니다.
grep mount /var/log/audit/audit.log | audit2allow -R -M mounts3fs
나는 마운트를 찾아서 올바른 것만 얻습니다.
이로 인해mounts3fs.pp그리고mounts3fs.te파일. 그만큼mounts3fs.te다음과 같습니다:
policy_module(mounts3fs, 1.0)
require {
type file_t;
type var_t;
type mount_t;
type cert_t;
class dir { write remove_name add_name };
class file { create unlink link setattr };
}
#============= mount_t ==============
#!!!! The source type 'mount_t' can write to a 'dir' of the following types:
# user_home_t, etc_runtime_t, var_run_t, mount_var_run_t, mount_tmp_t, user_home_dir_t, etc_t, nfs_t, tmpfs_t, tmp_t, var_t
allow mount_t cert_t:dir { write remove_name add_name };
allow mount_t cert_t:file { create unlink };
allow mount_t file_t:dir { remove_name add_name };
allow mount_t file_t:file { unlink link setattr };
allow mount_t var_t:file link;
정책을 설치하기 위해 다음을 실행합니다.
semodule -i mounts3fs.pp
특정 작업에는 이것이 충분하지 않다는 것을 알았기 때문에 다음과 같은 추가 정책을 만들었습니다.
module s3fs 1.0;
require {
type file_t;
type mount_t;
class dir create;
class file create;
}
#============= mount_t ==============
#!!!! This avc is allowed in the current policy
allow mount_t file_t:dir create;
allow mount_t file_t:file create;
selinux
여전히 지옥으로 직행할 수 있습니다.