-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Secure API #13308
Secure API #13308
Conversation
909e65b
to
42c8826
Compare
@jsvd I would appreciate a WIP-review to make sure this is headed in the right direction.
|
Good stuff!! I've been playing with this and I like the details around deprecating the old settings and the warnings when incompatible settings are used. Regarding authorization, I'm wondering if we should prepare the settings to account for multiple users instead of 1 single user. As soon as we add 1 feature that is more security sensitive like adding a pipeline we'll want separate users. For example, 1 for elastic agent doing monitoring and 1 for operators manipulating pipelines (and maybe even 1 other that can only grab metrics, for diagnostics). As for encryption, I'm worried about how much Puma's MiniSSL's mini nature will harm our ability to provide a good tls experience to users. Besides the issue you've hit with client authentication, here's a couple of other limitations:
|
My primary goal with this PR is to provide an interface that we can maintain and grow for the years to come, along-side an implementation that provides some value now. With that in mind:
I agree that a single user isn't going to be enough for features we want to add in the future, but I believe that the interface provides us room to add this in a backward-compatible way if and when those requirements become clear. For example, if we were to add role-based safeguards to different end-points, we could easily add
When we swap out minissl for a different implementation, we can add an option like
Absolutely. This interface is meant to be an ever-expanding subset of the one provided by Elasticsearch's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few comments, mostly minor.
git-wise I'd prefer for this PR to be split into two. wdyt?
One could group all internal changes to settings:
- docker/data/logstash/env2yaml/env2yaml.go
- logstash-core/lib/logstash/patches/clamp.rb
- logstash-core/lib/logstash/patches/puma.rb
- logstash-core/lib/logstash/settings.rb
- logstash-core/logstash-core.gemspec
- maybe parts of logstash-core/lib/logstash/webserver.rb
A second PR would have all the code for the new api settings, deprecating old ones:
- logstash-core/lib/logstash/agent.rb
- logstash-core/lib/logstash/runner.rb
- logstash-core/lib/logstash/environment.rb
- yml/docs
7619616
to
5f2e32f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functionality LGTM, I added only 3 nitpicks in this review.
You've mentioned this before and I'd appreciate a test, even if just for the happy path, confirming the correct emission of certificates from a jks/p12 keystore during TLS handshake.
For the assets, if needed we can have a separate repository with pregenerated root certs, server certs, etc, and a github action scheduled to, every 6 months, call the generate script to avoid expirations.
logstash-core/spec/logstash/settings/setting_with_deprecated_alias_spec.rb
Outdated
Show resolved
Hide resolved
a9ae89c
to
263202b
Compare
@jsvd I just now saw your comment requesting this be split into two PR's. I've just finished adding the requested tests and getting everything back to green, and will attempt to pare it off into two separate PR's along those lines shortly. I've been maintaining "one thing" per commit, rebasing and squashing as I go, so in theory it shouldn't be too difficult. |
@jsvd this should be ready for a final review; I've addressed your concerns and appreciate your help in building out the integration tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see 4 leftover files from the client cert cleanup, that should be deleted:
qa/integration/fixtures/webserver_certs/generated/client_from_intermediate.jks
qa/integration/fixtures/webserver_certs/generated/client_from_intermediate.p12
qa/integration/fixtures/webserver_certs/generated/client_from_root.jks
qa/integration/fixtures/webserver_certs/generated/client_from_root.p12
Other than that, it all LGTM!! 🎉
It looks like I checked in a mixed-generation of certificates, such that the |
🤦🏼 I was using |
jenkins test this again please (ES failed to download in integration test setup) |
jenkins test this again please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested a few scenarios locally: enabling tls, setting up basic auth, using passwords from logstash keystore, using wrong credentials.
All good, LGTM 🚢
* settings: add "deprecated alias" support A deprecated alias provides a path for renaming a setting. - When a deprecated alias is set on its own, a deprecation notice is emitted but fetching the canonical setting value will reflect the value set with the deprecated alias. - When both the canonical setting (new name) and the deprecated alias (old name) are specified, it is an error condition. - When the value of the deprecated alias is queried, a warning is emitted to the logger and only the value explicitly set to the deprecated alias is returned. Additionally, some relevant cleanup is also included: - Starting Logstash with invalid settings no longer results in the obtuse "An unexpected error occurred" with backtrace and exception data obscuring the issue. Instead, a simple message is emitted indicating that the settings are invalid along with the originating exception's message. - The various settings implementations share a common logger, instead of each implementation class providing its own. This is aimed to reduce noise from the logs and to ensure specs validating logging do not need to tie so closely to implementation details. * settings: add password-wrapped setting * settings: make any setting type capable of being nullable * settings: add `Settings#names` to power programatic iteration * cli: route CLI-flag deprecations in to deprecation logger * settings: group API-related settings under `api.*` retains deprecated aliases, and is fully backward-compatible. * webserver: cleanup orphaned attr accessors for never-set ivars * api: pull settings extraction down from agent This net-no-change refactor introduces a new method `WebServer#from_settings` that bridges the gap between Logstash settings and Puma-related options, so that future additions to the API settings don't add complexity to the Agent. It also has the benefit of initializing the API Rack App and just ONCE, instead of once per attempted HTTP port. * api: add optional TLS/SSL * docs: reference API security settings * api: when configured securely, bind to all available interfaces by default * cleanup: remove unused cert artifacts * tests: generate fresh webserver certificates * certs: actually add the binary keystores 🤦 Remove references to Java 8 in docs
…lastic#13380) With elastic#13308 configuration namespace that started with `http.` was renamed to `api.`, this commit fix a usage left behind. Use the new `api.enabled` setting in one place instead of the deprecated `http.enable`. Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com> (cherry picked from commit 88c80eb)
…lastic#13380) With elastic#13308 configuration namespace that started with `http.` was renamed to `api.`, this commit fix a usage left behind. Use the new `api.enabled` setting in one place instead of the deprecated `http.enable`. Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com> (cherry picked from commit 88c80eb)
…api.enabled' (#13380) (#13407) With #13308 configuration namespace that started with `http.` was renamed to `api.`, this commit fix a usage left behind. Use the new `api.enabled` setting in one place instead of the deprecated `http.enable`. Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com> (cherry picked from commit 88c80eb)
… 'api.enabled' (#13380) (#13408) With #13308 configuration namespace that started with `http.` was renamed to `api.`, this commit fix a usage left behind. Use the new `api.enabled` setting in one place instead of the deprecated `http.enable`. Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com> (cherry picked from commit 88c80eb)
Release notes
What does this PR do?
Partial implementation of #13196 adding SSL and Basic auth to the Logstash API
Why is it important/What is the impact to the user?
Empowers users to secure the Logstash API, and to bind to non-loopback interfaces by default when the API is secured.
This in turn will empower future development of the API features.
Checklist
Author's Checklist
api.*
api.ssl
settingsapi.ssl.enabled
api.ssl.keystore.path
andapi.ssl.keystore.password
api.client_authentication
api.ssl.supported_protocols
api.auth
settingsapi.auth.type
:none
andbasic
api.auth.basic.username
andapi.auth.basic.password
api.http.host
defaults tolocalhost
whenapi.ssl.enabled: true
andapi.auth.type: basic
api.http.host
defaults tolocalhost
whenapi.ssl.enabled: true
andapi.ssl.client_authentication: required