Skip to content

Commit 9adbe51

Browse files
committed
fix: add proper SELinux context and enable httpd_enable_cgi
* Add puppet/selinux to dependencies * 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: #336, #365
1 parent e1ba6f0 commit 9adbe51

File tree

2 files changed

+71
-10
lines changed

2 files changed

+71
-10
lines changed

manifests/init.pp

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,74 @@
275275
}
276276

277277
if $manage_selinux {
278-
selboolean { 'httpd_can_network_relay':
279-
persistent => true,
280-
value => 'on',
278+
# Include puppet/selinux
279+
include selinux
280+
# Set SELinux booleans required for httpd proper functioning
281+
# https://linux.die.net/man/8/httpd_selinux
282+
selinux::boolean {
283+
default:
284+
ensure => 'on',
285+
persistent => true,
286+
;
287+
# allow httpd scripts to connect to network: Puppetboard connects
288+
# to PuppetDB
289+
'httpd_can_network_connect':
290+
;
291+
# allow httpd script to connect to database servers: PuppetDB relies
292+
# on PostgreSQL
293+
'httpd_can_network_connect_db':
294+
;
295+
# allow httpd to be used as a forward/reverse proxy
296+
'httpd_can_network_relay':
297+
;
298+
# enable cgi support
299+
'httpd_enable_cgi':
300+
;
281301
}
282-
selboolean { 'httpd_can_network_connect':
283-
persistent => true,
284-
value => 'on',
302+
# Set context for wsgi and settings
303+
selinux::fcontext {
304+
default:
305+
ensure => present,
306+
notify => Selinux::Exec_restorecon["${basedir}/puppetboard"],
307+
;
308+
"${basedir}/puppetboard/wsgi.py":
309+
seltype => 'httpd_sys_script_exec_t',
310+
;
311+
$settings_file :
312+
require => File[$settings_file],
313+
seltype => 'httpd_sys_content_t',
314+
;
285315
}
286-
selboolean { 'httpd_can_network_connect_db':
287-
persistent => true,
288-
value => 'on',
316+
# Apply changes above
317+
selinux::exec_restorecon { "${basedir}/puppetboard":
318+
notify => Service['httpd'],
319+
}
320+
321+
if $manage_virtualenv {
322+
# Set context for venv files
323+
selinux::fcontext {
324+
default:
325+
ensure => present,
326+
require => Python::Pip['puppetboard'],
327+
notify => Selinux::Exec_restorecon[$virtualenv_dir],
328+
;
329+
"${virtualenv_dir} static files":
330+
seltype => 'httpd_sys_content_t',
331+
pathspec => "${virtualenv_dir}(/.*\\.(cfg|css|html|ico|js|pem|png|svg|ttf|txt|woff|woff2|xml))?",
332+
;
333+
"${virtualenv_dir} METADATA":
334+
seltype => 'httpd_sys_content_t',
335+
pathspec => "${virtualenv_dir}(/.*/METADATA)?",
336+
;
337+
"${virtualenv_dir} executables":
338+
seltype => 'httpd_sys_script_exec_t',
339+
pathspec => "${virtualenv_dir}(/.*\\.(pth|py|pyc|pyi|so))?",
340+
;
341+
}
342+
# Apply changes above
343+
selinux::exec_restorecon { $virtualenv_dir :
344+
notify => Service['httpd'],
345+
}
289346
}
290347
}
291348
}

metadata.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@
7676
},
7777
{
7878
"name": "puppet/python",
79-
"version_requirement": ">= 6.3.0 < 9.0.0"
79+
"version_requirement": ">= 6.3.0 < 8.0.0"
80+
},
81+
{
82+
"name": "puppet/selinux",
83+
"version_requirement": ">= 3.0.0 < 6.0.0"
8084
}
8185
]
8286
}

0 commit comments

Comments
 (0)