-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Moved Ruby ValidatedPassword setting to Java implementation #18185
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
Moved Ruby ValidatedPassword setting to Java implementation #18185
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
|
This pull request does not have a backport label. Could you fix it @andsel? 🙏
|
6ca07fb to
fc2e9aa
Compare
|
fc2e9aa to
37653a5
Compare
37653a5 to
42bd8bc
Compare
|
run exhaustive tests |
donoghuc
left a comment
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.
Looks good. One question about log level for one of the messages, but not a blocking review.
logstash-core/src/test/java/org/logstash/settings/PasswordSettingTest.java
Outdated
Show resolved
Hide resolved
logstash-core/src/main/java/org/logstash/settings/ValidatedPasswordSetting.java
Outdated
Show resolved
Hide resolved
| if (value instanceof Map) { | ||
| value = convertKeyRubyLabelsToStrings((Map<Object, Object>) value); | ||
| } | ||
| // TODO handle lists if needed ? |
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 dont see how lists would be used in practice with this setting. Symbols, maybe? Should we convert symbol to string somewhere?
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.
Given the places this setting is used (only LogStash::WebServer) and how the options tree is created
logstash/logstash-core/lib/logstash/webserver.rb
Lines 36 to 70 in b15c6c5
| options = {} | |
| options[:http_host] = settings.get('api.http.host') # may be overridden later if API configured securely | |
| options[:http_ports] = settings.get('api.http.port') | |
| options[:http_environment] = settings.get('api.environment') | |
| if settings.get('api.ssl.enabled') | |
| ssl_params = {} | |
| ssl_params[:keystore_path] = required_setting(settings, 'api.ssl.keystore.path', "api.ssl.enabled") | |
| ssl_params[:keystore_password] = required_setting(settings, 'api.ssl.keystore.password', "api.ssl.enabled") | |
| ssl_params[:supported_protocols] = settings.get('api.ssl.supported_protocols') | |
| options[:ssl_params] = ssl_params.freeze | |
| else | |
| warn_ignored(logger, settings, "api.ssl.", "api.ssl.enabled") | |
| end | |
| if settings.get('api.auth.type') == 'basic' | |
| auth_basic = {} | |
| auth_basic[:username] = required_setting(settings, 'api.auth.basic.username', "api.auth.type") | |
| auth_basic[:password] = required_setting(settings, 'api.auth.basic.password', "api.auth.type") | |
| password_policies = {} | |
| password_policies[:mode] = required_setting_with_changing_default(settings, 'api.auth.basic.password_policy.mode', "api.auth.type", "ERROR") | |
| password_policies[:length] = {} | |
| password_policies[:length][:minimum] = required_setting(settings, 'api.auth.basic.password_policy.length.minimum', "api.auth.type") | |
| if !password_policies[:length][:minimum].between?(8, 1024) | |
| fail(ArgumentError, "api.auth.basic.password_policy.length.minimum has to be between 8 and 1024.") | |
| end | |
| password_policies[:include] = {} | |
| password_policies[:include][:upper] = required_setting(settings, 'api.auth.basic.password_policy.include.upper', "api.auth.type") | |
| password_policies[:include][:lower] = required_setting(settings, 'api.auth.basic.password_policy.include.lower', "api.auth.type") | |
| password_policies[:include][:digit] = required_setting(settings, 'api.auth.basic.password_policy.include.digit', "api.auth.type") | |
| password_policies[:include][:symbol] = required_setting(settings, 'api.auth.basic.password_policy.include.symbol', "api.auth.type") | |
| auth_basic[:password_policies] = password_policies | |
| options[:auth_basic] = auth_basic.freeze |
- if a
ListorArrayis encountered throw a type error
~~2. convert the value to string
2a. or using explicit castingif (value instanceof RubySymbol) { ((RubySymbol) value).asJavaString(); }
2b. or usevalue.toString()~~
We can't convert because the value is handled in https://github.com/elastic/logstash/pull/18185/files#diff-8e93bdd2987d82a339de8febcd961849e191bc2ce9f5aab2a4a7b68afc1e9be3R87-R91 and we have to grant that if it's nil it's decoded as "" empty string, plus the toString() is already invoked there.
So RubySymbol shouldn't happen and neither List or Array.
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.
That makes sense. Thanks for the extra details.
Co-authored-by: Cas Donoghue <[email protected]>
logstash-core/src/main/java/org/logstash/settings/ValidatedPasswordSetting.java
Outdated
Show resolved
Hide resolved
donoghuc
left a comment
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.
Adjustments look good! One question about a new import but other than that its all good. #18185 (comment)
…abelsToStrings method needs to work on other collection values.
💚 Build Succeeded
History
cc @andsel |
|
@Mergifyio backport 8.19 9.1 9.2 |
✅ Backports have been created
|
Translates ValidatedPassword setting class into plain Java. This PR copies the Rspec test also to JUnit, plus removed a log validation test, because mocking of the ValidatedPasswordSetting Java class seems to do not work in Rspec. Co-authored-by: Cas Donoghue <[email protected]> (cherry picked from commit 3659b6f) # Conflicts: # logstash-core/lib/logstash/settings.rb # logstash-core/spec/logstash/settings_spec.rb # logstash-core/src/test/java/org/logstash/settings/PasswordSettingTest.java
Translates ValidatedPassword setting class into plain Java. This PR copies the Rspec test also to JUnit, plus removed a log validation test, because mocking of the ValidatedPasswordSetting Java class seems to do not work in Rspec. Co-authored-by: Cas Donoghue <[email protected]> (cherry picked from commit 3659b6f) # Conflicts: # logstash-core/lib/logstash/settings.rb # logstash-core/spec/logstash/settings_spec.rb # logstash-core/src/test/java/org/logstash/settings/PasswordSettingTest.java
Translates ValidatedPassword setting class into plain Java. This PR copies the Rspec test also to JUnit, plus removed a log validation test, because mocking of the ValidatedPasswordSetting Java class seems to do not work in Rspec. Co-authored-by: Cas Donoghue <[email protected]> (cherry picked from commit 3659b6f) # Conflicts: # logstash-core/lib/logstash/settings.rb # logstash-core/spec/logstash/settings_spec.rb # logstash-core/src/test/java/org/logstash/settings/PasswordSettingTest.java
|
This pull request does not have a backport label. Could you fix it @andsel? 🙏
|





Release notes
[rn:skip]
What does this PR do?
Translates ValidatedPassword setting class into plain Java. This PR copies the Rspec test also to JUnit, plus removed a log validation test, because mocking of the
ValidatedPasswordSettingJava class seems to do not work in Rspec.Why is it important/What is the impact to the user?
N/A
Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files (and/or docker env variables)Author's Checklist
How to test this PR locally
On
config/logstash.ymlenable basic authetication on HTTP API with an invalid password and configurepassword_policy.modeto warn a log message:run Logstash:
bin/logstash -e "input{stdin{}} output{stdout{codec=>rubydebug}}"and verify that in log appears:
and doesn't crash.
Then switch
api.auth.basic.password_policy.modetoERRORand check in logs appears a stacktrace:
Related issues