Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2506380pxb; Mon, 18 Jan 2021 21:31:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5MxU/mmemR+76RsCbCF5KKtkOWZilQH1t3IsCuTc624Hxshb73ywYzRZwI7zFtHt3fAEX X-Received: by 2002:a50:b246:: with SMTP id o64mr1929219edd.132.1611034317941; Mon, 18 Jan 2021 21:31:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611034317; cv=none; d=google.com; s=arc-20160816; b=ffgoP72uRN4NjUD2vloj8I+KCNdMuJf92+ASKs6Zu44JxVXj4sWjgU8DLhQ1Bp0MX6 XDpuWsauhKFL35Ybg2qpEp2lVE0tNqqOq9yBkNX2EQPPIYdggqMfyKhJR7Fumdqx86jP ERcBnd719z6LxfUXWrFoMQ11CsocDM58nPdRzSeoRVgFqVx+KUt/ab/sV5ErTKWOmidn u7pVJkT9Oek+JAqRdSjJ3N00PDRkgDm3XXFLb8uZsFfdidxTktKN1+r1DykclPf9Nq1w OTq76WXGfXgC/OtzRU1OYGtmMGAI0xA+W2xDLyWhNjrCyNsFUNW/Y5MIFF2OPTT2MFnx bsrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date:dkim-signature; bh=K+QR28Di08TRe/W1Sy8lJmw0hP2tFxfPlyrh8thasOY=; b=DSUSZjXCXj/04tJ53c2JN4SYEXHEC2OH6MZCuNLGuVDnl/auj8ucPdOWYm6XlJSLP6 oOIfxf9q2fWdLu2s1/eQsbFezMPGpVqgL1jABtxdsMLaf5201+MM+ZAovZ8zb7FB/OLJ XNopacS9Z7/VodVxQr695gqra+VJs0o+FfnE7TpeFN9t4ljSkDKiJ3uxxLdx+Duv8xYZ C1Zx6VNVq5hbWPpO3bDxMOBS7giSZf9QxeZ4RDPdm3WuxQu0D7wojEejKfbyfyf5MOlj eJ2a0mmxpT8H/r/7eeF0+vtV4NBYe/MyLDzxTvi2BJx3vv/AXtqTs8MZl0YtBobJwarW 0CZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@coker.com.au header.s=2008 header.b=Qzu1yjpW; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=coker.com.au Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si2897413ejz.170.2021.01.18.21.31.53; Mon, 18 Jan 2021 21:31:57 -0800 (PST) Received-SPF: pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@coker.com.au header.s=2008 header.b=Qzu1yjpW; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=coker.com.au Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732020AbhARXkl (ORCPT + 18 others); Mon, 18 Jan 2021 18:40:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726044AbhARXkj (ORCPT ); Mon, 18 Jan 2021 18:40:39 -0500 Received: from smtp.sws.net.au (smtp.sws.net.au [IPv6:2a01:4f8:140:71f5::dada:cafe]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7624AC061573 for ; Mon, 18 Jan 2021 15:39:59 -0800 (PST) Received: from xev.coker.com.au (localhost [127.0.0.1]) by smtp.sws.net.au (Postfix) with ESMTP id 44EEBF917 for ; Tue, 19 Jan 2021 10:39:57 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=coker.com.au; s=2008; t=1611013197; bh=K+QR28Di08TRe/W1Sy8lJmw0hP2tFxfPlyrh8thasOY=; l=5735; h=Date:From:To:Subject:From; b=Qzu1yjpWTv9lNGY5adq7kQmh1omvgV1sN4sDg0udmmQviilYJr96ZRiTOLPJ0lLOZ 5cq4VBkmnl7jVw45QbfeEiJN2oRIC9v9Bcis1/srwe4RChpxGYcwL5wL62V7Dx/pLz wq4SVmiE2RZFH/xVxG5Xg41gImCLbwWyBePWEN84= Received: by xev.coker.com.au (Postfix, from userid 1001) id 1E4FD131A4A6; Tue, 19 Jan 2021 10:39:53 +1100 (AEDT) Date: Tue, 19 Jan 2021 10:39:53 +1100 From: Russell Coker To: selinux-refpolicy@vger.kernel.org Subject: [PATCH] matrixd (synapse) policy 2 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: selinux-refpolicy@vger.kernel.org New version after review by Dominick. Signed-off-by: Russell Coker Index: refpolicy-2.20210115/policy/modules/kernel/corenetwork.te.in =================================================================== --- refpolicy-2.20210115.orig/policy/modules/kernel/corenetwork.te.in +++ refpolicy-2.20210115/policy/modules/kernel/corenetwork.te.in @@ -149,7 +149,7 @@ network_port(hadoop_namenode, tcp,8020,s network_port(hddtemp, tcp,7634,s0) network_port(howl, tcp,5335,s0, udp,5353,s0) network_port(hplip, tcp,1782,s0, tcp,2207,s0, tcp,2208,s0, tcp, 8290,s0, tcp,50000,s0, tcp,50002,s0, tcp,8292,s0, tcp,9100,s0, tcp,9101,s0, tcp,9102,s0, tcp,9220,s0, tcp,9221,s0, tcp,9222,s0, tcp,9280,s0, tcp,9281,s0, tcp,9282,s0, tcp,9290,s0, tcp,9291,s0) -network_port(http, tcp,80,s0, tcp,443,s0, tcp,488,s0, tcp,8008,s0, tcp,8009,s0, tcp,8443,s0) #8443 is mod_nss default port +network_port(http, tcp,80,s0, tcp,443,s0, tcp,488,s0, tcp,8008,s0, tcp,8009,s0, tcp,8443,s0, tcp,8448,s0) #8443 is mod_nss default port network_port(http_cache, tcp,3128,s0, udp,3130,s0, tcp,8080,s0, tcp,8118,s0, tcp,10001-10010,s0) # 8118 is for privoxy network_port(i18n_input, tcp,9010,s0) network_port(imaze, tcp,5323,s0, udp,5323,s0) Index: refpolicy-2.20210115/policy/modules/services/matrixd.fc =================================================================== --- /dev/null +++ refpolicy-2.20210115/policy/modules/services/matrixd.fc @@ -0,0 +1,4 @@ +/var/lib/matrix-synapse(/.*)? gen_context(system_u:object_r:matrixd_var_t,s0) +/var/log/matrix-synapse(/.*)? gen_context(system_u:object_r:matrixd_log_t,s0) +/etc/matrix-synapse(/.*)? gen_context(system_u:object_r:matrixd_conf_t,s0) +/usr/bin/synctl -- gen_context(system_u:object_r:matrixd_exec_t,s0) Index: refpolicy-2.20210115/policy/modules/services/matrixd.if =================================================================== --- /dev/null +++ refpolicy-2.20210115/policy/modules/services/matrixd.if @@ -0,0 +1 @@ +## Matrixd Index: refpolicy-2.20210115/policy/modules/services/matrixd.te =================================================================== --- /dev/null +++ refpolicy-2.20210115/policy/modules/services/matrixd.te @@ -0,0 +1,121 @@ +policy_module(matrixd, 1.0.0) + +######################################## +# +# Declarations +# + +## +##

+## Determine whether Matrixd is allowed to federate +## (bind all UDP ports and connect to all TCP ports). +##

+##
+gen_tunable(matrix_allow_federation, true) + +## +##

+## Determine whether Matrixd can connect to the Postgres database. +##

+##
+gen_tunable(matrix_postgresql_connect, false) + + +type matrixd_t; +type matrixd_exec_t; +init_daemon_domain(matrixd_t, matrixd_exec_t) + +type matrixd_var_t; +files_type(matrixd_var_t) +manage_files_pattern(matrixd_t, matrixd_var_t, matrixd_var_t) +files_search_var_lib(matrixd_t) +allow matrixd_t matrixd_var_t:file map; +allow matrixd_t matrixd_var_t:dir manage_dir_perms; + +type matrixd_log_t; +logging_log_file(matrixd_log_t) +logging_search_logs(matrixd_t) +manage_files_pattern(matrixd_t, matrixd_log_t, matrixd_log_t) + +type matrixd_conf_t; +files_config_file(matrixd_conf_t) +read_files_pattern(matrixd_t, matrixd_conf_t, matrixd_conf_t) +allow matrixd_t matrixd_conf_t:dir list_dir_perms; + +type matrixd_tmp_t; +files_tmp_file(matrixd_tmp_t) +allow matrixd_t matrixd_tmp_t:file { manage_file_perms map }; +files_tmp_filetrans(matrixd_t, matrixd_tmp_t, file) +fs_tmpfs_filetrans(matrixd_t, matrixd_tmp_t, file) + +######################################## +# +# Local policy +# + +allow matrixd_t self:fifo_file rw_file_perms; +allow matrixd_t self:tcp_socket create_stream_socket_perms; +allow matrixd_t self:netlink_route_socket r_netlink_socket_perms; + +corenet_tcp_connect_http_port(matrixd_t) +corenet_tcp_connect_http_cache_port(matrixd_t) +corenet_udp_bind_generic_port(matrixd_t) +corenet_tcp_bind_http_port(matrixd_t) +corenet_udp_bind_reserved_port(matrixd_t) + +allow matrixd_t self:udp_socket create_socket_perms; +allow matrixd_t self:unix_dgram_socket create_socket_perms; +# https://cffi.readthedocs.io/en/latest/using.html#callbacks +allow matrixd_t self:process execmem; + +kernel_read_system_state(matrixd_t) +kernel_search_fs_sysctls(matrixd_t) +kernel_read_vm_overcommit_sysctl(matrixd_t) +kernel_search_vm_sysctl(matrixd_t) + +corecmd_exec_bin(matrixd_t) +corecmd_exec_shell(matrixd_t) + +corenet_tcp_bind_generic_node(matrixd_t) +corenet_udp_bind_generic_node(matrixd_t) + +dev_read_urand(matrixd_t) + +files_read_etc_files(matrixd_t) +files_read_etc_runtime_files(matrixd_t) +files_read_etc_symlinks(matrixd_t) + +# for /usr/share/ca-certificates +files_read_usr_files(matrixd_t) + +init_search_runtime(matrixd_t) +libs_exec_ldconfig(matrixd_t) +libs_exec_lib_files(matrixd_t) +logging_send_syslog_msg(matrixd_t) + +miscfiles_read_generic_tls_privkey(matrixd_t) +miscfiles_read_generic_certs(matrixd_t) +miscfiles_read_localization(matrixd_t) + +sysnet_read_config(matrixd_t) + +userdom_search_user_runtime_root(matrixd_t) + +optional_policy(` + apache_search_config(matrixd_t) +') + +tunable_policy(`matrix_allow_federation',` + corenet_tcp_connect_all_unreserved_ports(matrixd_t) + corenet_tcp_connect_generic_port(matrixd_t) + corenet_udp_bind_all_ports(matrixd_t) +', ` + corenet_dontaudit_tcp_connect_all_ports(matrixd_t) + corenet_dontaudit_udp_bind_all_ports(matrixd_t) +') + +tunable_policy(`matrix_postgresql_connect',` + postgresql_stream_connect(matrixd_t) + postgresql_tcp_connect(matrixd_t) +') +