
나는 무엇보다도 Apache가 TCP를 통해 특정 포트에 연결할 수 있도록 하는 SELinux 모듈을 가지고 있습니다.
cat <<EOF > sgtest.te
module sgtest 1.0.0;
require {
attribute port_type;
type httpd_t;
class tcp_socket name_socket;
}
type my_port_t, port_type;
allow httpd_t my_port_t:tcp_socket name_socket;
EOF
echo > sgtest.fc
checkmodule -M -m -o sgtest.mod sgtest.te
semodule_package -o sgtest.pp -m sgtest.mod -f sgtest.fc
semodule -i sgtest.pp
semanage port -a -t my_port_t -p tcp 2002
정상적으로 설치되었으며 규칙이 작동하는 것 같습니다.
포트가 확실히 설치되어 있습니다.
$ semanage port -l | grep my_port_t
my_port_t tcp 2002
그러나 모듈을 제거할 수는 없습니다.
$ semodule -r sgtest
libsemanage.semanage_direct_remove_key: Removing last sgtest module (no other sgtest module exists at another priority).
libsepol.context_from_record: type my_port_t is not defined (No such file or directory).
libsepol.context_from_record: could not create context structure (Invalid argument).
libsepol.port_from_record: could not create port structure for range 2002:2002 (tcp) (Invalid argument).
libsepol.sepol_port_modify: could not load port range 2002 - 2002 (tcp) (Invalid argument).
libsemanage.dbase_policydb_modify: could not modify record value (Invalid argument).
libsemanage.semanage_base_merge_components: could not merge local modifications into policy (Invalid argument).
semodule: Failed!
이것은 CentOS 7.4.1708에 있습니다.
내가 뭘 잘못했나요?
답변1
이것이 어떻게 작동하는지 또는 오류 메시지와 어떻게 관련되는지 이해하지 못하지만 먼저 포트를 제거하면 상황에서 벗어날 수 있다는 것을 알았습니다.
semanage port -d -p tcp 2002
semodule -r sgtest