Skip to content

Commit 6e6f79f

Browse files
add RemoteClusterAuthenticationService interface
- define a new interface based on CrossClusterAccessAuthenticationService - hide method that accepts ApiKeyCredentials as it's only used for testing
1 parent 063f212 commit 6e6f79f

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/CrossClusterAccessAuthenticationService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import static org.elasticsearch.xpack.core.security.authc.CrossClusterAccessSubjectInfo.CROSS_CLUSTER_ACCESS_SUBJECT_INFO_HEADER_KEY;
3535
import static org.elasticsearch.xpack.security.authc.CrossClusterAccessHeaders.CROSS_CLUSTER_ACCESS_CREDENTIALS_HEADER_KEY;
3636

37-
public class CrossClusterAccessAuthenticationService {
37+
public class CrossClusterAccessAuthenticationService implements RemoteClusterAuthenticationService {
3838

3939
private static final Logger logger = LogManager.getLogger(CrossClusterAccessAuthenticationService.class);
4040

@@ -52,6 +52,7 @@ public CrossClusterAccessAuthenticationService(
5252
this.authenticationService = authenticationService;
5353
}
5454

55+
@Override
5556
public void authenticate(final String action, final TransportRequest request, final ActionListener<Authentication> listener) {
5657
final ThreadContext threadContext = clusterService.threadPool().getThreadContext();
5758
final CrossClusterAccessHeaders crossClusterAccessHeaders;
@@ -117,6 +118,7 @@ public void authenticate(final String action, final TransportRequest request, fi
117118
}
118119
}
119120

121+
@Override
120122
public void tryAuthenticate(Map<String, String> headers, ActionListener<Void> listener) {
121123
final ApiKeyService.ApiKeyCredentials credentials;
122124
try {
@@ -128,7 +130,8 @@ public void tryAuthenticate(Map<String, String> headers, ActionListener<Void> li
128130
tryAuthenticate(credentials, listener);
129131
}
130132

131-
public void tryAuthenticate(ApiKeyService.ApiKeyCredentials credentials, ActionListener<Void> listener) {
133+
// package-private for testing
134+
void tryAuthenticate(ApiKeyService.ApiKeyCredentials credentials, ActionListener<Void> listener) {
132135
Objects.requireNonNull(credentials);
133136
apiKeyService.tryAuthenticate(clusterService.threadPool().getThreadContext(), credentials, ActionListener.wrap(authResult -> {
134137
if (authResult.isAuthenticated()) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.security.authc;
9+
10+
import org.elasticsearch.action.ActionListener;
11+
import org.elasticsearch.transport.TransportRequest;
12+
import org.elasticsearch.xpack.core.security.authc.Authentication;
13+
14+
import java.util.Map;
15+
16+
/**
17+
* Service interface for authenticating remote cluster requests.
18+
*
19+
* <p>
20+
* This service handles authentication for cross-cluster requests.
21+
* It provides methods to authenticate both full transport requests
22+
* and credential headers only.
23+
*/
24+
public interface RemoteClusterAuthenticationService {
25+
26+
/**
27+
* Called to authenticates a remote cluster transport request.
28+
*
29+
* @param action the transport action being performed
30+
* @param request the transport request containing authentication headers
31+
* @param listener callback to receive the authenticated {@link Authentication}
32+
* object on success, or an exception on failure
33+
*/
34+
void authenticate(String action, TransportRequest request, ActionListener<Authentication> listener);
35+
36+
/**
37+
* This method is called to do a preliminary check if headers contain valid
38+
* remote cluster credentials, without the overhead of full authentication
39+
* processing.
40+
*
41+
* @param headers map of request headers containing authentication credentials
42+
* @param listener callback to receive {@code null} on successful authentication,
43+
* or an exception on authentication failure
44+
*/
45+
void tryAuthenticate(Map<String, String> headers, ActionListener<Void> listener);
46+
47+
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
package org.elasticsearch.xpack.security.crossclusteraccess;
8+
package org.elasticsearch.xpack.security.authc;
99

1010
import org.elasticsearch.ElasticsearchSecurityException;
1111
import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
@@ -31,10 +31,6 @@
3131
import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken;
3232
import org.elasticsearch.xpack.core.security.authz.RoleDescriptorsIntersection;
3333
import org.elasticsearch.xpack.core.security.user.InternalUsers;
34-
import org.elasticsearch.xpack.security.authc.ApiKeyService;
35-
import org.elasticsearch.xpack.security.authc.CrossClusterAccessAuthenticationService;
36-
import org.elasticsearch.xpack.security.authc.CrossClusterAccessHeaders;
37-
import org.elasticsearch.xpack.security.authc.CrossClusterAccessHeadersTests;
3834

3935
import java.io.IOException;
4036
import java.nio.charset.StandardCharsets;

0 commit comments

Comments
 (0)