-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Enroll additional nodes to cluster #77292
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
15 commits
Select commit
Hold shift + click to select a range
3ee60ac
wip, no tests
jkakavas 3942411
Error handling and try all addresses in the enrollment token
jkakavas b800f79
Add functionality to enroll to cluster
jkakavas 2fe6523
Merge remote-tracking branch 'origin/master' into enroll-additional-n…
jkakavas 598b4e1
simplify arg parsing
jkakavas b6c2784
Update docs/changelog/77292.yaml
jkakavas 56fb2b8
remove explicit CLI tool
jkakavas 6d61210
update changelog
jkakavas 3930fce
array expanding
jkakavas eaaa797
feedback
jkakavas 74150d2
Merge remote-tracking branch 'origin/master' into enroll-additional-n…
jkakavas 47b12c3
revert changes to startup scripts for now
jkakavas ddcaa8f
Add CLI tool that allows to configure TLS for a node so that it can j…
jkakavas a5322ee
Merge remote-tracking branch 'origin/master' into enroll-additional-n…
jkakavas e70fe6e
fix algorithm identifier
jkakavas 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 77292 | ||
summary: Enroll additional nodes to cluster | ||
area: "Security" | ||
type: enhancement | ||
issues: [] |
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
119 changes: 119 additions & 0 deletions
119
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/EnrollmentToken.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,119 @@ | ||
/* | ||
* 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.core.security; | ||
|
||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.DeprecationHandler; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.common.xcontent.ParseField; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.json.JsonXContent; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
public class EnrollmentToken { | ||
private final String apiKey; | ||
private final String fingerprint; | ||
private final String version; | ||
private final List<String > boundAddress; | ||
|
||
public String getApiKey() { return apiKey; } | ||
public String getFingerprint() { return fingerprint; } | ||
public String getVersion() { return version; } | ||
public List<String> getBoundAddress() { return boundAddress; } | ||
|
||
private static final ParseField API_KEY = new ParseField("key"); | ||
private static final ParseField FINGERPRINT = new ParseField("fgr"); | ||
private static final ParseField VERSION = new ParseField("ver"); | ||
private static final ParseField ADDRESS = new ParseField("adr"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<EnrollmentToken, Void> PARSER = new ConstructingObjectParser<>("enrollment_token", false, | ||
a -> new EnrollmentToken((String) a[0], (String) a[1], (String) a[2], (List<String>) a[3])); | ||
|
||
static { | ||
PARSER.declareString(constructorArg(), API_KEY); | ||
PARSER.declareString(constructorArg(), FINGERPRINT); | ||
PARSER.declareString(constructorArg(), VERSION); | ||
PARSER.declareStringArray(constructorArg(), ADDRESS); | ||
} | ||
/** | ||
* Create an EnrollmentToken | ||
* | ||
* @param apiKey API Key credential in the form apiKeyId:ApiKeySecret to be used for enroll calls | ||
* @param fingerprint hex encoded SHA256 fingerprint of the HTTP CA cert | ||
* @param version node version number | ||
* @param boundAddress IP Addresses and port numbers for the interfaces where the Elasticsearch node is listening on | ||
*/ | ||
public EnrollmentToken(String apiKey, String fingerprint, String version, List<String> boundAddress) { | ||
this.apiKey = Objects.requireNonNull(apiKey); | ||
this.fingerprint = Objects.requireNonNull(fingerprint); | ||
this.version = Objects.requireNonNull(version); | ||
this.boundAddress = Objects.requireNonNull(boundAddress); | ||
} | ||
|
||
public String getRaw() throws Exception { | ||
final XContentBuilder builder = JsonXContent.contentBuilder(); | ||
builder.startObject(); | ||
builder.field("ver", version); | ||
builder.startArray("adr"); | ||
for (String bound_address : boundAddress) { | ||
builder.value(bound_address); | ||
} | ||
builder.endArray(); | ||
builder.field("fgr", fingerprint); | ||
builder.field("key", apiKey); | ||
builder.endObject(); | ||
return Strings.toString(builder); | ||
} | ||
|
||
public String getEncoded() throws Exception { | ||
final String jsonString = getRaw(); | ||
return Base64.getUrlEncoder().encodeToString(jsonString.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
/** | ||
* Decodes and parses an enrollment token from its serialized form (created with {@link EnrollmentToken#getEncoded()} | ||
* @param encoded The Base64 encoded JSON representation of the enrollment token | ||
* @return the parsed EnrollmentToken | ||
* @throws IOException when failing to decode the serialized token | ||
*/ | ||
public static EnrollmentToken decodeFromString(String encoded) throws IOException { | ||
if (Strings.isNullOrEmpty(encoded)) { | ||
throw new IOException("Cannot decode enrollment token from an empty string"); | ||
} | ||
final XContentParser jsonParser = JsonXContent.jsonXContent.createParser( | ||
NamedXContentRegistry.EMPTY, | ||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, | ||
Base64.getDecoder().decode(encoded) | ||
); | ||
return EnrollmentToken.PARSER.parse(jsonParser, null); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
EnrollmentToken that = (EnrollmentToken) o; | ||
return apiKey.equals(that.apiKey) && fingerprint.equals(that.fingerprint) && version.equals(that.version) && boundAddress.equals( | ||
that.boundAddress); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(apiKey, fingerprint, version, boundAddress); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
x-pack/plugin/core/src/main/plugin-metadata/plugin-security.policy
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
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.
I moved CommandLineHttpClient, HttpResponse and EnrollmentToken to core so that I can use them in
EnrollNodeToCluster
without needing to add a dependency to thesecurity
plugin insecurity:cli
. The issue with that would be that I'd have a dependency conflict for Guava (30-1 as a jimfs dependency in security:cli vs 19 in security) I couldn't think of a way to solve this dependency issue, but more than happy to get suggestions and I'll move this back to the security plugin