-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add REST and Websocket authorization hooks and interface (#3000)
- Loading branch information
Showing
15 changed files
with
535 additions
and
80 deletions.
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.