Skip to content

Commit e7975ab

Browse files
add MS Graph third party tests to periodic tests job (#130380)
1 parent 6f0b262 commit e7975ab

File tree

5 files changed

+92
-14
lines changed

5 files changed

+92
-14
lines changed

.buildkite/pipelines/periodic.template.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ steps:
204204
image: family/elasticsearch-ubuntu-2404
205205
machineType: n2-standard-8
206206
buildDirectory: /dev/shm/bk
207+
- label: third-party / ms-graph
208+
command: |
209+
.ci/scripts/run-gradle.sh msGraphThirdPartyTest
210+
env:
211+
USE_3RD_PARTY_MS_GRAPH_CREDENTIALS: "true"
212+
timeout_in_minutes: 30
213+
agents:
214+
provider: gcp
215+
image: family/elasticsearch-ubuntu-2404
216+
machineType: n2-standard-8
217+
buildDirectory: /dev/shm/bk
207218
- group: lucene-compat
208219
steps:
209220
- label: "{{matrix.LUCENE_VERSION}} / lucene-compat"

.buildkite/pipelines/periodic.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,17 @@ steps:
642642
image: family/elasticsearch-ubuntu-2404
643643
machineType: n2-standard-8
644644
buildDirectory: /dev/shm/bk
645+
- label: third-party / ms-graph
646+
command: |
647+
.ci/scripts/run-gradle.sh msGraphThirdPartyTest
648+
env:
649+
USE_3RD_PARTY_MS_GRAPH_CREDENTIALS: "true"
650+
timeout_in_minutes: 30
651+
agents:
652+
provider: gcp
653+
image: family/elasticsearch-ubuntu-2404
654+
machineType: n2-standard-8
655+
buildDirectory: /dev/shm/bk
645656
- group: lucene-compat
646657
steps:
647658
- label: "{{matrix.LUCENE_VERSION}} / lucene-compat"

.buildkite/scripts/third-party-test-credentials.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ if [[ "${USE_3RD_PARTY_GCS_CREDENTIALS:-}" == "true" ]]; then
4848
.buildkite/scripts/third-party-test-credentials.gcs.sh "$google_storage_service_account"
4949
fi
5050

51+
if [[ "${USE_3RD_PARTY_MS_GRAPH_CREDENTIALS:-}" == "true" ]]; then
52+
json=$(vault read -format=json secret/ci/elastic-elasticsearch/ms_graph_thirdparty_test_creds)
5153

54+
MS_GRAPH_TENANT_ID=$(echo "$json" | jq -r .data.tenant_id)
55+
export ms_graph_tenant_id="$MS_GRAPH_TENANT_ID"
56+
57+
MS_GRAPH_CLIENT_ID=$(echo "$json" | jq -r .data.client_id)
58+
export ms_graph_client_id="$MS_GRAPH_CLIENT_ID"
59+
60+
MS_GRAPH_CLIENT_SECRET=$(echo "$json" | jq -r .data.client_secret)
61+
export ms_graph_client_secret="$MS_GRAPH_CLIENT_SECRET"
62+
63+
MS_GRAPH_USERNAME=$(echo "$json" | jq -r .data.username)
64+
export ms_graph_username="$MS_GRAPH_USERNAME"
65+
66+
MS_GRAPH_GROUP_ID=$(echo "$json" | jq -r .data.group_id)
67+
export ms_graph_group_id="$MS_GRAPH_GROUP_ID"
68+
fi
5269

5370
unset json

x-pack/plugin/security/qa/microsoft-graph-authz-tests/build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,34 @@ dependencies {
88
clusterModules project(":modules:analysis-common")
99
}
1010

11+
boolean useFixture = false
12+
String msGraphTenantId = System.getenv("ms_graph_tenant_id")
13+
String msGraphClientId = System.getenv("ms_graph_client_id")
14+
String msGraphClientSecret = System.getenv("ms_graph_client_secret")
15+
String msGraphUsername = System.getenv("ms_graph_username")
16+
String msGraphGroupId = System.getenv("ms_graph_group_id")
17+
18+
if (!msGraphTenantId || !msGraphClientId || !msGraphClientSecret || !msGraphUsername || !msGraphGroupId) {
19+
msGraphTenantId = "tenant-id"
20+
msGraphClientId = "client_id"
21+
msGraphClientSecret = "client_secret"
22+
msGraphUsername = "Thor"
23+
msGraphGroupId = "test_group"
24+
useFixture = true
25+
}
26+
1127
tasks.named("javaRestTest").configure {
28+
systemProperty "test.ms_graph.fixture", useFixture
29+
systemProperty "test.ms_graph.tenant_id", msGraphTenantId
30+
systemProperty "test.ms_graph.client_id", msGraphClientId
31+
systemProperty "test.ms_graph.client_secret", msGraphClientSecret
32+
systemProperty "test.ms_graph.username", msGraphUsername
33+
systemProperty "test.ms_graph.group_id", msGraphGroupId
34+
1235
// disable tests in FIPS mode as we need to use a custom truststore containing the certs used in MicrosoftGraphHttpFixture
1336
buildParams.withFipsEnabledOnly(it)
1437
}
38+
39+
tasks.register("msGraphThirdPartyTest") {
40+
dependsOn "javaRestTest"
41+
}

x-pack/plugin/security/qa/microsoft-graph-authz-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/authz/microsoft/MicrosoftGraphAuthzPluginIT.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.common.settings.SecureString;
1818
import org.elasticsearch.common.settings.Settings;
1919
import org.elasticsearch.common.util.concurrent.ThreadContext;
20+
import org.elasticsearch.core.Booleans;
2021
import org.elasticsearch.core.PathUtils;
2122
import org.elasticsearch.test.TestTrustStore;
2223
import org.elasticsearch.test.XContentTestUtils;
@@ -51,11 +52,12 @@
5152

5253
public class MicrosoftGraphAuthzPluginIT extends ESRestTestCase {
5354

54-
private static final String TENANT_ID = "tenant-id";
55-
private static final String CLIENT_ID = "client_id";
56-
private static final String CLIENT_SECRET = "client_secret";
57-
private static final String USERNAME = "Thor";
58-
private static final String EXPECTED_GROUP = "test_group";
55+
private static final String TENANT_ID = System.getProperty("test.ms_graph.tenant_id");
56+
private static final String CLIENT_ID = System.getProperty("test.ms_graph.client_id");
57+
private static final String CLIENT_SECRET = System.getProperty("test.ms_graph.client_secret");
58+
private static final String USERNAME = System.getProperty("test.ms_graph.username");
59+
private static final String EXPECTED_GROUP = System.getProperty("test.ms_graph.group_id");
60+
private static final Boolean USE_FIXTURE = Booleans.parseBoolean(System.getProperty("test.ms_graph.fixture"));
5961

6062
private static final List<MicrosoftGraphHttpFixture.TestUser> TEST_USERS = List.of(
6163
new MicrosoftGraphHttpFixture.TestUser(
@@ -90,12 +92,14 @@ public class MicrosoftGraphAuthzPluginIT extends ESRestTestCase {
9092
);
9193

9294
@ClassRule
93-
public static TestRule ruleChain = RuleChain.outerRule(graphFixture).around(trustStore).around(cluster);
95+
public static TestRule ruleChain = USE_FIXTURE
96+
? RuleChain.outerRule(graphFixture).around(trustStore).around(cluster)
97+
: RuleChain.outerRule(cluster);
9498

9599
private static final String IDP_ENTITY_ID = "http://idp.example.org/";
96100

97101
private static ElasticsearchCluster initTestCluster() {
98-
return ElasticsearchCluster.local()
102+
final var clusterBuilder = ElasticsearchCluster.local()
99103
.module("analysis-common")
100104
.setting("xpack.security.enabled", "true")
101105
.setting("xpack.license.self_generated.type", "trial")
@@ -118,15 +122,22 @@ private static ElasticsearchCluster initTestCluster() {
118122
.setting("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.client_id", CLIENT_ID)
119123
.keystore("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.client_secret", CLIENT_SECRET)
120124
.setting("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.tenant_id", TENANT_ID)
121-
.setting("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.graph_host", () -> graphFixture.getBaseUrl() + "/v1.0")
122-
.setting("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.access_token_host", graphFixture::getBaseUrl)
123125
.setting("logger.org.elasticsearch.xpack.security.authz.microsoft", "TRACE")
124126
.setting("logger.com.microsoft", "TRACE")
125-
.setting("logger.com.azure", "TRACE")
126-
.systemProperty("javax.net.ssl.trustStore", () -> trustStore.getTrustStorePath().toString())
127-
.systemProperty("javax.net.ssl.trustStoreType", "jks")
128-
.systemProperty("tests.azure.credentials.disable_instance_discovery", "true")
129-
.build();
127+
.setting("logger.com.azure", "TRACE");
128+
129+
if (USE_FIXTURE) {
130+
clusterBuilder.setting(
131+
"xpack.security.authc.realms.microsoft_graph.microsoft_graph1.graph_host",
132+
() -> graphFixture.getBaseUrl() + "/v1.0"
133+
)
134+
.setting("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.access_token_host", graphFixture::getBaseUrl)
135+
.systemProperty("javax.net.ssl.trustStore", () -> trustStore.getTrustStorePath().toString())
136+
.systemProperty("javax.net.ssl.trustStoreType", "jks")
137+
.systemProperty("tests.azure.credentials.disable_instance_discovery", "true");
138+
}
139+
140+
return clusterBuilder.build();
130141
}
131142

132143
private static String getIDPMetadata() {
@@ -210,6 +221,7 @@ public void testAuthenticationSuccessful() throws Exception {
210221
}
211222

212223
public void testConcurrentAuthentication() throws Exception {
224+
assumeTrue("This needs the test server as the real account only has one user configured", USE_FIXTURE);
213225
final var concurrentLogins = 3;
214226

215227
final var resultsListener = new PlainActionFuture<Collection<Map<String, Object>>>();

0 commit comments

Comments
 (0)