Skip to content
This repository has been archived by the owner on Apr 25, 2021. It is now read-only.

Helm: add support for secret rules and config #33

Merged
merged 2 commits into from
Sep 17, 2020
Merged

Conversation

cookandy
Copy link
Contributor

Hi there!

This PR adds support for loading the Elastalert configuration and/or rules via Kubernetes secrets.

Three new variables were added to values.yaml:

  • secretConfigName: name of the secret which holds the Elastalert config. Note: this will overwrite the generated config and must contain a full working config
  • secretRulesName: name of the secret which holds the Elastalert rules. Note: this will overwrite the generated rules and must contain all rules in separate data fields
  • secretRulesList: a list of rules to enable from the secret

It's worth mentioning that it was not possible to load a single secret with multiple rules separated by ---, it threw the error below. This is why secretRulesList was needed.

Index elastalert already exists. Skipping index creation.
Traceback (most recent call last):
  File "/usr/local/bin/elastalert", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/elastalert/elastalert.py", line 2049, in main
    client = ElastAlerter(args)
  File "/usr/local/lib/python3.6/site-packages/elastalert/elastalert.py", line 140, in __init__
    self.rules = self.rules_loader.load(self.conf, self.args)
  File "/usr/local/lib/python3.6/site-packages/elastalert/loaders.py", line 115, in load
    rule = self.load_configuration(rule_file, conf, args)
  File "/usr/local/lib/python3.6/site-packages/elastalert/loaders.py", line 179, in load_configuration
    rule = self.load_yaml(filename)
  File "/usr/local/lib/python3.6/site-packages/elastalert/loaders.py", line 197, in load_yaml
    loaded = self.get_yaml(filename)
  File "/usr/local/lib/python3.6/site-packages/elastalert/loaders.py", line 526, in get_yaml
    return yaml_loader(filename)
  File "/usr/local/lib/python3.6/site-packages/staticconf/loader.py", line 168, in yaml_loader
    return yaml.load(fh, Loader=SafeLoader) or {}
  File "/usr/local/lib/python3.6/site-packages/yaml/__init__.py", line 114, in load
    return loader.get_single_data()
  File "/usr/local/lib/python3.6/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "/usr/local/lib/python3.6/site-packages/yaml/composer.py", line 43, in get_single_node
    event.start_mark)
yaml.composer.ComposerError: expected a single document in the stream
  in "/opt/rules/all-secret-rules.yaml", line 2, column 1
but found another document
  in "/opt/rules/all-secret-rules.yaml", line 10, column 1

I have updated the documentation and provided examples of working secrets in the values.yaml.

Thanks!

Copy link
Owner

@jertel jertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Will you please bump the chart.yaml version to 1.8.0?

@cookandy cookandy requested a review from jertel September 16, 2020 23:01
@jertel jertel merged commit f1d7126 into jertel:master Sep 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants