Alternatively Git SELinux policy can be used to restrict "Git shell" users to git system shared
repositories. The policy allows for the creation of new types of Git system content and Git shell user
environment. The policy allows for delegation of types of "Git shell" environments to types of Git system
content.
To add a new Git system repository type, for example "project1" create a file named project1.te and add
to it:
policy_module(project1, 1.0.0)
git_content_template(project1)
Next create a file named project1.fc and add a file context specification for the new repository type to
it:
/srv/git/project1.git(/.*)? gen_context(system_u:object_r:git_project1_content_t,s0)
Build a binary representation of this source policy module, load it into the policy store and restore the
context of the repository:
make -f /usr/share/selinux/devel/Makefile project.pp
sudo semodule -i project1.pp
sudo restorecon -R -v /srv/git/project1
To create a "Git shell" domain that can interact with this repository create a file named project1user.te
in the same directory as where the source policy for the Git systemm content type is and add the
following:
policy_module(project1user, 1.0.0)
git_role_template(project1user)
git_content_delegation(project1user_t, git_project1_content_t)
gen_user(project1user_u, user, project1user_r, s0, s0)
Build a binary representation of this source policy module, load it into the policy store and map Linux
users to the new project1user_u SELinux user:
make -f /usr/share/selinux/devel/Makefile project1user.pp
sudo semodule -i project1user.pp
sudo useradd -Z project1user_u jane
system-config-selinux is a GUI tool available to customize SELinux policy settings.