Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1933690

Summary: "git init" fails with default fapolicyd rules
Product: Red Hat Enterprise Linux 8 Reporter: Renaud Métrich <rmetrich>
Component: fapolicydAssignee: Radovan Sroka <rsroka>
Status: CLOSED MIGRATED QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: high Docs Contact:
Priority: high    
Version: 8.3CC: amepatil, daniel.j.arevalo.civ, dapospis, sgrubb
Target Milestone: rcKeywords: MigratedToJIRA, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-09-19 17:36:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Renaud Métrich 2021-03-01 13:27:40 UTC
Description of problem:

This is kind of continuation of BZ #1903548.

When fapolicyd is active with default rules, it's not possible for users to perform a basic "git init" command.
This is due to hitting the following rule when git tries to copy a hook sample implemented using Perl:

-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
$ git init
fatal: cannot copy '/usr/share/git-core/templates/hooks/fsmonitor-watchman.sample' to '/home/rmetrich/FOO/.git/hooks/fsmonitor-watchman.sample': Operation not permitted
$ echo $?
128
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------


Rule being hit:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
deny_audit perm=any all : ftype=%languages
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

fapolicyd log in --debug-deny mode:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
rule=12 dec=deny_audit perm=open auid=0 pid=11058 exe=/usr/bin/git : path=/usr/share/git-core/templates/hooks/fsmonitor-watchman.sample ftype=text/x-perl
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

I think that everything that is shipped as a RPM package should be allowed (if we don't trust our own code, then there is a problem ...).

Version-Release number of selected component (if applicable):

fapolicyd-1.0-3.el8_3.4.x86_64

How reproducible:

Always

Steps to Reproduce:
1. Start fapolicyd
2. Create a directory as a user and try to "git init"

  $ mkdir FOO && cd FOO
  $ git init

Actual results:

fatal: cannot copy '/usr/share/git-core/templates/hooks/fsmonitor-watchman.sample' to '/home/rmetrich/FOO/.git/hooks/fsmonitor-watchman.sample': Operation not permitted


Expected results:

Initialized empty Git repository in /home/rmetrich/FOO/.git/

Comment 1 Dalibor Pospíšil 2021-03-04 11:29:32 UTC
I think this is closely related to the linked upstream issue.

Comment 2 Steve Grubb 2021-06-22 19:59:11 UTC
Software development generally means playing with code that is not trusted. Anyone doing software development should probably add a developer supplemental group to their account and then a rule can be created so that developer accounts can run things in the home dir. This is documented in github README.md.

allow perm=any gid=developer : ftype=%languages dir=/home

Comment 3 Renaud Métrich 2021-07-01 05:34:23 UTC
Hi Steve,

This doesn't work, I added your proposed rule as first rule and still get the deny:

$ id
uid=1000(myuser) gid=1000(myuser) groups=1000(myuser),1001(developer) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

$ git init
fatal: cannot copy '/usr/share/git-core/templates/hooks/fsmonitor-watchman.sample' to '/home/myuser/.git/hooks/fsmonitor-watchman.sample': Operation not permitted


This is because /usr/share/git-core/templates/hooks/fsmonitor-watchman.sample cannot be opened at all, as shown by strace:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
6623  07:33:12.049381 openat(AT_FDCWD, "/usr/share/git-core/templates/hooks/fsmonitor-watchman.sample", O_RDONLY) = -1 EPERM (Operation not permitted) <0.000623>
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Comment 5 Steve Grubb 2022-03-02 21:11:48 UTC
Fapolicyd needs very careful tweaking if it's used in a build server or developer's system. This is because by their very nature are creating software which sometimes involves running newly created programs which are certainly not in the trust database. Fapolicyd is better suited to a less volatile environment where applications that run are in the trust database.

This can be solved by modifying the configuration. The rule in comment #2 works. The retest failure reported in comment #3 was not in /home. Regarding git files in /usr/share/git-core/templates, these files are language files that do not follow language specific naming conventions. 
$fapolicyd-cli --ftype /usr/share/git-core/templates/hooks/fsmonitor-watchman.sample
text/x-perl

This causes them to get missed during rpm installation and they do not windup in the trust database. 

$ fapolicyd-cli --dump | grep fsmonitor-watchman.sample
$

There are two approaches, add them to the file trust db manually:

$ fapolicyd-cli --file add /usr/share/git-core/templates

The only drawback is the file trust db will need to be refreshed whenever git is updated.

$ fapolicyd-cli --file update /usr/share/git-core/templates

The second approach is to add another rule allowing developer gid to access /usr/share/git-core/templates.

In almost any situation, problems like this can be worked around by configuration changes. There are troubleshooting steps that need to be done to find a solution.

1) run in debug mode and see what the objection is. Which rule number made the decision?
2) run faplicyd-cli --list to see what that rule number is.
3) Is there a rule above it that should have allowed access? If so, did the trust not match? Verify the file's mime type.
4) Is the file in the trust database? If not add it or a directory in the path that contains it.
5) If you need a big loophole for a kind of user, make rules for their access.

Go the trust route first. Only add rules if the trust situation is volatile and unweildy.

Comment 8 Radovan Sroka 2023-07-04 17:00:52 UTC
Git can be enabled with a filter file. On 9.3/8.9: /etc/fapolicyd/fapolicyd-filter.conf can be set so git files won't be excluded from trust DB. On 9.2/8.8 it's /etc/fapolicyd/rpm-filter.conf.

Comment 9 Radovan Sroka 2023-07-04 17:51:00 UTC
I just added "+ git-core" there:

[root@Axis fapolicyd]# cat fapolicyd-filter.conf
# default filter file for fedora

+ /
 - usr/include/
 - usr/share/
  + git-core/
  # Python byte code
  + *.py?
  # Python text files
  + *.py
  # Some apps have a private libexec
  + */libexec/*
  # Ruby
  + *.rb
  # Perl
  + *.pl
  # System tap
  + *.stp
  # Javascript
  + *.js
  # Java archive 
  + *.jar
  # M4
  + *.m4
  # PHP
  + *.php
  # Perl Modules
  + *.pm
  # Lua
  + *.lua
  # Java
  + *.class
  # Typescript
  + *.ts
  # Typescript JSX
  + *.tsx
  # Lisp
  + *.el
  # Compiled Lisp
  + *.elc
 - usr/src/kernel*/
  + */scripts/*
  + */tools/objtool/*

Comment 10 Radovan Sroka 2023-08-30 09:28:06 UTC
As per comment 8 and 9, can we close this bugzilla since git can be enabled later by administrator?

Comment 11 RHEL Program Management 2023-09-19 17:31:48 UTC
Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug.

Comment 12 RHEL Program Management 2023-09-19 17:36:52 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.

Comment 13 Red Hat Bugzilla 2024-01-22 04:25:04 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 120 days