Compare commits

...

No commits in common. "c8-stream-2.0" and "c10s" have entirely different histories.

14 changed files with 5778 additions and 160 deletions

19
.gitignore vendored
View File

@ -1 +1,18 @@
SOURCES/v0.2.1.tar.gz
/v0.1.1.tar.gz
/v0.1.2.tar.gz
/v0.1.3.tar.gz
/v0.1.4.tar.gz
/v0.1.5.tar.gz
/v0.1.6.tar.gz
/v0.1.7.tar.gz
/v0.1.8.tar.gz
/v0.1.9.tar.gz
/v0.2.0.tar.gz
/v0.2.1.tar.gz
/v0.2.2.tar.gz
/v0.2.3.tar.gz
/v0.2.4.tar.gz
/v0.2.5.tar.gz
/v0.2.6.tar.gz
/v0.2.7.tar.gz
/v0.2.8.tar.gz

View File

@ -1 +0,0 @@
4040bc2746225acabf5c7038d8eb38ae2de30ac2 SOURCES/v0.2.1.tar.gz

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,170 @@
From d444e67ead27266d57184ab8bc032c5528f7e26c Mon Sep 17 00:00:00 2001
From: Vit Mojzis <vmojzis@redhat.com>
Date: Wed, 20 Dec 2023 14:33:27 +0100
Subject: [PATCH] Add tests covering confined user policy generation
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
---
tests/test_confined_abcdgilmns.cil | 24 ++++++++++++++++++++
tests/test_confined_cla.cil | 15 +++++++++++++
tests/test_confined_lb.cil | 12 ++++++++++
tests/test_confined_lsid.cil | 17 +++++++++++++++
tests/test_main.py | 35 +++++++++++++++++++++++++-----
5 files changed, 98 insertions(+), 5 deletions(-)
create mode 100644 tests/test_confined_abcdgilmns.cil
create mode 100644 tests/test_confined_cla.cil
create mode 100644 tests/test_confined_lb.cil
create mode 100644 tests/test_confined_lsid.cil
diff --git a/tests/test_confined_abcdgilmns.cil b/tests/test_confined_abcdgilmns.cil
new file mode 100644
index 0000000..5fd619f
--- /dev/null
+++ b/tests/test_confined_abcdgilmns.cil
@@ -0,0 +1,24 @@
+(boolean my_container_exec_content true)
+(role my_container_r)
+(type my_container_dbus_t)
+(type my_container_gkeyringd_t)
+(type my_container_ssh_agent_t)
+(type my_container_sudo_t)
+(type my_container_sudo_tmp_t)
+(type my_container_t)
+(type my_container_userhelper_t)
+(user my_container_u)
+(userrole my_container_u my_container_r)
+(userlevel my_container_u (s0))
+(userrange my_container_u ((s0 ) (s0 (c0))))
+
+(call confinedom_admin_commands_macro (my_container_t my_container_r my_container_sudo_t))
+(call confinedom_graphical_login_macro (my_container_t my_container_r my_container_dbus_t))
+(call confinedom_mozilla_usage_macro (my_container_t my_container_r))
+(call confinedom_networking_macro (my_container_t my_container_r))
+(call confinedom_security_advanced_macro (my_container_t my_container_r my_container_sudo_t my_container_userhelper_t))
+(call confinedom_security_basic_macro (my_container_t my_container_r))
+(call confinedom_sudo_macro (my_container_t my_container_r my_container_sudo_t my_container_sudo_tmp_t))
+(call confinedom_user_login_macro (my_container_t my_container_r my_container_gkeyringd_t my_container_dbus_t my_container_exec_content))
+(call confined_ssh_connect_macro (my_container_t my_container_r my_container_ssh_agent_t))
+(call confined_use_basic_commands_macro (my_container_t my_container_r))
\ No newline at end of file
diff --git a/tests/test_confined_cla.cil b/tests/test_confined_cla.cil
new file mode 100644
index 0000000..a633aaa
--- /dev/null
+++ b/tests/test_confined_cla.cil
@@ -0,0 +1,15 @@
+(boolean my_container_exec_content true)
+(role my_container_r)
+(type my_container_dbus_t)
+(type my_container_gkeyringd_t)
+(type my_container_ssh_agent_t)
+(type my_container_sudo_t)
+(type my_container_t)
+(user my_container_u)
+(userrole my_container_u my_container_r)
+(userlevel my_container_u (s0))
+(userrange my_container_u ((s0 ) (s0 (c0))))
+
+(call confinedom_admin_commands_macro (my_container_t my_container_r my_container_sudo_t))
+(call confinedom_user_login_macro (my_container_t my_container_r my_container_gkeyringd_t my_container_dbus_t my_container_exec_content))
+(call confined_ssh_connect_macro (my_container_t my_container_r my_container_ssh_agent_t))
\ No newline at end of file
diff --git a/tests/test_confined_lb.cil b/tests/test_confined_lb.cil
new file mode 100644
index 0000000..3e3c997
--- /dev/null
+++ b/tests/test_confined_lb.cil
@@ -0,0 +1,12 @@
+(boolean my_container_exec_content true)
+(role my_container_r)
+(type my_container_dbus_t)
+(type my_container_gkeyringd_t)
+(type my_container_t)
+(user my_container_u)
+(userrole my_container_u my_container_r)
+(userlevel my_container_u (s0))
+(userrange my_container_u ((s0 ) (s0 (c0))))
+
+(call confinedom_user_login_macro (my_container_t my_container_r my_container_gkeyringd_t my_container_dbus_t my_container_exec_content))
+(call confined_use_basic_commands_macro (my_container_t my_container_r))
\ No newline at end of file
diff --git a/tests/test_confined_lsid.cil b/tests/test_confined_lsid.cil
new file mode 100644
index 0000000..8719420
--- /dev/null
+++ b/tests/test_confined_lsid.cil
@@ -0,0 +1,17 @@
+(boolean my_container_exec_content true)
+(role my_container_r)
+(type my_container_dbus_t)
+(type my_container_gkeyringd_t)
+(type my_container_sudo_t)
+(type my_container_sudo_tmp_t)
+(type my_container_t)
+(type my_container_userhelper_t)
+(user my_container_u)
+(userrole my_container_u my_container_r)
+(userlevel my_container_u (s0))
+(userrange my_container_u ((s0 ) (s0 (c0))))
+
+(call confinedom_security_advanced_macro (my_container_t my_container_r my_container_sudo_t my_container_userhelper_t))
+(call confinedom_security_basic_macro (my_container_t my_container_r))
+(call confinedom_sudo_macro (my_container_t my_container_r my_container_sudo_t my_container_sudo_tmp_t))
+(call confinedom_user_login_macro (my_container_t my_container_r my_container_gkeyringd_t my_container_dbus_t my_container_exec_content))
\ No newline at end of file
diff --git a/tests/test_main.py b/tests/test_main.py
index fb6a9ab..0c73861 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -369,7 +369,26 @@ class TestBase(unittest.TestCase):
self.assert_templates(output, ["base_container"])
self.assert_policy(test_file("test_devices.podman.cil"))
- def run_udica(self, args):
+ # Confined user tests
+ def test_confined_user(self):
+ """udica confined_user <args> --level s0 --range s0:c0 my_container"""
+ for arg in ["cla", "lb", "lsid", "abcdgilmns"]:
+ output = self.run_udica(
+ [
+ "udica",
+ "confined_user",
+ "-{}".format(arg),
+ "--level",
+ "s0",
+ "--range",
+ "s0:c0",
+ "my_container",
+ ],
+ True,
+ )
+ self.assert_policy(test_file("test_confined_{}.cil".format(arg)))
+
+ def run_udica(self, args, confined=False):
with patch("sys.argv", args):
with patch("sys.stderr.write") as mock_err, patch(
"sys.stdout.write"
@@ -383,10 +402,16 @@ class TestBase(unittest.TestCase):
udica.__main__.main()
mock_err.assert_not_called()
- self.assertRegex(mock_out.output, "Policy my_container created")
- self.assertRegex(
- mock_out.output, "--security-opt label=type:my_container.process"
- )
+ if confined:
+ self.assertRegex(mock_out.output, "semodule -i my_container.cil")
+ self.assertRegex(
+ mock_out.output, "semanage login -a -s my_container_u my_container"
+ )
+ else:
+ self.assertRegex(mock_out.output, "Policy my_container created")
+ self.assertRegex(
+ mock_out.output, "--security-opt label=type:my_container.process"
+ )
return mock_out.output
--
2.43.0

View File

@ -0,0 +1,57 @@
From f411c146986fabe7375724528b2d4ba8cf78b904 Mon Sep 17 00:00:00 2001
From: Vit Mojzis <vmojzis@redhat.com>
Date: Mon, 12 Feb 2024 19:38:14 +0100
Subject: [PATCH] confined: make "-l" non optional
The confinedom_user_login_macro is needed for all custom users.
Also, allow the new user type to be accessed via remote login.
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
---
udica/__main__.py | 2 +-
udica/macros/confined_user_macros.cil | 8 +++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/udica/__main__.py b/udica/__main__.py
index 1ba8515..801499c 100644
--- a/udica/__main__.py
+++ b/udica/__main__.py
@@ -92,7 +92,7 @@ def get_args():
"-l",
"--user_login",
action="store_true",
- default=False,
+ default=True,
dest="user_login",
help="Basic rules common to all users (tty, pty, ...)",
)
diff --git a/udica/macros/confined_user_macros.cil b/udica/macros/confined_user_macros.cil
index ddb5689..06c4c56 100644
--- a/udica/macros/confined_user_macros.cil
+++ b/udica/macros/confined_user_macros.cil
@@ -2411,7 +2411,7 @@
(typetransition utype sudo_exec_t process sudo_type)
(allow sudo_type utype (fd (use)))
(allow sudo_type utype (fifo_file (ioctl read write getattr lock append)))
- (allow sudo_type utype (process (sigchld)))
+ (allow sudo_type utype (process (getpgid sigchld)))
(allow sudo_type bin_t (dir (getattr open search)))
(allow sudo_type bin_t (dir (ioctl read getattr lock open search)))
(allow sudo_type bin_t (dir (getattr open search)))
@@ -4006,6 +4006,12 @@
)
)
)
+ ; Telnet login
+ (optional confinedom_user_login_optional_3
+ (typeattributeset cil_gen_require remote_login_t)
+ (allow remote_login_t utype (process (signal transition)))
+ (allow utype self (bpf (prog_load)))
+ )
)
(macro confined_ssh_connect_macro ((type utype) (role urole) (type ssh_agent_type))
--
2.43.0

View File

@ -0,0 +1,31 @@
From 131d228c6a91eaaeccc1d000821beeccba69d134 Mon Sep 17 00:00:00 2001
From: Vit Mojzis <vmojzis@redhat.com>
Date: Mon, 4 Mar 2024 12:59:53 +0100
Subject: [PATCH] confined: allow asynchronous I/O operations
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
---
udica/macros/confined_user_macros.cil | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/udica/macros/confined_user_macros.cil b/udica/macros/confined_user_macros.cil
index 06c4c56..dcb5198 100644
--- a/udica/macros/confined_user_macros.cil
+++ b/udica/macros/confined_user_macros.cil
@@ -4012,6 +4012,13 @@
(allow remote_login_t utype (process (signal transition)))
(allow utype self (bpf (prog_load)))
)
+ ; asynchronous I/O operations RHEL 10
+ (optional confinedom_user_login_optional_4
+ (typeattributeset cil_gen_require io_uring_t)
+ (allow utype self (io_uring (sqpoll)))
+ (allow utype io_uring_t (anon_inode (create)))
+ (allow utype io_uring_t (anon_inode (read write getattr map)))
+ )
)
(macro confined_ssh_connect_macro ((type utype) (role urole) (type ssh_agent_type))
--
2.43.0

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# udica
The udica package

View File

@ -1,158 +0,0 @@
Summary: A tool for generating SELinux security policies for containers
Name: udica
Version: 0.2.1
Release: 2%{?dist}
Source0: https://github.com/containers/udica/archive/v%{version}.tar.gz
License: GPLv3+
BuildArch: noarch
Url: https://github.com/containers/udica
%if 0%{?fedora} || 0%{?rhel} > 7
BuildRequires: python3 python3-devel python3-setuptools
Requires: python3 python3-libsemanage python3-libselinux
%else
BuildRequires: python2 python2-devel python2-setuptools
Requires: python2 libsemanage-python libselinux-python
%endif
%description
Tool for generating SELinux security profiles for containers based on
inspection of container JSON file.
%prep
%setup -q
%build
%if 0%{?fedora} || 0%{?rhel} > 7
%{__python3} setup.py build
%else
%{__python2} setup.py build
%endif
%install
install --directory %%{buildroot}%{_datadir}/udica/templates
%if 0%{?fedora} || 0%{?rhel} > 7
%{__python3} setup.py install --single-version-externally-managed --root=%{buildroot}
%else
%{__python2} setup.py install --single-version-externally-managed --root=%{buildroot}
%endif
install --directory %{buildroot}%{_mandir}/man8
install -m 0644 udica/man/man8/udica.8 %{buildroot}%{_mandir}/man8/udica.8
%files
%{_mandir}/man8/udica.8*
%{_bindir}/udica
%dir %{_datadir}/udica
%dir %{_datadir}/udica/ansible
%dir %{_datadir}/udica/templates
%{_datadir}/udica/ansible/*
%{_datadir}/udica/templates/*
%if 0%{?fedora} || 0%{?rhel} > 7
%license LICENSE
%{python3_sitelib}/udica/
%{python3_sitelib}/udica-*.egg-info
%else
%{_datarootdir}/licenses/udica/LICENSE
%{python2_sitelib}/udica/
%{python2_sitelib}/udica-*.egg-info
%endif
%changelog
* Tue Nov 26 2019 Jindrich Novy <jnovy@redhat.com> - 0.2.1-2
- initial import to container-tools 8.2.0
- Related: RHELPLAN-25139
* Fri Oct 25 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.2.1-1
- New rebase https://github.com/containers/udica/releases/tag/v0.2.0
Resolves: rhbz#1757693
* Wed Oct 02 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.2.0-1
- New rebase https://github.com/containers/udica/releases/tag/v0.2.0
Resolves: rhbz#1757693
* Thu Jul 11 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.8-1
- Udica supports podman version 1.4.0+
Resolves: rhbz#1729115
* Fri May 17 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.6-1
- Update testsuite from upstream release
Resolves: rhbz#1673643
* Wed May 15 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.5-2
- Bump release because of gating tests
* Fri Apr 19 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.5-1
- Create mock selinux and semanage module
- Update testing section in README
- Add travis file for Travis CI
- Grammar fixes in the udica.8 manpage file
- Support port ranges (Resolves: #16)
- Test port ranges
* Mon Mar 11 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.4-1
- Fix minor problems reported by pylint #11
- Catch FileNotFoundError when inspecting containers #12
- Create basic tests #13
- Restore working directory #14
- udica cannot use the container ID once it is provided #10
* Mon Feb 25 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.3-4
- Update manpage with the latest known bug described in https://github.com/containers/udica/issues/8
- Add check if runtimes are installed on the system
* Sun Feb 17 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.3-3
- Improve capability parsing for docker containers
- Update small changes in manpage, like issue with mandatory option '-c' for docker containers
- Fix parsing Mountpoints in docker inspect JSON file
* Sun Feb 03 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
* Wed Jan 23 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.3-1
- Fix capability allow rules when capabilities are specified in JSON file
- Add additional SELinux allow rules to base container template to allow container to read proc_type types.
* Fri Jan 04 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.2-1
- Fix invalid syntax output when policy is using just one template
Resolves: #6
* Tue Oct 23 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.1.1-2
- Fix small issues in spec file like improve description and change files section.
* Mon Oct 22 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.1.1-1
- Add proper shebang to all source files
- Add License to all source files
* Sat Oct 13 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.1.0-1
- Add support for docker containers
* Mon Oct 08 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.5-1
- Update x_container template based on testing container related to Nvidia Cuda operations
* Mon Oct 08 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.4-2
- Build udica on Red Hat Enterprise Linux 7 with python version 2
* Mon Oct 08 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.4-1
- Add manpages
- Add support for communicating with libvirt daemon
- Add support for communicating with X server.
- Add support for read/write to the controlling terminal
* Sun Oct 07 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.3-1
- Remove required parameters -i or -j and added support for reading json file from stdin.
- Remove "-n" or "--name" parameter. Name of the container will be required for this tool
* Tue Sep 25 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.2-1
- Use subprocess.Popen instead of subprocess.run for inspecting to support also python2
* Thu Sep 20 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.1-3
- Update readme and setup.py files after migration to github
* Sun Sep 16 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.1-2
- Update LICENSE
- Improve %%files section
* Sun Sep 16 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.1-1
- Initial build

8
gating.yaml Normal file
View File

@ -0,0 +1,8 @@
#recipients: mmalik
--- !Policy
product_versions:
- rhel-10
decision_context: osci_compose_gate
rules:
- !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}

1
sources Normal file
View File

@ -0,0 +1 @@
SHA512 (v0.2.8.tar.gz) = 513d932cad65d75b5aa753f2b0e4a99c0f5fa930740c65c20343521bc74deca13b140a69b78ab001dcd144a14254d1dda8ca8989531070e545fddbb08c1e64f0

66
tests/docker/runtest.sh Executable file
View File

@ -0,0 +1,66 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Description: Compare udica output between podman and docker
# Author: Jan Zarsky <jzarsky@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2019 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="udica"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm "udica"
rlAssertRpm "container-selinux"
rlAssertRpm "policycoreutils"
rlAssertRpm "podman"
rlAssertRpm "docker"
rlRun "rlServiceStart docker"
OUTPUT_FILE=$(mktemp)
rlPhaseEnd
rlPhaseStartTest
for BACKEND in podman docker ; do
rlRun "$BACKEND run -dit --name test -v /home:/home:ro -v /var/spool:/var/spool:rw -p 21:21 fedora"
rlRun "$BACKEND ps | grep test"
CONT_ID=$($BACKEND ps | grep test | cut -d ' ' -f 1)
rlRun "udica -i $CONT_ID my_container"
rlRun "mv my_container.cil my_cont_$BACKEND.cil"
rlRun "$BACKEND stop test"
rlRun "$BACKEND rm test"
done
rlRun "sed -i '/capability/d' my_cont_podman.cil"
rlRun "diff -b -B my_cont_podman.cil my_cont_docker.cil"
rlRun "rm my_cont_podman.cil my_cont_docker.cil"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "rm -f $OUTPUT_FILE"
rlRun "rlServiceRestore docker"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

134
tests/sanity/runtest.sh Executable file
View File

@ -0,0 +1,134 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Description: Test basic functionality of udica
# Author: Jan Zarsky <jzarsky@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2019 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="udica"
CONTAINERS="fedora:latest fedora:rawhide ubi8 ubi7 centos:stream8 centos:7"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm "udica"
rlAssertRpm "container-selinux"
rlAssertRpm "policycoreutils"
rlAssertRpm "podman"
OUTPUT_FILE=$(mktemp)
rlPhaseEnd
rlPhaseStartTest
rlRun "udica --help"
rlRun "PAGER=cat man udica"
rlPhaseEnd
for CONTAINER_NAME in ${CONTAINERS} ; do
rlPhaseStartTest "Test basic scenario for ${CONTAINER_NAME} container"
rlRun "podman run -dit --name test -v /home:/home:ro -v /var/spool:/var/spool:rw -p 21:21 ${CONTAINER_NAME}"
rlRun "podman ps | grep test"
rlRun "ps -efZ | grep bash"
rlRun "ps -efZ | grep bash | grep container_t"
rlRun "podman exec test ls /home" 1,2
rlRun "podman exec test touch /var/spool/test" 1
rlRun "podman exec test yum install nmap-ncat -y" 0
rlWatchdog "rlRun \"podman exec test nc -l 53\"" 3
CONT_ID=$(podman ps | grep test | cut -d ' ' -f 1)
rlRun "podman inspect $CONT_ID | udica my_container >$OUTPUT_FILE"
rlRun "podman stop test"
rlRun "podman rm --force test"
rlRun "cat $OUTPUT_FILE"
rlAssertExists "my_container.cil"
SEMODULE=$(cat $OUTPUT_FILE | grep "semodule -i" | cut -d '#' -f 2)
rlRun "$SEMODULE"
PODMAN_OPT=$(cat $OUTPUT_FILE | grep "security-opt" | cut -d '"' -f 2)
rlRun "podman run -dit --name test2 $PODMAN_OPT -v /home:/home:ro -v /var/spool:/var/spool:rw -p 21:21 fedora"
rlRun "podman ps | grep test2"
rlRun "ps -efZ | grep bash"
rlRun "ps -efZ | grep bash | grep my_container.process"
rlRun "podman exec test2 ls /home" 0
rlRun "podman exec test2 touch /var/spool/test" 0
rlRun "podman exec test2 yum install nmap-ncat -y" 0
rlWatchdog "rlRun \"podman exec test2 nc -l 53\" 2" 3
rlRun "podman stop test2"
rlRun "podman rm --force test2"
rlRun "semodule -r my_container base_container net_container home_container"
rlRun "rm my_container.cil"
rlPhaseEnd
done
rlPhaseStartTest "Compare different ways of obtaining policy"
rlRun "podman run -dit --name test -v /home:/home:ro -v /var/spool:/var/spool:rw -p 21:21 fedora"
rlRun "podman ps | grep test"
CONT_ID=$(podman ps | grep test | cut -d ' ' -f 1)
rlRun "podman inspect $CONT_ID | udica my_container >pipe.result"
rlRun "podman inspect $CONT_ID >container.json"
rlRun "udica -j container.json my_container >json.result"
rlRun "udica -i $CONT_ID my_container >id.result"
rlRun "diff pipe.result json.result"
rlRun "diff pipe.result id.result"
rlRun "rm -f pipe.result json.result id.result container.json"
rlRun "podman stop test"
rlRun "podman rm test"
rlPhaseEnd
rlPhaseStartTest "Test loading modules"
rlRun "podman run -dit --name test -v /home:/home:ro -v /var/spool:/var/spool:rw -p 21:21 fedora"
rlRun "podman ps | grep test"
CONT_ID=$(podman ps | grep test | cut -d ' ' -f 1)
rlRun "podman inspect $CONT_ID | udica -l my_container"
rlRun "podman stop test"
rlRun "podman rm test"
rlRun "semodule -l >$OUTPUT_FILE"
rlAssertGrep "my_container" $OUTPUT_FILE
rlAssertGrep "base_container" $OUTPUT_FILE
rlAssertGrep "net_container" $OUTPUT_FILE
rlAssertGrep "home_container" $OUTPUT_FILE
rlRun "semodule -r my_container base_container net_container home_container"
rlRun "rm my_container.cil"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "rm -f $OUTPUT_FILE"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

34
tests/tests.yml Normal file
View File

@ -0,0 +1,34 @@
- hosts: localhost
tags:
- classic
- container
roles:
- role: standard-test-source
- role: standard-test-basic
required_packages:
- python3
- container-selinux
- git
tests:
- smoke:
dir: ./source
run: python3 -m unittest -v tests/test_unit.py
- smoke2:
dir: ./source
run: python3 tests/test_integration.py
- hosts: localhost
tags:
- classic
- container
roles:
- role: standard-test-beakerlib
tags:
- classic
tests:
- sanity
required_packages:
- podman
- udica
- container-selinux

261
udica.spec Normal file
View File

@ -0,0 +1,261 @@
Summary: A tool for generating SELinux security policies for containers
Name: udica
Version: 0.2.8
Release: 5%{?dist}
Source0: https://github.com/containers/udica/archive/v%{version}.tar.gz
#git format-patch -N v0.2.8 -- . ':!.cirrus.yml' ':!.github'
Patch0001: 0001-Add-option-to-generate-custom-policy-for-a-confined-.patch
Patch0002: 0002-Add-tests-covering-confined-user-policy-generation.patch
Patch0003: 0003-confined-make-l-non-optional.patch
Patch0004: 0004-confined-allow-asynchronous-I-O-operations.patch
License: GPL-3.0-or-later
BuildArch: noarch
Url: https://github.com/containers/udica
%if 0%{?fedora} || 0%{?rhel} > 7
BuildRequires: python3 python3-devel python3-setuptools
Requires: python3 python3-libsemanage python3-libselinux
%else
BuildRequires: python2 python2-devel python2-setuptools
Requires: python2 libsemanage-python libselinux-python
%endif
# container-selinux provides policy templates
Requires: container-selinux >= 2.168.0-2
%description
Tool for generating SELinux security profiles for containers based on
inspection of container JSON file.
%prep
%autosetup -p 1
%build
%if 0%{?fedora} || 0%{?rhel} > 7
%{__python3} setup.py build
%else
%{__python2} setup.py build
%endif
%install
%if 0%{?fedora} || 0%{?rhel} > 7
%{__python3} setup.py install --single-version-externally-managed --root=%{buildroot}
%else
%{__python2} setup.py install --single-version-externally-managed --root=%{buildroot}
%endif
install --directory %{buildroot}%{_datadir}/udica/macros
install --directory %{buildroot}%{_mandir}/man8
install -m 0644 udica/man/man8/udica.8 %{buildroot}%{_mandir}/man8/udica.8
%files
%{_mandir}/man8/udica.8*
%{_bindir}/udica
%dir %{_datadir}/udica
%dir %{_datadir}/udica/ansible
%dir %{_datadir}/udica/macros
%{_datadir}/udica/ansible/*
%{_datadir}/udica/macros/*
%if 0%{?fedora} || 0%{?rhel} > 7
%license LICENSE
%{python3_sitelib}/udica/
%{python3_sitelib}/udica-*.egg-info
%else
%{_datarootdir}/licenses/udica/LICENSE
%{python2_sitelib}/udica/
%{python2_sitelib}/udica-*.egg-info
%endif
%changelog
* Mon Jun 24 2024 Troy Dawson <tdawson@redhat.com> - 0.2.8-5
- Bump release for June 2024 mass rebuild
* Mon Feb 12 2024 Vit Mojzis <vmojzis@redhat.com> - 0.2.8-4
- confined: make "-l" non optional
- confined: allow asynchronous I/O operations
* Sat Jan 27 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.8-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild
* Thu Dec 21 2023 Vit Mojzis <vmojzis@redhat.com> - 0.2.8-2
- Add option to generate custom policy for a confined user
* Wed Nov 29 2023 Vit Mojzis <vmojzis@redhat.com> - 0.2.8-1
- New release
* Sat Jul 22 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.7-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
* Tue Jun 13 2023 Python Maint <python-maint@redhat.com> - 0.2.7-6
- Rebuilt for Python 3.12
* Tue Apr 11 2023 Vit Mojzis <vmojzis@redhat.com> - 0.2.7-5
- Show diff when checking formatting
- Fix several lint findings
- Fix generating policy for Crio mounts
* Sat Jan 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.7-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild
* Fri Oct 21 2022 Vit Mojzis <vmojzis@redhat.com> - 0.2.7-3
- Add --devices option
* Sat Jul 23 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.7-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
* Wed Jun 22 2022 Vit Mojzis <vmojzis@redhat.com> - 0.2.7-1
- Add support for containerd via "nerdctl inspect"
- Avoid duplicate rules for accessing mounts and devices
* Mon Jun 13 2022 Python Maint <python-maint@redhat.com> - 0.2.6-5
- Rebuilt for Python 3.11
* Mon May 02 2022 Vit Mojzis <vmojzis@redhat.com> - 0.2.6-4
- Improve label collection for mounts and devices
* Sat Jan 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.6-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
* Thu Nov 11 2021 Vit Mojzis <vmojzis@redhat.com> - 0.2.6-2
- Make sure each section of the inspect exists before accessing
* Mon Sep 13 2021 Vit Mojzis <vmojzis@redhat.com> - 0.2.6-1
- New release https://github.com/containers/udica/releases/tag/v0.2.6
- Move policy templates to container-selinux repo
* Wed Aug 25 2021 Vit Mojzis <vmojzis@redhat.com> - 0.2.5-1
- New rebase https://github.com/containers/udica/releases/tag/v0.2.5
- Replace capability dictionary with str.lower()
- Enable udica to generate policies with fifo class
- Sort container inspect data before processing
- Update templates to work properly with new cil parser
* Fri Jul 23 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.4-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
* Fri Jun 04 2021 Python Maint <python-maint@redhat.com> - 0.2.4-4
- Rebuilt for Python 3.10
* Wed Jan 27 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.4-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
* Sun Dec 13 2020 Lukas Vrabec <lvrabec@redhat.com> - 0.2.4-2
- Add %check section to run basic tests during rpm build process
* Wed Nov 25 2020 Lukas Vrabec <lvrabec@redhat.com> - 0.2.4-1
- New rebase https://github.com/containers/udica/releases/tag/v0.2.4
* Thu Aug 13 2020 Lukas Vrabec <lvrabec@redhat.com> - 0.2.3-1
- New rebase https://github.com/containers/udica/releases/tag/v0.2.3
* Mon Aug 03 2020 Lukas Vrabec <lvrabec@redhat.com> - 0.2.2-1
- New rebase https://github.com/containers/udica/releases/tag/v0.2.2
* Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.1-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
* Tue May 26 2020 Miro Hrončok <mhroncok@redhat.com> - 0.2.1-3
- Rebuilt for Python 3.9
* Fri Jan 31 2020 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
* Fri Oct 25 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.2.1-1
- New rebase https://github.com/containers/udica/releases/tag/v0.2.1
* Wed Sep 25 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.2.0-1
- New rebase https://github.com/containers/udica/releases/tag/v0.2.0
* Wed Aug 28 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.9-1
- Update tests test_basic.podman.cil, test_basic.docker.cil. Round 2
- New rebase https://github.com/containers/udica/releases/tag/v0.1.9
* Mon Aug 19 2019 Miro Hrončok <mhroncok@redhat.com> - 0.1.8-3
- Rebuilt for Python 3.8
* Sat Jul 27 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.8-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
* Thu Jul 11 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.8-1
- New rebase https://github.com/containers/udica/releases/tag/v0.1.8
* Wed Jun 12 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.7-1
- New rebase with upstream adding new param --ansible, to generate ansible playbook for deploying policies. https://github.com/containers/udica/releases/tag/v0.1.7
* Thu May 16 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.6-1
- New rebase with upstream adding new tests
* Tue Apr 30 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.5-2
- Add allow rules for container_runtime_t to base_container.cil, Podman version 1.2.0 requires new allow rules.
* Fri Apr 19 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.5-1
- Create mock selinux and semanage module
- Update testing section in README
- Add travis file for Travis CI
- Grammar fixes in the udica.8 manpage file
- Support port ranges (Resolves: #16)
- Test port ranges
* Mon Mar 11 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.4-1
- Fix minor problems reported by pylint #11
- Catch FileNotFoundError when inspecting containers #12
- Create basic tests #13
- Restore working directory #14
- udica cannot use the container ID once it is provided #10
* Mon Feb 25 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.3-4
- Update manpage with the latest known bug described in https://github.com/containers/udica/issues/8
- Add check if runtimes are installed on the system
* Sun Feb 17 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.3-3
- Improve capability parsing for docker containers
- Update small changes in manpage, like issue with mandatory option '-c' for docker containers
- Fix parsing Mountpoints in docker inspect JSON file
* Sun Feb 03 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
* Wed Jan 23 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.3-1
- Fix capability allow rules when capabilities are specified in JSON file
- Add additional SELinux allow rules to base container template to allow container to read proc_type types.
* Fri Jan 04 2019 Lukas Vrabec <lvrabec@redhat.com> - 0.1.2-1
- Fix invalid syntax output when policy is using just one template
Resolves: #6
* Tue Oct 23 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.1.1-2
- Fix small issues in spec file like improve description and change files section.
* Mon Oct 22 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.1.1-1
- Add proper shebang to all source files
- Add License to all source files
* Sat Oct 13 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.1.0-1
- Add support for docker containers
* Mon Oct 08 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.5-1
- Update x_container template based on testing container related to Nvidia Cuda operations
* Mon Oct 08 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.4-2
- Build udica on Red Hat Enterprise Linux 7 with python version 2
* Mon Oct 08 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.4-1
- Add manpages
- Add support for communicating with libvirt daemon
- Add support for communicating with X server.
- Add support for read/write to the controlling terminal
* Sun Oct 07 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.3-1
- Remove required parameters -i or -j and added support for reading json file from stdin.
- Remove "-n" or "--name" parameter. Name of the container will be required for this tool
* Tue Sep 25 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.2-1
- Use subprocess.Popen instead of subprocess.run for inspecting to support also python2
* Thu Sep 20 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.1-3
- Update readme and setup.py files after migration to github
* Sun Sep 16 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.1-2
- Update LICENSE
- Improve %%files section
* Sun Sep 16 2018 Lukas Vrabec <lvrabec@redhat.com> - 0.0.1-1
- Initial build