- Notifications
You must be signed in to change notification settings - Fork 25.6k
Role changes to support enforcing workflow restrictions #96744
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
slobodanadamovic merged 46 commits into elastic:main from slobodanadamovic:sa-workflows-role-restriction Jun 19, 2023
Merged
Changes from all commits
Commits
Show all changes
46 commits Select commit Hold shift + click to select a range
787c1d7 Role changes to support enforcing workflow restrictions
slobodanadamovic 1f89678 Change role filtering to explicit workflow restriction checking
slobodanadamovic 35e5af6 Merge branch 'main' of github.com:elastic/elasticsearch into sa-workf…
slobodanadamovic 6db9f8d Implement build role from role descriptor for workflows
slobodanadamovic d215be5 Add assertions
slobodanadamovic cd110aa Add more tests
slobodanadamovic d55c90b Change modifier to private
slobodanadamovic ebe8fbc Update assertion
slobodanadamovic 10b69a1 Remove unused parameter
slobodanadamovic 613191a Test restriction with search application query API
slobodanadamovic 69c93da Implement role filtering approach
slobodanadamovic e8c342d name nit
slobodanadamovic 2ff0f25 Apply spotless
slobodanadamovic 84ac3ea Simplify role filtering
slobodanadamovic 8516933 Fail early - immediately after authz info resolution
slobodanadamovic 2058f5e Check limitedByRole if it's restricted. Change assert to IAE
slobodanadamovic e6ea8cd Address review feedback
slobodanadamovic 50ff3af Fix failing tests
slobodanadamovic 7e51ffa Fail authz info resolving instead of returning denied object
slobodanadamovic f6d729e Revert accidentally removed check
slobodanadamovic 8346abd Merge branch 'main' of github.com:elastic/elasticsearch into sa-workf…
slobodanadamovic d0b2927 Change assert to IAE
slobodanadamovic 8cebf42 Fix failing test.
slobodanadamovic 6fe921e Change back to assertion
slobodanadamovic 5c63c7a Merge branch 'main' of github.com:elastic/elasticsearch into sa-workf…
slobodanadamovic f9ea677 Merge branch 'main' of github.com:elastic/elasticsearch into sa-workf…
slobodanadamovic 5a36c1c Fix condition check
slobodanadamovic c6b7beb Address review fedback
slobodanadamovic a2773c0 Merge branch 'main' of github.com:elastic/elasticsearch into sa-workf…
slobodanadamovic 4df1280 Fix failing test
slobodanadamovic 95fa2e3 Remove unnecessary resolve method. Update javadoc.
slobodanadamovic 0db7341 Merge branch 'main' of github.com:elastic/elasticsearch into sa-workf…
slobodanadamovic ac42c70 Add a TODO for future reference
slobodanadamovic 490e6a9 Merge branch 'main' of github.com:elastic/elasticsearch into sa-workf…
slobodanadamovic 1c6df81 Address review feedback:
slobodanadamovic 8423e81 Apply spotless.
slobodanadamovic 686a1ed Add tests for CompositeRolesStore.getRole
slobodanadamovic 61eac92 Merge branch 'main' of github.com:elastic/elasticsearch into sa-workf…
slobodanadamovic 2f3128a Fix failing tests by spying on real instance to avoid that callRealMe…
slobodanadamovic 4f87f58 Add debug log.
slobodanadamovic cef1633 Test RBACEngine.resolveAuthorizationInfo
slobodanadamovic a83aa3e Test AuthorizationService access denial
slobodanadamovic 339ad06 Apply review comments to ApiKeyWorkflowsRestrictionRestIT
slobodanadamovic 5272341 Merge branch 'main' of github.com:elastic/elasticsearch into sa-workf…
slobodanadamovic 2b13abb Update docs/changelog/96744.yaml
slobodanadamovic 629ab87 Update docs/changelog/96744.yaml
slobodanadamovic 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: 96744 | ||
| summary: Support restricting access of API keys to only certain workflows | ||
| area: Authorization | ||
| type: feature | ||
| 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
35 changes: 35 additions & 0 deletions 35 server/src/main/java/org/elasticsearch/ElasticsearchRoleRestrictionException.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,35 @@ | ||
| /* | ||
| * 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; | ||
| | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.rest.RestStatus; | ||
| | ||
| import java.io.IOException; | ||
| | ||
| /** | ||
| * This exception is thrown to indicate that the access has been denied because of role restrictions that | ||
| * an authenticated subject might have (e.g. not allowed to access certain APIs). | ||
| * This differs from other 403 error in sense that it's additional access control that is enforced after role | ||
| * is resolved and before permissions are checked. | ||
| */ | ||
| public class ElasticsearchRoleRestrictionException extends ElasticsearchSecurityException { | ||
| | ||
| public ElasticsearchRoleRestrictionException(String msg, Throwable cause, Object... args) { | ||
| super(msg, RestStatus.FORBIDDEN, cause, args); | ||
| } | ||
| | ||
| public ElasticsearchRoleRestrictionException(String msg, Object... args) { | ||
| this(msg, null, args); | ||
| } | ||
| | ||
| public ElasticsearchRoleRestrictionException(StreamInput in) throws IOException { | ||
| super(in); | ||
| } | ||
| } |
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
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
52 changes: 52 additions & 0 deletions 52 ...in/java/org/elasticsearch/xpack/core/security/authz/restriction/WorkflowsRestriction.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,52 @@ | ||
| /* | ||
| * 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.authz.restriction; | ||
| | ||
| import org.elasticsearch.core.Nullable; | ||
| | ||
| import java.util.Set; | ||
| import java.util.function.Predicate; | ||
| | ||
| public final class WorkflowsRestriction { | ||
| | ||
| /** | ||
| * Default behaviour is no restriction which allows all workflows. | ||
| */ | ||
| public static final WorkflowsRestriction NONE = new WorkflowsRestriction(null); | ||
| | ||
| private final Set<String> names; | ||
| private final Predicate<String> predicate; | ||
| | ||
| public WorkflowsRestriction(Set<String> names) { | ||
| this.names = names; | ||
| if (names == null) { | ||
| // No restriction, all workflows are allowed | ||
| this.predicate = name -> true; | ||
| } else if (names.isEmpty()) { | ||
| // Empty restriction, no workflow is allowed | ||
| this.predicate = name -> false; | ||
| } else { | ||
| this.predicate = name -> { | ||
| if (name == null) { | ||
| return false; | ||
| } else { | ||
| return names.contains(name); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| | ||
| public boolean hasWorkflows() { | ||
| return this.names != null; | ||
| } | ||
| | ||
| public boolean isWorkflowAllowed(@Nullable String workflow) { | ||
| return predicate.test(workflow); | ||
| } | ||
| | ||
| } | ||
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.