mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Make use of single configuration point for SELinux
For now, FreeIPA supports SELinux things as they are in RedHat/Fedora. But different distributions may have their own SELinux customizations. This moves SELinux configuration out to platform constants: - SELINUX_MCS_MAX - SELINUX_MCS_REGEX - SELINUX_MLS_MAX - SELINUX_MLS_REGEX - SELINUX_USER_REGEX - SELINUX_USERMAP_DEFAULT - SELINUX_USERMAP_ORDER and applies corresponding changes to the test code. Fixes: https://pagure.io/freeipa/issue/7996 Signed-off-by: Stanislav Levin <slev@altlinux.org> Reviewed-By: Rob Crittenden <rcritten@redhat.com> Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
committed by
Alexander Bokovoy
parent
215e8f768c
commit
b2acd65013
@@ -59,6 +59,7 @@ class TestWinsyncMigrate(IntegrationTest):
|
||||
ipa_group = 'ipa_group'
|
||||
ad_user = 'testuser'
|
||||
default_shell = platformconstants.DEFAULT_SHELL
|
||||
selinuxuser = platformconstants.SELINUX_USERMAP_ORDER.split("$$")[0]
|
||||
test_role = 'test_role'
|
||||
test_hbac_rule = 'test_hbac_rule'
|
||||
test_selinux_map = 'test_selinux_map'
|
||||
@@ -102,7 +103,7 @@ class TestWinsyncMigrate(IntegrationTest):
|
||||
cls.master.run_command(['ipa', 'hbacrule-add', cls.test_hbac_rule])
|
||||
cls.master.run_command([
|
||||
'ipa', 'selinuxusermap-add', cls.test_selinux_map,
|
||||
'--selinuxuser', 'guest_u:s0'])
|
||||
'--selinuxuser', cls.selinuxuser])
|
||||
|
||||
@classmethod
|
||||
def setup_user_memberships(cls, user):
|
||||
|
||||
@@ -2,6 +2,19 @@
|
||||
# Copyright (C) 2018 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
|
||||
from ipaplatform.constants import constants as platformconstants
|
||||
|
||||
# for example, user_u:s0
|
||||
selinuxuser1 = platformconstants.SELINUX_USERMAP_ORDER.split("$$")[0]
|
||||
selinuxuser2 = platformconstants.SELINUX_USERMAP_ORDER.split("$$")[1]
|
||||
|
||||
selinux_mcs_max = platformconstants.SELINUX_MCS_MAX
|
||||
selinux_mls_max = platformconstants.SELINUX_MLS_MAX
|
||||
|
||||
second_mls_level = 's{}'.format(list(range(0, selinux_mls_max + 1))[0])
|
||||
second_mcs_level = 'c{}'.format(list(range(0, selinux_mcs_max + 1))[0])
|
||||
mcs_range = '{0}.{0}'.format(second_mcs_level)
|
||||
|
||||
ENTITY = 'selinuxusermap'
|
||||
|
||||
PKEY = 'itest-selinuxusermap'
|
||||
@@ -9,7 +22,7 @@ DATA = {
|
||||
'pkey': PKEY,
|
||||
'add': [
|
||||
('textbox', 'cn', PKEY),
|
||||
('textbox', 'ipaselinuxuser', 'user_u:s0'),
|
||||
('textbox', 'ipaselinuxuser', selinuxuser1),
|
||||
],
|
||||
'mod': [
|
||||
('textarea', 'description', 'itest-selinuxusermap desc'),
|
||||
@@ -21,7 +34,7 @@ DATA2 = {
|
||||
'pkey': PKEY2,
|
||||
'add': [
|
||||
('textbox', 'cn', PKEY2),
|
||||
('textbox', 'ipaselinuxuser', 'unconfined_u:s0-s0:c0.c1023'),
|
||||
('textbox', 'ipaselinuxuser', selinuxuser2),
|
||||
],
|
||||
'mod': [
|
||||
('textarea', 'description', 'itest-selinuxusermap desc2'),
|
||||
@@ -33,7 +46,7 @@ DATA_MLS_RANGE = {
|
||||
'pkey': PKEY_MLS_RANGE,
|
||||
'add': [
|
||||
('textbox', 'cn', PKEY_MLS_RANGE),
|
||||
('textbox', 'ipaselinuxuser', 'user_u:s0-s1'),
|
||||
('textbox', 'ipaselinuxuser', 'foo:s0-{}'.format(second_mls_level)),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -42,7 +55,9 @@ DATA_MCS_RANGE = {
|
||||
'pkey': PKEY_MCS_RANGE,
|
||||
'add': [
|
||||
('textbox', 'cn', PKEY_MCS_RANGE),
|
||||
('textbox', 'ipaselinuxuser', 'user_u:s0-s15:c0.c1023'),
|
||||
('textbox', 'ipaselinuxuser',
|
||||
'foo:s0-s{}:c0.c{}'.format(selinux_mls_max, selinux_mcs_max)
|
||||
),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -51,7 +66,10 @@ DATA_MCS_COMMAS = {
|
||||
'pkey': PKEY_MCS_COMMAS,
|
||||
'add': [
|
||||
('textbox', 'cn', PKEY_MCS_COMMAS),
|
||||
('textbox', 'ipaselinuxuser', 'user_u:s0-s1:c0,c2,c15.c26'),
|
||||
('textbox', 'ipaselinuxuser',
|
||||
'foo:s0-{}:c0,{},{}'.format(
|
||||
second_mls_level, second_mcs_level, mcs_range),
|
||||
),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -60,7 +78,9 @@ DATA_MLS_SINGLE_VAL = {
|
||||
'pkey': PKEY_MLS_SINGLE_VAL,
|
||||
'add': [
|
||||
('textbox', 'cn', PKEY_MLS_SINGLE_VAL),
|
||||
('textbox', 'ipaselinuxuser', 'user_u:s0-s0:c0.c1023'),
|
||||
('textbox', 'ipaselinuxuser',
|
||||
'foo:s0-s0:c0.c{}'.format(selinux_mcs_max)
|
||||
),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -69,7 +89,7 @@ DATA_NON_EXIST_SEUSER = {
|
||||
'pkey': PKEY_NON_EXIST_SEUSER,
|
||||
'add': [
|
||||
('textbox', 'cn', PKEY_NON_EXIST_SEUSER),
|
||||
('textbox', 'ipaselinuxuser', 'abc:s0'),
|
||||
('textbox', 'ipaselinuxuser', 'foo:s0'),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -78,7 +98,7 @@ DATA_INVALID_MCS = {
|
||||
'pkey': PKEY_INVALID_MCS,
|
||||
'add': [
|
||||
('textbox', 'cn', PKEY_INVALID_MCS),
|
||||
('textbox', 'ipaselinuxuser', 'user:s0:c'),
|
||||
('textbox', 'ipaselinuxuser', 'foo:s0:c'),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -87,7 +107,7 @@ DATA_INVALID_MLS = {
|
||||
'pkey': PKEY_INVALID_MLS,
|
||||
'add': [
|
||||
('textbox', 'cn', PKEY_INVALID_MLS),
|
||||
('textbox', 'ipaselinuxuser', 'user'),
|
||||
('textbox', 'ipaselinuxuser', 'foo'),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
SELinux user map tests
|
||||
"""
|
||||
|
||||
from ipaplatform.constants import constants as platformconstants
|
||||
from ipatests.test_webui.ui_driver import UI_driver
|
||||
from ipatests.test_webui.ui_driver import screenshot
|
||||
import ipatests.test_webui.data_user as user
|
||||
@@ -41,10 +42,14 @@ RULE_ALR_EXIST = 'SELinux User Map rule with name "{}" already exists'
|
||||
RULE_UPDATED = 'SELinux User Map {} updated'
|
||||
RULE_ADDED = 'SELinux User Map successfully added'
|
||||
INVALID_SEUSER = 'SELinux user {} not found in ordering list (in config)'
|
||||
INVALID_MCS = ("invalid 'selinuxuser': Invalid MCS value, must match c[0-1023]"
|
||||
".c[0-1023] and/or c[0-1023]-c[0-c0123]")
|
||||
INVALID_MLS = ("invalid 'selinuxuser': Invalid MLS value, must match "
|
||||
"s[0-15](-s[0-15])")
|
||||
INVALID_MCS = ("invalid 'selinuxuser': Invalid MCS value, must match {}, "
|
||||
"where max category {}").format(
|
||||
platformconstants.SELINUX_MCS_REGEX,
|
||||
platformconstants.SELINUX_MCS_MAX)
|
||||
INVALID_MLS = ("invalid 'selinuxuser': Invalid MLS value, must match {}, "
|
||||
"where max level {}").format(
|
||||
platformconstants.SELINUX_MLS_REGEX,
|
||||
platformconstants.SELINUX_MLS_MAX)
|
||||
HBAC_DEL_ERR = ('{} cannot be deleted because SELinux User Map {} requires '
|
||||
'it')
|
||||
HBAC_MEMBER_ERR = 'HBAC rule and local members cannot both be set'
|
||||
|
||||
@@ -23,6 +23,7 @@ Test the `ipaserver/plugins/config.py` module.
|
||||
"""
|
||||
|
||||
from ipalib import api, errors
|
||||
from ipaplatform.constants import constants as platformconstants
|
||||
from ipatests.test_xmlrpc.xmlrpc_test import Declarative
|
||||
import pytest
|
||||
|
||||
@@ -109,8 +110,11 @@ class test_config(Declarative):
|
||||
desc='Try to set invalid ipaselinuxusermapdefault',
|
||||
command=('config_mod', [],
|
||||
dict(ipaselinuxusermapdefault=u'foo')),
|
||||
expected=errors.ValidationError(name='ipaselinuxusermapdefault',
|
||||
error='Invalid MLS value, must match s[0-15](-s[0-15])'),
|
||||
expected=errors.ValidationError(
|
||||
name='ipaselinuxusermapdefault',
|
||||
error='Invalid MLS value, must match {}, where max level '
|
||||
'{}'.format(platformconstants.SELINUX_MLS_REGEX,
|
||||
platformconstants.SELINUX_MLS_MAX)),
|
||||
),
|
||||
|
||||
dict(
|
||||
@@ -140,10 +144,13 @@ class test_config(Declarative):
|
||||
dict(
|
||||
desc='Try to set invalid selinux user in ipaselinuxusermaporder',
|
||||
command=('config_mod', [],
|
||||
dict(ipaselinuxusermaporder=u'unconfined_u:s0-s0:c0.c1023$baduser$guest_u:s0')),
|
||||
expected=errors.ValidationError(name='ipaselinuxusermaporder',
|
||||
dict(ipaselinuxusermaporder=u'baduser')),
|
||||
expected=errors.ValidationError(
|
||||
name='ipaselinuxusermaporder',
|
||||
error='SELinux user \'baduser\' is not valid: Invalid MLS '
|
||||
'value, must match s[0-15](-s[0-15])'),
|
||||
'value, must match {}, where max level {}'.format(
|
||||
platformconstants.SELINUX_MLS_REGEX,
|
||||
platformconstants.SELINUX_MLS_MAX)),
|
||||
),
|
||||
|
||||
dict(
|
||||
@@ -151,9 +158,7 @@ class test_config(Declarative):
|
||||
command=(
|
||||
'config_mod', [],
|
||||
dict(
|
||||
ipaselinuxusermaporder=u'xguest_u:s0$guest_u:s0'
|
||||
u'$user_u:s0-s0:c0.c1023$staff_u:s0-s0:c0.c1023'
|
||||
u'$sysadm_u:s0-s0:c0.c1023$unconfined_u:s0-s0:c0.c1023',
|
||||
ipaselinuxusermaporder=u'foo:s0',
|
||||
ipaselinuxusermapdefault=u'unknown_u:s0')),
|
||||
expected=errors.ValidationError(name='ipaselinuxusermapdefault',
|
||||
error='SELinux user map default user not in order list'),
|
||||
|
||||
@@ -21,6 +21,8 @@ Test the `ipaserver/plugins/selinuxusermap.py` module.
|
||||
"""
|
||||
|
||||
from ipalib import api, errors
|
||||
from ipaplatform.constants import constants as platformconstants
|
||||
|
||||
from ipatests.test_xmlrpc import objectclasses
|
||||
from ipatests.test_xmlrpc.xmlrpc_test import (Declarative, fuzzy_digits,
|
||||
fuzzy_uuid)
|
||||
@@ -30,8 +32,16 @@ from ipatests.test_xmlrpc.test_user_plugin import get_user_result
|
||||
import pytest
|
||||
|
||||
rule1 = u'selinuxrule1'
|
||||
selinuxuser1 = u'guest_u:s0'
|
||||
selinuxuser2 = u'xguest_u:s0'
|
||||
selinuxuser1 = platformconstants.SELINUX_USERMAP_ORDER.split("$$")[0]
|
||||
selinuxuser2 = platformconstants.SELINUX_USERMAP_ORDER.split("$$")[1]
|
||||
|
||||
INVALID_MCS = "Invalid MCS value, must match {}, where max category {}".format(
|
||||
platformconstants.SELINUX_MCS_REGEX,
|
||||
platformconstants.SELINUX_MCS_MAX)
|
||||
|
||||
INVALID_MLS = "Invalid MLS value, must match {}, where max level {}".format(
|
||||
platformconstants.SELINUX_MLS_REGEX,
|
||||
platformconstants.SELINUX_MLS_MAX)
|
||||
|
||||
user1 = u'tuser1'
|
||||
group1 = u'testgroup1'
|
||||
@@ -623,44 +633,46 @@ class test_selinuxusermap(Declarative):
|
||||
),
|
||||
expected=errors.ValidationError(
|
||||
name='selinuxuser',
|
||||
error=u'Invalid SELinux user name, only a-Z, _ '
|
||||
'and . are allowed'
|
||||
error=u'Invalid SELinux user name, must match {}'.format(
|
||||
platformconstants.SELINUX_USER_REGEX)
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create rule with invalid MCS xguest_u:s999',
|
||||
desc='Create rule with invalid MLS foo:s{}'.format(
|
||||
platformconstants.SELINUX_MLS_MAX + 1),
|
||||
command=(
|
||||
'selinuxusermap_add', [rule1],
|
||||
dict(ipaselinuxuser=u'xguest_u:s999')
|
||||
dict(ipaselinuxuser=u'foo:s{}'.format(
|
||||
platformconstants.SELINUX_MLS_MAX + 1))
|
||||
),
|
||||
expected=errors.ValidationError(name='selinuxuser',
|
||||
error=u'Invalid MLS value, must match s[0-15](-s[0-15])'),
|
||||
error=INVALID_MLS),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create rule with invalid MLS xguest_u:s0:p88',
|
||||
desc='Create rule with invalid MCS foo:s0:p88',
|
||||
command=(
|
||||
'selinuxusermap_add', [rule1],
|
||||
dict(ipaselinuxuser=u'xguest_u:s0:p88')
|
||||
dict(ipaselinuxuser=u'foo:s0:p88')
|
||||
),
|
||||
expected=errors.ValidationError(name='selinuxuser',
|
||||
error=u'Invalid MCS value, must match c[0-1023].c[0-1023] ' +
|
||||
u'and/or c[0-1023]-c[0-c0123]'),
|
||||
error=INVALID_MCS),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create rule with invalid MLS xguest_u:s0:c0.c1028',
|
||||
desc='Create rule with invalid MCS foo:s0:c0.c{}'.format(
|
||||
platformconstants.SELINUX_MCS_MAX + 1),
|
||||
command=(
|
||||
'selinuxusermap_add', [rule1],
|
||||
dict(ipaselinuxuser=u'xguest_u:s0-s0:c0.c1028')
|
||||
dict(ipaselinuxuser=u'foo:s0-s0:c0.c{}'.format(
|
||||
platformconstants.SELINUX_MCS_MAX + 1))
|
||||
),
|
||||
expected=errors.ValidationError(name='selinuxuser',
|
||||
error=u'Invalid MCS value, must match c[0-1023].c[0-1023] ' +
|
||||
u'and/or c[0-1023]-c[0-c0123]'),
|
||||
error=INVALID_MCS),
|
||||
),
|
||||
|
||||
|
||||
@@ -671,7 +683,7 @@ class test_selinuxusermap(Declarative):
|
||||
dict(setattr=u'ipaselinuxuser=deny')
|
||||
),
|
||||
expected=errors.ValidationError(name='ipaselinuxuser',
|
||||
error=u'Invalid MLS value, must match s[0-15](-s[0-15])'),
|
||||
error=INVALID_MLS),
|
||||
),
|
||||
|
||||
dict(
|
||||
|
||||
Reference in New Issue
Block a user