-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP - DO NOT MERGE - Allow users to ignore errors when removing built-in policy #122
WIP - DO NOT MERGE - Allow users to ignore errors when removing built-in policy #122
Conversation
This will help us greatly simplify the code in the logging role (and probably several other roles where we want to use the selinux role) see https://github.com/linux-system-roles/logging/pull/292/files#diff-86218b7c9c831a3bdd5513a24d268f2701a9d814094c4dd9b6219e58d8a04d92R303 |
fbb14ce
to
26a848d
Compare
[citest] |
1 similar comment
[citest] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
I verified that we could get rid of this extra treatment for the selinux custom ports by applying this pr.
https://github.com/linux-system-roles/logging/pull/292/files#diff-d3f39b8ac347ef1e1b1de226be985fa4c3e9350f7d86bee8711513c587dedefa
Thanks, @richm.
[citest pending] |
Are the failures like this https://dl.fedoraproject.org/pub/alt/linuxsystemroles/logs/lsr-citool_selinux-122-26a848d_RHEL-9.1.0-20220824.0_20220825-025015/artifacts/tests_port-FAILED.log will be solved when this pr gluetool-modules mr/187 is moved to the production? |
Could you please explain what exactly does logging role when it tries to remove default mapping? Have you considered locales?
|
Yes. This is because we don't have support for collection-requirements.yml |
@nhosoi can you provide some explanation/examples?
Ok - so my approach won't work. I don't suppose there is a unique numeric exit code in this situation . . . if not, then another way is - the role creates a list of local changes, and if the policy passed to seport is not a local change, it will be skipped if the flag is set. |
@bachradsusi The problem is that the selinux role allows you to do For example - I am setting up logging across rhel7, rhel8, rhel9, and fedora systems. All I know is that the syslog listener port must be allowed in policy with |
This is exactly what I ran into while I was working on linux-system-roles/logging#292 (and still am working on...) To workaround the failure with |
seport module checks whether there's existing mapping to the same type, port and protocol and if it's already defined it skips it - https://github.com/ansible-collections/community.general/blob/8e59e5252506aeeccb6ca5cfe38662df2f66fb23/plugins/modules/system/seport.py#L201 If the role didn't use seport it could do steps similar to the following steps in shell:
The question is whether we want to update selinux role to stop using seport module or whether logging role should implement this on its own and don't use selinux role just for port mappings. |
I'd say that the behavior of seport is correct. If it didn't skip already existing mappings and added local modifications then next run with 'absent' would remove just the local modification and left the policy default without warning users that the mapping still exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@bachradsusi Here is the problem: Note that you can replace "deploy logging" with "deploy X" where "X" is one of our 20 system roles that may want to use the selinux role to configure selinux policy for ports, and you can replace "
I think this should be done in the selinux role. In addition - I would strongly prefer not to break the existing role API
That's why I'm proposing a parameter that tells the selinux role "I'm removing the label for this port, but it may be a built-in policy, so please ignore it" |
Starting with the logging role, I continue working on the project to use the selinux role in the roles belonging to the linux-system-roles. So far, |
fcc5fcb
to
ec518d8
Compare
This implementation works by first getting the list of local policy modifications in the usual output form:
(NOTE: The above are built-in policy, just for illustration purposes)
For example, the - setype: i18n_input_port_t
state: absent
proto: tcp
ports: 9010
- setype: i18n_input_port_t
state: absent
proto: tcp
ports: "9010"
- setype: i18n_input_port_t
state: absent
ports: 9010
- setype: i18n_input_port_t
state: absent
ports: "9010" this is so that we can match any of the 4 possible ways the user might specify to remove this port. Then, if This implementation is quite complex, but it has the benefit of not relying on the l10n output of I'm open to suggestions about how to otherwise implement this. |
[citest] |
ec518d8
to
f6ac462
Compare
[citest] |
I guess it's too early to start reviewing(?); FYI, with the current pr, this including the selinux role in the logging role works nicely. :)
|
If you find a problem in my code, please comment
Good to know - thanks!
|
[citest] |
3 similar comments
[citest] |
[citest] |
[citest] |
If you attempt to remove built-in policy, you will get an error like this: ``` Port tcp/NNNN is defined in policy, cannot be deleted ``` If you want to have the role ignore errors like this, use `selinux_ignore_builtin_removal: true`
9160652
to
b673553
Compare
[citest] |
Another option - have a state include_role:
name: linux-system-roles.selinux
vars:
selinux_ports:
- { ports: 2049, setype: 'nfs_port_t', state: 'default' } then the role would do the following:
Not sure if |
The rhel-6/ansible 2.9 failure is due to reboot taking too long - I guess it is trying to relabel the filesystem during boot? The timeout is 300 seconds, and the previous reboot takes 245 seconds - I'm guessing 300 seconds is just on the edge of the time, and sometimes it takes a little longer than that. I guess we'll need a PR to change that to 360 or 420? |
I like the idea. I'd think it's more secure compared to ignoring the specific error. And +1 to |
At the moment selinux role does not use
In shell
What about other way around: A calling role knows that it could want to remove the mapping it requests, so it say that it wants add new port mappings (instead of just checking that the mapping is present), e.g. I think that the code for this would be much simpler than the analysis of local modification in the current proposal. |
Yes, I know. I have looked at the module source code too. What I'm saying is that we cannot change the behavior, the semantics, of the selinux role - that would break the role API.
. . . and would break the role API if we changed the role to use this.
Yes. Use cases:
Ok - I'll work on a PoC implementation |
There's still logical problem with absent for builtin ports - after added and absent the port will be still present so users would really have know what this mean and how to use it correctly. How hard is the requirement to use selinux role for use case 1. and 2.? For me it feels like the role is not the proper tool for incremental changing of SELinux policy even though it somehow supports it. And for other roles it would not be harder to use directly seport module as it uses same parameters - https://github.com/linux-system-roles/selinux/blob/master/tasks/main.yml#L90 |
Right. Initially, it would when using the selinux role from other system roles, so we would definitely know how to use it correctly. Essentially, we would use
|
Another issue with
ok
ok
ERROR: ValueError: Port tcp/1234 is defined in policy, cannot be deleted This is another reason why the |
Proposal: add When
Also bachradsusi@7e8dd1f#diff-2724eed26cf6ff821e08cad7c68bd4a3d9c274ddd7153cc1971ea1d446e26b3eR56
If this is acceptable solution, the |
The same concept but as a local module instead of script - master...bachradsusi:linux-system-roles-selinux:seport_local The difference between ansible collection seport and local seport is available at ansible-collections/community.general@main...bachradsusi:ansible-collections-community.general:seport-local |
ansible collection seport PR - ansible-collections/community.general#5203 |
This works for me - please submit a PR for this, and I will either drop or amend my PR |
closing in favor of #124 |
If you attempt to remove built-in policy, you will get an error like this:
If you want to have the role ignore errors like this, use
selinux_ignore_builtin_removal: true