SELinux
@charset "UTF-8";.markdown-body{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;color:#24292e;font-family:-apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;line-height:1.5;word-wrap:break-word;box-sizing:border-box;min-width:200px;margin:0 auto;padding:45px}.markdown-body a{color:#0366d6;background-color:transparent;text-decoration:none;-webkit-text-decoration-skip:objects}.markdown-body a:active,.markdown-body a:hover{outline-width:0}.markdown-body a:hover{text-decoration:underline}.markdown-body a:not([href]){color:inherit;text-decoration:none}.markdown-body strong{font-weight:600}.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6{margin-top:24px;margin-bottom:16px;font-weight:600;line-height:1.25}.markdown-body h1{font-size:2em;margin:.67em 0;padding-bottom:.3em;border-bottom:1px solid #eaecef}.markdown-body h2{padding-bottom:.3em;font-size:1.5em;border-bottom:1px solid #eaecef}.markdown-body h3{font-size:1.25em}.markdown-body h4{font-size:1em}.markdown-body h5{font-size:.875em}.markdown-body h6{font-size:.85em;color:#6a737d}.markdown-body img{border-style:none}.markdown-body svg:not(:root){overflow:hidden}.markdown-body hr{box-sizing:content-box;height:.25em;margin:24px 0;padding:0;overflow:hidden;background-color:#e1e4e8;border:0}.markdown-body hr::before{display:table;content:""}.markdown-body hr::after{display:table;clear:both;content:""}.markdown-body input{margin:0;overflow:visible;font:inherit;font-family:inherit;font-size:inherit;line-height:inherit}.markdown-body [type=checkbox]{box-sizing:border-box;padding:0}.markdown-body *{box-sizing:border-box}.markdown-body blockquote{margin:0}.markdown-body ol,.markdown-body ul{padding-left:2em}.markdown-body ol ol,.markdown-body ul ol{list-style-type:lower-roman}.markdown-body ol ol,.markdown-body ol ul,.markdown-body ul ol,.markdown-body ul ul{margin-top:0;margin-bottom:0}.markdown-body ol ol ol,.markdown-body ol ul ol,.markdown-body ul ol ol,.markdown-body ul ul ol{list-style-type:lower-alpha}.markdown-body li>p{margin-top:16px}.markdown-body li+li{margin-top:.25em}.markdown-body dd{margin-left:0}.markdown-body dl{padding:0}.markdown-body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:600}.markdown-body dl dd{padding:0 16px;margin-bottom:16px}.markdown-body code{font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace}.markdown-body pre{font:12px SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;word-wrap:normal}.markdown-body blockquote,.markdown-body dl,.markdown-body ol,.markdown-body p,.markdown-body pre,.markdown-body table,.markdown-body ul{margin-top:0;margin-bottom:16px}.markdown-body blockquote{padding:0 1em;color:#6a737d;border-left:.25em solid #dfe2e5}.markdown-body blockquote>:first-child{margin-top:0}.markdown-body blockquote>:last-child{margin-bottom:0}.markdown-body table{display:block;width:100%;overflow:auto;border-spacing:0;border-collapse:collapse}.markdown-body table th{font-weight:600}.markdown-body table td,.markdown-body table th{padding:6px 13px;border:1px solid #dfe2e5}.markdown-body table tr{background-color:#fff;border-top:1px solid #c6cbd1}.markdown-body table tr:nth-child(2n){background-color:#f6f8fa}.markdown-body img{max-width:100%;box-sizing:content-box;background-color:#fff}.markdown-body code{padding:.2em 0;margin:0;font-size:85%;background-color:rgba(27,31,35,.05);border-radius:3px}.markdown-body code::after,.markdown-body code::before{letter-spacing:-.2em;content:" "}.markdown-body pre>code{padding:0;margin:0;font-size:100%;word-break:normal;white-space:pre;background:0 0;border:0}.markdown-body .highlight{margin-bottom:16px}.markdown-body .highlight pre{margin-bottom:0;word-break:normal}.markdown-body .highlight pre,.markdown-body pre{padding:16px;overflow:auto;font-size:85%;line-height:1.45;background-color:#f6f8fa;border-radius:3px}.markdown-body pre code{display:inline;max-width:auto;padding:0;margin:0;overflow:visible;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}.markdown-body pre code::after,.markdown-body pre code::before{content:normal}.markdown-body .full-commit .btn-outline:not(:disabled):hover{color:#005cc5;border-color:#005cc5}.markdown-body kbd{box-shadow:inset 0 -1px 0 #959da5;display:inline-block;padding:3px 5px;font:11px/10px SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;color:#444d56;vertical-align:middle;background-color:#fcfcfc;border:1px solid #c6cbd1;border-bottom-color:#959da5;border-radius:3px;box-shadow:inset 0 -1px 0 #959da5}.markdown-body :checked+.radio-label{position:relative;z-index:1;border-color:#0366d6}.markdown-body .task-list-item{list-style-type:none}.markdown-body .task-list-item+.task-list-item{margin-top:3px}.markdown-body .task-list-item input{margin:0 .2em .25em -1.6em;vertical-align:middle}.markdown-body::before{display:table;content:""}.markdown-body::after{display:table;clear:both;content:""}.markdown-body>:first-child{margin-top:0!important}.markdown-body>:last-child{margin-bottom:0!important}.Alert,.Error,.Note,.Success,.Warning{padding:11px;margin-bottom:24px;border-style:solid;border-width:1px;border-radius:4px}.Alert p,.Error p,.Note p,.Success p,.Warning p{margin-top:0}.Alert p:last-child,.Error p:last-child,.Note p:last-child,.Success p:last-child,.Warning p:last-child{margin-bottom:0}.Alert{color:#246;background-color:#e2eef9;border-color:#bac6d3}.Warning{color:#4c4a42;background-color:#fff9ea;border-color:#dfd8c2}.Error{color:#911;background-color:#fcdede;border-color:#d2b2b2}.Success{color:#22662c;background-color:#e2f9e5;border-color:#bad3be}.Note{color:#2f363d;background-color:#f6f8fa;border-color:#d5d8da}.Alert h1,.Alert h2,.Alert h3,.Alert h4,.Alert h5,.Alert h6{color:#246;margin-bottom:0}.Warning h1,.Warning h2,.Warning h3,.Warning h4,.Warning h5,.Warning h6{color:#4c4a42;margin-bottom:0}.Error h1,.Error h2,.Error h3,.Error h4,.Error h5,.Error h6{color:#911;margin-bottom:0}.Success h1,.Success h2,.Success h3,.Success h4,.Success h5,.Success h6{color:#22662c;margin-bottom:0}.Note h1,.Note h2,.Note h3,.Note h4,.Note h5,.Note h6{color:#2f363d;margin-bottom:0}.Alert h1:first-child,.Alert h2:first-child,.Alert h3:first-child,.Alert h4:first-child,.Alert h5:first-child,.Alert h6:first-child,.Error h1:first-child,.Error h2:first-child,.Error h3:first-child,.Error h4:first-child,.Error h5:first-child,.Error h6:first-child,.Note h1:first-child,.Note h2:first-child,.Note h3:first-child,.Note h4:first-child,.Note h5:first-child,.Note h6:first-child,.Success h1:first-child,.Success h2:first-child,.Success h3:first-child,.Success h4:first-child,.Success h5:first-child,.Success h6:first-child,.Warning h1:first-child,.Warning h2:first-child,.Warning h3:first-child,.Warning h4:first-child,.Warning h5:first-child,.Warning h6:first-child{margin-top:0}h1.title,p.subtitle{text-align:center}h1.title.followed-by-subtitle{margin-bottom:0}p.subtitle{font-size:1.5em;font-weight:600;line-height:1.25;margin-top:0;margin-bottom:16px;padding-bottom:.3em}div.line-block{white-space:pre-line}
code{white-space: pre;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
SELinux
Contents
Expected functionality
Essentially provide mechanisms to manage local customizations:
- Set enforcing/permissive
- restorecon portions of filesystem tree
- Set/Get Booleans
- Set/Get file contexts
- Manage logins
- Manage ports
Note: If you want to manage SELinux customizations
in disabled
mode, you need SELinux targeted
policy installed.
Requirements
See below
Collection requirements
The role requires external collections. Use the following command to
install them:
ansible-galaxy collection install -vv -r meta/collection-requirements.yml
Modules provided by this
repository
selinux_modules_facts
Gather state of SELinux modules
Role Variables
purge local modifications
By default, the modifications specified in
selinux_booleans
, selinux_fcontexts
,
selinux_ports
and selinux_logins
are applied
on top of pre-existing modifications. To purge local modifications prior
to setting new ones, set following variables to true
:
selinux_booleans_purge
- SELinux booleans
selinux_fcontexts_purge
- SELinux file contexts
selinux_ports_purge
- SELinux ports
selinux_logins_purge
- SELinux user mapping
You can purge all modifications by using
selinux_all_purge: true
:
selinux_policy, selinux_state
Manage the SELinux policy type and mode.
selinux_policy: targeted
selinux_state: enforcing
Allowed values for selinux_state
are
disabled
, enforcing
and
permissive
.
If selinux_state
is not set, the SELinux state is not
changed. If selinux_policy
is not set and SELinux is to be
enabled, it defaults to targeted
. If SELinux is already
enabled, the policy is not changed.
This uses the selinux
module to manage the SELinux mode and policy.
selinux_booleans
Manage the state of SELinux booleans. This is a list
of
dict
, where each dict
is in the same format as
used by the seboolean
module.
selinux_booleans:
- name: samba_enable_home_dirs
state: true
- name: ssh_sysadm_login
state: true
persistent: true
selinux_fcontexts
Manage the state of SELinux file context mapping definitions. This is
a list
of dict
, where each dict
is in the same format as used by the sefcontext
module.
selinux_fcontexts:
- target: '/tmp/test_dir(/.*)?'
setype: 'user_home_dir_t'
ftype: d
state: present
Users may also pass the following optional parameters:
seuser
: to set the SELinux user
selevel
: to set the MLS/MCS Security Range (MLS/MCS
Systems only). SELinux Range for SELinux login mapping defaults to the
SELinux user record range.
Individual modifications can be dropped by setting state
to absent
.
selinux_ports
Manage the state of SELinux port policy. This is a list
of dict
, where each dict
is in the same format
as used by the seport
module.
selinux_ports:
- ports: 22100
proto: tcp
setype: ssh_port_t
state: present
local: true
selinux_restore_dirs
This is a list
of strings, where each string is a
filesystem tree where you want to run restorecon
:
selinux_restore_dirs:
- /tmp/test_dir
selinux_logins
Manage the linux user to SELinux user mapping. This is a
list
of dict
, where each dict
is
in the same format as used by the selogin
module.
selinux_logins:
- login: plautrba
seuser: staff_u
state: absent
- login: default
seuser: staff_u
serange: s0-s0:c0.c1023
state: present
selinux_modules
It is possible to manage SELinux modules using
selinux_modules
variable which would contain a
list
of dict
, e.g.:
selinux_modules:
- path: localmodule.pp
state: enabled
- path: localmodule.cil
priority: 350
state: enabled
- name: unconfineduser
state: disabled
- name: localmodule
priority: 350
state: absent
path
: a local module file (either .cil or .pp) to be
installed on a node, used for installing new modules
name
: module name, used for enabling disabled modules,
disabling enabled modules, removing modules
priority
: SELinux module priority, default is
"400". "100" is used for modules installed from
selinux-policy packages, "200" for other modules
installed from 3rd party rpms, "300" is used by
SETroubleshoot
state
: one of the following values
enabled
: install or enable module
disabled
: disable module
absent
: remove module
Note: Building modules from source on nodes is not
supported. However, in many cases a binary pp or cil
module could be used on different systems if all systems support types,
classes and permissions used in the module. In case of pp
module it also needs to be built with the lowest supported policydb
module version on target systems, i.e. on the oldest system.
Note: Module priorities are ignored in Red Hat
Enterprise Linux 6
Note: Managing modules is idempotent only on Fedora,
and EL 8.6 and later. You can manage modules on older releases, but it
will not be idempotent.
selinux_transactional_update_reboot_ok
This variable is used to handle reboots required by transactional
updates. If a transactional update requires a reboot, the role will
proceed with the reboot if selinux_transactional_update_reboot_ok is set
to true. If set to false, the role will notify the user that a reboot is
required, allowing for custom handling of the reboot requirement. If
this variable is not set, the role will fail to ensure the reboot
requirement is not overlooked.
selinux_transactional_update_reboot_ok: true
Ansible Facts
selinux_reboot_required
This custom fact is set to true
if system reboot is
necessary when SELinux is set from disabled
to
enabled
or vice versa. Otherwise the fact is set to
false
. In the case that system reboot is needed, it will be
indicated by returning failure from the role which needs to be handled
using a block:
...rescue:
construct. The reboot
needs to be performed in the playbook, the role itself never reboots the
managed host. After the reboot the role needs to be reapplied to finish
the changes.
selinux_installed_modules
This custom fact represents SELinux module store structure
"selinux_installed_modules": {
<module name>: {
<module priority>: ("enabled"|"disabled"),
...
},
...
}
e.g.
"ansible_facts": {
"selinux_installed_modules": {
"abrt": {
"100": "enabled",
"400": "disabled"
},
"accountsd": {
"100": "enabled"
},
"acct": {
"100": "enabled"
}
}
}
NOTE: Module priority is set to "0" when priorities
are not supported, e.g. on Red Hat Enterprise Linux 6
Examples
The general usage is demonstrated in selinux-playbook.yml
playbook.
rpm-ostree
See README-ostree.md