-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: Add REST and Websocket authorization hooks and interface #3000
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ad549a
Add authorization interface and hooks to REST and WS endpoints
spena d870469
Add authorization integration tests
spena 4cb522c
Fix tests
spena b67f1c7
Address Victoria's feedback
spena 8944526
Remove KsqlException from KsqlAuthorizationProvider interface
spena 407155a
refactor: authorization functional tests
spena 3616535
test: remove test case causing spotbugs failures
spena 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 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
54 changes: 54 additions & 0 deletions
54
...rest-app/src/main/java/io/confluent/ksql/rest/server/filters/KsqlAuthorizationFilter.java
This file contains 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 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.rest.server.filters; | ||
|
||
import io.confluent.ksql.rest.server.resources.Errors; | ||
import io.confluent.ksql.rest.server.security.KsqlAuthorizationProvider; | ||
import java.security.Principal; | ||
import javax.annotation.Priority; | ||
import javax.ws.rs.Priorities; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.container.ContainerRequestFilter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Authorization filter for REST endpoints. | ||
*/ | ||
@Priority(Priorities.AUTHORIZATION) | ||
public class KsqlAuthorizationFilter implements ContainerRequestFilter { | ||
private static final Logger log = LoggerFactory.getLogger(KsqlAuthorizationFilter.class); | ||
|
||
private final KsqlAuthorizationProvider authorizationProvider; | ||
|
||
public KsqlAuthorizationFilter(final KsqlAuthorizationProvider authorizationProvider) { | ||
this.authorizationProvider = authorizationProvider; | ||
} | ||
|
||
@Override | ||
public void filter(final ContainerRequestContext requestContext) { | ||
final Principal user = requestContext.getSecurityContext().getUserPrincipal(); | ||
final String method = requestContext.getMethod(); // i.e GET, POST | ||
final String path = "/" + requestContext.getUriInfo().getPath(); | ||
|
||
try { | ||
authorizationProvider.checkEndpointAccess(user, method, path); | ||
} catch (final Throwable t) { | ||
log.warn(String.format("User:%s is denied access to \"%s %s\"", user, method, path), t); | ||
requestContext.abortWith(Errors.accessDenied(t.getMessage())); | ||
} | ||
} | ||
} |
This file contains 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 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
32 changes: 32 additions & 0 deletions
32
...t-app/src/main/java/io/confluent/ksql/rest/server/security/KsqlAuthorizationProvider.java
This file contains 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,32 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.rest.server.security; | ||
|
||
import java.security.Principal; | ||
|
||
/** | ||
* Interface that provides authorization to KSQL. | ||
*/ | ||
public interface KsqlAuthorizationProvider { | ||
/** | ||
* Checks if the user is authorized to access the endpoint. | ||
* | ||
* @param user The user who is requesting access to the endpoint | ||
* @param method The endpoint method used, i.e. POST, GET, DELETE | ||
* @param path The endpoint path to access, i.e. "/ksql", "/ksql/terminate", "/query"* | ||
*/ | ||
void checkEndpointAccess(Principal user, String method, String path); | ||
} |
40 changes: 0 additions & 40 deletions
40
ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/security/KsqlAuthorizer.java
This file was deleted.
Oops, something went wrong.
This file contains 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 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.
nit: this comment isn't really helpful, and is a bit confusing (since the impersonation stuff is really a detail of the plugin)
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.
Right. I was actually going to remove this call in another PR. My plan is to wrap the impersonation implementation into a call like
extension.getUserContext(principal)
, and make that call from the REST and WS endpoints to get the Kafka and SR clients for that user.This PR is only authorization so I didn't want to add more functionality.