Skip to content

Commit d8d0dcc

Browse files
authored
Merge pull request #86 from pebenito/4.4
Backport fixes for 4.4.2.
2 parents bec5c81 + 1ca3750 commit d8d0dcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+112
-181
lines changed

.github/workflows/tests.yml

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@ name: Build tests
33
on: [push, pull_request]
44

55
env:
6+
# This should be the minimum version required to run setools:
67
SELINUX_USERSPACE_VERSION: 3.2
78

9+
# GitHub doesn't support building env
10+
# vars from others in this block.
11+
USERSPACE_SRC: /tmp/selinux-src
12+
#SEPOL_SRC: ${USERSPACE_SRC}/libsepol
13+
SEPOL_SRC: /tmp/selinux-src/libsepol
14+
#LIBSEPOLA: ${SEPOL_SRC}/src/libsepol.a
15+
LIBSEPOLA: /tmp/selinux-src/libsepol/src/libsepol.a
16+
#SELINUX_SRC: ${USERSPACE_SRC}/libselinux
17+
SELINUX_SRC: /tmp/selinux-src/libselinux
18+
#CHECKPOLICY_SRC: ${USERSPACE_SRC}/checkpolicy
19+
CHECKPOLICY_SRC: /tmp/selinux-src/checkpolicy
20+
821
jobs:
922
build:
1023
runs-on: ubuntu-20.04
@@ -23,7 +36,8 @@ jobs:
2336
- {python: '3.6', tox: pep8}
2437
- {python: '3.6', tox: lint}
2538
- {python: '3.6', tox: mypy}
26-
#- {python: '3.6', tox: coverage}
39+
- {python: '3.6', tox: coverage}
40+
- {python: '3.6', tox: install}
2741

2842
steps:
2943
- uses: actions/checkout@v2
@@ -43,26 +57,20 @@ jobs:
4357
gettext \
4458
libaudit-dev \
4559
libbz2-dev \
46-
libpcre3-dev \
47-
python3-pip
60+
libpcre3-dev
4861
49-
sudo pip3 install \
50-
cython \
51-
setuptools \
62+
sudo python -m pip install -U \
5263
tox
5364
54-
- name: Configure environment
55-
run: |
56-
USERSPACE_SRC=/tmp/selinux-src
57-
SEPOL_SRC=${USERSPACE_SRC}/libsepol
58-
LIBSEPOLA=${SEPOL_SRC}/src/libsepol.a
59-
echo "USERSPACE_SRC=$USERSPACE_SRC" >> $GITHUB_ENV
60-
echo "SEPOL_SRC=${SEPOL_SRC}" >> $GITHUB_ENV
61-
echo "LIBSEPOLA=${LIBSEPOLA}" >> $GITHUB_ENV
62-
echo "SELINUX_SRC=${USERSPACE_SRC}/libselinux" >> $GITHUB_ENV
63-
echo "CHECKPOLICY_SRC=${USERSPACE_SRC}/checkpolicy" >> $GITHUB_ENV
65+
- name: Cache SELinux userspace
66+
uses: actions/cache@v3
67+
id: cache-userspace
68+
with:
69+
path: ${{ env.USERSPACE_SRC }}
70+
key: ${{ runner.os }}-selinux-userspace-${{ env.SELINUX_USERSPACE_VERSION }}
6471

65-
- name: Build toolchain
72+
- name: Build SELinux userspace
73+
if: ${{ steps.cache-userspace.outputs.cache-hit != 'true' }}
6674
run: |
6775
# Download current SELinux userspace tools and libraries
6876
git clone https://github.com/SELinuxProject/selinux.git ${USERSPACE_SRC} -b ${SELINUX_USERSPACE_VERSION}
@@ -72,14 +80,7 @@ jobs:
7280
make CFLAGS="-O2 -pipe -fPIC -Wall -I${SEPOL_SRC}/include" LDFLAGS="-L${SEPOL_SRC}/src" -C ${SELINUX_SRC}
7381
make CFLAGS="-O2 -pipe -fPIC -Wall -I${SEPOL_SRC}/include" -C ${CHECKPOLICY_SRC}
7482
75-
- name: Set up setools for CI build
76-
run: |
77-
sed -i \
78-
-e "/Wwrite-strings/s/,/, '-Wno-maybe-uninitialized',/" \
79-
-e "s/-Wno-cast-function-type/-Wno-missing-include-dirs/" \
80-
setup.py
81-
8283
- name: Run test
8384
run: |
8485
export LD_LIBRARY_PATH="${SEPOL_SRC}/src:${SELINUX_SRC}/src:${LD_LIBRARY_PATH}"
85-
tox -vv -e ${{ matrix.build-opts.tox }}
86+
tox -e ${{ matrix.build-opts.tox }}

.pylintrc

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ unsafe-load-any-extension=no
3030
# run arbitrary code
3131
extension-pkg-whitelist=setools.policyrep
3232

33-
# Allow optimization of some AST trees. This will activate a peephole AST
34-
# optimizer, which will apply various small optimizations. For instance, it can
35-
# be used to obtain the result of joining multiple strings with the addition
36-
# operator. Joining a lot of strings can lead to a maximum recursion error in
37-
# Pylint and this flag can prevent that. It has one side effect, the resulting
38-
# AST will be different than the one from reality.
39-
optimize-ast=no
40-
4133

4234
[MESSAGES CONTROL]
4335

@@ -69,11 +61,6 @@ disable=I,logging-format-interpolation,format,similarities
6961
# mypackage.mymodule.MyReporterClass.
7062
output-format=text
7163

72-
# Put messages in a separate file for each module / package specified on the
73-
# command line instead of printing them on stdout. Reports (if any) will be
74-
# written in a file name "pylint_global.[txt|html]".
75-
files-output=no
76-
7764
# Tells whether to display a full report or only the messages
7865
reports=no
7966

@@ -110,21 +97,12 @@ include-naming-hint=no
11097
# Regular expression matching correct constant names
11198
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
11299

113-
# Naming hint for constant names
114-
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
115-
116100
# Regular expression matching correct method names
117101
method-rgx=[a-z_][a-z0-9_]{2,30}$
118102

119-
# Naming hint for method names
120-
method-name-hint=[a-z_][a-z0-9_]{2,30}$
121-
122103
# Regular expression matching correct function names
123104
function-rgx=[a-z_][a-z0-9_]{2,30}$
124105

125-
# Naming hint for function names
126-
function-name-hint=[a-z_][a-z0-9_]{2,30}$
127-
128106
# Regular expression matching correct class attribute names
129107
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
130108

@@ -134,39 +112,21 @@ class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
134112
# Regular expression matching correct attribute names
135113
attr-rgx=[a-z_][a-z0-9_]{2,30}$
136114

137-
# Naming hint for attribute names
138-
attr-name-hint=[a-z_][a-z0-9_]{2,30}$
139-
140115
# Regular expression matching correct class names
141116
class-rgx=[A-Z_][a-zA-Z0-9]+$
142117

143-
# Naming hint for class names
144-
class-name-hint=[A-Z_][a-zA-Z0-9]+$
145-
146118
# Regular expression matching correct module names
147119
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
148120

149-
# Naming hint for module names
150-
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
151-
152121
# Regular expression matching correct inline iteration names
153122
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
154123

155-
# Naming hint for inline iteration names
156-
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
157-
158124
# Regular expression matching correct argument names
159125
argument-rgx=[a-z_][a-z0-9_]{2,30}$
160126

161-
# Naming hint for argument names
162-
argument-name-hint=[a-z_][a-z0-9_]{2,30}$
163-
164127
# Regular expression matching correct variable names
165128
variable-rgx=[a-z_][a-z0-9_]{2,30}$
166129

167-
# Naming hint for variable names
168-
variable-name-hint=[a-z_][a-z0-9_]{2,30}$
169-
170130
# Regular expression which should only match function or class names that do
171131
# not require a docstring.
172132
no-docstring-rgx=^_
@@ -224,12 +184,6 @@ ignore-long-lines=^\s*(# )?<?https?://\S+>?$
224184
# else.
225185
single-line-if-stmt=no
226186

227-
# List of optional constructs for which whitespace checking is disabled. `dict-
228-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
229-
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
230-
# `empty-line` allows space-only lines.
231-
no-space-check=trailing-comma,dict-separator
232-
233187
# Maximum number of lines in a module
234188
max-module-lines=1000
235189

@@ -375,4 +329,4 @@ exclude-protected=_asdict,_fields,_replace,_source,_make
375329

376330
# Exceptions that will emit a warning when being caught. Defaults to
377331
# "Exception"
378-
overgeneral-exceptions=Exception
332+
overgeneral-exceptions=builtins.Exception

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
*setools-4-4.2 (19 Apr 2023)
2+
3+
* Make NetworkX optional. sedta and seinfoflow tools, along with the
4+
equivalent analyses in apol require NetworkX.
5+
* Changed unit test runner to pytest, as setuptools' test command is
6+
deprecated.
7+
* Remove neverallow options in sesearch and apol. These are not usable
8+
since they are removed in the final binary policy.
9+
* Unit tests and CI tests improvements.
10+
111
*setools-4.4.1 (6 Feb 2023)
212

313
* Replace deprecated NetworkX function use in information flow and domain

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ addition to the development packages from the above list:
3131

3232
To run SETools unit tests, the following packages are required, in
3333
addition to the above dependencies:
34+
* pytest
3435
* tox (optional)
3536

3637
### Obtaining SETools
@@ -129,9 +130,11 @@ for up-to-date information on build and install options, respectively.
129130

130131
One goal for SETools is to provide confidence in the validity of the
131132
output for the tools. The unit tests for SETools can be run with
132-
the following command
133+
the following commands:
134+
133135
```
134-
$ python setup.py test
136+
$ python setup.py build_ext -i
137+
$ pytest tests
135138
```
136139

137140
## Features

man/ru/sesearch.1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,12 @@ sesearch \- утилита опроса политики SELinux
3535
Найти правила включения журналирования событий.
3636
.IP "--dontaudit"
3737
Найти правила запрета журналирования событий.
38-
.IP "--neverallow"
39-
Найти запрещающие правила.
4038
.IP "--allowxperm"
4139
Найти расширенные разрешительные правила.
4240
.IP "--auditallowxperm"
4341
Найти расширенные правила включения журналирования событий.
4442
.IP "--dontauditxperm"
4543
Найти расширенные правила запрета журналирования событий.
46-
.IP "--neverallowxperm"
47-
Найти расширенные запрещающие правила.
4844
.IP "-T, --type_trans"
4945
Найти правила перехода типов.
5046
.IP "--type_member"

man/sesearch.1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,12 @@ Find allow rules.
3030
Find auditallow rules.
3131
.IP "--dontaudit"
3232
Find dontaudit rules.
33-
.IP "--neverallow"
34-
Find neverallow rules.
3533
.IP "--allowxperm"
3634
Find allowxperm rules.
3735
.IP "--auditallowxperm"
3836
Find auditallowxperm rules.
3937
.IP "--dontauditxperm"
4038
Find dontauditxperm rules.
41-
.IP "--neverallowxperm"
42-
Find neverallowxperm rules.
4339
.IP "-T, --type_trans"
4440
Find type_transition rules.
4541
.IP "--type_member"

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[build-system]
22
requires = ["setuptools", "Cython>=0.27"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.pytest.ini_options]
6+
addopts = ["--import-mode=importlib",]
7+
pythonpath = "."

sesearch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ rtypes.add_argument("--dontaudit", action="append_const",
4141
rtypes.add_argument("--dontauditxperm", action="append_const",
4242
const=setools.TERuletype.dontauditxperm, dest="tertypes",
4343
help="Search dontauditxperm rules.")
44-
rtypes.add_argument("--neverallow", action="append_const",
45-
const=setools.TERuletype.neverallow, dest="tertypes",
46-
help="Search neverallow rules.")
47-
rtypes.add_argument("--neverallowxperm", action="append_const",
48-
const=setools.TERuletype.neverallowxperm, dest="tertypes",
49-
help="Search neverallowxperm rules.")
44+
# rtypes.add_argument("--neverallow", action="append_const",
45+
# const=setools.TERuletype.neverallow, dest="tertypes",
46+
# help="Search neverallow rules.")
47+
# rtypes.add_argument("--neverallowxperm", action="append_const",
48+
# const=setools.TERuletype.neverallowxperm, dest="tertypes",
49+
# help="Search neverallowxperm rules.")
5050
rtypes.add_argument("-T", "--type_trans", action="append_const",
5151
const=setools.TERuletype.type_transition, dest="tertypes",
5252
help="Search type_transition rules.")

setools/diff/typing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
from typing import DefaultDict, Dict, List, Optional, TypeVar
44

5-
from ..policyrep import PolicyObject, SELinuxPolicy
5+
from ..policyrep import PolicyEnum, PolicyObject, SELinuxPolicy
66

77
from .difference import Wrapper, SymbolWrapper
88

@@ -12,4 +12,5 @@
1212
Cache = DefaultDict[SELinuxPolicy, Dict[T, U]]
1313
SymbolCache = Cache[T, SymbolWrapper[T]]
1414

15-
RuleList = Optional[DefaultDict[T, List[U]]]
15+
E = TypeVar("E", bound=PolicyEnum)
16+
RuleList = Optional[DefaultDict[E, List[T]]]

setools/dta.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
from contextlib import suppress
1111
from typing import DefaultDict, Iterable, List, NamedTuple, Optional, Union
1212

13-
import networkx as nx
14-
from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound
13+
try:
14+
import networkx as nx
15+
from networkx.exception import NetworkXError, NetworkXNoPath, NodeNotFound
16+
except ImportError:
17+
logging.getLogger(__name__).debug("NetworkX failed to import.")
1518

1619
from .descriptors import EdgeAttrDict, EdgeAttrList
1720
from .policyrep import AnyTERule, SELinuxPolicy, TERuletype, Type
@@ -73,8 +76,15 @@ def __init__(self, policy: SELinuxPolicy, reverse: bool = False,
7376
self.reverse = reverse
7477
self.rebuildgraph = True
7578
self.rebuildsubgraph = True
76-
self.G = nx.DiGraph()
77-
self.subG = self.G.copy()
79+
80+
try:
81+
self.G = nx.DiGraph()
82+
self.subG = self.G.copy()
83+
except NameError:
84+
self.log.critical("NetworkX is not available. This is "
85+
"requried for Domain Transition Analysis.")
86+
self.log.critical("This is typically in the python3-networkx package.")
87+
raise
7888

7989
@property
8090
def reverse(self) -> bool:

0 commit comments

Comments
 (0)