Skip to content

Commit

Permalink
fix: add proper SELinux context and enable httpd_enable_cgi
Browse files Browse the repository at this point in the history
* Set SELinux context for files in ${basedir}/puppetboard, if virtualenv is managed, set context for it too
* Enable httpd_enable_cgi SELinux boolean to allow WSGI execution

Fixes: voxpupuli#336, voxpupuli#365
  • Loading branch information
Francesco Di Nucci committed Apr 4, 2024
1 parent dfbfc3e commit d593ea8
Showing 1 changed file with 61 additions and 10 deletions.
71 changes: 61 additions & 10 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,68 @@
}

if $manage_selinux {
selboolean { 'httpd_can_network_relay':
persistent => true,
value => 'on',
# Include puppet/selinux
include selinux
# Set SELinux booleans required for httpd proper functioning
# https://linux.die.net/man/8/httpd_selinux
selinux::boolean {
default:
ensure => 'on',
persistent => true,
;
# allow httpd scripts to connect to network: Puppetboard connects
# to PuppetDB
'httpd_can_network_connect':
;
# allow httpd script to connect to database servers: PuppetDB relies
# on PostgreSQL
'httpd_can_network_connect_db':
;
# allow httpd to be used as a forward/reverse proxy
'httpd_can_network_relay':
;
# enable cgi support
'httpd_enable_cgi':
;
}
selboolean { 'httpd_can_network_connect':
persistent => true,
value => 'on',
# Set context for wsgi and settings
selinux::fcontext {
default:
ensure => present,
notify => Selinux::Exec_restorecon["${basedir}/puppetboard"],
;
"${basedir}/puppetboard/wsgi.py":
seltype => 'httpd_sys_script_exec_t',
;
$settings_file :
require => File[$settings_file],
seltype => 'httpd_sys_content_t',
;
}
selboolean { 'httpd_can_network_connect_db':
persistent => true,
value => 'on',
# Apply changes above
selinux::exec_restorecon { "${basedir}/puppetboard":
}

if $manage_virtualenv {
# Set context for venv files
selinux::fcontext {
default:
ensure => present,
require => Python::Pyvenv[$virtualenv_dir],
notify => Selinux::Exec_restorecon[$virtualenv_dir],
;
"${virtualenv_dir}(/.*\.(cfg|css|html|ico|js|pem|png|svg|ttf|txt|woff|woff2|xml))?":
seltype => 'httpd_sys_content_t',
;
"${virtualenv_dir}(/.*/METADATA)?":
seltype => 'httpd_sys_content_t',
;
"${virtualenv_dir}(/.*\.(pth|py|pyc|pyi|so))?":
seltype => 'httpd_sys_script_exec_t',
;
}
# Apply changes above
selinux::exec_restorecon { $virtualenv_dir :
}
}
}
}

0 comments on commit d593ea8

Please sign in to comment.