9
0
Fork 1
soc-ops/global/overlay/etc/puppet/modules/soc/manifests/intelmq.pp

323 lines
8.2 KiB
ObjectPascal
Raw Normal View History

2024-11-13 16:25:14 +01:00
class soc::intelmq(
2024-11-14 14:16:39 +01:00
Optional[String] $tls_cert = undef,
Optional[String] $tls_chain = undef,
Optional[String] $tls_key = undef,
2024-11-14 14:20:01 +01:00
String $servername = $facts['networking']['fqdn'],
2024-11-14 14:16:39 +01:00
Boolean $use_snakeoil = false,
2024-11-13 16:25:14 +01:00
) {
2024-11-14 14:16:39 +01:00
include sunet::systemd_reload
2024-11-13 16:25:14 +01:00
2024-11-19 10:25:44 +01:00
# Set some global variables
$api_user = lookup('intelmq_api_user.username', undef, undef, 'test')
$api_pass = lookup('intelmq_api_user.password', undef, undef, 'pass')
$db_user = lookup('intelmq_db_user.username', undef, undef, 'test')
$db_pass = lookup('intelmq_db_user.password', undef, undef, 'pass')
2024-11-13 16:25:14 +01:00
group { 'intelmq':
ensure => present,
}
user { 'intelmq':
2024-11-13 16:49:11 +01:00
ensure => present,
gid => 'intelmq',
groups => 'www-data',
home => '/opt/intelmq',
managehome => true,
2024-11-14 10:24:57 +01:00
shell => '/bin/bash',
2024-11-13 16:25:14 +01:00
}
file { '/etc/intelmq':
ensure => directory,
owner => 'intelmq',
group => 'intelmq',
}
2024-11-18 13:14:49 +01:00
file { '/etc/intelmq/api':
ensure => directory,
owner => 'intelmq',
2024-11-18 13:16:19 +01:00
group => 'www-data',
2024-11-18 13:14:49 +01:00
mode => '0770',
}
2024-11-19 10:25:44 +01:00
file { '/etc/intelmq/fody':
ensure => directory,
owner => 'intelmq',
group => 'www-data',
mode => '0770',
}
2024-11-13 16:25:14 +01:00
2024-11-14 12:28:48 +01:00
package { 'apache2':
ensure => 'latest',
}
package { 'libapache2-mod-wsgi-py3':
2024-11-14 12:29:32 +01:00
ensure => 'latest',
2024-11-14 12:28:48 +01:00
}
2024-11-19 10:25:44 +01:00
file { '/opt/intelmq/install':
ensure => directory,
owner => 'intelmq',
group => 'intelmq',
mode => '0755',
}
2024-11-19 12:37:31 +01:00
file {
2024-11-19 12:36:50 +01:00
'/opt/intelmq/www':
ensure => directory,
owner => 'intelmq',
group => 'intelmq',
mode => '0755',
;
'/opt/intelmq/www/intelmq-manager':
ensure => directory,
owner => 'intelmq',
group => 'www-data',
mode => '0750',
;
'/opt/intelmq/www/fody':
ensure => directory,
owner => 'intelmq',
group => 'www-data',
mode => '0750',
;
}
2024-11-19 10:25:44 +01:00
file { '/opt/intelmq/install/setup-nodesource.sh':
2024-11-18 16:31:44 +01:00
ensure => file,
content => file('soc/intelmq/setup-nodesource.sh'),
2024-11-19 10:25:44 +01:00
mode => '0540',
2024-11-18 16:31:44 +01:00
}
exec { 'Add nodesource repo':
2024-11-19 10:25:44 +01:00
command => '/opt/intelmq/install/setup-nodesource.sh',
2024-11-18 16:31:44 +01:00
creates => '/etc/apt/sources.list.d/nodesource.list',
}
2024-11-19 12:12:13 +01:00
package { ['postgresql', 'python3-venv', 'python3-pip', 'python3-gpg', 'python3-psycopg2', 'redict', 'nodejs', ]:
2024-11-13 16:25:14 +01:00
ensure => 'latest',
}
2024-11-19 12:12:13 +01:00
package { ['cmdtest', ]:
ensure => 'absent',
}
exec { 'Install yarn from npm':
command => 'npm install --global yarn',
creates => '/usr/bin/yarn',
}
2024-11-14 12:16:26 +01:00
exec { 'Install IntelMQ venv':
command => 'sudo -u intelmq /usr/bin/python3 -m venv --system-site-packages /opt/intelmq/venv',
creates => '/opt/intelmq/venv',
2024-11-13 16:25:14 +01:00
}
2024-11-18 13:46:41 +01:00
exec { 'Always active venv for IntelMQ':
2024-11-18 13:47:40 +01:00
command => 'echo ". venv/bin/activate" >> /opt/intelmq/.profile',
2024-11-18 13:45:45 +01:00
unless => 'grep -q activate /opt/intelmq/.profile 2> /dev/null',
}
2024-11-19 10:25:44 +01:00
file { '/opt/intelmq/install/eventdb-notifications.sql':
ensure => file,
2024-11-19 10:27:08 +01:00
content => file('soc/intelmq/eventdb-notifications.sql'),
2024-11-19 10:25:44 +01:00
}
file { '/opt/intelmq/install/install-intelmq.sh':
2024-11-14 10:24:57 +01:00
ensure => file,
2024-11-19 10:28:02 +01:00
content => file('soc/intelmq/install-intelmq.sh'),
2024-11-14 10:27:12 +01:00
mode => '0555',
2024-11-14 10:24:57 +01:00
}
2024-11-14 12:16:26 +01:00
exec { 'Install IntelMQ':
2024-11-19 10:25:44 +01:00
command => 'sudo -u intelmq /opt/intelmq/install/install-intelmq.sh',
2024-11-14 12:16:26 +01:00
creates => '/opt/intelmq/.installed'
2024-11-13 16:25:14 +01:00
}
2024-11-14 10:51:10 +01:00
2024-11-14 12:16:26 +01:00
exec { 'Run IntelMQ setup script':
2024-11-18 13:42:43 +01:00
command => '/opt/intelmq/venv/bin/intelmqsetup',
creates => '/opt/intelmq/var/lib/state.json',
2024-11-14 10:58:37 +01:00
returns => ['0', '1',],
2024-11-14 10:51:10 +01:00
}
2024-11-19 12:12:13 +01:00
file { '/usr/bin/intelmqctl':
ensure => file,
mode => '0555',
content => file('soc/intelmq/usr-bin-intelmqctl'),
}
2024-11-19 10:25:44 +01:00
file { '/opt/intelmq/install/setup-pgsql.sh':
2024-11-18 14:32:01 +01:00
ensure => file,
2024-11-19 12:21:16 +01:00
content => template('soc/intelmq/setup-pgsql.sh'),
2024-11-18 14:32:01 +01:00
mode => '0500',
}
exec { 'Setup IntelMQ eventdb':
2024-11-19 10:25:44 +01:00
command => '/opt/intelmq/install/setup-pgsql.sh',
creates => '/opt/intelmq/.pgsql-installed',
2024-11-18 14:32:01 +01:00
}
2024-11-14 10:52:32 +01:00
file { '/etc/sudoers.d/01_intelmq-api':
2024-11-14 10:51:10 +01:00
ensure => file,
content => file('soc/intelmq/sudoers-01-intelmq-api'),
mode => '0440',
}
2024-11-14 12:16:26 +01:00
service { 'apache2':
ensure => 'running',
enable => true,
2024-11-14 12:28:48 +01:00
require => Package['apache2'],
2024-11-14 12:16:26 +01:00
}
exec { 'Enable Apache2 modules':
2024-11-14 12:47:14 +01:00
command => 'a2enmod ssl wsgi proxy proxy_http headers rewrite',
2024-11-14 12:28:48 +01:00
require => Package['libapache2-mod-wsgi-py3'],
2024-11-14 12:47:14 +01:00
notify => Service['apache2'],
2024-11-14 12:16:26 +01:00
}
2024-11-14 12:47:14 +01:00
file { '/etc/apache2/conf-available/wsgi-venv.conf':
ensure => file,
content => file('soc/intelmq/apache/wsgi-venv.conf'),
}
exec { 'Enable wsgi-venv conf':
2024-11-14 12:48:16 +01:00
command => 'a2enconf wsgi-venv',
creates => '/etc/apache2/conf-enabled/wsgi-venv.conf',
2024-11-14 12:47:14 +01:00
notify => Service['apache2'],
}
2024-11-14 14:16:39 +01:00
file { '/etc/apache2/sites-available/intelmq-vhost.conf':
2024-11-14 14:38:54 +01:00
ensure => file,
2024-11-14 14:23:08 +01:00
content => template('soc/intelmq/intelmq-vhost.conf.erb'),
2024-11-14 14:38:54 +01:00
notify => Service['apache2'],
2024-11-14 14:16:39 +01:00
}
file { '/etc/intelmq/api-config.json':
ensure => file,
owner => 'intelmq',
group => 'intelmq',
2024-11-14 14:17:42 +01:00
mode => '0444',
2024-11-14 14:31:30 +01:00
content => file('soc/intelmq/api-config.json'),
2024-11-14 14:16:39 +01:00
}
2024-11-19 10:33:28 +01:00
file { '/etc/intelmq/fody-session.conf':
2024-11-19 10:25:44 +01:00
ensure => file,
owner => 'intelmq',
group => 'intelmq',
mode => '0444',
2024-11-19 10:33:28 +01:00
content => file('soc/intelmq/fody-session.conf'),
2024-11-19 10:25:44 +01:00
}
2024-11-14 15:58:03 +01:00
exec { 'Setup intelmq-api user':
2024-11-14 16:16:16 +01:00
command => "sudo -u intelmq /opt/intelmq/venv/bin/intelmq-api-adduser --user ${api_user} --password ${api_pass}",
2024-11-18 13:14:49 +01:00
creates => '/etc/intelmq/api/api-session.sqlite',
2024-11-14 15:58:03 +01:00
}
2024-11-18 13:14:49 +01:00
file { '/etc/intelmq/api/api-session.sqlite':
2024-11-14 14:16:39 +01:00
ensure => 'present',
replace => 'no',
owner => 'intelmq',
group => 'www-data',
mode => '0660'
}
2024-11-19 10:25:44 +01:00
exec { 'Setup fody-api user':
command => "sudo -u intelmq /opt/intelmq/venv/bin/fody-adduser --user ${api_user} --password ${api_pass}",
unless => "sqlite3 /etc/intelmq/api/api-session.sqlite \"SELECT username FROM user WHERE username ='${api_user}'\" | grep -q ${api_user}",
}
file {
'/etc/intelmq/contactdb-serve.conf':
ensure => file,
owner => 'intelmq',
group => 'www-data',
mode => '0440',
2024-11-19 10:34:22 +01:00
content => template('soc/intelmq/contactdb-serve.conf.erb'),
2024-11-19 10:25:44 +01:00
;
'/etc/intelmq/eventdb-serve.conf':
ensure => file,
owner => 'intelmq',
group => 'www-data',
mode => '0440',
2024-11-19 10:34:22 +01:00
content => template('soc/intelmq/eventdb-serve.conf.erb'),
2024-11-19 10:25:44 +01:00
;
'/etc/intelmq/tickets-serve.conf':
ensure => file,
owner => 'intelmq',
group => 'www-data',
mode => '0440',
2024-11-19 10:34:22 +01:00
content => template('soc/intelmq/tickets-serve.conf.erb'),
2024-11-19 10:25:44 +01:00
;
}
2024-11-14 14:16:39 +01:00
file { '/etc/systemd/system/intelmq-api.service':
ensure => file,
2024-11-14 14:30:19 +01:00
content => file('soc/intelmq/intelmq-api.service'),
2024-11-14 14:20:56 +01:00
notify => [Class['sunet::systemd_reload'], Service['intelmq-api.service'],],
2024-11-14 14:16:39 +01:00
}
file { '/etc/systemd/system/intelmq-api.socket':
ensure => file,
2024-11-14 14:30:19 +01:00
content => file('soc/intelmq/intelmq-api.socket'),
2024-11-14 14:20:56 +01:00
notify => [Class['sunet::systemd_reload'], Service['intelmq-api.socket'],],
2024-11-14 14:16:39 +01:00
}
2024-11-18 13:29:43 +01:00
file { '/opt/intelmq/etc/runtime.yaml':
ensure => 'present',
replace => 'no',
owner => 'intelmq',
group => 'www-data',
mode => '0660',
}
file { '/opt/intelmq/etc/runtime.yaml.bak':
ensure => 'present',
replace => 'no',
owner => 'www-data',
group => 'www-data',
mode => '0660',
content => '',
}
2024-11-18 13:34:08 +01:00
file { '/opt/intelmq/etc/manager':
ensure => directory,
owner => 'www-data',
group => 'www-data',
mode => '0775',
}
2024-11-14 14:16:39 +01:00
service { 'intelmq-api.service':
ensure => running,
name => 'intelmq-api.service',
2024-11-14 14:24:32 +01:00
enable => true,
2024-11-14 14:16:39 +01:00
hasrestart => true,
}
service { 'intelmq-api.socket':
ensure => running,
name => 'intelmq-api.socket',
2024-11-14 14:24:32 +01:00
enable => true,
2024-11-14 14:16:39 +01:00
hasrestart => true,
}
2024-11-14 14:38:54 +01:00
exec { 'Disable default apache conf':
command => 'a2dissite 000-default',
onlyif => 'test -f /etc/apache2/sites-enabled/000-default.conf',
notify => Service['apache2'],
}
exec { 'Enable intelmq apache conf':
command => 'a2ensite intelmq-vhost',
2024-11-14 14:39:55 +01:00
creates => '/etc/apache2/sites-enabled/intelmq-vhost.conf',
2024-11-14 14:38:54 +01:00
notify => Service['apache2'],
}
2024-11-14 14:50:44 +01:00
2024-11-14 15:00:33 +01:00
sunet::nftables::allow { 'allow_http':
2024-11-14 14:50:44 +01:00
from => any,
port => 80,
}
2024-11-14 15:00:33 +01:00
sunet::nftables::allow { 'allow_https':
2024-11-14 14:50:44 +01:00
from => any,
port => 443,
}
2024-11-13 16:25:14 +01:00
}