1
1
Fork 0
mirror of https://github.com/containers/udica synced 2024-05-25 01:56:14 +02:00
Commit Graph

96 Commits

Author SHA1 Message Date
Vit Mojzis 131d228c6a confined: allow asynchronous I/O operations
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2024-03-04 12:59:53 +01:00
Vit Mojzis f411c14698 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>
2024-03-01 18:48:20 +01:00
Vit Mojzis 3cda61f9a5 Add option to generate custom policy for a confined user
Udica can now generate cil policy for a confined user using a list of
macros.
The macros are based on policy templates created by Patrik Končitý:
https://github.com/Koncpa/confined-users-policy

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2024-02-12 19:53:57 +01:00
Vit Mojzis b19842e937 udica-0.2.8
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2023-11-29 11:02:48 +01:00
Vit Mojzis 6a7382bead Fix generating policy for Crio mounts
Fix issue introduced by
Commit 7c7b9ad505
"Avoid duplicate rules for accessing  mounts and devices"
where policy rules for "read-only mounts" are not generated properly.

Adjust Crio basic test to incorporate a read only mount that is not
covered by a special case ("/home" is handled by "home_container" and
anything under "/var/lib/kubelet" is ignored).

Thanks https://github.com/arcardon (jamjcardona@sbcglobal.net) for
spotting this in the code.

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2023-04-20 13:17:24 +02:00
Chris Evich 5d6feb3a6c
Fix several lint findings
Signed-off-by: Chris Evich <cevich@redhat.com>
2023-03-29 15:34:28 -04:00
Vit Mojzis 34c0f13758 Rename --device-access to --devices
This makes parameters more consistent.
Also, describe the new parameter in man page.

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2022-10-20 16:50:15 +02:00
Martin Skøtt a2f0e4588e Syntax changes after running black
Signed-off-by: Martin Skøtt <martin@skoett.name>
2022-10-04 10:25:37 +02:00
Martin Skøtt a72b8fffc8 Add ---device--access option
Signed-off-by: Martin Skøtt <martin@skoett.name>
2022-10-04 10:25:37 +02:00
Vit Mojzis e7a4418143 udica-0.2.7
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2022-06-22 13:41:06 +02:00
Vit Mojzis 7c7b9ad505 Avoid duplicate rules for accessing mounts and devices
list_contexts may return duplicate contexts. This combined with multiple
mounts/devices that may share contexts leads to many duplicate allow
rules.

Example:
  tests/test_basic.podman.cil:8-11
  tests/test_basic.podman.cil:392-395
  duplicate RW mount permissions for var_spool_t

  tests/test_basic.podman.cil:28-31
  tests/test_basic.podman.cil:264-267
  tests/test_basic.podman.cil:304-307
  duplicate RW mount permissions for abrt_retrace_spool_t

This patch significantly reduces most test cil policies
e.g. test_basic.podman.cil 396 -> 253 lines
     test_basic.docker.cil 394 -> 254 lines

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2022-06-22 11:41:10 +02:00
Vit Mojzis d296573806 Improve containerd support
- Auto-detct containerd inspect files
- Use write_policy_for_podman_devices instead of a custom function
- Fix "path" to capabilities
- Fix issues reported by lint and black

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2022-06-22 11:41:10 +02:00
alegrey91 e5e919bebe feat: add devices and capabilities support for containerd engine
Signed-off-by: Alessio Greggi <ale_grey_91@hotmail.it>
2022-06-20 18:05:46 +02:00
alegrey91 696cea1e87 feat: add ports and mounts support for containerd engine
Signed-off-by: Alessio Greggi <ale_grey_91@hotmail.it>
2022-06-20 18:02:19 +02:00
Vit Mojzis 2e1f70537b Improve label collection for mounts and devices
Catch exception triggered by selabel_lookup when it encounters file
context definition containing "<<none>>"

Real label of given path may differ from what selable_lookup
(matchpathcon) returns. Udica should allow access to both.

Fixes:
        https://github.com/containers/udica/issues/98
        https://github.com/containers/udica/issues/109
2022-04-29 16:15:06 +02:00
Vit Mojzis dd05dbe742 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:
0c56d98b8c

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2021-11-11 18:05:23 +01:00
Vit Mojzis 2a352551b7 udica-0.2.6
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2021-09-13 16:36:48 +02:00
Vit Mojzis aa3561d4de Move policy templates to container-selinux repo
Move udica policy templates to container-selinux package so that
administrators can deploy udica-generated policies on OpenShift nodes
without installing udica everywhere.

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2021-09-13 16:21:41 +02:00
Vit Mojzis 09bf6b339f Update templates to work properly with new cil parser
Cil parser was recently updated to reject the following:
(block template1 (type t) )
(block template2 (blockinherit template1))
(block b (blockinherit template1) (blockinherit template2))

Re-declaration of type t
Previous declaration of type at /var/lib/selinux/targeted/tmp/modules/400/test/cil:1
Failed to copy block contents into blockinherit
Failed to resolve AST
semodule:  Failed!

Remove (blockinherit container) from all templates so that "process" and
"socket" are only defined once (by inheriting "container" block in the
generated policy).
All allow rules referencing "process" and "socket" now need to be
enclosed in an optional block.

While at it, unify indentation.

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2021-08-26 18:16:40 +02:00
Vit Mojzis aa2da32f11 Sort container inspect data
This should diminish differences between policies generated for the same
container (allow rules should be in the same order).

Fixes:  Two subsequent calls to Udica on the same container sometimes
        generate different policy files (functionally equivalent, but
        with different rule order). This issue makes it difficult to use
        udica for CI purposes.

        https://github.com/containers/udica/issues/84

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2021-08-25 12:26:02 +02:00
Lukas Vrabec f436537ba8 Enable udica to generate policies with fifo class
Udica generates SELinux security allow rules only for files,dirs and
sockets. Following commit adds also FIFO files.

The change required also to modify existing unit tests.

Fixes: #85
2021-08-25 12:12:22 +02:00
Lukas Vrabec c19810736c Internal change renaming variables for perms sets
The reason for the internal change is to improve readability of
permissions in udica code.

Several variables related to permissions sets renamed:
* dro -> dir_ro
* drw -> dir_rw
* fro -> file_ro
* frw -> file_rw
* sro -> socket_ro
* srw -> socket_rw
* devrw -> device_rw
2021-08-25 12:12:22 +02:00
Vit Mojzis 6e74f83e6a Replace capability dictionary with str.lower()
The "cap" dictionary didn't bring any value and needed to be updated
with new capabilities.

Fixes:
        Udica fails when container info contains CAP_PERFMON
        Couldn't create policy: 'PERFMON'
        Error: Process completed with exit code 4.

        https://github.com/containers/udica/issues/88

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2021-07-08 15:57:57 +02:00
Chris Evich 42b3eb339b Update F34beta -> F34
Also update automation library to resemble what's done in other
containers-org. repositories.

Lastly, a minor python change to satisfy the linter.

Signed-off-by: Chris Evich <cevich@redhat.com>
2021-05-05 17:35:16 +02:00
Lukas Vrabec 4a648346b5
Increase version number to 0.2.4
Match udica version in code with the upstream github release.
2020-12-13 11:49:51 +01:00
Lukas Vrabec 31bccb3100 Support '--device /dev/XXX' podman parameter
Commit adds functionality to generate allow rules when --device switch
is used for podman e.g: podman run --device /dev/tty0 fedora /bin/bash

The output policy should looks like:
(block devtest
    (blockinherit container)
    (allow process process ( capability ( audit_write chown dac_override fowner fsetid kill mknod net_bind_service net_raw setfcap setgid setpcap setuid sys_chroot )))

    (allow process tty_device_t ( blk_file ( getattr read write append ioctl lock open )))
    (allow process tty_device_t ( chr_file ( getattr read write append ioctl lock open )))
)

The feature is applicable for podman and docker engines, CRI-O uses
bind-mount solution.
2020-11-25 17:54:14 +01:00
Martin Bašti 0905fefe3d
Refactor to proper abstract class
EngineHelper is an abstract class and should be treated like abstract class using python stdlib tools

Note: `ABC` class available from py3.4

Signed-off-by: Martin Bašti <mbasti@redhat.com>
2020-10-19 17:27:24 +02:00
Martin Bašti d3832e082c Fix formatting to pass black check
Fixing to make CI green and allow PR merge

Signed-off-by: Martin Bašti <mbasti@redhat.com>
2020-10-19 17:21:29 +02:00
Jed Lejosne 808ec744a4 Make container types mcs-constrained
Signed-off-by: Jed Lejosne <jed@redhat.com>
2020-09-17 22:00:55 +02:00
Lukas Vrabec 2c3183d7da
Bump release 2020-08-13 17:25:39 +02:00
Lukas Vrabec 3678e2fe32 Enable container port, not the host port
Udica should allow container port in generated policy not the host port.

Resolves: #62
2020-08-13 17:13:59 +02:00
Juan Antonio Osorio Robles 00b166f417 Refactor engine-specific handling code to use classes
This is a small refactor that moves the if statements for
engine-specific cases in the parsing code to use classes instead.
2020-08-13 16:22:32 +02:00
Ondrej Mosnacek cb6ef7e09c Add --version command-line argument
Create a sub-module to store the version string and use it both in
setup.py (to set version in package metadata) and in __main__.py (to
implement the --version command-line argument).

Fixes: https://github.com/containers/udica/issues/66
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
2020-08-13 16:05:14 +02:00
Lukas Vrabec c56e91d16f
Update supported podman version
In repository readme file and manpages update the supported podman
version from v1.4 to v2.0
2020-08-03 18:45:16 +02:00
Lukas Vrabec d81afa9f1a Fix parsing ports from podman engine
Podman container engine version 2.0.2 introduced new change to generate inspection JSON
files same as docker container engine for exposed ports. Because of this change, also
udica requires some changes in parsing inspection JSON file.

Because of the change how podman and docker generates same structure
related to ports so there is no need to do adjustments.

Resolves: #60
2020-08-03 18:18:38 +02:00
Thorsten Scherf b690fb4235 Fix some formatting issues in udica man page 2020-06-29 14:50:24 +02:00
Steve Milner d56d6cf957 Use constants for engines
Replace copy/paste strings referencing container engines with
constants for reuse. These constants live under parse.

- ENGINE_PODMAN: Constant for the podman engine
- ENGINE_CRIO: Constant for the cri-o engine
- ENGINE_DOCKER: Constant for the docker engine
- ENGINE_ALL: All supported engines

Signed-off-by: Steve Milner <smilner@redhat.com>
2020-05-15 21:23:04 +02:00
Lukas Vrabec bf6df45366 Update permission set for generated rules
Udica doesn't add permissions "setattr, rmdir" for dir class and
permissions "rename, setattr, unlink" for file class, for generated
rules when the block(template) is not defined. This cause
troubles when whole dirs are bind-mounted to the container space like "/var/lib/mysql".

Commit adding missing permissions to both classes and listing all
classes in alphabetical order.

"Basic" part of tests was regenerated due to the change
2020-04-25 13:10:17 +02:00
Lukas Vrabec b406f782c5
sctp socket support
The net_container template is updated, when restricted_net_container block
is used, container could also create and use sctp sockets.

Also when container exposes sctp sockets, udica will identify it and
generate policy where only sctp communication is allowed.
2019-11-11 13:00:08 +01:00
Lukas Vrabec b5fd92d03f
New feature: parameter "--container-engine"
Following commit adds new parameter for to specify which container
engine is used for inspecting container.

Example:
        # udica --container-engine podman -j my_container.json my_container
        ...

        # udica -e docker -j my_container.json my_container
        ...

In some situations udica fails to identify which engine is used,
therefore this parameter has to be used.

Commit includes also test for the feature.
2019-10-25 19:58:16 +02:00
Lukas Vrabec 57f661a4c6
Update json_is_podman_format() function
json_is_podman_format() returns true if inspection json file is list and
contains environment variable "container" set to "podman".

Several containers (e.g: ubi8[1]) container sets this env variable to
"oci" instead of "podman". This commit improves json_is_podman_format()
function to allow generate SELinux policy also when the variable is set
to "oci".

Part of the fix are also 2 new test cases testing ubi8 images

[1] https://access.redhat.com/containers/#/registry.access.redhat.com/ubi8
2019-10-25 17:34:17 +02:00
Lukas Vrabec cdf857ab6b
Make udica code compliant to the PEP-8 style.
Fix formatting on all python source code files to follow PEP-8 code
style.
https://www.python.org/dev/peps/pep-0008/
2019-10-16 12:28:12 +02:00
Juan Antonio Osorio Robles 9e382480ff Fix unused imports
These imports were reported by pyflakes.
2019-09-25 10:01:07 +02:00
Juan Antonio Osorio Robles 6c7a3929ed udica/policy.py: Remove unused imports
Some of the imports in udica/policy.py weren't used. This cleans them
up.
2019-09-24 10:21:49 +02:00
Lukas Vrabec dd018188e1
Update man pages and README because of CRI support
- Added CRI-O to supported container engines in man pages and README
file

- Added new paragraph to README file about running udica in OpenShift
2019-09-24 10:10:00 +02:00
Lukas Vrabec bdd18b7c60
Fix gen. policy when no template is used in CRI
This commit fixes the issue when udica generates wrong SELinux policy when no
template is used and moutpoint is mounted as readonly. Final policy
contained also write permission.

Fix is just improved if statement, when udica looks how a mountpoint is
mounted to the container.
2019-09-23 20:26:37 +02:00
Juan Antonio Osorio Robles f993f9e218 Initial CRI-O support
This takes modifies udica to also take the "inspect" format that crictl
gives out, and not only the docker/podman one.

Note that in this implementation, only the json file works; support for
parsing the input from the crictl command will come in a separate PR.
2019-09-23 20:02:05 +02:00
Juan Antonio Osorio Robles db10deb2c3 Improve permission set for log_container template
For the log_rw_container it wasn't possible to create new files, which
is something that's normally required. So we're adding this
capability, while still not allowing that container to rename that
directory or remove files from it as a security measure.

The audit_log_t file was also modified to be more restrictive for the
log_rw_container block, so we only allow reads now. However, the write
capability was left for the log_manage_container block.
2019-09-18 21:46:05 +02:00
Lukas Vrabec aa30540f51
Document supported container engine versions
Update README.md and man page of udica to document supported version of
container engines.

Resolves: #43
2019-09-18 21:42:18 +02:00
Lukas Vrabec 5c9c21dcb7 New feature: Cross Container Communication
This feature allows specify container communication using stream sockets.

Communication is specified via new parameter "--stream-connect".
Feature example:

    Create containerA:
    # udica -j containerA.json containerA

    Create containerB which could stream connect to containerA:
    # udica -j containerB.json --stream-connect containerA containerB

Now, containerB contains following additional rules and communicate with
containerA via stream socket:
    allow containerB.process containerA.process:unix_stream_socket connectto;
    allow containerB.process containerA.socket ( sock_file ( getattr write open append )))

This feature also add new object to base container template for creating
socket file under every container namespace. e.g: my_container.socket,
network_container.socket.
2019-08-13 10:32:51 +02:00