Skip to content

Conversation

@mashhurs
Copy link
Contributor

@mashhurs mashhurs commented Feb 8, 2024

Description

This change includes number of Logstash improvements:

  • auto pipeline reload: sometimes we need to update the pipeline config and run with some integrations. Todo so, we need to make pipeline config writable (disable read-only set logic) and add --config.reload.automatic when running Logstash to avoid extra container restart.
  • Separated elastic-package generated config as it will be mounted file system, cannot be writable while docker container is active. Current approach generates and copies to a writable file where final file can be changed and Logstash automatically reloads pipeline.
  • enable SSL between LS and agent: depends on Refactor New cert to use enum #1664, most users use SSL between agent and Logstash and it is the best practise.
  • remove doc id in pipeline config to cover generic cases: the integrations with time series do not accept the document with ID set (reference) - this will cause integration tests fail and we believe this will be anyway short term solution, we should rather focus on long-term: changeable config, so I am leaving this AS-IS as well.

@mashhurs mashhurs requested review from a team and bhapas February 8, 2024 20:15
@mashhurs mashhurs self-assigned this Feb 8, 2024
bhapas
bhapas previously requested changes Feb 9, 2024
Copy link
Contributor

@bhapas bhapas left a comment

Choose a reason for hiding this comment

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

To have ssl enabled between logstash and agent, a client certificate needs to be added to the fleet-logstash-output created in fleet. Similar to https://github.com/elastic/elastic-package/pull/1646/files#diff-16829f0b151b844f24aebc77c8aea194ae3b84fca32debdd296aa22cba7a99bfR36

These certificates are then authorized by logstash

@mashhurs mashhurs force-pushed the logstash-improvements-reload branch from f8d5bb3 to bd9c877 Compare February 9, 2024 18:13
@mashhurs
Copy link
Contributor Author

mashhurs commented Feb 9, 2024

To have ssl enabled between logstash and agent, a client certificate needs to be added to the fleet-logstash-output created in fleet. Similar to https://github.com/elastic/elastic-package/pull/1646/files#diff-16829f0b151b844f24aebc77c8aea194ae3b84fca32debdd296aa22cba7a99bfR36

These certificates are then authorized by logstash

Thanks for letting me know. Since I don't have much internal detail knowledge, I will leave this part AS-IS and focus on my current needs.

@mashhurs mashhurs force-pushed the logstash-improvements-reload branch from edfec7c to 6cdd220 Compare February 12, 2024 23:38
@mashhurs mashhurs requested a review from bhapas February 13, 2024 00:10
@bhapas bhapas dismissed their stale review February 13, 2024 05:22

changes provided

@mashhurs mashhurs force-pushed the logstash-improvements-reload branch from 774fbf1 to 75ca508 Compare February 13, 2024 20:43
@mashhurs mashhurs requested review from bhapas and jsoriano February 13, 2024 20:47
@mashhurs mashhurs requested a review from bhapas February 13, 2024 23:45
Comment on lines 175 to 176
- "../certs/logstash:/usr/share/logstash/config/certs"
- "../certs/elasticsearch/cert.pem:/usr/share/logstash/config/certs/elasticsearch.pem"
Copy link
Member

Choose a reason for hiding this comment

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

To ensure that we neither try to write here when running locally.

Suggested change
- "../certs/logstash:/usr/share/logstash/config/certs"
- "../certs/elasticsearch/cert.pem:/usr/share/logstash/config/certs/elasticsearch.pem"
- "../certs/logstash:/usr/share/logstash/config/certs:ro"
- "../certs/elasticsearch/cert.pem:/usr/share/logstash/config/certs/elasticsearch.pem:ro"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems making config/certs read-only, mounting elasticsearch.pem is failing?! Removing read-only from certs works fine, we need to mount file one by one if it is strictly required.

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/opt/buildkite-agent/.elastic-package/profiles/logstash/certs/elasticsearch/cert.pem" to rootfs at "/usr/share/logstash/config/certs/elasticsearch.pem": open /var/lib/docker/overlay2/c73fe26af0e42262b9972a5dc32a073d3141e9dee2467ca8ed3bc5d07ce6733b/merged/usr/share/logstash/config/certs/elasticsearch.pem: read-only file system: unknown

@mashhurs mashhurs force-pushed the logstash-improvements-reload branch from 91972a2 to eaed0b5 Compare February 14, 2024 15:54
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @mashhurs

@mashhurs mashhurs requested a review from jsoriano February 15, 2024 00:18
Copy link
Contributor

@bhapas bhapas left a comment

Choose a reason for hiding this comment

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

LGTM. Please hold for @jsoriano to approve as well

# Also logstash-filter-elastic_integration plugin is installed by default to run ingest pipelines in logstash.
# elastic-package#1637 made improvements to enable logstash stats through port 9600.
command: bash -c 'openssl pkcs8 -inform PEM -in /usr/share/logstash/config/certs/key.pem -topk8 -nocrypt -outform PEM -out /tmp/logstash.pkcs8.key && chmod +x /tmp/logstash.pkcs8.key && if [[ ! $(bin/logstash-plugin list) == *"logstash-filter-elastic_integration"* ]]; then echo "Missing plugin logstash-filter-elastic_integration, installing now" && bin/logstash-plugin install logstash-filter-elastic_integration; fi && bin/logstash -f /usr/share/logstash/pipeline/logstash.conf'
command: bash /usr/share/logstash/startup.sh
Copy link
Member

Choose a reason for hiding this comment

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

👍 thanks!


# runs Logstash
run() {
bin/logstash -f "$LOGSTASH_HOME/pipeline/logstash.conf" --config.reload.automatic
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Could we use exec to replace the process?

Suggested change
bin/logstash -f "$LOGSTASH_HOME/pipeline/logstash.conf" --config.reload.automatic
exec bin/logstash -f "$LOGSTASH_HOME/pipeline/logstash.conf" --config.reload.automatic

Comment on lines +11 to +12
openssl pkcs8 -inform PEM -in "$ls_cert_path/key.pem" -topk8 -nocrypt -outform PEM -out "/tmp/logstash.pkcs8.key"
chmod 777 "/tmp/logstash.pkcs8.key"
Copy link
Member

Choose a reason for hiding this comment

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

Nit. It doesn't use to be a good practice to write a key in /tmp or with 777. But this is a testing scenario, so as you prefer if we don't have another way to do it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good! Let me follow up Nits with separate PR because this is somehow blocking my another task: elastic/logstash-filter-elastic_integration#122 (comment)

@mashhurs mashhurs merged commit b2ee264 into elastic:main Feb 15, 2024
@mashhurs mashhurs deleted the logstash-improvements-reload branch February 15, 2024 14:43
jsoriano added a commit that referenced this pull request Feb 19, 2024
Polish some things in the logstash scenario:
* Pre-build logstash image:
  * It includes the plugin now so it doesn't need to be installed on every run, speeding up startup after first run.
  * It includes the configuration, so it can be modified with auto-reload, as introduced in #1668.
* Use private key without converting it to PKCS8.
* Use actual CA instead of elasticsearch certificate as CA in logstash output.
* Startup script removed as operations moved to other places or not needed.
* Use the same configuration template for serverless and compose providers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants