-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Service Accounts - Fleet integration #70724
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
ywangd
merged 16 commits into
elastic:master
from
ywangd:service-account-fleet-integration
Mar 31, 2021
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
92aea02
Service Account - fleet integration
ywangd d989ae8
[Test] Service Account - fix test assumption
ywangd f47a90a
Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/…
ywangd ebd871a
Fix tests and remove legacy code
ywangd a32bf58
Add more tests
ywangd 96af0c6
Complete tests
ywangd a0c26ad
revert unwanted changes
ywangd 9252cbf
fix test
ywangd b396716
extract tls runtime checker
ywangd 5b5a3f1
Merge remote-tracking branch 'origin/master' into service-account-fle…
ywangd f2ce8f7
Apply suggestions from code review
ywangd 5b14f19
address feedback
ywangd f4af54d
improve http tls runtime check
ywangd e1c7580
forbidden API
ywangd a0fa91c
Rename elastic/fleet to elastic/fleet-server
ywangd 731de18
Merge remote-tracking branch 'origin/master' into service-account-fle…
ywangd 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
20 changes: 20 additions & 0 deletions
20
...org/elasticsearch/xpack/core/security/action/service/CreateServiceAccountTokenAction.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,20 @@ | ||
/* | ||
* 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.action.service; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
|
||
public class CreateServiceAccountTokenAction extends ActionType<CreateServiceAccountTokenResponse> { | ||
|
||
public static final String NAME = "cluster:admin/xpack/security/service_account/token/create"; | ||
public static final CreateServiceAccountTokenAction INSTANCE = new CreateServiceAccountTokenAction(); | ||
|
||
private CreateServiceAccountTokenAction() { | ||
super(NAME, CreateServiceAccountTokenResponse::new); | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
...rg/elasticsearch/xpack/core/security/action/service/CreateServiceAccountTokenRequest.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,117 @@ | ||
/* | ||
* 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.action.service; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.support.WriteRequest; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
||
public class CreateServiceAccountTokenRequest extends ActionRequest { | ||
|
||
private final String namespace; | ||
private final String serviceName; | ||
private final String tokenName; | ||
private WriteRequest.RefreshPolicy refreshPolicy = WriteRequest.RefreshPolicy.WAIT_UNTIL; | ||
|
||
public CreateServiceAccountTokenRequest(String namespace, String serviceName, String tokenName) { | ||
this.namespace = namespace; | ||
this.serviceName = serviceName; | ||
this.tokenName = tokenName; | ||
} | ||
|
||
public CreateServiceAccountTokenRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.namespace = in.readString(); | ||
this.serviceName = in.readString(); | ||
this.tokenName = in.readString(); | ||
this.refreshPolicy = WriteRequest.RefreshPolicy.readFrom(in); | ||
} | ||
|
||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
public String getServiceName() { | ||
return serviceName; | ||
} | ||
|
||
public String getTokenName() { | ||
return tokenName; | ||
} | ||
|
||
public WriteRequest.RefreshPolicy getRefreshPolicy() { | ||
return refreshPolicy; | ||
} | ||
|
||
public void setRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy) { | ||
this.refreshPolicy = Objects.requireNonNull(refreshPolicy, "refresh policy may not be null"); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
CreateServiceAccountTokenRequest that = (CreateServiceAccountTokenRequest) o; | ||
return Objects.equals(namespace, that.namespace) && Objects.equals(serviceName, that.serviceName) | ||
&& Objects.equals(tokenName, that.tokenName) && refreshPolicy == that.refreshPolicy; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(namespace, serviceName, tokenName, refreshPolicy); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(namespace); | ||
out.writeString(serviceName); | ||
out.writeString(tokenName); | ||
refreshPolicy.writeTo(out); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (Strings.isNullOrEmpty(namespace)) { | ||
validationException = addValidationError("service account namespace is required", validationException); | ||
} | ||
|
||
if (Strings.isNullOrEmpty(serviceName)) { | ||
validationException = addValidationError("service account service-name is required", validationException); | ||
} | ||
|
||
if (Strings.isNullOrEmpty(tokenName)) { | ||
validationException = addValidationError("service account token name is required", validationException); | ||
} else { | ||
if (tokenName.length() > 256) { | ||
validationException = addValidationError( | ||
"service account token name may not be more than 256 characters long", validationException); | ||
} | ||
if (tokenName.equals(tokenName.trim()) == false) { | ||
validationException = addValidationError( | ||
"service account token name may not begin or end with whitespace", validationException); | ||
} | ||
if (tokenName.startsWith("_")) { | ||
validationException = addValidationError( | ||
"service account token name may not begin with an underscore", validationException); | ||
} | ||
} | ||
return validationException; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...g/elasticsearch/xpack/core/security/action/service/CreateServiceAccountTokenResponse.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,84 @@ | ||
/* | ||
* 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.action.service; | ||
|
||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.settings.SecureString; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class CreateServiceAccountTokenResponse extends ActionResponse implements ToXContentObject { | ||
|
||
@Nullable | ||
private final String name; | ||
@Nullable | ||
private final SecureString value; | ||
|
||
private CreateServiceAccountTokenResponse(boolean created, String name, SecureString value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public CreateServiceAccountTokenResponse(StreamInput in) throws IOException { | ||
super(in); | ||
this.name = in.readOptionalString(); | ||
this.value = in.readOptionalSecureString(); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public SecureString getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject() | ||
.field("created", true) | ||
.field("token") | ||
.startObject() | ||
.field("name", name) | ||
.field("value", value.toString()) | ||
.endObject() | ||
.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeOptionalString(name); | ||
out.writeOptionalSecureString(value); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
CreateServiceAccountTokenResponse that = (CreateServiceAccountTokenResponse) o; | ||
return Objects.equals(name, that.name) && Objects.equals(value, that.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, value); | ||
} | ||
|
||
public static CreateServiceAccountTokenResponse created(String name, SecureString value) { | ||
return new CreateServiceAccountTokenResponse(true, name, value); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...a/org/elasticsearch/xpack/core/security/action/service/GetServiceAccountTokensAction.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,20 @@ | ||
/* | ||
* 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.action.service; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
|
||
public class GetServiceAccountTokensAction extends ActionType<GetServiceAccountTokensResponse> { | ||
|
||
public static final String NAME = "cluster:admin/xpack/security/service_account/token/get"; | ||
public static final GetServiceAccountTokensAction INSTANCE = new GetServiceAccountTokensAction(); | ||
|
||
public GetServiceAccountTokensAction() { | ||
super(NAME, GetServiceAccountTokensResponse::new); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
.../org/elasticsearch/xpack/core/security/action/service/GetServiceAccountTokensRequest.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,79 @@ | ||
/* | ||
* 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.action.service; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
|
||
public class GetServiceAccountTokensRequest extends ActionRequest { | ||
|
||
private final String namespace; | ||
private final String serviceName; | ||
|
||
public GetServiceAccountTokensRequest(String namespace, String serviceName) { | ||
this.namespace = namespace; | ||
this.serviceName = serviceName; | ||
} | ||
|
||
public GetServiceAccountTokensRequest(StreamInput in) throws IOException { | ||
super(in); | ||
this.namespace = in.readString(); | ||
this.serviceName = in.readString(); | ||
} | ||
|
||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
public String getServiceName() { | ||
return serviceName; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
GetServiceAccountTokensRequest that = (GetServiceAccountTokensRequest) o; | ||
return Objects.equals(namespace, that.namespace) && Objects.equals(serviceName, that.serviceName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(namespace, serviceName); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeString(namespace); | ||
out.writeString(serviceName); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if (Strings.isNullOrEmpty(namespace)) { | ||
validationException = addValidationError("service account namespace is required", validationException); | ||
} | ||
|
||
if (Strings.isNullOrEmpty(serviceName)) { | ||
validationException = addValidationError("service account service-name is required", validationException); | ||
} | ||
return validationException; | ||
} | ||
} |
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.