-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Create enrollment token API #72186
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
Closed
Closed
Create enrollment token API #72186
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2bb52b5
Create enrollment token API
BigPandaToo f78af77
Create enrolment token
BigPandaToo 6441ac6
Create enrollment token API
BigPandaToo 60c0574
Addressing PR feedback
BigPandaToo 906a013
Merge branch 'master' into Create_ET
elasticmachine 97b2d32
Addressing PR feedback
BigPandaToo 3eedc37
Merge branch 'master' into Create_ET
elasticmachine 23d2907
Addressing PR comments
BigPandaToo 4151e40
Addressing PR comments
BigPandaToo 97537f2
Merge branch 'master' into Create_ET
BigPandaToo db56545
Addressing PR comments adding tests
BigPandaToo 77bf9d5
Addressing PR comments adding tests
BigPandaToo 626d957
fixing tests and style
BigPandaToo d107633
fixing tests
BigPandaToo f4be25b
fixing tests
BigPandaToo fb7b523
Adding test
BigPandaToo 1800069
Disabling running enrollment test with Fips
BigPandaToo 865eb0a
Merge branch 'master' into Create_ET
elasticmachine 009cc45
Merge branch 'master' into Create_ET
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
26 changes: 26 additions & 0 deletions
26
...h-level/src/main/java/org/elasticsearch/client/security/CreateEnrollmentTokenRequest.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,26 @@ | ||
| /* | ||
| * 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.HttpPut; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.Validatable; | ||
|
|
||
| public class CreateEnrollmentTokenRequest implements Validatable { | ||
|
|
||
| public CreateEnrollmentTokenRequest() { | ||
| } | ||
|
|
||
| public static final CreateEnrollmentTokenRequest INSTANCE = new CreateEnrollmentTokenRequest(); | ||
|
|
||
|
|
||
| public Request getRequest() { | ||
| return new Request(HttpPut.METHOD_NAME, "/_security/enrollment_token"); | ||
| } | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
...-level/src/main/java/org/elasticsearch/client/security/CreateEnrollmentTokenResponse.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,54 @@ | ||
| /* | ||
| * 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.Objects; | ||
|
|
||
| public class CreateEnrollmentTokenResponse { | ||
| private String enrollmentToken; | ||
|
|
||
| public CreateEnrollmentTokenResponse(String enrollmentToken) { | ||
| this.enrollmentToken = enrollmentToken; | ||
| } | ||
|
|
||
| public String getEnrollmentToken() { | ||
| return enrollmentToken; | ||
| } | ||
|
|
||
| private static final ParseField ENROLLMENT_TOKEN = new ParseField("enrollment_token"); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static final ConstructingObjectParser<CreateEnrollmentTokenResponse, Void> PARSER = | ||
| new ConstructingObjectParser<>(CreateEnrollmentTokenResponse.class.getName(), true, | ||
| a -> new CreateEnrollmentTokenResponse((String) a[0])); | ||
|
|
||
| static { | ||
| PARSER.declareString(ConstructingObjectParser.constructorArg(), ENROLLMENT_TOKEN); | ||
| } | ||
|
|
||
| public static CreateEnrollmentTokenResponse 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; | ||
| CreateEnrollmentTokenResponse that = (CreateEnrollmentTokenResponse) o; | ||
| return enrollmentToken.equals(that.enrollmentToken); | ||
| } | ||
|
|
||
| @Override public int hashCode() { | ||
| return Objects.hash(enrollmentToken); | ||
| } | ||
| } |
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
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
39 changes: 39 additions & 0 deletions
39
...l/src/test/java/org/elasticsearch/client/security/CreateEnrollmentTokenResponseTests.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,39 @@ | ||
| /* | ||
| * 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.UUIDs; | ||
| import org.elasticsearch.common.bytes.BytesReference; | ||
| import org.elasticsearch.common.settings.SecureString; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.common.xcontent.XContentFactory; | ||
| import org.elasticsearch.common.xcontent.XContentType; | ||
| import org.elasticsearch.test.ESTestCase; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class CreateEnrollmentTokenResponseTests extends ESTestCase { | ||
|
|
||
| public void testFromXContent() throws IOException { | ||
| final SecureString enrollment_token = UUIDs.randomBase64UUIDSecureString(); | ||
|
|
||
| final XContentType xContentType = randomFrom(XContentType.values()); | ||
| final XContentBuilder builder = XContentFactory.contentBuilder(xContentType); | ||
| builder.startObject() | ||
| .field("enrollment_token", enrollment_token.toString()); | ||
| builder.endObject(); | ||
| BytesReference xContent = BytesReference.bytes(builder); | ||
|
|
||
| final CreateEnrollmentTokenResponse response = CreateEnrollmentTokenResponse.fromXContent(createParser(xContentType.xContent(), | ||
| xContent)); | ||
| assertThat(response.getEnrollmentToken(), equalTo(enrollment_token.toString())); | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
docs/java-rest/high-level/security/create-enrollment-token.asciidoc
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,40 @@ | ||
| -- | ||
| :api: create-enrollment-token | ||
| :request: CreateEnrollmentTokenRequest | ||
| :response: CreateEnrollmentTokenResponse | ||
| -- | ||
| [role="xpack"] | ||
| [id="{upid}-{api}"] | ||
| === Create Enrollment Token API | ||
|
|
||
| Enrollment Tokens can be created using this API. | ||
|
|
||
| [id="{upid}-{api}-request"] | ||
| ==== Create Enrollment Token Request | ||
|
|
||
| A +{request}+ contains no parameters. | ||
|
|
||
| ["source","java",subs="attributes,callouts,macros"] | ||
| -------------------------------------------------- | ||
| include-tagged::{doc-tests-file}[{api}-request] | ||
| -------------------------------------------------- | ||
|
|
||
| include::../execution.asciidoc[] | ||
|
|
||
| [id="{upid}-{api}-response"] | ||
| ==== Create Enrollment Token Response | ||
|
|
||
| The returned +{response}+ contains a string with the enrollment token with which user can enroll a new node | ||
| in an existing secured elasticsearch cluster, or a client can configure itself to | ||
| communicate with a secured elasticsearch cluster. | ||
BigPandaToo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ["source","java",subs="attributes,callouts,macros"] | ||
| -------------------------------------------------- | ||
| include-tagged::{doc-tests-file}[{api}-response] | ||
| -------------------------------------------------- | ||
| <1> The enrollment token contains the following information: | ||
| - IP Address and port number for the interface where the Elasticsearch node is listening for HTTP connections; | ||
| - The fingerprint of the CA certificate that is used to sign the certificate that the Elasticsearch node presents for TLS on the HTTP layer; | ||
| - An API key which allows a holder of the token to authenticate themself to the elasticsearch node; | ||
|
|
||
| as Base64 encoded string. | ||
25 changes: 25 additions & 0 deletions
25
rest-api-spec/src/main/resources/rest-api-spec/api/security.create_enrollment_token.json
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,25 @@ | ||
| { | ||
| "security.create_enrollment_token":{ | ||
| "documentation":{ | ||
| "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/security-create-enrollment-token.html", | ||
| "description":"Create an enrollment token to allow a new node to enroll in an existing secured elasticsearch cluster, or a client to configure itself to communicate with a secured elasticsearch cluster." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the live discussion, we can remove the "enroll client" bit here for now. |
||
| }, | ||
| "stability":"stable", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this should be |
||
| "visibility":"public", | ||
| "headers":{ | ||
| "accept": [ "application/json"], | ||
| "content_type": ["application/json"] | ||
| }, | ||
| "url":{ | ||
| "paths":[ | ||
| { | ||
| "path":"/_security/enrollment_token", | ||
| "methods":[ | ||
| "PUT", | ||
| "POST" | ||
BigPandaToo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Lets use
POSThere, please.EDIT: but maybe this class should be removed completely until we find the need for it to be exposed, see #72186 (review)