Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp2490822pxb; Sat, 19 Feb 2022 13:04:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcjToCwrYk8mmpOy7ROksp3N7n9qMAElS5F09F4v4sYZ0jsNPSwPL2yQVq78gt8EyqayzM X-Received: by 2002:a17:906:71cc:b0:6cf:73fe:84e5 with SMTP id i12-20020a17090671cc00b006cf73fe84e5mr10728842ejk.148.1645304698087; Sat, 19 Feb 2022 13:04:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645304698; cv=none; d=google.com; s=arc-20160816; b=c1Kj/HycgnQ9i8ozi2ZGb2SiJumdjI1WZYNH9DVT4fvfEgr8IBX9BJuRCXm+FeMRH3 ShXSNksCixnnvU9I2WwowMzWc2ZiHbJ+h77ayxruesBgWVu+rP64n9wSpko3ZBEWuRNM Nn7q7x9hjoxIRAPhfo4I42chJKJZRnULkmmkFv8S5qTNaWQcgdRwWZsgDXo3H1uPV1E/ prJR4caETqVtfurbDpvS6EI7azP13x3up265RpnODOt9a5OMzi7nYlu4Sgnh5u7zkTj5 bhQVKFoIPItm0o50uB4/Ab6+UoVTbV7jLC8gGstr6s/2TMe5JYWhS07yUpYgx1OXRnuW Ch0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=Z0xIWPfokg8Gwug4dHNxMQxTwEt/rYWGcF/7WMImAm4=; b=ohrmE5eqJefGcTEYTJeSxksgM8QeEKNsP4Ms6GlQ2TNPyWAYzOhUfcf8kWUdRrGfT7 Kcxkyhx4wpUWIZn+O2K27S2fb+sFqlNPiMnwHvIpz4JCJf5bdX6P3Lo9MJFpsufiLu7E ktR3VnInCTv4VvqOvcjRlFd4yIjBjWMAe+/UIGkL9QvV6OyJTZqE17nGalM7br0sc0oz kywWerpw8eTCCPSlXWsAXWqimlZAwZUXnRcwvSuPoQjEUQ2JcHZekyXAC3Zzf9KpRCT/ r+mYRqka2+aZZW+0tOFHnvQQMz8mWnLxxWrgGoTVeGsOKtNq8eWZJ/OwbW0fJqNLLZbA NwmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ieee.org header.s=google header.b=Vue+eM4F; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ieee.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w25si8599316edt.600.2022.02.19.13.04.49; Sat, 19 Feb 2022 13:04:58 -0800 (PST) Received-SPF: pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ieee.org header.s=google header.b=Vue+eM4F; spf=pass (google.com: domain of selinux-refpolicy-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=selinux-refpolicy-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ieee.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239413AbiBRSsZ (ORCPT + 22 others); Fri, 18 Feb 2022 13:48:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239409AbiBRSsY (ORCPT ); Fri, 18 Feb 2022 13:48:24 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 561AA13E10 for ; Fri, 18 Feb 2022 10:48:06 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id d3so16431529qvb.5 for ; Fri, 18 Feb 2022 10:48:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ieee.org; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=Z0xIWPfokg8Gwug4dHNxMQxTwEt/rYWGcF/7WMImAm4=; b=Vue+eM4FjNLjNednriO1krv66MIlt6Xh5oXDDZQTp54hItmakaPPTzGTIELD9VLtUM Ah90dZUM+V7Lke/mGXTc+PzkNgWmdHwV6KGt0PWHr+MlCRB/qKEVsT95HwTkcNw1ASkO Jn+Ch7JAHIPKV5aHeDuDhuEvCd9k2s4uc5nV8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=Z0xIWPfokg8Gwug4dHNxMQxTwEt/rYWGcF/7WMImAm4=; b=c67eHcU9ZQn6kP1M8a/bu59SW+pyWxUmYlE9VmeV3GF4OcvAEEBMwrKdRwQLY8YrV5 PMAYPzOjxazr6ykCJtT9lPSIMm5rR+cAKWlT50MsSH909AxSgZEJga4NgNwUh8EXBE/+ jGCGkfENDkcvrYRcW1Wp8gtcS+gFLlGPijX5idnx+g/GFuFaws4slj6Exi2ba809uXw7 jW49x2MaTQic0ykRMNvFBlWshQfBxrS0nbaPmegeyO3awEAXAUfFhgjx4LVlQyb7fUlj H2HE3N5lT6+UKHhKx76aZwW8FgxDYJVvET6X2i22N64AaQAy9/VTPEPk2e6/5qxaMyJs sNwA== X-Gm-Message-State: AOAM533oUVU3INe43Y2dmjbwTKXTzhk34zdPdH0pU6CvbGkoqbeZ0GBd IFhmFj+8ZRpl1uqwjNnAhSit04vpE2soBA== X-Received: by 2002:ad4:5522:0:b0:42c:3a01:510c with SMTP id ba2-20020ad45522000000b0042c3a01510cmr6896895qvb.49.1645210085464; Fri, 18 Feb 2022 10:48:05 -0800 (PST) Received: from [192.168.1.126] ([72.85.44.115]) by smtp.gmail.com with ESMTPSA id g13sm5878753qtp.26.2022.02.18.10.48.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Feb 2022 10:48:04 -0800 (PST) Message-ID: <412aee66-5f6b-f5e8-53ab-e1d5f083ee47@ieee.org> Date: Fri, 18 Feb 2022 13:17:35 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] matrixd-synapse policy V3 Content-Language: en-US To: Russell Coker , selinux-refpolicy@vger.kernel.org References: From: Chris PeBenito In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On 2/17/22 20:21, Russell Coker wrote: > 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) > +') > + Merged. -- Chris PeBenito