Skip to content
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

Pr 5733 #18

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1dc60de
[#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin supports File…
Dec 3, 2024
0bb997b
[#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin supports File…
Dec 3, 2024
f48a0fd
Merge branch 'main' into issue_5731
theoryxu Dec 4, 2024
8a212a6
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 4, 2024
2e8283d
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 4, 2024
2b021ab
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 4, 2024
adbfc53
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 4, 2024
55ec12e
Merge branch 'main' into issue_5731
theoryxu Dec 4, 2024
4991698
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 4, 2024
8198437
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 4, 2024
cd0613e
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 5, 2024
2882c37
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 5, 2024
08e0513
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 5, 2024
1fc522d
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 5, 2024
f01eb81
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 5, 2024
6e3ab7a
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 5, 2024
07bb69d
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 6, 2024
4e711af
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 6, 2024
10617a6
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 6, 2024
9e987f9
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 8, 2024
1618cda
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 9, 2024
a0f58c9
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 9, 2024
ec234c3
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 11, 2024
df5c91f
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 11, 2024
e767e21
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 11, 2024
5a44c88
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 12, 2024
69944a4
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 12, 2024
364e0ef
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 12, 2024
ec8343b
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 12, 2024
f2998a5
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 12, 2024
b13fc7c
[apache#5731]feat(auth-ranger): RangerAuthorizationHDFSPlugin support…
Dec 12, 2024
49ff945
test
xunliu Dec 12, 2024
1aec3b2
debug action
xunliu Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/access-control-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ jobs:
run: |
dev/ci/util_free_space.sh

- name: Setup debug Github Action
if: ${{ contains(github.event.pull_request.labels.*.name, 'debug action') }}
uses: csexton/debugger-action@master

- name: Authorization Integration Test (JDK${{ matrix.java-version }})
id: integrationTest
run: |
Expand Down
3 changes: 2 additions & 1 deletion authorizations/authorization-ranger/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ tasks {

tasks.test {
doFirst {
environment("GRAVITINO_TEST", "true")
environment("HADOOP_USER_NAME", "gravitino")
}
dependsOn(":catalogs:catalog-hive:jar", ":catalogs:catalog-hive:runtimeJars", ":catalogs:catalog-lakehouse-iceberg:jar", ":catalogs:catalog-lakehouse-iceberg:runtimeJars", ":catalogs:catalog-lakehouse-paimon:jar", ":catalogs:catalog-lakehouse-paimon:runtimeJars")
dependsOn(":catalogs:catalog-hive:jar", ":catalogs:catalog-hive:runtimeJars", ":catalogs:catalog-lakehouse-iceberg:jar", ":catalogs:catalog-lakehouse-iceberg:runtimeJars", ":catalogs:catalog-lakehouse-paimon:jar", ":catalogs:catalog-lakehouse-paimon:runtimeJars", ":catalogs:catalog-hadoop:jar", ":catalogs:catalog-hadoop:runtimeJars")

val skipITs = project.hasProperty("skipITs")
if (skipITs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ protected AuthorizationPlugin newPlugin(
case "lakehouse-iceberg":
case "lakehouse-paimon":
return RangerAuthorizationHadoopSQLPlugin.getInstance(metalake, config);
case "hadoop":
return RangerAuthorizationHDFSPlugin.getInstance(metalake, config);
default:
throw new IllegalArgumentException("Unknown catalog provider: " + catalogProvider);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
/*
* 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.gravitino.authorization.ranger;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import org.apache.gravitino.GravitinoEnv;
import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.authorization.AuthorizationMetadataObject;
import org.apache.gravitino.authorization.AuthorizationPrivilege;
import org.apache.gravitino.authorization.AuthorizationSecurableObject;
import org.apache.gravitino.authorization.Privilege;
import org.apache.gravitino.authorization.SecurableObject;
import org.apache.gravitino.authorization.SecurableObjects;
import org.apache.gravitino.authorization.ranger.reference.RangerDefines;
import org.apache.gravitino.catalog.FilesetDispatcher;
import org.apache.gravitino.exceptions.AuthorizationPluginException;
import org.apache.gravitino.file.Fileset;
import org.apache.ranger.plugin.model.RangerPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RangerAuthorizationHDFSPlugin extends RangerAuthorizationPlugin {
private static final Logger LOG = LoggerFactory.getLogger(RangerAuthorizationHDFSPlugin.class);

private static final Pattern pattern = Pattern.compile("^hdfs://[^/]*");

private static volatile RangerAuthorizationHDFSPlugin instance = null;

private RangerAuthorizationHDFSPlugin(String metalake, Map<String, String> config) {
super(metalake, config);
}

public static synchronized RangerAuthorizationHDFSPlugin getInstance(
String metalake, Map<String, String> config) {
if (instance == null) {
synchronized (RangerAuthorizationHadoopSQLPlugin.class) {
if (instance == null) {
instance = new RangerAuthorizationHDFSPlugin(metalake, config);
}
}
}
return instance;
}

public static synchronized RangerAuthorizationHDFSPlugin getInstanceForTest(
String metalake, Map<String, String> config) {
getInstance(metalake, config);
return instance;
}

@Override
public Map<Privilege.Name, Set<AuthorizationPrivilege>> privilegesMappingRule() {
return ImmutableMap.of(
Privilege.Name.READ_FILESET,
ImmutableSet.of(
RangerPrivileges.RangerHdfsPrivilege.READ,
RangerPrivileges.RangerHdfsPrivilege.EXECUTE),
Privilege.Name.WRITE_FILESET,
ImmutableSet.of(
RangerPrivileges.RangerHdfsPrivilege.WRITE,
RangerPrivileges.RangerHdfsPrivilege.EXECUTE));
}

@Override
public Set<AuthorizationPrivilege> ownerMappingRule() {
return ImmutableSet.of(
RangerPrivileges.RangerHdfsPrivilege.READ,
RangerPrivileges.RangerHdfsPrivilege.WRITE,
RangerPrivileges.RangerHdfsPrivilege.EXECUTE);
}

@Override
public List<String> policyResourceDefinesRule() {
return ImmutableList.of(RangerDefines.PolicyResource.PATH.getName());
}

@Override
protected RangerPolicy createPolicyAddResources(AuthorizationMetadataObject metadataObject) {
RangerPolicy policy = new RangerPolicy();
policy.setService(rangerServiceName);
policy.setName(metadataObject.fullName());
RangerPolicy.RangerPolicyResource policyResource =
new RangerPolicy.RangerPolicyResource(metadataObject.names().get(0), false, true);
policy.getResources().put(RangerDefines.PolicyResource.PATH.getName(), policyResource);
return policy;
}

@Override
public AuthorizationSecurableObject generateAuthorizationSecurableObject(
List<String> names,
AuthorizationMetadataObject.Type type,
Set<AuthorizationPrivilege> privileges) {
AuthorizationMetadataObject authMetadataObject =
new RangerPathBaseMetadataObject(AuthorizationMetadataObject.getLastName(names), type);
authMetadataObject.validateAuthorizationMetadataObject();
return new RangerPathBaseSecurableObject(
authMetadataObject.name(), authMetadataObject.type(), privileges);
}

@Override
public Set<Privilege.Name> allowPrivilegesRule() {
return ImmutableSet.of(
Privilege.Name.CREATE_FILESET, Privilege.Name.READ_FILESET, Privilege.Name.WRITE_FILESET);
}

@Override
public Set<MetadataObject.Type> allowMetadataObjectTypesRule() {
return ImmutableSet.of(
MetadataObject.Type.FILESET,
MetadataObject.Type.SCHEMA,
MetadataObject.Type.CATALOG,
MetadataObject.Type.METALAKE);
}

@Override
public List<AuthorizationSecurableObject> translatePrivilege(SecurableObject securableObject) {
List<AuthorizationSecurableObject> rangerSecurableObjects = new ArrayList<>();

securableObject.privileges().stream()
.filter(Objects::nonNull)
.forEach(
gravitinoPrivilege -> {
Set<AuthorizationPrivilege> rangerPrivileges = new HashSet<>();
// Ignore unsupported privileges
if (!privilegesMappingRule().containsKey(gravitinoPrivilege.name())) {
return;
}
privilegesMappingRule().get(gravitinoPrivilege.name()).stream()
.forEach(
rangerPrivilege ->
rangerPrivileges.add(
new RangerPrivileges.RangerHivePrivilegeImpl(
rangerPrivilege, gravitinoPrivilege.condition())));

switch (gravitinoPrivilege.name()) {
case CREATE_FILESET:
// Ignore the Gravitino privilege `CREATE_FILESET` in the
// RangerAuthorizationHDFSPlugin
break;
case READ_FILESET:
case WRITE_FILESET:
switch (securableObject.type()) {
case METALAKE:
case CATALOG:
case SCHEMA:
break;
case FILESET:
rangerSecurableObjects.add(
generateAuthorizationSecurableObject(
translateMetadataObject(securableObject).names(),
RangerPathBaseMetadataObject.Type.PATH,
rangerPrivileges));
break;
default:
throw new AuthorizationPluginException(
"The privilege %s is not supported for the securable object: %s",
gravitinoPrivilege.name(), securableObject.type());
}
break;
default:
LOG.warn(
"RangerAuthorizationHDFSPlugin -> privilege {} is not supported for the securable object: {}",
gravitinoPrivilege.name(),
securableObject.type());
}
});

return rangerSecurableObjects;
}

@Override
public List<AuthorizationSecurableObject> translateOwner(MetadataObject gravitinoMetadataObject) {
List<AuthorizationSecurableObject> rangerSecurableObjects = new ArrayList<>();
switch (gravitinoMetadataObject.type()) {
case METALAKE:
case CATALOG:
case SCHEMA:
return rangerSecurableObjects;
case FILESET:
rangerSecurableObjects.add(
generateAuthorizationSecurableObject(
translateMetadataObject(gravitinoMetadataObject).names(),
RangerPathBaseMetadataObject.Type.PATH,
ownerMappingRule()));
break;
default:
throw new AuthorizationPluginException(
"The owner privilege is not supported for the securable object: %s",
gravitinoMetadataObject.type());
}

return rangerSecurableObjects;
}

@Override
public AuthorizationMetadataObject translateMetadataObject(MetadataObject metadataObject) {
Preconditions.checkArgument(
allowMetadataObjectTypesRule().contains(metadataObject.type()),
String.format(
"The metadata object type %s is not supported in the RangerAuthorizationHDFSPlugin",
metadataObject.type()));
List<String> nsMetadataObject =
Lists.newArrayList(SecurableObjects.DOT_SPLITTER.splitToList(metadataObject.fullName()));
Preconditions.checkArgument(
nsMetadataObject.size() > 0, "The metadata object must have at least one name.");

if (metadataObject.type() == MetadataObject.Type.FILESET) {
RangerPathBaseMetadataObject rangerHDFSMetadataObject =
new RangerPathBaseMetadataObject(
getFileSetPath(metadataObject), RangerPathBaseMetadataObject.Type.PATH);
rangerHDFSMetadataObject.validateAuthorizationMetadataObject();
return rangerHDFSMetadataObject;
} else {
return new RangerPathBaseMetadataObject("", RangerPathBaseMetadataObject.Type.PATH);
}
}

private String getFileSetPath(MetadataObject metadataObject) {
FilesetDispatcher filesetDispatcher = GravitinoEnv.getInstance().filesetDispatcher();
boolean testEnv = System.getenv("GRAVITINO_TEST") != null;
LOG.debug("testEnv: {}", testEnv);
if (filesetDispatcher == null && testEnv) {
return "/test";
}
NameIdentifier identifier =
NameIdentifier.parse(String.format("%s.%s", metalake, metadataObject.fullName()));
Fileset fileset = filesetDispatcher.loadFileset(identifier);
Preconditions.checkArgument(
fileset != null, String.format("Fileset %s is not found", identifier));
String filesetLocation = fileset.storageLocation();
Preconditions.checkArgument(
filesetLocation != null, String.format("Fileset %s location is not found", identifier));
return pattern.matcher(filesetLocation).replaceAll("");
}
}
Loading
Loading