Skip to content

Conversation

@jkakavas
Copy link
Contributor

@jkakavas jkakavas commented Apr 5, 2020

The secure_settings_password was never taken into consideration in
the ReloadSecureSettings API. This commit fixes that and adds
necessary REST layer testing. Doing so, it also

  • Allows TestClusters to have a password protected keystore
    so that it can be set for tests.
  • Adds a parameter to the run task so that elastisearch can
    be run with a password protected keystore from source.

jkakavas added 3 commits April 5, 2020 16:21
The secure_settings_password was never taken into consideration in
the ReloadSecureSettings API. This commit fixes that and adds
necessary REST layer testing. Doing so, it also

- Allows TestClusters to have a password protected keystore
so that it can be set for tests.
- Adds a parameter to the run task so that elastisearch can
be run with a password protected keystore.
-
@jkakavas jkakavas added >bug :Delivery/Build Build or test infrastructure :Security/Security Security issues without another label v8.0.0 v7.7.0 labels Apr 5, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Build)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (:Security/Security)

request.withContentOrSourceParamParserOrNull(parser -> {
if (parser != null) {
final NodesReloadSecureSettingsRequest nodesRequest = nodesRequestBuilder.request();
final NodesReloadSecureSettingsRequest nodesRequest = PARSER.parse(parser, null);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the result of a master merge gone wrong in the feature branch : 4780880#diff-0187f4b109fbd7256c987cceae7691caL76

This is the actual fix and the only change necessary. If the buildSrc changes need further discussion, we could just merge the fix and the rest of the test changes when ready.

if (keystorePassword != null && keystorePassword.length() > 0) {
try {
Files.write(esStdinFile, (keystorePassword + "\n").getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE);
processBuilder.redirectInput(esStdinFile.toFile());
Copy link
Member

Choose a reason for hiding this comment

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

nits: the redirectInput call can be placed outside of the try block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do we gain by doing so? If Files#write throws, we would still fail with aTestClustersException before we reach redirectInput`

Copy link
Member

Choose a reason for hiding this comment

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

It makes no difference in actual execution outcome for this particular scenario. It's a choice of style, keep error handling specific and accurate to what is targeting for. It's akin to formatting and method extraction, but a bit more: if future changes make the extra method calls throw the same exception, it will not be handled automatically and potentially unwanted by the broader-than-necessary try-catch block. It does not apply to this particular case, that's why I called it "nits". But woud anyhow prefer keeping any context as small as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, gotcha

"secure_settings_password": "s3cr3t"
}
--------------------------------------------------
// NOTCONSOLE
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these NOTCONSOLE? They look console to me.

I realise it's existing, but it seems like this docs issue is due in part to these not being treated as testable snippets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I forgot to enable them :) When this was first introduced, I think NOTCONSOLE was there to cater for the fact that we couldn't set the keystore password in a proper way in the docs cluster

}
},
"body": {
"description": "The password for the elasticsearch keystore",
Copy link
Contributor

Choose a reason for hiding this comment

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

This implies that the body should be the raw password, I think we want something more like:

Suggested change
"description": "The password for the elasticsearch keystore",
"description": "An object containing password for the elasticsearch keystore",

- is_true: cluster_name
- match: { nodes.$node_id.reload_exception.type: "security_exception" }
- match: { nodes.$node_id.reload_exception.reason: "Provided keystore password was incorrect" }

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have a version with no password as well?
That should fail with the same error, but I think it's worth a test that it's not failing on "password is required" or a NPE, etc.

@jkakavas
Copy link
Contributor Author

jkakavas commented Apr 6, 2020

@mark-vieira , @williamrandolph I'm not sure what is the best way to set keystorePassword is dor multiple qa projects that need this, open to ideas and suggestions. It's either we set a keystore password in all our test clusters ( on one hand why not, on the other this is not our default behavior ) we try to figure out all the tests that would run rest-api-spec/test/nodes.reload_secure_settings/10_basic.yml ( do we have a way to do this? ) and set the keystore password only for those test clusters

@jkakavas
Copy link
Contributor Author

jkakavas commented Apr 6, 2020

Chatted with @rjernst about this, I will remove the keystore password from the core rest tests and I will add a new QA project with an ESRestTestCase test for reloading secure settings with a password protected keystore

@@ -0,0 +1,52 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason this is created in x-pack is that calling the reload settings api with a password require transport SSL to be configured. We could move this to qa and run with OSS too, if we limit this to an 1 node cluster

@jkakavas
Copy link
Contributor Author

jkakavas commented Apr 7, 2020

@elasticmachine update branch

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

A few suggestions, otherwise LGTM

}

@Option(
option = "keystore-password",
Copy link
Member

Choose a reason for hiding this comment

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

While I'm not opposed to this, I wonder how useful it is in practice since we have no ability to set values in the keystore via the run task?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm not sold on it either. And given that we currently don't have a way to set keystore properties in the run task, maybe it's not worth adding ? I don't know , it seemed like a good idea when I added it but I'm not so sure now

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is only relevant when compiled with the --data-dir option to point at an existing directory which might have a manually setup keystore?


import java.util.Map;

public class ReloadSecureSettingsWithPasswordProtectedKeystoreRestIT extends ESRestTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

Could this just be a yaml test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find these easier to write, debug and argue about so if you don't have a strong view on why we should make them a yaml test, I'd prefer to keep this

@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
Copy link
Member

Choose a reason for hiding this comment

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

I'm just curious: we used to generate these types of materials within build.gradle in other qa tests: why are we now committing them instead of generating on the fly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We used to depend on BouncyCastle to generate keys and certificates as JDK doesn't expose the necessary APIs for the certificate generation (https://bugs.openjdk.java.net/browse/JDK-8058778) and we removed BouncyCastle dependency as part of the FIPS 140 effort

@jkakavas
Copy link
Contributor Author

jkakavas commented Apr 8, 2020

@elasticmachine update branch

@jkakavas
Copy link
Contributor Author

jkakavas commented Apr 9, 2020

@mark-vieira , @williamrandolph any thoughts on #54771 (comment) or any other feedback ? If not, I'll merge this since @rjernst LGTM'd it

@williamrandolph
Copy link
Contributor

This looks good to me — thanks for adding this coverage!

@jkakavas jkakavas merged commit 16e9433 into elastic:master Apr 10, 2020
jkakavas added a commit to jkakavas/elasticsearch that referenced this pull request Apr 10, 2020
The secure_settings_password was never taken into consideration in
the ReloadSecureSettings API. This commit fixes that and adds
necessary REST layer testing. Doing so, it also

- Allows TestClusters to have a password protected keystore
so that it can be set for tests.
- Adds a parameter to the run task so that elastisearch can
be run with a password protected keystore from source.
jkakavas added a commit to jkakavas/elasticsearch that referenced this pull request Apr 10, 2020
The secure_settings_password was never taken into consideration in
the ReloadSecureSettings API. This commit fixes that and adds
necessary REST layer testing. Doing so, it also

- Allows TestClusters to have a password protected keystore
so that it can be set for tests.
- Adds a parameter to the run task so that elastisearch can
be run with a password protected keystore from source.
jkakavas added a commit that referenced this pull request Apr 13, 2020
The secure_settings_password was never taken into consideration in
the ReloadSecureSettings API. This commit fixes that and adds
necessary REST layer testing. Doing so, it also:

- Allows TestClusters to have a password protected keystore
so that it can be set for tests.
- Adds a parameter to the run task so that elastisearch can
be run with a password protected keystore from source.
jkakavas added a commit that referenced this pull request Apr 13, 2020
The secure_settings_password was never taken into consideration in
the ReloadSecureSettings API. This commit fixes that and adds
necessary REST layer testing. Doing so, it also:

- Allows TestClusters to have a password protected keystore
so that it can be set for tests.
- Adds a parameter to the run task so that elastisearch can
be run with a password protected keystore from source.
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :Delivery/Build Build or test infrastructure :Security/Security Security issues without another label Team:Delivery Meta label for Delivery team v7.7.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants