{"id":624,"date":"2018-10-17T23:40:44","date_gmt":"2018-10-17T23:40:44","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=624"},"modified":"2018-10-18T14:55:32","modified_gmt":"2018-10-18T14:55:32","slug":"configure-graylog-server-with-puppet-lisenet-com-linux-security","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/configure-graylog-server-with-puppet-lisenet-com-linux-security\/","title":{"rendered":"Configure Graylog Server with Puppet | Lisenet.com :: Linux | Security"},"content":{"rendered":"<p>We\u2019re going to use Puppet to install and configure a Graylog server.<\/p>\n<p>This article is part of the <a href=\"https:\/\/www.lisenet.com\/2018\/homelab-project-with-kvm-katello-and-puppet\/\" target=\"_blank\" rel=\"noopener\">Homelab Project with KVM, Katello and Puppet<\/a> series. See <a href=\"https:\/\/www.lisenet.com\/2015\/install-graylog2-server-on-centos-7\/\" target=\"_blank\" rel=\"noopener\">here<\/a> (CentOS 7) and <a href=\"https:\/\/www.lisenet.com\/2015\/install-graylog2-server-on-centos-6\/\" target=\"_blank\" rel=\"noopener\">here<\/a> (CentOS 6) for blog posts on how to configure a Graylog server manually.<\/p>\n<h2>Homelab<\/h2>\n<p>We have a CentOS 7 VM installed which we want to configure as a Graylog server:<\/p>\n<p>syslog.hl.local (10.11.1.14) \u2013 Graylog\/Elasticsearch\/MongoDB with Apache frontend<\/p>\n<p>SELinux set to enforcing mode.<\/p>\n<p>See the image below to identify the homelab part this article applies to.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lisenet.com\/wp-content\/uploads\/2018\/04\/lisenet-homelab-diagram_syslog.png\" alt=\"\" width=\"1200\" height=\"793\" \/><\/p>\n<h2>Configuration with Puppet<\/h2>\n<p>Puppet master runs on the <a href=\"https:\/\/www.lisenet.com\/2016\/install-katello-on-centos-7\/\" target=\"_blank\" rel=\"noopener\">Katello<\/a> server.<\/p>\n<h3>Puppet Modules<\/h3>\n<p>We use <a href=\"https:\/\/forge.puppet.com\/graylog\/graylog\" target=\"_blank\" rel=\"noopener\">graylog-graylog<\/a> Puppet module to configure the server. The module only manages Graylog itself. We need other modules to install the required dependencies like Java, MongoDB, Elasticsearch and Apache (as a reverse proxy):<\/p>\n<ol>\n<li><a href=\"https:\/\/forge.puppet.com\/puppetlabs\/java\" target=\"_blank\" rel=\"noopener\">puppetlabs-java<\/a><\/li>\n<li><a href=\"https:\/\/forge.puppet.com\/elastic\/elasticsearch\" target=\"_blank\" rel=\"noopener\">elastic-elasticsearch<\/a><\/li>\n<li><a href=\"https:\/\/forge.puppet.com\/puppet\/mongodb\" target=\"_blank\" rel=\"noopener\">puppet-mongodb<\/a><\/li>\n<li><a href=\"https:\/\/forge.puppet.com\/puppetlabs\/apache\" target=\"_blank\" rel=\"noopener\">puppetlabs-apache<\/a><\/li>\n<li><a href=\"https:\/\/forge.puppet.com\/saz\/rsyslog\" target=\"_blank\" rel=\"noopener\">saz-rsyslog<\/a><\/li>\n<\/ol>\n<p>Please see each module\u2019s documentation for features supported and configuration options available.<\/p>\n<h3>Katello Repositories<\/h3>\n<p>Repositories for Graylog, Elasticsearch and MongoDB are provided by Katello (we configured them <a href=\"https:\/\/www.lisenet.com\/2018\/katello-create-products-repositories-content-views-lifecycle-environments-activation-keys\/\" target=\"_blank\" rel=\"noopener\">here<\/a>).<\/p>\n<p>Note that Graylog 2.4 does not work with Elasticsearch 6.x, we\u2019ll therefore use Elasticsearch 5.x.<\/p>\n<h3>Install MongoDB<\/h3>\n<p>class { &#8216;mongodb::globals&#8217;:<br \/>\n<em>## Use Katello repository<\/em><br \/>\nmanage_package_repo =&gt; false,<br \/>\n}-&gt;<br \/>\nclass { &#8216;mongodb::server&#8217;:<br \/>\nensure =&gt; &#8216;present&#8217;,<br \/>\nrestart =&gt; true,<br \/>\nbind_ip =&gt; [&#8216;127.0.0.1&#8217;],<br \/>\nport =&gt; 27017,<br \/>\nsmallfiles =&gt; true,<br \/>\n}<\/p>\n<h3>Install Elasticsearch<\/h3>\n<p>class { &#8216;elasticsearch&#8217;:<br \/>\nensure =&gt; &#8216;present&#8217;,<br \/>\nstatus =&gt; &#8216;enabled&#8217;,<br \/>\n<em>## Use Katello repository<\/em><br \/>\nmanage_repo =&gt; false,<br \/>\nrestart_on_change =&gt; true,<br \/>\n}-&gt;<br \/>\nelasticsearch::instance { &#8216;graylog&#8217;:<br \/>\nconfig =&gt; {<br \/>\n&#8216;cluster.name&#8217; =&gt; &#8216;graylog&#8217;,<br \/>\n&#8216;network.host&#8217; =&gt; &#8216;127.0.0.1&#8217;,<br \/>\n},<br \/>\njvm_options =&gt; [<br \/>\n&#8216;-Xms512m&#8217;,<br \/>\n&#8216;-Xmx512m&#8217;<br \/>\n]<br \/>\n}<\/p>\n<h3>Install Java and Graylog<\/h3>\n<p>include ::java<\/p>\n<p>class { &#8216;graylog::server&#8217;:<br \/>\nenable =&gt; true,<br \/>\nensure =&gt; &#8216;running&#8217;,<br \/>\nconfig =&gt; {<br \/>\n&#8216;is_master&#8217; =&gt; true,<br \/>\n&#8216;password_secret&#8217; =&gt; &#8216;3jC93bTD&#8230;OS7F7H87O&#8217;,<br \/>\n&#8216;root_password_sha2&#8217; =&gt; &#8216;008e3a245354b&#8230;f0d9913325f26b&#8217;,<br \/>\n&#8216;web_enable&#8217; =&gt; true,<br \/>\n&#8216;web_listen_uri&#8217; =&gt; &#8216;http:\/\/syslog.hl.local:9000\/&#8217;,<br \/>\n&#8216;rest_listen_uri&#8217; =&gt; &#8216;http:\/\/syslog.hl.local:9000\/api\/&#8217;,<br \/>\n&#8216;rest_transport_uri&#8217; =&gt; &#8216;http:\/\/syslog.hl.local:9000\/api\/&#8217;,<br \/>\n&#8216;root_timezone&#8217; =&gt; &#8216;GMT&#8217;,<br \/>\n}<br \/>\n}-&gt;<br \/>\n<em>##<br \/>\n## Use a script to automatically create<br \/>\n## UDP Syslog\/GELF inputs via Graylog API.<br \/>\n##<\/em><br \/>\nfile { &#8216;\/root\/syslog_inputs.sh&#8217;:<br \/>\nensure =&gt; file,<br \/>\nsource =&gt; &#8216;puppet:\/\/\/homelab_files\/syslog_inputs.sh&#8217;,<br \/>\nowner =&gt; &#8216;0&#8217;,<br \/>\ngroup =&gt; &#8216;0&#8217;,<br \/>\nmode =&gt; &#8216;0700&#8217;,<br \/>\nnotify =&gt; Exec[&#8216;create_syslog_inputs&#8217;],<br \/>\n}<br \/>\nexec {&#8216;create_syslog_inputs&#8217;:<br \/>\ncommand =&gt; &#8216;\/root\/syslog_inputs.sh&#8217;,<br \/>\nrefreshonly =&gt; true,<br \/>\n}<\/p>\n<p>The content of the file syslog_inputs.sh can be seen below.<\/p>\n<p>We create two Graylog inputs, one for syslog to bind to UDP 1514, and one for GELF. See the section below for port redirection from UDP 514 to UDP 1514 as Graylog cannot bind to UDP 514 unless run as root.<\/p>\n<p>#!\/bin\/bash<br \/>\nGRAYLOG_URL=&#8221;http:\/\/admin:<a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a>:9000\/api\/system\/inputs&#8221;;<\/p>\n<p>GRAYLOG_INPUT_SYSLOG_UDP=&#8217;<br \/>\n{<br \/>\n&#8220;global&#8221;: &#8220;true&#8221;,<br \/>\n&#8220;title&#8221;: &#8220;Syslog UDP&#8221;,<br \/>\n&#8220;configuration&#8221;: {<br \/>\n&#8220;port&#8221;: 1514,<br \/>\n&#8220;bind_address&#8221;: &#8220;0.0.0.0&#8221;<br \/>\n},<br \/>\n&#8220;type&#8221;: &#8220;org.graylog2.inputs.syslog.udp.SyslogUDPInput&#8221;<br \/>\n}&#8217;;<\/p>\n<p>GRAYLOG_INPUT_GELF_UDP=&#8217;<br \/>\n{<br \/>\n&#8220;global&#8221;: &#8220;true&#8221;,<br \/>\n&#8220;title&#8221;: &#8220;Gelf UDP&#8221;,<br \/>\n&#8220;configuration&#8221;: {<br \/>\n&#8220;port&#8221;: 12201,<br \/>\n&#8220;bind_address&#8221;: &#8220;0.0.0.0&#8221;<br \/>\n},<br \/>\n&#8220;type&#8221;: &#8220;org.graylog2.inputs.gelf.udp.GELFUDPInput&#8221;<br \/>\n}&#8217;;<\/p>\n<p>curl -s -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;$&#8221; $ &gt;\/dev\/null;<br \/>\ncurl -s -X POST -H &#8220;Content-Type: application\/json&#8221; -d &#8220;$&#8221; $ &gt;\/dev\/null;<\/p>\n<p>exit 0;<\/p>\n<h3>Configure Firewall<\/h3>\n<p>Configure firewall to allow WebUI, syslog and GELF traffic. Also configure port redirection as Graylog cannot bind to UDP 514 unless run as root.<\/p>\n<p>firewall { &#8216;007 allow Graylog HTTP\/S&#8217;:<br \/>\ndport =&gt; [80, 443, 9000],<br \/>\nsource =&gt; &#8216;10.11.1.0\/24&#8217;,<br \/>\nproto =&gt; tcp,<br \/>\naction =&gt; accept,<br \/>\n}-&gt;<br \/>\nfirewall { &#8216;008 allow Syslog&#8217;:<br \/>\ndport =&gt; [&#8216;514&#8217;, &#8216;1514&#8217;],<br \/>\nsource =&gt; &#8216;10.11.1.0\/24&#8217;,<br \/>\nproto =&gt; udp,<br \/>\naction =&gt; accept,<br \/>\n}-&gt;<br \/>\nfirewall { &#8216;009 redirect Syslog 514 to Graylog 1514&#8217;:<br \/>\nchain =&gt; &#8216;PREROUTING&#8217;,<br \/>\njump =&gt; &#8216;REDIRECT&#8217;,<br \/>\nproto =&gt; &#8216;udp&#8217;,<br \/>\ndport =&gt; &#8216;514&#8217;,<br \/>\ntoports =&gt; &#8216;1514&#8217;,<br \/>\ntable =&gt; &#8216;nat&#8217;,<br \/>\n}-&gt;<br \/>\nfirewall { &#8216;010 allow Gelf&#8217;:<br \/>\ndport =&gt; [&#8216;12201&#8217;],<br \/>\nsource =&gt; &#8216;10.11.1.0\/24&#8217;,<br \/>\nproto =&gt; udp,<br \/>\naction =&gt; accept,<br \/>\n}<\/p>\n<h3>Apache Reverse Proxy with TLS<\/h3>\n<p>Install Apache as a reverse proxy for Graylog.<\/p>\n<p>class { &#8216;apache&#8217;:<br \/>\ndefault_vhost =&gt; false,<br \/>\ndefault_ssl_vhost =&gt; false,<br \/>\ndefault_mods =&gt; false,<br \/>\nmpm_module =&gt; &#8216;prefork&#8217;,<br \/>\nserver_signature =&gt; &#8216;Off&#8217;,<br \/>\nserver_tokens =&gt; &#8216;Prod&#8217;,<br \/>\ntrace_enable =&gt; &#8216;Off&#8217;,<br \/>\n}<br \/>\ninclude apache::mod::proxy<br \/>\ninclude apache::mod::proxy_http<br \/>\ninclude apache::mod::rewrite<br \/>\ninclude apache::mod::ssl<br \/>\ninclude apache::mod::headers<\/p>\n<p>apache::vhost { &#8216;graylog_http&#8217;:<br \/>\nport =&gt; 80,<br \/>\nservername =&gt; &#8216;syslog.hl.local&#8217;,<br \/>\nrewrites =&gt; [<br \/>\n{ rewrite_rule =&gt; [&#8216;(.*) https:\/\/%%&#8217;],<br \/>\nrewrite_cond =&gt; [&#8216;% off&#8217;],<br \/>\n},<br \/>\n],<br \/>\ndocroot =&gt; false,<br \/>\nmanage_docroot =&gt; false,<br \/>\nsuphp_engine =&gt; &#8216;off&#8217;,<br \/>\n}<br \/>\napache::vhost { &#8216;graylog_https&#8217;:<br \/>\nport =&gt; 443,<br \/>\nservername =&gt; &#8216;syslog.hl.local&#8217;,<br \/>\ndocroot =&gt; false,<br \/>\nmanage_docroot =&gt; false,<br \/>\nsuphp_engine =&gt; &#8216;off&#8217;,<br \/>\nssl =&gt; true,<br \/>\nssl_cert =&gt; &#8216;\/etc\/pki\/tls\/certs\/hl.crt&#8217;,<br \/>\nssl_key =&gt; &#8216;\/etc\/pki\/tls\/private\/hl.key&#8217;,<br \/>\nssl_protocol =&gt; [&#8216;all&#8217;, &#8216;-SSLv2&#8217;, &#8216;-SSLv3&#8217;],<br \/>\nssl_cipher =&gt; &#8216;HIGH:!aNULL!MD5:!RC4&#8217;,<br \/>\nssl_honorcipherorder =&gt; &#8216;On&#8217;,<br \/>\n<em>## Pass a string of custom configuration directives<\/em><br \/>\ncustom_fragment =&gt; &#8216;<br \/>\nProxyRequests Off<br \/>\n&lt;Proxy *&gt;<br \/>\nRequire ip 10.11.1.0\/24<br \/>\n&lt;\/Proxy&gt;<br \/>\n&lt;Location \/&gt;<br \/>\nRequestHeader set X-Graylog-Server-URL &#8220;https:\/\/syslog.hl.local\/api\/&#8221;<br \/>\nProxyPass http:\/\/syslog.hl.local:9000\/<br \/>\nProxyPassReverse http:\/\/syslog.hl.local:9000\/<br \/>\n&lt;\/Location&gt;<br \/>\n&#8216;,<br \/>\n}<\/p>\n<h2>Configure Log Forwarding on All Servers<\/h2>\n<p>We want to configure all homelab servers to forward syslog to Graylog.<\/p>\n<p>This needs to go in to the main environment manifest file \/etc\/puppetlabs\/code\/environments\/homelab\/manifests\/site.pp so that configuration is applied to all servers.<\/p>\n<p>class { &#8216;rsyslog::client&#8217;:<br \/>\nlog_remote =&gt; true,<br \/>\nlog_local =&gt; true,<br \/>\nremote_servers =&gt; false,<br \/>\nserver =&gt; &#8216;syslog.hl.local&#8217;,<br \/>\nport =&gt; &#8216;1514&#8217;,<br \/>\nremote_type =&gt; &#8216;udp&#8217;,<br \/>\nremote_forward_format =&gt; &#8216;RSYSLOG_SyslogProtocol23Format&#8217;,<br \/>\n}<\/p>\n<p>The result should be something like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lisenet.com\/wp-content\/uploads\/2018\/03\/lisenet-homelab-graylog.png\" alt=\"\" width=\"763\" height=\"507\" \/><\/p>\n<p>All servers forward logs to Graylog.<\/p>\n<p><a href=\"https:\/\/www.lisenet.com\/2018\/configure-graylog-server-with-puppet\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re going to use Puppet to install and configure a Graylog server. This article is part of the Homelab Project with KVM, Katello and Puppet series. See here (CentOS 7) and here (CentOS 6) for blog posts on how to configure a Graylog server manually. Homelab We have a CentOS 7 VM installed which we &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/configure-graylog-server-with-puppet-lisenet-com-linux-security\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Configure Graylog Server with Puppet | Lisenet.com :: Linux | Security&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-624","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=624"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/624\/revisions"}],"predecessor-version":[{"id":751,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/624\/revisions\/751"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}