From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A369EB64D9 for ; Tue, 27 Jun 2023 14:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbjF0OGD (ORCPT ); Tue, 27 Jun 2023 10:06:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbjF0OGC (ORCPT ); Tue, 27 Jun 2023 10:06:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CCAE211B for ; Tue, 27 Jun 2023 07:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687874712; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Qw9fyNNl3Wup6h2O0S3N4OlDjjCJsrPZ9gvPgu40PPs=; b=cjd3h7MpaqQKn5D04DJBQFQ9z2Fs11XgF1L72rCFW7x79T2rTwKBALuUy5biUy1thNFIOn yIBeufPG+EhrUkLHQuxEWimKmVZgTkaExwafKmEiH7yqXaPLbOklYF4bEzVxudG3M+K5NW WqQJR7r6swxJa0LcliYNi77ZDVM4bo4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-551-K4CZP4mSMaG5e_89q2Ejag-1; Tue, 27 Jun 2023 10:04:45 -0400 X-MC-Unique: K4CZP4mSMaG5e_89q2Ejag-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02FFF1C17100 for ; Tue, 27 Jun 2023 14:04:23 +0000 (UTC) Received: from localhost (unknown [10.45.225.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9F2FF5CD0; Tue, 27 Jun 2023 14:04:22 +0000 (UTC) From: Petr Lautrbach To: Vit Mojzis , selinux@vger.kernel.org Subject: Re: [PATCH] python/sepolicy: Add/remove user even when SELinux is disabled In-Reply-To: <87r0q36dd1.fsf@redhat.com> References: <20230529161702.1920540-1-vmojzis@redhat.com> <87r0q36dd1.fsf@redhat.com> Date: Tue, 27 Jun 2023 16:04:22 +0200 Message-ID: <87y1k50zo9.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Petr Lautrbach writes: > Vit Mojzis writes: > >> Use "semanage user -a/-d" in spec file generated by "sepolicy generate" >> even when SELinux is disabled. The command works properly when SELinux >> is disabled and with this change the user will be present once SELinux >> is re-enabled. >> Also, do not execute the command when the package is updated, only when >> it is first installed. >> >> Signed-off-by: Vit Mojzis > > Acked-by: Petr Lautrbach merged, thanks! > >> --- >> python/sepolicy/sepolicy/templates/spec.py | 7 +++++-- >> 1 file changed, 5 insertions(+), 2 deletions(-) >> >> diff --git a/python/sepolicy/sepolicy/templates/spec.py b/python/sepolicy/sepolicy/templates/spec.py >> index 16a22081..433c298a 100644 >> --- a/python/sepolicy/sepolicy/templates/spec.py >> +++ b/python/sepolicy/sepolicy/templates/spec.py >> @@ -43,20 +43,23 @@ install -m 644 %{SOURCE3} %{buildroot}/etc/selinux/targeted/contexts/users/DOMAI >> >> %post >> semodule -n -i %{_datadir}/selinux/packages/MODULENAME.pp >> +# Add the new user defined in DOMAINNAME_u only when the package is installed (not during updates) >> +if [ $1 -eq 1 ]; then >> + /usr/sbin/semanage user -a -R DOMAINNAME_r DOMAINNAME_u >> +fi >> if /usr/sbin/selinuxenabled ; then >> /usr/sbin/load_policy >> %relabel_files >> - /usr/sbin/semanage user -a -R DOMAINNAME_r DOMAINNAME_u >> fi; >> exit 0 >> >> %postun >> if [ $1 -eq 0 ]; then >> + /usr/sbin/semanage user -d DOMAINNAME_u >> semodule -n -r MODULENAME >> if /usr/sbin/selinuxenabled ; then >> /usr/sbin/load_policy >> %relabel_files >> - /usr/sbin/semanage user -d DOMAINNAME_u >> fi; >> fi; >> exit 0 >> -- >> 2.40.0