Skip to content

Commit

Permalink
Merge pull request #101 from VariableDeclared/lma-improvements/graylo…
Browse files Browse the repository at this point in the history
…g-tls

Enable TLS in filebeat
  • Loading branch information
esunar committed Jan 3, 2023
2 parents 10317fc + 756339e commit 4e3a715
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ parts:
bases:
- build-on:
- name: ubuntu
channel: "20.04"
channel: "22.04"
architectures: ["amd64"]
run-on:
- name: ubuntu
Expand Down
4 changes: 3 additions & 1 deletion layer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ repo: https://github.com/juju-solutions/layer-filebeat.git
includes:
- 'layer:beats-base'
- 'layer:logrotate'
- 'layer:tls-client'
options:
apt:
packages:
Expand All @@ -15,4 +16,5 @@ options:
- weekly
- compress
- missingok

tls-client:
ca_certificate_path: /etc/ssl/certs/filebeat-logstash.crt
13 changes: 13 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,16 @@ description: |
sends this information to Logstash for further parsing and enrichment or to
Elasticsearch for centralized storage and analysis.
series: []
subordinate: true
tags:
- filebeat
requires:
beats-host:
interface: juju-info
scope: container
logstash:
interface: elastic-beats
elasticsearch:
interface: elasticsearch
kafka:
interface: kafka
23 changes: 16 additions & 7 deletions reactive/filebeat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import charms.apt
from charms.layer import status
from charms.reactive import when
from charms.reactive import when_not
from charms.reactive import set_state
from charms.reactive import remove_state
from charms.reactive import hook
from charms.reactive import (
hook,
is_state,
when,
when_not,
set_state,
remove_state
)
from charms.reactive.helpers import data_changed

from charmhelpers.core import unitdata
Expand All @@ -29,7 +32,7 @@
KUBE_CONFIG = '/root/.kube/config'
LOGSTASH_SSL_CERT = '/etc/ssl/certs/filebeat-logstash.crt'
LOGSTASH_SSL_KEY = '/etc/ssl/private/filebeat-logstash.key'

TLS_CLIENT_CA_PATH = '/etc/ssl/certs/filebeat-logstash.crt'

@when_not('apt.installed.filebeat')
def install_filebeat():
Expand All @@ -50,6 +53,7 @@ def blocked_until_reinstall():

@when('beat.render')
@when('apt.installed.filebeat')
@when('certificates.available')

This comment has been minimized.

Copy link
@verterok

verterok Jan 6, 2023

Contributor

This is causing problems...as in the render not happening unless the charm has certificates available

@restart_on_change({
LOGSTASH_SSL_CERT: ['filebeat'],
LOGSTASH_SSL_KEY: ['filebeat'],
Expand All @@ -76,7 +80,8 @@ def render_filebeat_template():
cfg_original_hash = file_hash(FILEBEAT_CONFIG)
connections = render_without_context(
'filebeat-{}.yml'.format(version),
FILEBEAT_CONFIG
FILEBEAT_CONFIG,
{ "logstash_ssl_cert": is_state('certificates.available') }
)
cfg_new_hash = file_hash(FILEBEAT_CONFIG)

Expand All @@ -100,6 +105,9 @@ def manage_filebeat_logstash_ssl():
Create the cert/key files when both logstash_ssl options have been set;
update when either config option changes; remove if either gets unset.
"""
if is_state('certificates.available'):
return

logstash_ssl_cert = config().get('logstash_ssl_cert')
logstash_ssl_key = config().get('logstash_ssl_key')
if logstash_ssl_cert and logstash_ssl_key:
Expand Down Expand Up @@ -210,3 +218,4 @@ def update_status():
message = "filebeat service not running"

status_set(state, message)

0 comments on commit 4e3a715

Please sign in to comment.