2014-09-30 01:24:14 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# (c) 2015, Michael Scherer <misc@zarb.org>
|
|
|
|
# inspired by code of github.com/dandiker/
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2014-09-30 01:24:14 +00:00
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
2016-12-06 10:35:25 +00:00
|
|
|
|
2014-09-30 01:24:14 +00:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: selinux_permissive
|
|
|
|
short_description: Change permissive domain in SELinux policy
|
|
|
|
description:
|
2018-10-03 17:04:25 +00:00
|
|
|
- Add and remove a domain from the list of permissive domains.
|
2016-12-08 05:34:16 +00:00
|
|
|
version_added: "2.0"
|
2014-09-30 01:24:14 +00:00
|
|
|
options:
|
|
|
|
domain:
|
|
|
|
description:
|
2018-10-03 17:04:25 +00:00
|
|
|
- The domain that will be added or removed from the list of permissive domains.
|
2014-09-30 01:24:14 +00:00
|
|
|
required: true
|
|
|
|
permissive:
|
|
|
|
description:
|
2018-10-03 17:04:25 +00:00
|
|
|
- Indicate if the domain should or should not be set as permissive.
|
2014-09-30 01:24:14 +00:00
|
|
|
required: true
|
2018-03-15 21:15:24 +00:00
|
|
|
type: bool
|
2014-09-30 01:24:14 +00:00
|
|
|
no_reload:
|
|
|
|
description:
|
2018-10-03 17:04:25 +00:00
|
|
|
- Disable reloading of the SELinux policy after making change to a domain's permissive setting.
|
|
|
|
- The default is C(no), which causes policy to be reloaded when a domain changes state.
|
|
|
|
- Reloading the policy does not work on older versions of the C(policycoreutils-python) library, for example in EL 6."
|
2018-03-15 21:15:24 +00:00
|
|
|
type: bool
|
|
|
|
default: 'no'
|
2014-09-30 01:24:14 +00:00
|
|
|
store:
|
|
|
|
description:
|
2018-10-03 17:04:25 +00:00
|
|
|
- "Name of the SELinux policy store to use."
|
2014-09-30 01:24:14 +00:00
|
|
|
notes:
|
2018-10-03 17:04:25 +00:00
|
|
|
- Requires a recent version of SELinux and C(policycoreutils-python) (EL 6 or newer).
|
2014-09-30 01:24:14 +00:00
|
|
|
requirements: [ policycoreutils-python ]
|
2018-08-24 23:43:35 +00:00
|
|
|
author: Michael Scherer (@mscherer) <misc@zarb.org>
|
2014-09-30 01:24:14 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
2018-10-03 17:04:25 +00:00
|
|
|
- name: Change the httpd_t domain to permissive
|
|
|
|
selinux_permissive:
|
2016-12-02 15:48:22 +00:00
|
|
|
name: httpd_t
|
|
|
|
permissive: true
|
2014-09-30 01:24:14 +00:00
|
|
|
'''
|
|
|
|
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
import traceback
|
|
|
|
|
2014-09-30 01:24:14 +00:00
|
|
|
HAVE_SEOBJECT = False
|
|
|
|
try:
|
|
|
|
import seobject
|
|
|
|
HAVE_SEOBJECT = True
|
|
|
|
except ImportError:
|
|
|
|
pass
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils._text import to_native
|
2014-09-30 01:24:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
domain=dict(aliases=['name'], required=True),
|
|
|
|
store=dict(required=False, default=''),
|
|
|
|
permissive=dict(type='bool', required=True),
|
|
|
|
no_reload=dict(type='bool', required=False, default=False),
|
|
|
|
),
|
|
|
|
supports_check_mode=True
|
|
|
|
)
|
|
|
|
|
|
|
|
# global vars
|
|
|
|
changed = False
|
|
|
|
store = module.params['store']
|
|
|
|
permissive = module.params['permissive']
|
|
|
|
domain = module.params['domain']
|
|
|
|
no_reload = module.params['no_reload']
|
|
|
|
|
|
|
|
if not HAVE_SEOBJECT:
|
|
|
|
module.fail_json(changed=False, msg="policycoreutils-python required for this module")
|
|
|
|
|
|
|
|
try:
|
|
|
|
permissive_domains = seobject.permissiveRecords(store)
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
except ValueError as e:
|
|
|
|
module.fail_json(domain=domain, msg=to_native(e), exception=traceback.format_exc())
|
2014-09-30 01:24:14 +00:00
|
|
|
|
|
|
|
# not supported on EL 6
|
|
|
|
if 'set_reload' in dir(permissive_domains):
|
|
|
|
permissive_domains.set_reload(not no_reload)
|
|
|
|
|
|
|
|
try:
|
|
|
|
all_domains = permissive_domains.get_all()
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
except ValueError as e:
|
|
|
|
module.fail_json(domain=domain, msg=to_native(e), exception=traceback.format_exc())
|
2014-09-30 01:24:14 +00:00
|
|
|
|
|
|
|
if permissive:
|
|
|
|
if domain not in all_domains:
|
|
|
|
if not module.check_mode:
|
|
|
|
try:
|
|
|
|
permissive_domains.add(domain)
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
except ValueError as e:
|
|
|
|
module.fail_json(domain=domain, msg=to_native(e), exception=traceback.format_exc())
|
2014-09-30 01:24:14 +00:00
|
|
|
changed = True
|
|
|
|
else:
|
|
|
|
if domain in all_domains:
|
|
|
|
if not module.check_mode:
|
|
|
|
try:
|
|
|
|
permissive_domains.delete(domain)
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
except ValueError as e:
|
|
|
|
module.fail_json(domain=domain, msg=to_native(e), exception=traceback.format_exc())
|
2014-09-30 01:24:14 +00:00
|
|
|
changed = True
|
|
|
|
|
|
|
|
module.exit_json(changed=changed, store=store,
|
|
|
|
permissive=permissive, domain=domain)
|
|
|
|
|
|
|
|
|
2016-12-05 16:24:19 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|