Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp888836pxb; Thu, 17 Feb 2022 17:38:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3h8bbqzDvj1Fp2cEkbV7DogWSgF4nQKTdTJHzQ+tvQNWAhkWE57xKL1M/YQlbRlwPaoL1 X-Received: by 2002:a17:903:244f:b0:14e:d886:3b5c with SMTP id l15-20020a170903244f00b0014ed8863b5cmr5319112pls.146.1645148298947; Thu, 17 Feb 2022 17:38:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645148298; cv=none; d=google.com; s=arc-20160816; b=QScr/CmuI2Ei2SuhjsC3VtP20xUhOKB2XQrIyU8rtNkvsnn7mXWNu+0G39REpbX15q YoSRxYvilgDn7SEPKlalFKJVxizah3NeIgJnPlMNYr6HV+qonIZKp2fa3x9zQThr/g5Y 4tG5ejai5BvgTgEEuFgAztxWl8jmRDywIBcY2OkUS7tDWfFU2SU9FjrEmnQDYJczlY6m IKsXEXfg8PH5rQwzCTOuZAx/SnBRepUkOu0WeFPK5eqjuz/WH3JgImyYKjnsuC5dXxYt JPDNRoo958226n77miAYbS9IK6JE43OIebtB87YcUO+0Z5YMUFKUc02e6iJ/gVGHZ7LW QzFA== 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=fLVS16/87/gOyF4CnTJAbTczLYURa4W/QaSSrV54COQ=; b=GC3Rn/91oQ75SSdaCprynGaxFV1eECi+WW5ICDDSgHGDcyqlro/bvc+fYtNZ/vYJBP s4anjZHfsTBH+zZ86kGZgLqnz4KBWz6jzBaHu7vrsyiiz+sXRJb1hJvpHfubBO41+VLG ef+HV0q8jEsV4Rg8KwWERHefsrIuyUCMLg8PHsH3wtkbXXqxhZTDU05lUcAgAy2cTOy5 bqCeEU1IwpdP6CmIV+XYzYmyt5eiXxYhGXAEMJ5MXNNG9PviBFA2orDqawvcNawU+pD1 fwDa32ei96VbkiE/txtXpqaA/NC+7+UagE6mbyl50jCMAgxT+XL9LIgrqvP5yq8QVSc7 LOtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@coker.com.au header.s=2008 header.b="y3u608/U"; spf=softfail (google.com: domain of transitioning selinux-refpolicy-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h184si9266756pgc.695.2022.02.17.17.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 17:38:18 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning selinux-refpolicy-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@coker.com.au header.s=2008 header.b="y3u608/U"; spf=softfail (google.com: domain of transitioning selinux-refpolicy-owner@vger.kernel.org does not designate 23.128.96.19 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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C65252E458E; Thu, 17 Feb 2022 17:22:02 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229567AbiBRBWQ (ORCPT + 22 others); Thu, 17 Feb 2022 20:22:16 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:39070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230339AbiBRBWQ (ORCPT ); Thu, 17 Feb 2022 20:22:16 -0500 Received: from smtp.sws.net.au (smtp.sws.net.au [IPv6:2a01:4f8:201:1e6::dada:cafe]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 974BB2E3E54 for ; Thu, 17 Feb 2022 17:22:00 -0800 (PST) Received: from xev.coker.com.au (localhost [127.0.0.1]) by smtp.sws.net.au (Postfix) with ESMTP id 88AFA12941 for ; Fri, 18 Feb 2022 12:21:57 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=coker.com.au; s=2008; t=1645147317; bh=fLVS16/87/gOyF4CnTJAbTczLYURa4W/QaSSrV54COQ=; l=5925; h=Date:From:To:Subject:From; b=y3u608/UZj4r65CPjM+wFcCG+cUB1JcRCYtaV8Wy+qNIVukjrjIFaazNSjEqOdWEV fbfYxM+CR7n2sXArIo+FNSxquopp3EFbAXSiQFgG2IDQeX+eGofLA8hp+FQDsD2ZYo 7XocQX1uAMsKLnj/L4hGapIB/VWKqyHgpuYhEuj4= Received: by xev.coker.com.au (Postfix, from userid 1001) id C068D1736C69; Fri, 18 Feb 2022 12:21:52 +1100 (AEDT) Date: Fri, 18 Feb 2022 12:21:52 +1100 From: Russell Coker To: selinux-refpolicy@vger.kernel.org Subject: [PATCH] matrixd-synapse policy V3 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: selinux-refpolicy@vger.kernel.org Here's the latest version of the matrixd-synapse policy including all the suggestions from a year ago. Probably ready to merge. Signed-off-by: Russell Coker Index: refpolicy-2.20220217/policy/modules/kernel/corenetwork.te.in =================================================================== --- refpolicy-2.20220217.orig/policy/modules/kernel/corenetwork.te.in +++ refpolicy-2.20220217/policy/modules/kernel/corenetwork.te.in @@ -154,7 +154,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.20220217/policy/modules/services/matrixd.fc =================================================================== --- /dev/null +++ refpolicy-2.20220217/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.20220217/policy/modules/services/matrixd.if =================================================================== --- /dev/null +++ refpolicy-2.20220217/policy/modules/services/matrixd.if @@ -0,0 +1 @@ +## Matrixd Index: refpolicy-2.20220217/policy/modules/services/matrixd.te =================================================================== --- /dev/null +++ refpolicy-2.20220217/policy/modules/services/matrixd.te @@ -0,0 +1,126 @@ +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) + +type matrixd_log_t; +logging_log_file(matrixd_log_t) + +type matrixd_conf_t; +files_config_file(matrixd_conf_t) + +type matrixd_tmp_t; +files_tmp_file(matrixd_tmp_t) + +######################################## +# +# 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; + +allow matrixd_t self:udp_socket create_socket_perms; +allow matrixd_t self:unix_dgram_socket create_socket_perms; +# execmem is needed for Python callbacks +# https://cffi.readthedocs.io/en/latest/using.html#callbacks +allow matrixd_t self:process execmem; + +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) + +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; + +logging_search_logs(matrixd_t) +manage_files_pattern(matrixd_t, matrixd_log_t, matrixd_log_t) + +read_files_pattern(matrixd_t, matrixd_conf_t, matrixd_conf_t) +allow matrixd_t matrixd_conf_t:dir list_dir_perms; + +kernel_read_system_state(matrixd_t) +kernel_read_vm_overcommit_sysctl(matrixd_t) + +# The following in the systemd service file causes a domain transition when +# running python3: +# SELinuxContext=system_u:system_r:matrixd_t:s0 +corecmd_bin_entry_type(matrixd_t) +corecmd_exec_bin(matrixd_t) +corecmd_exec_shell(matrixd_t) + +corenet_tcp_bind_generic_node(matrixd_t) +corenet_tcp_bind_http_port(matrixd_t) +corenet_tcp_connect_http_cache_port(matrixd_t) +corenet_tcp_connect_http_port(matrixd_t) + +corenet_udp_bind_generic_node(matrixd_t) +corenet_udp_bind_generic_port(matrixd_t) +corenet_udp_bind_reserved_port(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) +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) +') +