Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp92907iob; Tue, 3 May 2022 12:16:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQR07SxbPL5sdbr1Zm4IepqjrT8JxRVetuh8qWkBIRTEl83CPJsSQzZ6Bd2E7/Sl+ab6Rv X-Received: by 2002:a05:6a00:2310:b0:4fa:7eb1:e855 with SMTP id h16-20020a056a00231000b004fa7eb1e855mr17396000pfh.14.1651605403067; Tue, 03 May 2022 12:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651605403; cv=none; d=google.com; s=arc-20160816; b=Blr2d5b7DvZ9daLgmGcvpMize0v4o7ted8u4Kc1ClsMMUUhjRr0Op5Yh4bGFHMHySn xxQga9/BsKXvWkOmx8VUD6soncNMTcwdOwz+KgvP7+aTwZTDJy7U5chv1S7V0womZzUd 70V4+ZkgWIeITi616SVX5W//VKAnuWoNPNI0ZNj/tK3bCtRFMWTLYN3XVyWDgoLCOQRe euefJHlPBmIrcE/zKiBTBC1QH/PuzVM79/jYfmxgTxTXWahm0qooMb/pEVwdcmL6mh9/ r1ykfNW+tiKzNXX6kH3hyvFbawA6Zx6G49uvB0qx40yZRN9bSb50zYXX9R3PK0qnMNXE agcA== 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=MKormK6iE7G36ESmhWH1ld5QzOyCAmTIaQwp9omXWzE=; b=aqPsxVhajS3YCtOpBgf2sDBFpndVRuVG/j1/dR1FkZpLFoFFKFAaxWLq9ulOn24+fi T8beyL0xReaB9DDRTGwUvMJM4xjPB8NoT3STAp8GHT3J/NSYTA511jFLry0pHOb1IkON jlG6x3/cio3XfepOk2sT74oQDNRMyPXIwXHthv4NMLJ4chJJ0h0ZuZ1EIe46Ws9Wb2ct framFFK/GtSdkIRsr5S82dccdaaYBXOzN1vtMDPdQARVLJolm+cP6Kk1kRSeNjcXruGz yieI+qN1/L4zf91tnLjL85j3sSGbye/HU4HZQQb0v2dEj6vtdRCNAD6GiTbRI2BNj0R+ YBsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ieee.org header.s=google header.b=Qz85rdHV; 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 x20-20020a17090a531400b001d931aa3f3fsi2709849pjh.184.2022.05.03.12.16.35; Tue, 03 May 2022 12:16:43 -0700 (PDT) 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=Qz85rdHV; 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 S241221AbiECSW4 (ORCPT + 22 others); Tue, 3 May 2022 14:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241218AbiECSWy (ORCPT ); Tue, 3 May 2022 14:22:54 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4C03EF38 for ; Tue, 3 May 2022 11:19:19 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id c1so14363571qkf.13 for ; Tue, 03 May 2022 11:19:19 -0700 (PDT) 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=MKormK6iE7G36ESmhWH1ld5QzOyCAmTIaQwp9omXWzE=; b=Qz85rdHVDd2YhAj1r5Cx0L26OlVrDCVrP+0CnUwP3D8guuHYLJwqpo339itUI0dfZP 985IOO1NXzcyw/T/9WVvZXAnFGfo9brqpuMTbzJPjBUavwW3HUmr1IBlq/wNyKjEekph 3d6lwS22NOQzt/Fi0qN8INHtMkGNYccLJJUUE= 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=MKormK6iE7G36ESmhWH1ld5QzOyCAmTIaQwp9omXWzE=; b=DS3KRsoqn0+eDLFExbwiY3L5j8gclvo6Vi+M6N1Wp9J0AiiMdr+8IoPtGTp+gIfAoo ZDRGJ7M6L2hAMb6oHaBls9F0E2n+HpwcDnaMkcO/nWV7nF+r1CwtLr2hC8zRPjGcevur EFhgfTsWYiZh1kJ+EYFp7R0wOwpf5ICXM8hL68r47buK86DTL8IRW6XjTiusmkFgLB0B eqUgUM+Z+8NTOC89B1GlvUmZaU4W4eVPeRJCYDOKHzGiW2EzIDCVexHGwqART+FBoGep qgzGZn7QhJgd1YmRAKFXroKigqmZEgBCCvAZYy7t7umskKOFIIh1YqlT6SG8OZJOJi+/ 5LHA== X-Gm-Message-State: AOAM532VFmmLdkjzlI84C+shX4Qq3zq1vqk0Tqgg44OHn4rCdLHRuMrg x/nRNNpOK8kjJW+Dc7oi/zp2KKAeJkZoaEbt X-Received: by 2002:a05:620a:1925:b0:69e:b500:5f41 with SMTP id bj37-20020a05620a192500b0069eb5005f41mr12880806qkb.579.1651601958873; Tue, 03 May 2022 11:19:18 -0700 (PDT) Received: from [192.168.1.242] (pool-68-134-25-67.bltmmd.fios.verizon.net. [68.134.25.67]) by smtp.gmail.com with ESMTPSA id w4-20020a05620a128400b0069fc6484c06sm5736824qki.23.2022.05.03.11.19.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 May 2022 11:19:18 -0700 (PDT) Message-ID: <804d8b8d-394a-5070-c773-b074fe5b6a5d@ieee.org> Date: Tue, 3 May 2022 14:19:17 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: Daemons writing into HOME_DIR Content-Language: en-US To: Stefan Schulze Frielinghaus , 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=-5.6 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 5/3/22 13:01, Stefan Schulze Frielinghaus wrote: > Hi all, > > In short I'm wondering what the refpolicy way is to let a daemon write into > HOME_DIR and how those files---especially the SELinux user part---should be > labeled? > > Currently I have a daemon (systemd service) running under context > > system_u:system_r:foobar_t:s0 > > and the policy contains > > init_daemon_domain(foobar_t, foobar_exec_t) > > The daemon reads and writes files under HOME_DIR/foobar which are labeled as > foobar_rw_t and the policy has the following file context entry: > > HOME_DIR/foobar(/.*)? gen_context(system_u:object_r:foobar_rw_t,s0) > > However, newly created files still seem to have a wrong user according to > restorecon (the daemon runs under Linux user marge which is assigned to SELinux > user user_u): > > $ restorecon -FRvn /home/marge/foobar > Would relabel /home/marge/foobar/baz from system_u:object_r:foobar_rw_t:s0 to user_u:object_r:foobar_rw_t:s0 > > It looks like as if user_u wins over system_u for files under HOME_DIR. This > does not have any effect on the functionality of the daemon, however, it still > feels wrong to me. This is genhomedircon setting the seuser of the files to match the seuser mapping in `semanage login`. You want this behavior, especially if you have UBAC turned on, otherwise UBAC doesn't provide a benefit, since system_u is excluded from UBAC. > So I'm wondering how to fix this and thought about: > > 1) Can/Should a daemon run under a different SELinux user than system_u? If this is a system daemon, e.g. started by systemd (pid 1) then that is not expected in refpolicy, not generally suggested. If this is a daemon running out of a user session, such as systemd --user, then yes, it should have the user's seuser, e.g. user_u. > 2) Another option, which I think is worse, would be to the change the SELinux > user from user_u to system_u for Linux user marge under which the daemon runs. Running an interactive user as system_u is contrary to system_u's purpose, which is for non-interactive system processes only. > 3) A third option would be to keep the users as is, i.e., let the daemon run > under system_u and let marge be assigned to user_u, but tweak the policy to keep > the file context labels under HOME_DIR with system_u. See my first comment. > Any thoughts? You could change the default_user[1] so the seuser comes from the parent directory, but that would change it for the entire system which may have unintended and worse consequences. You're seeing the behavior I expect to see for this type of policy design. [1] https://github.com/SELinuxProject/selinux-notebook/blob/main/src/default_rules.md#default_user -- Chris PeBenito