-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Add a smoke test for security realms #68881
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e467cf
Add a smoke test for security realms
tvernum 668d723
Merge branch 'master' into all-realm-smoke-test
tvernum 2c2db80
Address feedback: Reserved realm, WAIT_UNTIL
tvernum b90bf09
Revert formatting changes in ESRestTestCase
tvernum c72eaeb
Merge branch 'master' into all-realm-smoke-test
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
x-pack/plugin/security/qa/smoke-test-all-realms/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * This QA test is intended to smoke test all security realms with minimal dependencies. | ||
| * That is, it makes sure a node that has every realm configured can start, and tests those realms that can be tested without needing external services. | ||
| * This tradeoff is intentional because we want this set of tests to be very stable - failures in this QA suite should be an indicator that | ||
| * something is broken in Elasticsearch (and not that an external docker fixture broke) | ||
| * This test is also intended to work correctly on FIPS mode because we also want to know if a realm breaks on FIPS. | ||
| */ | ||
|
|
||
| apply plugin: 'elasticsearch.java-rest-test' | ||
|
|
||
| dependencies { | ||
| javaRestTestImplementation project(path: xpackModule('core')) | ||
| javaRestTestImplementation project(path: xpackModule('security'), configuration: 'testArtifacts') | ||
| javaRestTestImplementation project(path: xpackModule('core'), configuration: 'testArtifacts') | ||
| } | ||
|
|
||
| testClusters.javaRestTest { | ||
| testDistribution = 'DEFAULT' | ||
| numberOfNodes = 2 | ||
|
|
||
| extraConfigFile 'http-server.key', file('src/javaRestTest/resources/ssl/http-server.key') | ||
| extraConfigFile 'http-server.crt', file('src/javaRestTest/resources/ssl/http-server.crt') | ||
| extraConfigFile 'http-client-ca.crt', file('src/javaRestTest/resources/ssl/http-client-ca.crt') | ||
| extraConfigFile 'saml-metadata.xml', file('src/javaRestTest/resources/saml-metadata.xml') | ||
| extraConfigFile 'kerberos.keytab', file('src/javaRestTest/resources/kerberos.keytab') | ||
| extraConfigFile 'oidc-jwkset.json', file('src/javaRestTest/resources/oidc-jwkset.json') | ||
|
|
||
| setting 'xpack.ml.enabled', 'false' | ||
| setting 'xpack.security.enabled', 'true' | ||
| setting 'xpack.security.authc.token.enabled', 'true' | ||
| setting 'xpack.security.authc.api_key.enabled', 'true' | ||
|
|
||
| // Need a trial license (not basic) to enable all realms | ||
| setting 'xpack.license.self_generated.type', 'trial' | ||
| // Need SSL to enable PKI realms | ||
| setting 'xpack.security.http.ssl.enabled', 'true' | ||
| setting 'xpack.security.http.ssl.certificate', 'http-server.crt' | ||
| setting 'xpack.security.http.ssl.key', 'http-server.key' | ||
| setting 'xpack.security.http.ssl.key_passphrase', 'http-password' | ||
| setting 'xpack.security.http.ssl.client_authentication', 'optional' | ||
| setting 'xpack.security.http.ssl.certificate_authorities', 'http-client-ca.crt' | ||
|
|
||
| // Don't need transport SSL, so leave it out | ||
| setting 'xpack.security.transport.ssl.enabled', 'false' | ||
|
|
||
| // Configure every realm type | ||
| // - File | ||
| setting 'xpack.security.authc.realms.file.file0.order', '0' | ||
| // - Native | ||
| setting 'xpack.security.authc.realms.native.native1.order', '1' | ||
| // - LDAP (configured but won't work because we don't want external fixtures in this test suite) | ||
| setting 'xpack.security.authc.realms.ldap.ldap2.order', '2' | ||
| setting 'xpack.security.authc.realms.ldap.ldap2.url', 'ldap://localhost:7777' | ||
| setting 'xpack.security.authc.realms.ldap.ldap2.user_search.base_dn', 'OU=users,DC=example,DC=com' | ||
| // - AD (configured but won't work because we don't want external fixtures in this test suite) | ||
| setting 'xpack.security.authc.realms.active_directory.ad3.order', '3' | ||
| setting 'xpack.security.authc.realms.active_directory.ad3.domain_name', 'localhost' | ||
| // - PKI (works) | ||
| setting 'xpack.security.authc.realms.pki.pki4.order', '4' | ||
| // - SAML (configured but won't work because we don't want external fixtures in this test suite) | ||
| setting 'xpack.security.authc.realms.saml.saml5.order', '5' | ||
| setting 'xpack.security.authc.realms.saml.saml5.idp.metadata.path', 'saml-metadata.xml' | ||
| setting 'xpack.security.authc.realms.saml.saml5.idp.entity_id', 'http://idp.example.com/' | ||
| setting 'xpack.security.authc.realms.saml.saml5.sp.entity_id', 'http://kibana.example.net/' | ||
| setting 'xpack.security.authc.realms.saml.saml5.sp.acs', 'http://kibana.example.net/api/security/v1/saml' | ||
| setting 'xpack.security.authc.realms.saml.saml5.attributes.principal', 'uid' | ||
| // - Kerberos (configured but won't work because we don't want external fixtures in this test suite) | ||
| setting 'xpack.security.authc.realms.kerberos.kerb6.order', '6' | ||
| setting 'xpack.security.authc.realms.kerberos.kerb6.keytab.path', 'kerberos.keytab' | ||
| // - OIDC (configured but won't work because we don't want external fixtures in this test suite) | ||
| setting 'xpack.security.authc.realms.oidc.openid7.order', '7' | ||
| setting 'xpack.security.authc.realms.oidc.openid7.rp.client_id', 'http://rp.example.net' | ||
| setting 'xpack.security.authc.realms.oidc.openid7.rp.response_type', 'id_token' | ||
| setting 'xpack.security.authc.realms.oidc.openid7.rp.redirect_uri', 'https://kibana.example.net/api/security/v1/oidc' | ||
| setting 'xpack.security.authc.realms.oidc.openid7.op.issuer', 'https://op.example.com/' | ||
| setting 'xpack.security.authc.realms.oidc.openid7.op.authorization_endpoint', 'https://op.example.com/auth' | ||
| setting 'xpack.security.authc.realms.oidc.openid7.op.jwkset_path', 'oidc-jwkset.json' | ||
| setting 'xpack.security.authc.realms.oidc.openid7.claims.principal', 'sub' | ||
| keystore 'xpack.security.authc.realms.oidc.openid7.rp.client_secret', 'this-is-my-secret' | ||
|
|
||
| extraConfigFile 'roles.yml', file('src/javaRestTest/resources/roles.yml') | ||
| user username: "admin_user", password: "admin-password" | ||
| user username: "security_test_user", password: "security-test-password", role: "security_test_role" | ||
| } | ||
|
|
38 changes: 38 additions & 0 deletions
38
...-realms/src/javaRestTest/java/org/elasticsearch/xpack/security/authc/FileRealmAuthIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.security.authc; | ||
|
|
||
| import org.elasticsearch.client.RequestOptions; | ||
| import org.elasticsearch.common.settings.SecureString; | ||
| import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Integration Rest Test for testing authentication when all possible realms are configured | ||
| */ | ||
| public class FileRealmAuthIT extends SecurityRealmSmokeTestCase { | ||
|
|
||
| // Declared in build.gradle | ||
| private static final String USERNAME = "security_test_user"; | ||
| private static final SecureString PASSWORD = new SecureString("security-test-password".toCharArray()); | ||
| private static final String ROLE_NAME = "security_test_role"; | ||
|
|
||
| public void testAuthenticationUsingFileRealm() throws IOException { | ||
| Map<String, Object> authenticate = super.authenticate( | ||
| RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", | ||
| UsernamePasswordToken.basicAuthHeaderValue(USERNAME, PASSWORD)) | ||
| ); | ||
|
|
||
| assertUsername(authenticate, USERNAME); | ||
| assertRealm(authenticate, "file", "file0"); | ||
| assertRoles(authenticate, ROLE_NAME); | ||
| } | ||
|
|
||
| } |
53 changes: 53 additions & 0 deletions
53
...ealms/src/javaRestTest/java/org/elasticsearch/xpack/security/authc/NativeRealmAuthIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.security.authc; | ||
|
|
||
| import org.elasticsearch.client.RequestOptions; | ||
| import org.elasticsearch.common.settings.SecureString; | ||
| import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Integration Rest Test for testing authentication when all possible realms are configured | ||
| */ | ||
| public class NativeRealmAuthIT extends SecurityRealmSmokeTestCase { | ||
|
|
||
| private static final String USERNAME = "test_native_user"; | ||
| private static final SecureString PASSWORD = new SecureString("native-user-password".toCharArray()); | ||
| private static final String ROLE_NAME = "native_role"; | ||
|
|
||
| @Before | ||
| public void createUsersAndRoles() throws IOException { | ||
| createUser(USERNAME, PASSWORD, List.of(ROLE_NAME)); | ||
| createRole("native_role", Set.of("monitor")); | ||
| } | ||
|
|
||
| @After | ||
| public void cleanUp() throws IOException { | ||
| deleteUser(USERNAME); | ||
| deleteRole(ROLE_NAME); | ||
| } | ||
|
|
||
| public void testAuthenticationUsingNativeRealm() throws IOException { | ||
| Map<String, Object> authenticate = super.authenticate( | ||
| RequestOptions.DEFAULT.toBuilder().addHeader("Authorization", | ||
| UsernamePasswordToken.basicAuthHeaderValue(USERNAME, PASSWORD)) | ||
| ); | ||
|
|
||
| assertUsername(authenticate, USERNAME); | ||
| assertRealm(authenticate, "native", "native1"); | ||
| assertRoles(authenticate, ROLE_NAME); | ||
| } | ||
|
|
||
| } |
44 changes: 44 additions & 0 deletions
44
...l-realms/src/javaRestTest/java/org/elasticsearch/xpack/security/authc/PkiRealmAuthIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.security.authc; | ||
|
|
||
| import org.elasticsearch.client.RequestOptions; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Integration Rest Test for testing authentication when all possible realms are configured | ||
| */ | ||
| public class PkiRealmAuthIT extends SecurityRealmSmokeTestCase { | ||
|
|
||
| // Derived from certificate attributes (pki-auth.crt) | ||
| private static final String USERNAME = "pki-auth"; | ||
|
|
||
| @Override | ||
| protected Settings restClientSettings() { | ||
| Settings.Builder builder = Settings.builder() | ||
| .put(super.restClientSettings()) | ||
| .put(CLIENT_CERT_PATH, getDataPath("/ssl/pki-auth.crt")) | ||
| .put(CLIENT_KEY_PATH, getDataPath("/ssl/pki-auth.key")) | ||
| .put(CLIENT_KEY_PASSWORD, "http-password"); | ||
| builder.remove(ThreadContext.PREFIX + ".Authorization"); | ||
| return builder.build(); | ||
| } | ||
|
|
||
| public void testAuthenticationUsingFileRealm() throws IOException { | ||
| Map<String, Object> authenticate = super.authenticate(RequestOptions.DEFAULT.toBuilder()); | ||
|
|
||
| assertUsername(authenticate, USERNAME); | ||
| assertRealm(authenticate, "pki", "pki4"); | ||
| assertRoles(authenticate, new String[0]); | ||
| } | ||
|
|
||
| } | ||
36 changes: 36 additions & 0 deletions
36
...-all-realms/src/javaRestTest/java/org/elasticsearch/xpack/security/authc/RealmInfoIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.security.authc; | ||
|
|
||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.Response; | ||
| import org.elasticsearch.test.rest.yaml.ObjectPath; | ||
| import org.hamcrest.Matchers; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Integration Rest Test for testing authentication when all possible realms are configured | ||
| */ | ||
| public class RealmInfoIT extends SecurityRealmSmokeTestCase { | ||
|
|
||
| public void testThatAllRealmTypesAreEnabled() throws IOException { | ||
| final Request request = new Request("GET", "_xpack/usage"); | ||
| final Response response = client().performRequest(request); | ||
| Map<String, Object> usage = entityAsMap(response); | ||
|
|
||
| Map<String, Object> realms = ObjectPath.evaluate(usage, "security.realms"); | ||
| realms.forEach((type, config) -> { | ||
| assertThat(config, Matchers.instanceOf(Map.class)); | ||
| assertThat("Realm type [" + type + "] is not enabled", | ||
| ((Map<?, ?>) config).get("enabled"), Matchers.equalTo(true)); | ||
| }); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
new String[0]argument is redundant since the method takes varargs. Or did you intentionally add it for more clarity?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.
It is for clarity. I find
a bit weird. Technically it does the same thing, but it doesn't read well.
The method normally reads like:
fooWith the empty array it reads
But with no argument at all it reads