forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enroll node API can be used by new nodes in order to join an existing cluster that has security features enabled. The response of a call to this API contains all the necessary information that the new node requires in order to configure itself and bootstrap trust with the existing cluster.
- Loading branch information
Showing
35 changed files
with
1,027 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
This file contains 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 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
29 changes: 29 additions & 0 deletions
29
...est-high-level/src/main/java/org/elasticsearch/client/security/NodeEnrollmentRequest.java
This file contains 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,29 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client.security; | ||
|
||
import org.apache.http.client.methods.HttpGet; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.Validatable; | ||
|
||
/** | ||
* Retrieves information needed about configuration so that new node can join a secured cluster | ||
*/ | ||
public final class NodeEnrollmentRequest implements Validatable { | ||
|
||
public static final NodeEnrollmentRequest INSTANCE = new NodeEnrollmentRequest(); | ||
|
||
private NodeEnrollmentRequest(){ | ||
|
||
} | ||
|
||
public Request getRequest() { | ||
return new Request(HttpGet.METHOD_NAME, "/_security/enroll_node"); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...st-high-level/src/main/java/org/elasticsearch/client/security/NodeEnrollmentResponse.java
This file contains 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,108 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.client.security; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class NodeEnrollmentResponse { | ||
|
||
private final String httpCaKey; | ||
private final String httpCaCert; | ||
private final String transportKey; | ||
private final String transportCert; | ||
private final String clusterName; | ||
private final List<String> nodesAddresses; | ||
|
||
public NodeEnrollmentResponse(String httpCaKey, String httpCaCert, String transportKey, String transportCert, String clusterName, | ||
List<String> nodesAddresses){ | ||
this.httpCaKey = httpCaKey; | ||
this.httpCaCert = httpCaCert; | ||
this.transportKey = transportKey; | ||
this.transportCert = transportCert; | ||
this.clusterName = clusterName; | ||
this.nodesAddresses = Collections.unmodifiableList(nodesAddresses); | ||
} | ||
|
||
public String getHttpCaKey() { | ||
return httpCaKey; | ||
} | ||
|
||
public String getHttpCaCert() { | ||
return httpCaCert; | ||
} | ||
|
||
public String getTransportKey() { | ||
return transportKey; | ||
} | ||
|
||
public String getTransportCert() { | ||
return transportCert; | ||
} | ||
|
||
public String getClusterName() { | ||
return clusterName; | ||
} | ||
|
||
public List<String> getNodesAddresses() { | ||
return nodesAddresses; | ||
} | ||
|
||
private static final ParseField HTTP_CA_KEY = new ParseField("http_ca_key"); | ||
private static final ParseField HTTP_CA_CERT = new ParseField("http_ca_cert"); | ||
private static final ParseField TRANSPORT_KEY = new ParseField("transport_key"); | ||
private static final ParseField TRANSPORT_CERT = new ParseField("transport_cert"); | ||
private static final ParseField CLUSTER_NAME = new ParseField("cluster_name"); | ||
private static final ParseField NODES_ADDRESSES = new ParseField("nodes_addresses"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<NodeEnrollmentResponse, Void> | ||
PARSER = | ||
new ConstructingObjectParser<>(NodeEnrollmentResponse.class.getName(), true, a -> { | ||
final String httpCaKey = (String) a[0]; | ||
final String httpCaCert = (String) a[1]; | ||
final String transportKey = (String) a[2]; | ||
final String transportCert = (String) a[3]; | ||
final String clusterName = (String) a[4]; | ||
final List<String> nodesAddresses = (List<String>) a[5]; | ||
return new NodeEnrollmentResponse(httpCaKey, httpCaCert, transportKey, transportCert, clusterName, nodesAddresses); | ||
}); | ||
|
||
static { | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), HTTP_CA_KEY); | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), HTTP_CA_CERT); | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), TRANSPORT_KEY); | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), TRANSPORT_CERT); | ||
PARSER.declareString(ConstructingObjectParser.constructorArg(), CLUSTER_NAME); | ||
PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), NODES_ADDRESSES); | ||
} | ||
|
||
public static NodeEnrollmentResponse fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.apply(parser, null); | ||
} | ||
|
||
@Override public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
NodeEnrollmentResponse that = (NodeEnrollmentResponse) o; | ||
return httpCaKey.equals(that.httpCaKey) && httpCaCert.equals(that.httpCaCert) && transportKey.equals(that.transportKey) | ||
&& transportCert.equals(that.transportCert) && clusterName.equals(that.clusterName) | ||
&& nodesAddresses.equals(that.nodesAddresses); | ||
} | ||
|
||
@Override public int hashCode() { | ||
return Objects.hash(httpCaKey, httpCaCert, transportKey, transportCert, clusterName, nodesAddresses); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -386,4 +386,5 @@ public void testComponentTemplates() throws Exception { | |
|
||
assertFalse(exist); | ||
} | ||
|
||
} |
This file contains 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 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 |
---|---|---|
|
@@ -696,4 +696,5 @@ public void onFailure(Exception e) { | |
|
||
assertTrue(latch.await(30L, TimeUnit.SECONDS)); | ||
} | ||
|
||
} |
This file contains 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
Binary file not shown.
This file contains 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
Binary file not shown.
This file contains 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,64 @@ | ||
-- | ||
:api: node-enrollment | ||
:request: NodeEnrollmentRequest | ||
:response: NodeEnrollmentResponse | ||
-- | ||
|
||
[id="{upid}-{api}"] | ||
=== Enroll Node API | ||
|
||
Allows a new node to join an existing cluster with security features enabled. | ||
|
||
The purpose of the enroll node API is to allow a new node to join an existing cluster | ||
where security is enabled. The enroll node API response contains all the necessary information | ||
for the joining node to bootstrap discovery and security related settings so that it | ||
can successfully join the cluster. | ||
|
||
NOTE: The response contains key and certificate material that allows the | ||
caller to generate valid signed certificates for the HTTP layer of all nodes in the cluster. | ||
|
||
include::../execution.asciidoc[] | ||
|
||
[id="{upid}-{api}-response"] | ||
==== Enroll Node Response | ||
|
||
The returned +{response}+ allows to retrieve information about the | ||
executed operation as follows: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests-file}[{api}-response] | ||
-------------------------------------------------- | ||
<1> The CA private key that can be used by the new node in order to sign its certificate | ||
for the HTTP layer, as a Base64 encoded string of the ASN.1 DER encoding of the key. | ||
<2> The CA certificate that can be used by the new node in order to sign its certificate | ||
for the HTTP layer, as a Base64 encoded string of the ASN.1 DER encoding of the certificate. | ||
<3> The private key that the node can use for TLS for its transport layer, as a Base64 | ||
encoded string of the ASN.1 DER encoding of the key. | ||
<4> The certificate that the node can use for TLS for its transport layer, as a Base64 | ||
encoded string of the ASN.1 DER encoding of the certificate. | ||
<5> The name of the cluster the new node is joining | ||
<6> A list of transport addresses in the form of `host:port` for the nodes that are already | ||
members of the cluster. | ||
|
||
|
||
[id="{upid}-{api}-execute-async"] | ||
==== Asynchronous Execution | ||
|
||
This request can be executed asynchronously using the `security().enrollNodeAsync()` | ||
method: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests-file}[{api}-execute-async] | ||
-------------------------------------------------- | ||
|
||
A typical listener for a `NodeEnrollmentResponse` looks like: | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests-file}[{api}-execute-listener] | ||
-------------------------------------------------- | ||
<1> Called when the execution is successfully completed. The response is | ||
provided as an argument | ||
<2> Called in case of failure. The raised exception is provided as an argument |
Binary file not shown.
Oops, something went wrong.