-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add access control for Pinot server segment download api. (#5260)
* Add access control for Pinot server segment download api. * Update pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java Co-Authored-By: Subbu Subramaniam <mcvsubbu@users.noreply.github.com> * Revise based on comments. * Revise based on comments. Co-authored-by: Subbu Subramaniam <mcvsubbu@users.noreply.github.com>
- Loading branch information
Showing
9 changed files
with
235 additions
and
5 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
38 changes: 38 additions & 0 deletions
38
pinot-server/src/main/java/org/apache/pinot/server/api/access/AccessControl.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,38 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.server.api.access; | ||
|
||
import javax.ws.rs.core.HttpHeaders; | ||
import org.apache.pinot.spi.annotations.InterfaceAudience; | ||
import org.apache.pinot.spi.annotations.InterfaceStability; | ||
|
||
|
||
@InterfaceAudience.Public | ||
@InterfaceStability.Stable | ||
public interface AccessControl { | ||
|
||
/** | ||
* Return whether the client has data access to the given table. | ||
* | ||
* @param httpHeaders Http headers | ||
* @param tableName Name of the table to be accessed | ||
* @return Whether the client has data access to the table | ||
*/ | ||
boolean hasDataAccess(HttpHeaders httpHeaders, String tableName); | ||
} |
30 changes: 30 additions & 0 deletions
30
pinot-server/src/main/java/org/apache/pinot/server/api/access/AccessControlFactory.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,30 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.server.api.access; | ||
|
||
import org.apache.pinot.spi.annotations.InterfaceAudience; | ||
import org.apache.pinot.spi.annotations.InterfaceStability; | ||
|
||
|
||
@InterfaceAudience.Public | ||
@InterfaceStability.Stable | ||
public interface AccessControlFactory { | ||
|
||
AccessControl create(); | ||
} |
37 changes: 37 additions & 0 deletions
37
pinot-server/src/main/java/org/apache/pinot/server/api/access/AllowAllAccessFactory.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,37 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.server.api.access; | ||
|
||
import javax.ws.rs.core.HttpHeaders; | ||
|
||
|
||
public class AllowAllAccessFactory implements AccessControlFactory { | ||
private static final AccessControl ALLOW_ALL_ACCESS = new AccessControl() { | ||
@Override | ||
public boolean hasDataAccess(HttpHeaders httpHeaders, String tableName) { | ||
return true; | ||
} | ||
}; | ||
|
||
@Override | ||
public AccessControl create() { | ||
return ALLOW_ALL_ACCESS; | ||
} | ||
} | ||
|
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
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
87 changes: 87 additions & 0 deletions
87
pinot-server/src/test/java/org/apache/pinot/server/api/AccessControlTest.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,87 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.server.api; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.Response; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.pinot.common.utils.CommonConstants; | ||
import org.apache.pinot.core.data.manager.TableDataManager; | ||
import org.apache.pinot.server.api.access.AccessControl; | ||
import org.apache.pinot.server.api.access.AccessControlFactory; | ||
import org.apache.pinot.server.starter.ServerInstance; | ||
import org.apache.pinot.server.starter.helix.AdminApiApplication; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
|
||
public class AccessControlTest { | ||
private static final File INDEX_DIR = new File(FileUtils.getTempDirectory(), "AccessControlTest"); | ||
protected static final String TABLE_NAME = "testTable"; | ||
|
||
private final Map<String, TableDataManager> _tableDataManagerMap = new HashMap<>(); | ||
private AdminApiApplication _adminApiApplication; | ||
protected WebTarget _webTarget; | ||
|
||
@BeforeClass | ||
public void setUp() | ||
throws Exception { | ||
FileUtils.deleteQuietly(INDEX_DIR); | ||
Assert.assertTrue(INDEX_DIR.mkdirs()); | ||
|
||
// Mock the instance data manager | ||
// Mock the server instance | ||
ServerInstance serverInstance = mock(ServerInstance.class); | ||
|
||
_adminApiApplication = new AdminApiApplication(serverInstance, new DenyAllAccessFactory()); | ||
_adminApiApplication.start(CommonConstants.Server.DEFAULT_ADMIN_API_PORT); | ||
_webTarget = ClientBuilder.newClient().target(_adminApiApplication.getBaseUri()); | ||
} | ||
|
||
@AfterClass | ||
public void tearDown() { | ||
_adminApiApplication.stop(); | ||
FileUtils.deleteQuietly(INDEX_DIR); | ||
} | ||
|
||
@Test | ||
public void testAccessDenied() { | ||
String segmentPath = "/segments/testTable_REALTIME/segment_name"; | ||
// Download any segment will be denied. | ||
Response response = _webTarget.path(segmentPath).request().get(Response.class); | ||
Assert.assertNotEquals(response.getStatus(), Response.Status.FORBIDDEN); | ||
} | ||
|
||
public static class DenyAllAccessFactory implements AccessControlFactory { | ||
private static final AccessControl DENY_ALL_ACCESS = (httpHeaders, tableName) -> false; | ||
|
||
@Override | ||
public AccessControl create() { | ||
return DENY_ALL_ACCESS; | ||
} | ||
} | ||
} |
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