Compare commits
No commits in common. "stream-container-tools-4.0-rhel-8.9.0" and "c8-stream-2.0" have entirely different histories.
stream-con
...
c8-stream-
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1 @@
|
||||
/*.tar.*
|
||||
SOURCES/v0.2.1.tar.gz
|
||||
|
1
.udica.metadata
Normal file
1
.udica.metadata
Normal file
@ -0,0 +1 @@
|
||||
4040bc2746225acabf5c7038d8eb38ae2de30ac2 SOURCES/v0.2.1.tar.gz
|
@ -1,133 +0,0 @@
|
||||
From dd05dbe742384dd22f4a63889c56cb75e4e2f571 Mon Sep 17 00:00:00 2001
|
||||
From: Vit Mojzis <vmojzis@redhat.com>
|
||||
Date: Tue, 9 Nov 2021 18:04:39 +0100
|
||||
Subject: [PATCH] Make sure each section of the inspect exists before accessing
|
||||
|
||||
Fixes: https://github.com/containers/udica/issues/105,
|
||||
https://github.com/containers/udica/issues/103
|
||||
|
||||
Inspired by:
|
||||
https://github.com/WellIDKRealy/udica/commit/0c56d98b8c58a8a4ceb89b04d700c834c13778fd
|
||||
|
||||
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
|
||||
---
|
||||
udica/parse.py | 62 ++++++++++++++++++++++++++++++++++++++------------
|
||||
1 file changed, 48 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/udica/parse.py b/udica/parse.py
|
||||
index 0797095..59b3dc5 100644
|
||||
--- a/udica/parse.py
|
||||
+++ b/udica/parse.py
|
||||
@@ -29,6 +29,24 @@ ENGINE_DOCKER = "docker"
|
||||
ENGINE_ALL = [ENGINE_PODMAN, ENGINE_CRIO, ENGINE_DOCKER]
|
||||
|
||||
|
||||
+# Decorator for verifying that getting value from "data" won't
|
||||
+# result in Key error or Type error
|
||||
+# e.g. in data[0]["HostConfig"]["Devices"]
|
||||
+# missing "HostConfig" key in data[0] produces KeyError and
|
||||
+# data[0]["HostConfig"] == none produces TypeError
|
||||
+def getter_decorator(function):
|
||||
+ # Verify that each element in path exists and return the corresponding value,
|
||||
+ # otherwise return [] -- can be safely processed by iterators
|
||||
+ def wrapper(self, data, *args):
|
||||
+ try:
|
||||
+ value = function(self, data, *args)
|
||||
+ return value if value else []
|
||||
+ except (KeyError, TypeError):
|
||||
+ return []
|
||||
+
|
||||
+ return wrapper
|
||||
+
|
||||
+
|
||||
def json_is_podman_or_docker_format(json_rep):
|
||||
"""Check if the inspected file is in a format from docker or podman.
|
||||
|
||||
@@ -91,19 +109,22 @@ class EngineHelper(abc.ABC):
|
||||
|
||||
def get_caps(self, data, opts):
|
||||
if opts["Caps"]:
|
||||
- if opts["Caps"] == "None":
|
||||
+ if opts["Caps"] in ["None", "none"]:
|
||||
return []
|
||||
return opts["Caps"].split(",")
|
||||
return []
|
||||
|
||||
|
||||
class PodmanDockerHelper(EngineHelper):
|
||||
+ @getter_decorator
|
||||
def get_devices(self, data):
|
||||
return data[0]["HostConfig"]["Devices"]
|
||||
|
||||
+ @getter_decorator
|
||||
def get_mounts(self, data):
|
||||
return data[0]["Mounts"]
|
||||
|
||||
+ @getter_decorator
|
||||
def get_ports(self, data):
|
||||
ports = []
|
||||
for key, value in data[0]["NetworkSettings"]["Ports"].items():
|
||||
@@ -120,8 +141,13 @@ class PodmanHelper(PodmanDockerHelper):
|
||||
def __init__(self):
|
||||
super().__init__(ENGINE_PODMAN)
|
||||
|
||||
+ @getter_decorator
|
||||
def get_caps(self, data, opts):
|
||||
- if not opts["Caps"]:
|
||||
+ if opts["Caps"]:
|
||||
+ return (
|
||||
+ opts["Caps"].split(",") if opts["Caps"] not in ["None", "none"] else []
|
||||
+ )
|
||||
+ else:
|
||||
return data[0]["EffectiveCaps"]
|
||||
return []
|
||||
|
||||
@@ -138,18 +164,25 @@ class DockerHelper(PodmanDockerHelper):
|
||||
def adjust_json_from_docker(self, json_rep):
|
||||
"""If the json comes from a docker call, we need to adjust it to make use
|
||||
of it."""
|
||||
-
|
||||
- if not isinstance(json_rep[0]["NetworkSettings"]["Ports"], dict):
|
||||
- raise Exception(
|
||||
- "Error parsing docker engine inspection JSON structure, try to specify container engine using '--container-engine' parameter"
|
||||
- )
|
||||
-
|
||||
- for item in json_rep[0]["Mounts"]:
|
||||
- item["source"] = item["Source"]
|
||||
- if item["Mode"] == "rw":
|
||||
- item["options"] = "rw"
|
||||
- if item["Mode"] == "ro":
|
||||
- item["options"] = "ro"
|
||||
+ try:
|
||||
+ if not isinstance(json_rep[0]["NetworkSettings"]["Ports"], dict):
|
||||
+ raise Exception(
|
||||
+ "Error parsing docker engine inspection JSON structure, try to specify container engine using '--container-engine' parameter"
|
||||
+ )
|
||||
+ except (KeyError, TypeError):
|
||||
+ # "Ports" not specified in given json file
|
||||
+ pass
|
||||
+
|
||||
+ try:
|
||||
+ for item in json_rep[0]["Mounts"]:
|
||||
+ item["source"] = item["Source"]
|
||||
+ if item["Mode"] == "rw":
|
||||
+ item["options"] = "rw"
|
||||
+ if item["Mode"] == "ro":
|
||||
+ item["options"] = "ro"
|
||||
+ except (KeyError, TypeError):
|
||||
+ # "Mounts" not specified in given json file
|
||||
+ pass
|
||||
|
||||
|
||||
class CrioHelper(EngineHelper):
|
||||
@@ -161,6 +194,7 @@ class CrioHelper(EngineHelper):
|
||||
# bind mounting device on the container
|
||||
return []
|
||||
|
||||
+ @getter_decorator
|
||||
def get_mounts(self, data):
|
||||
return data["status"]["mounts"]
|
||||
|
||||
--
|
||||
2.30.2
|
||||
|
@ -1,9 +1,8 @@
|
||||
Summary: A tool for generating SELinux security policies for containers
|
||||
Name: udica
|
||||
Version: 0.2.6
|
||||
Release: 4%{?dist}
|
||||
Version: 0.2.1
|
||||
Release: 2%{?dist}
|
||||
Source0: https://github.com/containers/udica/archive/v%{version}.tar.gz
|
||||
Patch0: 0001-Make-sure-each-section-of-the-inspect-exists-before-.patch
|
||||
License: GPLv3+
|
||||
BuildArch: noarch
|
||||
Url: https://github.com/containers/udica
|
||||
@ -14,15 +13,13 @@ Requires: python3 python3-libsemanage python3-libselinux
|
||||
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
|
||||
%setup -q
|
||||
|
||||
%build
|
||||
%if 0%{?fedora} || 0%{?rhel} > 7
|
||||
@ -32,6 +29,8 @@ inspection of container JSON file.
|
||||
%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
|
||||
@ -46,7 +45,9 @@ install -m 0644 udica/man/man8/udica.8 %{buildroot}%{_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
|
||||
@ -59,48 +60,6 @@ install -m 0644 udica/man/man8/udica.8 %{buildroot}%{_mandir}/man8/udica.8
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Tue Mar 14 2023 Jindrich Novy <jnovy@redhat.com> - 0.2.6-4
|
||||
- sync with stream-container-tools-4.0-rhel-8.8.0
|
||||
- Related: #2176055
|
||||
|
||||
* Wed Dec 01 2021 Vit Mojzis <vmojzis@redhat.com> - 0.2.6-3
|
||||
- Make sure each section of the inspect exists before accessing (#2027662)
|
||||
|
||||
* Tue Sep 21 2021 Vit Mojzis <vmojzis@redhat.com> - 0.2.6-2
|
||||
- Require container-selinux shipping policy templates (#2005866)
|
||||
|
||||
* Fri Sep 17 2021 Jindrich Novy <jnovy@redhat.com> - 0.2.6-1
|
||||
- update to https://github.com/containers/udica/releases/tag/v0.2.6
|
||||
- Related: #2001445
|
||||
|
||||
* Fri Aug 27 2021 Jindrich Novy <jnovy@redhat.com> - 0.2.5-2
|
||||
- New rebase https://github.com/containers/udica/releases/tag/v0.2.5 (#1995041)
|
||||
- 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
|
||||
- Related: #1934415
|
||||
|
||||
* Thu Aug 26 2021 Jindrich Novy <jnovy@redhat.com> - 0.2.5-1
|
||||
- update to https://github.com/containers/udica/releases/tag/v0.2.5
|
||||
- Related: #1934415
|
||||
|
||||
* Tue Jun 15 2021 Jindrich Novy <jnovy@redhat.com> - 0.2.4-2
|
||||
- remove %%check again and all related BRs
|
||||
- Related: #1934415
|
||||
|
||||
* Thu Nov 26 2020 Jindrich Novy <jnovy@redhat.com> - 0.2.4-1
|
||||
- update to https://github.com/containers/udica/releases/tag/v0.2.4
|
||||
- Related: #1883490
|
||||
|
||||
* Wed Oct 21 2020 Jindrich Novy <jnovy@redhat.com> - 0.2.3-1
|
||||
- synchronize with stream-container-tools-rhel8
|
||||
- Related: #1883490
|
||||
|
||||
* Mon Aug 10 2020 Jindrich Novy <jnovy@redhat.com> - 0.2.2-1
|
||||
- https://github.com/containers/udica/releases/tag/v0.2.2
|
||||
- Related: #1821193
|
||||
|
||||
* Tue Nov 26 2019 Jindrich Novy <jnovy@redhat.com> - 0.2.1-2
|
||||
- initial import to container-tools 8.2.0
|
||||
- Related: RHELPLAN-25139
|
@ -1,9 +0,0 @@
|
||||
#recipients: mmalik
|
||||
--- !Policy
|
||||
product_versions:
|
||||
- rhel-8
|
||||
decision_context: osci_compose_gate
|
||||
rules:
|
||||
- !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}
|
||||
- !PassingTestCaseRule {test_case_name: baseos-ci.brew-build.tier1.functional}
|
||||
|
1
sources
1
sources
@ -1 +0,0 @@
|
||||
SHA512 (v0.2.6.tar.gz) = 29295c9d95ecb15aed7e226d92a0b838046cf607e98956c66a83ad0f4ddf58b255586c24d407216ae9ddf5b11f502ae2b3a6822208d8dc8141124e68dac19265
|
@ -1,22 +0,0 @@
|
||||
- hosts: localhost
|
||||
tags:
|
||||
- classic
|
||||
- container
|
||||
roles:
|
||||
- role: standard-test-source
|
||||
|
||||
- role: standard-test-basic
|
||||
required_packages:
|
||||
- make
|
||||
- python3
|
||||
- udica
|
||||
tests:
|
||||
- build_test:
|
||||
dir: ./source
|
||||
run: make
|
||||
- smoke:
|
||||
dir: ./source
|
||||
run: python3 -m unittest -v tests/test_unit.py
|
||||
- smoke2:
|
||||
dir: ./source
|
||||
run: python3 tests/test_integration.py
|
Loading…
Reference in New Issue
Block a user