-
Notifications
You must be signed in to change notification settings - Fork 340
Store Scheduled Job User Information in an index owned by the Security plugin #2773
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
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
18417b3
WIP on extension settings
cwperks 38b27c8
Merge branch 'main' into extension-security-settings
cwperks b3ba5b4
Merge branch 'main' into extension-security-settings
cwperks 1957eb3
WIP on Scheduled Job Identity Manager
cwperks eb2051b
Add ToXContent for user
cwperks 369d9cc
Use Search Query instead of Get Request since docIds aren't unique ac…
cwperks e6005c1
Change indentation
cwperks 3b5b028
Remove extensions settings changes
cwperks 14d9111
Remove extensions settings changes
cwperks fd64dc8
Merge branch 'main' into scheduled-job-identity
cwperks f1513de
Remove references
cwperks 1a183a3
Remove reference to AD
cwperks 9dc058f
Update ScheduledJobIdentity
cwperks 871b057
Add SecurityIndices for security index related methods
cwperks 7ad9dd6
WIP on tests
cwperks c75c65b
Merge branch 'main' into scheduled-job-identity
cwperks f4c55bf
Use ScheduledJobOperator from core
cwperks fa21481
Create BearerToken
cwperks 83e8f3c
Implemente deleteUserDetails
cwperks ec6d843
Merge branch 'main' into scheduled-job-identity
cwperks 0203554
Run spotlessApply
cwperks 9fd6350
Merge branch 'main' into scheduled-job-identity
cwperks 34887e8
Return ROOT for user not in threadcontext
cwperks 8c2d18b
Update bearer token
cwperks 34195a7
Merge branch 'main' into scheduled-job-identity
cwperks 84121b1
Run spotlessApply
cwperks 609fa51
Merge branch 'main' into scheduled-job-identity
cwperks c02c40c
Use durable threadcontext
cwperks 85ce526
Merge branch 'main' into scheduled-job-identity
cwperks 238c103
Update extension point names
cwperks c485095
Merge branch 'main' into scheduled-job-identity
cwperks dddfc6a
Create convertOperatorToUser
cwperks 612a691
WIP on extracting user info from token
cwperks 699eeba
Merge branch 'main' into scheduled-job-identity
cwperks 28098f7
Run spotlessApply
cwperks 0fcd476
No header overlap
cwperks 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
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
180 changes: 180 additions & 0 deletions
180
src/main/java/org/opensearch/security/identity/ScheduledJobIdentity.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,180 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| * Modifications Copyright OpenSearch Contributors. See | ||
| * GitHub history for details. | ||
| */ | ||
|
|
||
| package org.opensearch.security.identity; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.Instant; | ||
|
|
||
| import com.google.common.base.Objects; | ||
|
|
||
| import org.opensearch.common.io.stream.StreamInput; | ||
| import org.opensearch.common.io.stream.StreamOutput; | ||
| import org.opensearch.common.io.stream.Writeable; | ||
| import org.opensearch.core.xcontent.ToXContentObject; | ||
| import org.opensearch.core.xcontent.XContentBuilder; | ||
| import org.opensearch.core.xcontent.XContentParser; | ||
| import org.opensearch.security.user.User; | ||
|
|
||
| import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
|
||
| /** | ||
| * Scheduled Job Identity. | ||
| */ | ||
| public class ScheduledJobIdentity implements Writeable, ToXContentObject { | ||
| public static final String JOB_ID_FIELD = "job_id"; | ||
| public static final String JOB_INDEX_FIELD = "job_index"; | ||
| public static final String LAST_UPDATE_TIME_FIELD = "last_update_time"; | ||
| public static final String CREATED_TIME_FIELD = "created_time"; | ||
| public static final String USER_FIELD = "user"; | ||
|
|
||
| private final String jobId; | ||
| private final String jobIndex; | ||
| private final Instant createdTime; | ||
| private final Instant lastUpdateTime; | ||
| private final User user; | ||
|
|
||
| public ScheduledJobIdentity(String jobId, String jobIndex, Instant createdTime, Instant lastUpdateTime, User user) { | ||
| this.jobId = jobId; | ||
| this.jobIndex = jobIndex; | ||
| this.createdTime = createdTime; | ||
| this.lastUpdateTime = lastUpdateTime; | ||
| this.user = user; | ||
| } | ||
|
|
||
| public ScheduledJobIdentity(StreamInput input) throws IOException { | ||
| jobId = input.readString(); | ||
| jobIndex = input.readString(); | ||
| createdTime = input.readInstant(); | ||
| lastUpdateTime = input.readInstant(); | ||
| if (input.readBoolean()) { | ||
| user = new User(input); | ||
| } else { | ||
| user = null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Parse content parser to {@link java.time.Instant}. | ||
| * | ||
| * @param parser json based content parser | ||
| * @return instance of {@link java.time.Instant} | ||
| * @throws IOException IOException if content can't be parsed correctly | ||
| */ | ||
| public static Instant toInstant(XContentParser parser) throws IOException { | ||
| if (parser.currentToken() == null || parser.currentToken() == XContentParser.Token.VALUE_NULL) { | ||
| return null; | ||
| } | ||
| if (parser.currentToken().isValue()) { | ||
| return Instant.ofEpochMilli(parser.longValue()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| XContentBuilder xContentBuilder = builder.startObject() | ||
| .field(JOB_ID_FIELD, jobId) | ||
| .field(JOB_INDEX_FIELD, jobIndex) | ||
| .field(CREATED_TIME_FIELD, createdTime.toEpochMilli()) | ||
| .field(LAST_UPDATE_TIME_FIELD, lastUpdateTime.toEpochMilli()); | ||
| if (user != null) { | ||
| xContentBuilder.field(USER_FIELD, user); | ||
| } | ||
| return xContentBuilder.endObject(); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput output) throws IOException { | ||
| output.writeString(jobId); | ||
| output.writeString(jobIndex); | ||
| output.writeInstant(createdTime); | ||
| output.writeInstant(lastUpdateTime); | ||
| if (user != null) { | ||
| output.writeBoolean(true); // user exists | ||
| user.writeTo(output); | ||
| } else { | ||
| output.writeBoolean(false); // user does not exist | ||
| } | ||
| } | ||
|
|
||
| public static ScheduledJobIdentity parse(XContentParser parser) throws IOException { | ||
| String jobId = null; | ||
| String jobIndex = null; | ||
| Instant createdTime = null; | ||
| Instant lastUpdateTime = null; | ||
| User user = null; | ||
|
|
||
| ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser); | ||
| while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
| String fieldName = parser.currentName(); | ||
| parser.nextToken(); | ||
|
|
||
| switch (fieldName) { | ||
| case JOB_ID_FIELD: | ||
| jobId = parser.text(); | ||
| break; | ||
| case JOB_INDEX_FIELD: | ||
| jobIndex = parser.text(); | ||
| break; | ||
| case CREATED_TIME_FIELD: | ||
| createdTime = toInstant(parser); | ||
| break; | ||
| case LAST_UPDATE_TIME_FIELD: | ||
| lastUpdateTime = toInstant(parser); | ||
| break; | ||
| case USER_FIELD: | ||
| user = User.parse(parser); | ||
| break; | ||
| default: | ||
| parser.skipChildren(); | ||
| break; | ||
| } | ||
| } | ||
| return new ScheduledJobIdentity(jobId, jobIndex, createdTime, lastUpdateTime, user); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| ScheduledJobIdentity that = (ScheduledJobIdentity) o; | ||
| return Objects.equal(getJobId(), that.getJobId()) | ||
| && Objects.equal(getJobIndex(), that.getJobIndex()) | ||
| && Objects.equal(getCreatedTime(), that.getCreatedTime()) | ||
| && Objects.equal(getLastUpdateTime(), that.getLastUpdateTime()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hashCode(jobId, jobIndex, createdTime, lastUpdateTime); | ||
| } | ||
|
|
||
| public String getJobId() { | ||
| return jobId; | ||
| } | ||
|
|
||
| public String getJobIndex() { | ||
| return jobIndex; | ||
| } | ||
|
|
||
| public Instant getCreatedTime() { | ||
| return createdTime; | ||
| } | ||
|
|
||
| public Instant getLastUpdateTime() { | ||
| return lastUpdateTime; | ||
| } | ||
|
|
||
| public User getUser() { | ||
| return user; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/opensearch/security/identity/SecurityIndex.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,48 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| * Modifications Copyright OpenSearch Contributors. See | ||
| * GitHub history for details. | ||
| */ | ||
|
|
||
| package org.opensearch.security.identity; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| import org.opensearch.security.util.ThrowingSupplierWrapper; | ||
|
|
||
| import static org.opensearch.security.identity.SecurityIndices.SCHEDULED_JOB_IDENTITY_INDEX; | ||
|
|
||
| /** | ||
| * Represent a security index | ||
| * | ||
| */ | ||
| public enum SecurityIndex { | ||
DarshitChanpura marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // throw RuntimeException since we don't know how to handle the case when the mapping reading throws IOException | ||
| SCHEDULED_JOB_IDENTITY( | ||
| SCHEDULED_JOB_IDENTITY_INDEX, | ||
| ThrowingSupplierWrapper.throwingSupplierWrapper(SecurityIndices::getScheduledJobIdentityMappings) | ||
| ); | ||
|
|
||
| private final String indexName; | ||
| private final String mapping; | ||
|
|
||
| SecurityIndex(String name, Supplier<String> mappingSupplier) { | ||
|
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. Why use Supplier here? Asking because we are just returning a String and not a custom class object |
||
| this.indexName = name; | ||
| this.mapping = mappingSupplier.get(); | ||
| } | ||
|
|
||
| public String getIndexName() { | ||
| return indexName; | ||
| } | ||
|
|
||
| public String getMapping() { | ||
| return mapping; | ||
| } | ||
|
|
||
| } | ||
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.