-
Notifications
You must be signed in to change notification settings - Fork 382
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
[#5775] feat(auth): Chain authorization plugin framework #5786
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fe7b35b
[#5775] feat(auth): Chain authorization plugin
xunliu 35aba1f
address comments
xunliu f5a7933
Add license head
xunliu b52e9e0
refactor JdbcProperties.java
xunliu 4a57e7d
address comments
xunliu 535bcd6
rename to chained
xunliu d2944ca
address comments
xunliu 5010cdb
improve code
xunliu c7d60b0
improve
xunliu 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
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,146 @@ | ||
/* | ||
* 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. | ||
*/ | ||
description = "authorization-chain" | ||
|
||
plugins { | ||
`maven-publish` | ||
id("java") | ||
id("idea") | ||
} | ||
|
||
val scalaVersion: String = project.properties["scalaVersion"] as? String ?: extra["defaultScalaVersion"].toString() | ||
val sparkVersion: String = libs.versions.spark35.get() | ||
val kyuubiVersion: String = libs.versions.kyuubi4paimon.get() | ||
val sparkMajorVersion: String = sparkVersion.substringBeforeLast(".") | ||
|
||
dependencies { | ||
implementation(project(":api")) { | ||
exclude(group = "*") | ||
} | ||
implementation(project(":core")) { | ||
exclude(group = "*") | ||
} | ||
implementation(project(":common")) { | ||
exclude(group = "*") | ||
} | ||
implementation(project(":authorizations:authorization-common")) { | ||
exclude(group = "*") | ||
} | ||
implementation(libs.bundles.log4j) | ||
implementation(libs.commons.lang3) | ||
implementation(libs.guava) | ||
implementation(libs.javax.jaxb.api) { | ||
exclude("*") | ||
} | ||
implementation(libs.javax.ws.rs.api) | ||
implementation(libs.jettison) | ||
implementation(libs.rome) | ||
compileOnly(libs.lombok) | ||
|
||
testImplementation(project(":core")) | ||
testImplementation(project(":clients:client-java")) | ||
testImplementation(project(":server")) | ||
testImplementation(project(":catalogs:catalog-common")) | ||
testImplementation(project(":integration-test-common", "testArtifacts")) | ||
testImplementation(project(":authorizations:authorization-ranger")) | ||
testImplementation(project(":authorizations:authorization-ranger", "testArtifacts")) | ||
testImplementation(libs.junit.jupiter.api) | ||
testImplementation(libs.mockito.core) | ||
testImplementation(libs.testcontainers) | ||
testRuntimeOnly(libs.junit.jupiter.engine) | ||
testImplementation(libs.mysql.driver) | ||
testImplementation(libs.postgresql.driver) | ||
testImplementation(libs.ranger.intg) { | ||
Comment on lines
+56
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we still have some alphabetical ordering issues, can you fix them all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DONE |
||
exclude("org.apache.hadoop", "hadoop-common") | ||
exclude("org.apache.hive", "hive-storage-api") | ||
exclude("org.apache.lucene") | ||
exclude("org.apache.solr") | ||
exclude("org.apache.kafka") | ||
exclude("org.elasticsearch") | ||
exclude("org.elasticsearch.client") | ||
exclude("org.elasticsearch.plugin") | ||
exclude("org.apache.ranger", "ranger-plugins-audit") | ||
exclude("org.apache.ranger", "ranger-plugins-cred") | ||
exclude("org.apache.ranger", "ranger-plugin-classloader") | ||
exclude("net.java.dev.jna") | ||
exclude("javax.ws.rs") | ||
exclude("org.eclipse.jetty") | ||
} | ||
testImplementation("org.apache.spark:spark-hive_$scalaVersion:$sparkVersion") | ||
testImplementation("org.apache.spark:spark-sql_$scalaVersion:$sparkVersion") { | ||
exclude("org.apache.avro") | ||
exclude("org.apache.hadoop") | ||
exclude("org.apache.zookeeper") | ||
exclude("io.dropwizard.metrics") | ||
exclude("org.rocksdb") | ||
} | ||
testImplementation("org.apache.kyuubi:kyuubi-spark-authz-shaded_$scalaVersion:$kyuubiVersion") { | ||
exclude("com.sun.jersey") | ||
} | ||
testImplementation(libs.hadoop3.client) | ||
testImplementation(libs.hadoop3.common) { | ||
exclude("com.sun.jersey") | ||
exclude("javax.servlet", "servlet-api") | ||
} | ||
testImplementation(libs.hadoop3.hdfs) { | ||
exclude("com.sun.jersey") | ||
exclude("javax.servlet", "servlet-api") | ||
exclude("io.netty") | ||
} | ||
} | ||
|
||
tasks { | ||
val runtimeJars by registering(Copy::class) { | ||
from(configurations.runtimeClasspath) | ||
into("build/libs") | ||
} | ||
|
||
val copyAuthorizationLibs by registering(Copy::class) { | ||
dependsOn("jar", runtimeJars) | ||
from("build/libs") { | ||
exclude("guava-*.jar") | ||
exclude("log4j-*.jar") | ||
exclude("slf4j-*.jar") | ||
} | ||
into("$rootDir/distribution/package/authorizations/chain/libs") | ||
} | ||
|
||
register("copyLibAndConfig", Copy::class) { | ||
dependsOn(copyAuthorizationLibs) | ||
} | ||
|
||
jar { | ||
dependsOn(runtimeJars) | ||
} | ||
} | ||
|
||
tasks.test { | ||
doFirst { | ||
environment("HADOOP_USER_NAME", "gravitino") | ||
} | ||
dependsOn(":catalogs:catalog-hive:jar", ":catalogs:catalog-hive:runtimeJars", ":authorizations:authorization-ranger:jar", ":authorizations:authorization-ranger:runtimeJars") | ||
|
||
val skipITs = project.hasProperty("skipITs") | ||
if (skipITs) { | ||
// Exclude integration tests | ||
exclude("**/integration/test/**") | ||
} else { | ||
dependsOn(tasks.jar) | ||
} | ||
} |
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
197 changes: 197 additions & 0 deletions
197
...in/src/main/java/org/apache/gravitino/authorization/chain/ChainedAuthorizationPlugin.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,197 @@ | ||
/* | ||
* 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.chain; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Lists; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import org.apache.gravitino.Catalog; | ||
import org.apache.gravitino.MetadataObject; | ||
import org.apache.gravitino.authorization.Group; | ||
import org.apache.gravitino.authorization.MetadataObjectChange; | ||
import org.apache.gravitino.authorization.Owner; | ||
import org.apache.gravitino.authorization.Role; | ||
import org.apache.gravitino.authorization.RoleChange; | ||
import org.apache.gravitino.authorization.User; | ||
import org.apache.gravitino.authorization.common.AuthorizationProperties; | ||
import org.apache.gravitino.authorization.common.ChainedAuthorizationProperties; | ||
import org.apache.gravitino.connector.authorization.AuthorizationPlugin; | ||
import org.apache.gravitino.connector.authorization.BaseAuthorization; | ||
import org.apache.gravitino.exceptions.AuthorizationPluginException; | ||
import org.apache.gravitino.utils.IsolatedClassLoader; | ||
|
||
/** Chained authorization operations plugin class. <br> */ | ||
public class ChainedAuthorizationPlugin implements AuthorizationPlugin { | ||
private List<AuthorizationPlugin> plugins = Lists.newArrayList(); | ||
private final String metalake; | ||
|
||
public ChainedAuthorizationPlugin( | ||
String metalake, String catalogProvider, Map<String, String> config) { | ||
this.metalake = metalake; | ||
initPlugins(catalogProvider, config); | ||
} | ||
|
||
private void initPlugins(String catalogProvider, Map<String, String> properties) { | ||
ChainedAuthorizationProperties chainedAuthzProperties = | ||
new ChainedAuthorizationProperties(properties); | ||
chainedAuthzProperties.validate(); | ||
// Validate the properties for each plugin | ||
chainedAuthzProperties | ||
.plugins() | ||
.forEach( | ||
pluginName -> { | ||
Map<String, String> pluginProperties = | ||
chainedAuthzProperties.fetchAuthPluginProperties(pluginName); | ||
String authzProvider = chainedAuthzProperties.getPluginProvider(pluginName); | ||
AuthorizationProperties.validate(authzProvider, pluginProperties); | ||
}); | ||
// Create the plugins | ||
chainedAuthzProperties | ||
.plugins() | ||
.forEach( | ||
pluginName -> { | ||
String authzProvider = chainedAuthzProperties.getPluginProvider(pluginName); | ||
Map<String, String> pluginConfig = | ||
chainedAuthzProperties.fetchAuthPluginProperties(pluginName); | ||
|
||
ArrayList<String> libAndResourcesPaths = Lists.newArrayList(); | ||
BaseAuthorization.buildAuthorizationPkgPath( | ||
ImmutableMap.of(Catalog.AUTHORIZATION_PROVIDER, authzProvider)) | ||
.ifPresent(libAndResourcesPaths::add); | ||
IsolatedClassLoader classLoader = | ||
IsolatedClassLoader.buildClassLoader(libAndResourcesPaths); | ||
try { | ||
BaseAuthorization<?> authorization = | ||
BaseAuthorization.createAuthorization(classLoader, authzProvider); | ||
AuthorizationPlugin authorizationPlugin = | ||
authorization.newPlugin(metalake, catalogProvider, pluginConfig); | ||
plugins.add(authorizationPlugin); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
for (AuthorizationPlugin plugin : plugins) { | ||
plugin.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public Boolean onMetadataUpdated(MetadataObjectChange... changes) | ||
throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onMetadataUpdated(changes)); | ||
} | ||
|
||
@Override | ||
public Boolean onRoleCreated(Role role) throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onRoleCreated(role)); | ||
} | ||
|
||
@Override | ||
public Boolean onRoleAcquired(Role role) throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onRoleAcquired(role)); | ||
} | ||
|
||
@Override | ||
public Boolean onRoleDeleted(Role role) throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onRoleDeleted(role)); | ||
} | ||
|
||
@Override | ||
public Boolean onRoleUpdated(Role role, RoleChange... changes) | ||
throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onRoleUpdated(role, changes)); | ||
} | ||
|
||
@Override | ||
public Boolean onGrantedRolesToUser(List<Role> roles, User user) | ||
throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onGrantedRolesToUser(roles, user)); | ||
} | ||
|
||
@Override | ||
public Boolean onRevokedRolesFromUser(List<Role> roles, User user) | ||
throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onRevokedRolesFromUser(roles, user)); | ||
} | ||
|
||
@Override | ||
public Boolean onGrantedRolesToGroup(List<Role> roles, Group group) | ||
throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onGrantedRolesToGroup(roles, group)); | ||
} | ||
|
||
@Override | ||
public Boolean onRevokedRolesFromGroup(List<Role> roles, Group group) | ||
throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onRevokedRolesFromGroup(roles, group)); | ||
} | ||
|
||
@Override | ||
public Boolean onUserAdded(User user) throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onUserAdded(user)); | ||
} | ||
|
||
@Override | ||
public Boolean onUserRemoved(User user) throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onUserRemoved(user)); | ||
} | ||
|
||
@Override | ||
public Boolean onUserAcquired(User user) throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onUserAcquired(user)); | ||
} | ||
|
||
@Override | ||
public Boolean onGroupAdded(Group group) throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onGroupAdded(group)); | ||
} | ||
|
||
@Override | ||
public Boolean onGroupRemoved(Group group) throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onGroupRemoved(group)); | ||
} | ||
|
||
@Override | ||
public Boolean onGroupAcquired(Group group) throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onGroupAcquired(group)); | ||
} | ||
|
||
@Override | ||
public Boolean onOwnerSet(MetadataObject metadataObject, Owner preOwner, Owner newOwner) | ||
throws AuthorizationPluginException { | ||
return chainedAction(plugin -> plugin.onOwnerSet(metadataObject, preOwner, newOwner)); | ||
} | ||
|
||
private Boolean chainedAction(Function<AuthorizationPlugin, Boolean> action) { | ||
for (AuthorizationPlugin plugin : plugins) { | ||
if (!action.apply(plugin)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.
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.
Can you make this alphabetically ordering?
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.
DONE