forked from StarRocks/starrocks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Support Apache Ranger as StarRocks RBAC Authorizer (StarRoc…
…ks#29154) Support Apache Ranger as StarRocks RBAC Authorizer Signed-off-by: HangyuanLiu <[email protected]>
- Loading branch information
1 parent
ed4e2d0
commit f934dad
Showing
20 changed files
with
1,909 additions
and
7 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
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
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
58 changes: 58 additions & 0 deletions
58
fe/fe-core/src/main/java/com/starrocks/privilege/ranger/RangerStarRocksAccessRequest.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,58 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// Licensed 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 | ||
// | ||
// https://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 com.starrocks.privilege.ranger; | ||
|
||
import com.starrocks.catalog.MaterializedView; | ||
import com.starrocks.sql.ast.UserIdentity; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl; | ||
import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl; | ||
|
||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class RangerStarRocksAccessRequest extends RangerAccessRequestImpl { | ||
private static final Logger LOG = LogManager.getLogger(MaterializedView.class); | ||
|
||
private RangerStarRocksAccessRequest() { | ||
} | ||
|
||
public static RangerStarRocksAccessRequest createAccessRequest(RangerAccessResourceImpl resource, UserIdentity user, | ||
String accessType) { | ||
UserGroupInformation ugi = UserGroupInformation.createRemoteUser(user.getQualifiedUser()); | ||
String[] groups = ugi.getGroupNames(); | ||
Set<String> userGroups = null; | ||
if (groups != null && groups.length > 0) { | ||
userGroups = new HashSet<>(Arrays.asList(groups)); | ||
} | ||
RangerStarRocksAccessRequest request = new RangerStarRocksAccessRequest(); | ||
request.setUser(user.getQualifiedUser()); | ||
request.setUserGroups(userGroups); | ||
request.setAccessType(accessType); | ||
request.setResource(resource); | ||
request.setClientIPAddress(user.getHost()); | ||
request.setClientType("starrocks"); | ||
request.setClusterName("starrocks"); | ||
request.setAccessTime(new Date()); | ||
|
||
LOG.debug("RangerStarRocksAccessRequest | " + request.toString()); | ||
|
||
return request; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
fe/fe-core/src/main/java/com/starrocks/privilege/ranger/SecurityPolicyRewriteRule.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,94 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// Licensed 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 | ||
// | ||
// https://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 com.starrocks.privilege.ranger; | ||
|
||
import com.starrocks.analysis.Expr; | ||
import com.starrocks.analysis.SlotRef; | ||
import com.starrocks.analysis.TableName; | ||
import com.starrocks.catalog.Column; | ||
import com.starrocks.catalog.InternalCatalog; | ||
import com.starrocks.common.Config; | ||
import com.starrocks.qe.ConnectContext; | ||
import com.starrocks.sql.analyzer.Authorizer; | ||
import com.starrocks.sql.ast.QueryStatement; | ||
import com.starrocks.sql.ast.Relation; | ||
import com.starrocks.sql.ast.SelectList; | ||
import com.starrocks.sql.ast.SelectListItem; | ||
import com.starrocks.sql.ast.SelectRelation; | ||
import com.starrocks.sql.ast.TableRelation; | ||
import com.starrocks.sql.ast.ViewRelation; | ||
import com.starrocks.sql.parser.NodePosition; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class SecurityPolicyRewriteRule { | ||
public static QueryStatement buildView(ConnectContext context, Relation relation, TableName tableName) { | ||
if (!Config.access_control.equals("ranger") && | ||
(tableName.getCatalog() == null | ||
|| tableName.getCatalog().equals(InternalCatalog.DEFAULT_INTERNAL_CATALOG_NAME))) { | ||
return null; | ||
} | ||
|
||
if (relation instanceof TableRelation && ((TableRelation) relation).isSyncMVQuery()) { | ||
return null; | ||
} | ||
|
||
List<Column> columns; | ||
if (relation instanceof ViewRelation) { | ||
ViewRelation viewRelation = (ViewRelation) relation; | ||
columns = viewRelation.getView().getBaseSchema(); | ||
} else if (relation instanceof TableRelation) { | ||
TableRelation tableRelation = (TableRelation) relation; | ||
columns = tableRelation.getTable().getBaseSchema(); | ||
} else { | ||
return null; | ||
} | ||
|
||
boolean hasPolicy = false; | ||
List<SelectListItem> selectListItemList = new ArrayList<>(); | ||
for (Column column : columns) { | ||
Expr maskingExpr = Authorizer.getColumnMaskingPolicy( | ||
context, tableName, column.getName(), column.getType()); | ||
|
||
if (maskingExpr != null) { | ||
hasPolicy = true; | ||
selectListItemList.add(new SelectListItem(maskingExpr, column.getName(), NodePosition.ZERO)); | ||
} else { | ||
selectListItemList.add(new SelectListItem(new SlotRef(tableName, column.getName()), column.getName(), | ||
NodePosition.ZERO)); | ||
} | ||
} | ||
|
||
Expr rowAccessExpr = Authorizer.getRowAccessPolicy(context, tableName); | ||
if (rowAccessExpr != null) { | ||
hasPolicy = true; | ||
} | ||
|
||
if (!hasPolicy) { | ||
return null; | ||
} | ||
|
||
SelectRelation selectRelation = new SelectRelation( | ||
new SelectList(selectListItemList, false), | ||
relation, | ||
rowAccessExpr, | ||
null, | ||
null); | ||
selectRelation.setOrderBy(Collections.emptyList()); | ||
return new QueryStatement(selectRelation); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
fe/fe-core/src/main/java/com/starrocks/privilege/ranger/hive/HiveAccessType.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,19 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// Licensed 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 | ||
// | ||
// https://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 com.starrocks.privilege.ranger.hive; | ||
|
||
public enum HiveAccessType { | ||
NONE, CREATE, ALTER, DROP, INDEX, LOCK, SELECT, UPDATE, USE, READ, WRITE, ALL, SERVICEADMIN, TEMPUDFADMIN; | ||
} |
Oops, something went wrong.