Skip to content

Enforce SELinux on EL and Enable Apparmor in Ubuntu/Debian/SUSE#225

Draft
weizhouapache wants to merge 1 commit into
masterfrom
enforce-selinux-apparmor
Draft

Enforce SELinux on EL and Enable Apparmor in Ubuntu/Debian/SUSE#225
weizhouapache wants to merge 1 commit into
masterfrom
enforce-selinux-apparmor

Conversation

@weizhouapache

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces shared Ansible task snippets to enforce SELinux on Enterprise Linux hosts and enable/enforce AppArmor on Ubuntu/Debian/SUSE, and then wires those snippets into the MySQL, KVM, CloudStack manager, and Marvin roles (replacing prior “permissive/disable” logic).

Changes:

  • Add Ansible/tasks/configure_selinux.yml to switch SELinux to enforcing (runtime + persistent).
  • Add Ansible/tasks/configure_apparmor.yml to install AppArmor tooling and enforce AppArmor profiles.
  • Replace per-role SELinux/AppArmor handling with include calls to the shared task files across multiple distro-specific role task files.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
Ansible/tasks/configure_selinux.yml New shared SELinux enforcement tasks used by EL roles.
Ansible/tasks/configure_apparmor.yml New shared AppArmor enable/enforce tasks used by Debian/Ubuntu/SUSE roles.
Ansible/roles/mysql/tasks/suse.yml Switch SUSE MySQL role to include shared AppArmor configuration.
Ansible/roles/mysql/tasks/el9.yml Switch EL9 MySQL role to include shared SELinux enforcement.
Ansible/roles/mysql/tasks/centos8.yml Switch CentOS 8 MySQL role to include shared SELinux enforcement.
Ansible/roles/mysql/tasks/centos.yml Switch CentOS MySQL role to include shared SELinux enforcement.
Ansible/roles/marvin/tasks/main.yml Replace Marvin role SELinux permissive setup with shared SELinux enforcement include.
Ansible/roles/kvm/tasks/ubuntu.yml Replace libvirt AppArmor disable steps with shared AppArmor enforcement include.
Ansible/roles/kvm/tasks/suse.yml Switch SUSE KVM role to include shared AppArmor configuration.
Ansible/roles/kvm/tasks/el9.yml Switch EL9 KVM role to include shared SELinux enforcement.
Ansible/roles/kvm/tasks/debian.yml Replace libvirt AppArmor disable steps with shared AppArmor enforcement include.
Ansible/roles/kvm/tasks/centos8.yml Switch CentOS 8 KVM role to include shared SELinux enforcement.
Ansible/roles/kvm/tasks/centos.yml Switch CentOS KVM role to include shared SELinux enforcement.
Ansible/roles/cloudstack-manager/tasks/ubuntu.yml Add shared AppArmor configuration include before DB setup.
Ansible/roles/cloudstack-manager/tasks/suse.yml Switch SUSE mgmt role from SELinux permissive handling to shared AppArmor configuration.
Ansible/roles/cloudstack-manager/tasks/el9.yml Switch EL9 mgmt role to include shared SELinux enforcement.
Ansible/roles/cloudstack-manager/tasks/debian.yml Add shared AppArmor configuration include before DB setup.
Ansible/roles/cloudstack-manager/tasks/centos8.yml Switch CentOS 8 mgmt role to include shared SELinux enforcement.
Ansible/roles/cloudstack-manager/tasks/centos.yml Switch CentOS mgmt role to include shared SELinux enforcement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 38 to 41
- mysqlconf

- name: Set selinux to permissive
command: setenforce permissive
changed_when: false
tags:
- mysql
- mysqlconf

- name: Ensure selinux is set permanently
selinux:
policy: targeted
state: permissive
tags:
- mysql
- mysqlconf
- include: ../../../tasks/configure_selinux.yml

Comment on lines 38 to 41
- mysqlconf

- name: Set selinux to permissive
command: setenforce permissive
changed_when: false
tags:
- mysql
- mysqlconf

- name: Ensure selinux is set permanently
selinux:
policy: targeted
state: permissive
tags:
- mysql
- mysqlconf
- include: ../../../tasks/configure_selinux.yml

Comment on lines 47 to 50
ignore_errors: yes

- name: Set selinux to permissive
command: setenforce permissive
changed_when: false
tags:
- mysql
- mysqlconf
ignore_errors: yes

- name: Ensure selinux is set permanently
selinux: policy=targeted state=permissive
tags:
- kvm
ignore_errors: yes
- include: ../../../tasks/configure_apparmor.yml

Comment on lines 16 to 19
- kvm

- name: Set selinux to permissive
command: setenforce permissive
changed_when: false
tags:
- kvm

- name: Ensure selinux is set permanently
selinux: policy=targeted state=permissive
tags:
- kvm
- include: ../../../tasks/configure_selinux.yml

Comment on lines 16 to 20
tags:
- kvm

- name: Set selinux to permissive
command: setenforce permissive
changed_when: false
tags:
- kvm

- name: Ensure selinux is set permanently
selinux: policy=targeted state=permissive
tags:
- kvm
- include: ../../../tasks/configure_selinux.yml

Comment on lines 30 to 34
shell: "zypper install -y net-tools-deprecated"
ignore_errors: yes # This package is deprecated. ignoring errors for older distros

- name: Set selinux to permissive
command: setenforce permissive
changed_when: false
tags:
- kvm
ignore_errors: yes

- name: Ensure selinux is set permanently
selinux: policy=targeted state=permissive
tags:
- kvm
ignore_errors: yes
- include: ../../../tasks/configure_apparmor.yml

Comment on lines +2 to +6
- name: Install apparmor-utils
apt:
pkg: apparmor-utils
state: latest
update_cache: yes
Comment on lines +3 to +7
- name: Get current SELinux mode
shell: getenforce || true
register: selinux_mode

- name: Set selinux to enforcing
selinux: policy=targeted state=permissive
tags:
- kvm
- include: ../../../tasks/configure_selinux.yml
@andrijapanicsb

Copy link
Copy Markdown
Contributor

@wei do these copilot stuff have any sense, or do we just say "when kvm tag included" at a much higher level ("wrapper" script which when tag KVM - invokes these specific Ubuntu/EL sub tasks) ?

@weizhouapache

Copy link
Copy Markdown
Member Author

@wei do these copilot stuff have any sense, or do we just say "when kvm tag included" at a much higher level ("wrapper" script which when tag KVM - invokes these specific Ubuntu/EL sub tasks) ?

@andrijapanicsb
I can add the tags. but I think it does not matter if we enable selinux/apparmor multiple times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants