-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#4993] feat(iceberg): integrate credential framework to iceberg REST…
… server (#5134) ### What changes were proposed in this pull request? integrate credential framework to iceberg REST server ### Why are the changes needed? Fix: #4993 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? set up a local environment to request credential with the configuration `spark.sql.catalog.rest.header.X-Iceberg-Access-Delegation=vended-credentials`
- Loading branch information
Showing
23 changed files
with
711 additions
and
257 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
26 changes: 26 additions & 0 deletions
26
...ogs/catalog-common/src/main/java/org/apache/gravitino/credential/CredentialConstants.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,26 @@ | ||
/* | ||
* 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.credential; | ||
|
||
public class CredentialConstants { | ||
public static final String CREDENTIAL_PROVIDER_TYPE = "credential-provider-type"; | ||
|
||
private CredentialConstants() {} | ||
} |
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
common/src/main/java/org/apache/gravitino/credential/CredentialPropertyUtils.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.gravitino.credential; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Helper class to generate specific credential properties for different table format and engine. | ||
*/ | ||
public class CredentialPropertyUtils { | ||
/** | ||
* Transforms a specific credential into a map of Iceberg properties. | ||
* | ||
* @param credential the credential to be transformed into Iceberg properties | ||
* @return a map of Iceberg properties derived from the credential | ||
*/ | ||
public static Map<String, String> toIcebergProperties(Credential credential) { | ||
// todo: transform specific credential to iceberg properties | ||
return credential.toProperties(); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
core/src/main/java/org/apache/gravitino/credential/CredentialProviderManager.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,73 @@ | ||
/* | ||
* 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.credential; | ||
|
||
import com.google.common.base.Preconditions; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import javax.annotation.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CredentialProviderManager { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(CredentialProviderManager.class); | ||
private Map<String, CredentialProvider> credentialProviders; | ||
|
||
public CredentialProviderManager() { | ||
this.credentialProviders = new ConcurrentHashMap<>(); | ||
} | ||
|
||
public void registerCredentialProvider( | ||
String catalogName, CredentialProvider credentialProvider) { | ||
CredentialProvider current = credentialProviders.putIfAbsent(catalogName, credentialProvider); | ||
Preconditions.checkState( | ||
!credentialProvider.equals(current), | ||
String.format( | ||
"Should not register multiple times to CredentialProviderManager, catalog: %s, " | ||
+ "credential provider: %s", | ||
catalogName, credentialProvider.credentialType())); | ||
LOG.info( | ||
"Register catalog:%s credential provider:%s to CredentialProviderManager", | ||
catalogName, credentialProvider.credentialType()); | ||
} | ||
|
||
public void unregisterCredentialProvider(String catalogName) { | ||
CredentialProvider credentialProvider = credentialProviders.remove(catalogName); | ||
// Not all catalog has credential provider | ||
if (credentialProvider != null) { | ||
LOG.info( | ||
"Unregister catalog:{} credential provider:{} to CredentialProviderManager", | ||
catalogName, | ||
credentialProvider.credentialType()); | ||
try { | ||
credentialProvider.close(); | ||
} catch (IOException e) { | ||
LOG.warn("Close credential provider failed", e); | ||
} | ||
} | ||
} | ||
|
||
@Nullable | ||
public CredentialProvider getCredentialProvider(String catalogName) { | ||
return credentialProviders.get(catalogName); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
core/src/main/java/org/apache/gravitino/credential/CredentialUtils.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 @@ | ||
/* | ||
* 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.credential; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import org.apache.gravitino.utils.PrincipalUtils; | ||
|
||
public class CredentialUtils { | ||
public static Credential vendCredential(CredentialProvider credentialProvider, String path) { | ||
PathBasedCredentialContext pathBasedCredentialContext = | ||
new PathBasedCredentialContext( | ||
PrincipalUtils.getCurrentUserName(), ImmutableSet.of(path), ImmutableSet.of()); | ||
return credentialProvider.getCredential(pathBasedCredentialContext); | ||
} | ||
} |
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
Oops, something went wrong.