Skip to content

Conversation

@tvernum
Copy link
Contributor

@tvernum tvernum commented Feb 11, 2021

This changes adds a new QA test that runs a smoke test on a node that
has been configured with one realm of each type.

Not all of the realms work, because some of them would depend on
external fixtures (LDAP, SAML, etc) and this particularly test suite
is intended to be as stable as possible and have no external
dependencies.

The primary purpose of this test is to catch any issues that prevent
a node from starting with particular realms configured (e.g. security
manager or classpath issues). We don't depend on external fixtures
because we want this to be a smoke test that clearly indicates when a
(seemingly unrelated) change in Elasticsearch has unintended
consequences on realms. The use of external dependencies would
increase the number of things that could go wrong and move this from a
smoke test to a potentially noisy integration test.

Relates: #68838, #68872

This changes adds a new QA test that runs a smoke test on a node that
has been configured with one realm of each type.

Not all of the realms work, because some of them would depend on
external fixtures (LDAP, SAML, etc) and this particularly test suite
is intended to be as stable as possible and have no external
dependencies.

The primary purpose of this test is to catch any issues that prevent
a node from starting with particular realms configurd (e.g. security
manager or classpath issues). We don't depend on external fixtures
becaused we want this to be a smoke test that clearly indicates when a
(seemingly unrelated) change in Elasticsearch has unintended
consequences on realms. The use of external dependencies would
increase the number of things that could go wrong and move this from a
smoke test to a potentially noisy integration test.
@tvernum tvernum added >test Issues or PRs that are addressing/adding tests :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) v8.0.0 v7.12.0 v7.11.1 labels Feb 11, 2021
@tvernum tvernum requested review from jkakavas and ywangd February 11, 2021 04:11
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Feb 11, 2021
@elasticmachine
Copy link
Collaborator

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

@tvernum
Copy link
Contributor Author

tvernum commented Feb 11, 2021

For verification purposes here is a gradle scan where this test passes (because the bug is fixed).

If I cherry pick this test on top of the last commit before the LDAP bug was fixed (683368c), then we get this gradle scan that has the expected classloading failure.

Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

LGTM.
Just to be paranoid, we could test the reserved realm as well.


assertUsername(authenticate, USERNAME);
assertRealm(authenticate, "pki", "pki4");
assertRoles(authenticate, new String[0]);
Copy link
Member

Choose a reason for hiding this comment

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

The new String[0] argument is redundant since the method takes varargs. Or did you intentionally add it for more clarity?

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 is for clarity. I find

 assertRoles(authenticate);

a bit weird. Technically it does the same thing, but it doesn't read well.

The method normally reads like:

  • Assert the the authentication response has roles foo

With the empty array it reads

  • Assert the the authentication response has roles empty

But with no argument at all it reads

  • Assert the the authentication response has roles ...

protected void createRole(String name, Collection<String> clusterPrivileges) throws IOException {
final RestHighLevelClient client = getHighLevelAdminClient();
final Role role = Role.builder().name(name).clusterPrivileges(clusterPrivileges).build();
client.security().putRole(new PutRoleRequest(role, null), RequestOptions.DEFAULT);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I'd also use RefreshPolicy.WAIT_UNTIL for PutRoleRequest even though it is not necessary for existing use cases. The performance gain with null is trivial and it feels more future proof to use WAIT_UNTIL or even IMMEDIATE.

Comment on lines 1072 to 1073
} else if (clientCertificatePath != null) {
throw new IllegalStateException("Client certificates are currently only support when using a custom CA");
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have this restriction? Is it just so we don't need to bother writing code for this branch (no test would be setup like this anyway)?

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 didn't want to write yet another block of code if no one was going to use it (and therefore it had a good chance of not actually working).

But I also didn't want to leave it in a state where someone would try and use it (e.g. a truststore and a client cert in PEM) and then have to debug why their code didn't do what they thought it should do.

@ywangd
Copy link
Member

ywangd commented Feb 11, 2021

For verification purposes here is a gradle scan where this test passes (because the bug is fixed).

If I cherry pick this test on top of the last commit before the LDAP bug was fixed (683368c), then we get this gradle scan that has the expected classloading failure.

It is also FIPS worthy!

Copy link
Contributor

@jkakavas jkakavas left a comment

Choose a reason for hiding this comment

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

LGTM. I guess there can still be things that we miss ( i.e. because a class can be loaded in the process of authenticating to an external system and not realm initialization - but hopefully realm integ tests can catch these? ) but I fully agree with the idea of having this smoke test be stripped of all external dependencies.

throw new RuntimeException("Error setting up ssl", e);
}
} else if (clientCertificatePath != null) {
throw new IllegalStateException("Client certificates are currently only support when using a custom CA");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new IllegalStateException("Client certificates are currently only support when using a custom CA");
throw new IllegalStateException("Client certificates are currently only supported when using a custom CA");

Copy link
Contributor

Choose a reason for hiding this comment

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

This ended up being the only comment, I wouldn't necessarily respin all CI checks just to change this now.

assertThat("License must exist", map.containsKey("license"), equalTo(true));
@SuppressWarnings("unchecked")
final Map<String, ?> license = (Map<String, ?>) map.get("license");
@SuppressWarnings("unchecked") final Map<String, ?> license = (Map<String, ?>) map.get("license");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the IDE doing autoformatting or our spotless plugin being applied on changes? Keeping the diff to reflect actual changes helps a lot in reviewing ( "hide whitespace changes" is not enough.. )

Writing this mostly as a mental note so that we can discuss it at some point

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 was IDE. I'm not sure what the official style guide is - I didn't even notice the change this time.

@tvernum
Copy link
Contributor Author

tvernum commented Feb 11, 2021

@elasticmachine update branch

@tvernum tvernum merged commit 4d9ebca into elastic:master Feb 12, 2021
@tvernum tvernum deleted the all-realm-smoke-test branch February 12, 2021 01:43
tvernum added a commit to tvernum/elasticsearch that referenced this pull request Feb 12, 2021
This changes adds a new QA test that runs a smoke test on a node that
has been configured with one realm of each type.

Not all of the realms work, because some of them would depend on
external fixtures (LDAP, SAML, etc) and this particularly test suite
is intended to be as stable as possible and have no external
dependencies.

The primary purpose of this test is to catch any issues that prevent
a node from starting with particular realms configurd (e.g. security
manager or classpath issues). We don't depend on external fixtures
becaused we want this to be a smoke test that clearly indicates when a
(seemingly unrelated) change in Elasticsearch has unintended
consequences on realms. The use of external dependencies would
increase the number of things that could go wrong and move this from a
smoke test to a potentially noisy integration test.

Backport of: elastic#68881
tvernum added a commit to tvernum/elasticsearch that referenced this pull request Feb 12, 2021
This changes adds a new QA test that runs a smoke test on a node that
has been configured with one realm of each type.

Not all of the realms work, because some of them would depend on
external fixtures (LDAP, SAML, etc) and this particularly test suite
is intended to be as stable as possible and have no external
dependencies.

The primary purpose of this test is to catch any issues that prevent
a node from starting with particular realms configurd (e.g. security
manager or classpath issues). We don't depend on external fixtures
becaused we want this to be a smoke test that clearly indicates when a
(seemingly unrelated) change in Elasticsearch has unintended
consequences on realms. The use of external dependencies would
increase the number of things that could go wrong and move this from a
smoke test to a potentially noisy integration test.

Backport of: elastic#68881
tvernum added a commit that referenced this pull request Feb 13, 2021
This changes adds a new QA test that runs a smoke test on a node that
has been configured with one realm of each type.

Not all of the realms work, because some of them would depend on
external fixtures (LDAP, SAML, etc) and this particularly test suite
is intended to be as stable as possible and have no external
dependencies.

The primary purpose of this test is to catch any issues that prevent
a node from starting with particular realms configurd (e.g. security
manager or classpath issues). We don't depend on external fixtures
becaused we want this to be a smoke test that clearly indicates when a
(seemingly unrelated) change in Elasticsearch has unintended
consequences on realms. The use of external dependencies would
increase the number of things that could go wrong and move this from a
smoke test to a potentially noisy integration test.

Backport of: #68881
tvernum added a commit that referenced this pull request Feb 13, 2021
This changes adds a new QA test that runs a smoke test on a node that
has been configured with one realm of each type.

Not all of the realms work, because some of them would depend on
external fixtures (LDAP, SAML, etc) and this particularly test suite
is intended to be as stable as possible and have no external
dependencies.

The primary purpose of this test is to catch any issues that prevent
a node from starting with particular realms configurd (e.g. security
manager or classpath issues). We don't depend on external fixtures
becaused we want this to be a smoke test that clearly indicates when a
(seemingly unrelated) change in Elasticsearch has unintended
consequences on realms. The use of external dependencies would
increase the number of things that could go wrong and move this from a
smoke test to a potentially noisy integration test.

Backport of: #68881
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) Team:Security Meta label for security team >test Issues or PRs that are addressing/adding tests v7.11.2 v7.12.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants