-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Encryption for REST catalog #13225
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
Open
smaheshwar-pltr
wants to merge
18
commits into
apache:main
Choose a base branch
from
smaheshwar-pltr:rest-encrypt-on-main-cherry-pick
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Encryption for REST catalog #13225
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
af672ed
Encryption for REST catalog
smaheshwar-pltr 7ad846d
Nit improvements
smaheshwar-pltr 9ed8d8e
Suppress test method length
smaheshwar-pltr 2d18a6a
Merge branch 'main' into rest-encrypt-on-main-cherry-pick
smaheshwar-pltr 745a959
Spotless
smaheshwar-pltr 1106a26
Merge branch 'main' into rest-encrypt-on-main-cherry-pick
smaheshwar-pltr 8ac5228
Fix conflicts and update test
smaheshwar-pltr 73e0980
Undo 4.0 changes
smaheshwar-pltr a774a9c
Fix checkstyle
smaheshwar-pltr 86abfab
empty
smaheshwar-pltr 1e42400
Nit: Simplify adding encryption keys
smaheshwar-pltr 3c055ce
Respect `CatalogProperties.ENCRYPTION_KMS_TYPE`
smaheshwar-pltr b9e5822
Merge
smaheshwar-pltr cd04290
Fix merge
smaheshwar-pltr ee27d5d
Nits + spotless
smaheshwar-pltr 2092454
Add TODO for encryption <> scan planning
smaheshwar-pltr cfb7345
Fixes
smaheshwar-pltr 0af4ef4
Merge remote-tracking branch 'origin/main' into rest-encrypt-on-main-…
smaheshwar-pltr 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 hidden or 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 |
|---|---|---|
|
|
@@ -51,6 +51,8 @@ | |
| import org.apache.iceberg.catalog.Namespace; | ||
| import org.apache.iceberg.catalog.TableCommit; | ||
| import org.apache.iceberg.catalog.TableIdentifier; | ||
| import org.apache.iceberg.encryption.EncryptionUtil; | ||
| import org.apache.iceberg.encryption.KeyManagementClient; | ||
| import org.apache.iceberg.exceptions.AlreadyExistsException; | ||
| import org.apache.iceberg.exceptions.NoSuchNamespaceException; | ||
| import org.apache.iceberg.exceptions.NoSuchTableException; | ||
|
|
@@ -167,6 +169,7 @@ public class RESTSessionCatalog extends BaseViewSessionCatalog | |
| private CloseableGroup closeables = null; | ||
| private Set<Endpoint> endpoints; | ||
| private Supplier<Map<String, String>> mutationHeaders = Map::of; | ||
| private KeyManagementClient keyManagementClient = null; | ||
| private String namespaceSeparator = null; | ||
|
|
||
| private RESTTableCache tableCache; | ||
|
|
@@ -272,6 +275,12 @@ public void initialize(String name, Map<String, String> unresolved) { | |
| mergedProps, | ||
| RESTCatalogProperties.METRICS_REPORTING_ENABLED, | ||
| RESTCatalogProperties.METRICS_REPORTING_ENABLED_DEFAULT); | ||
|
|
||
| if (mergedProps.containsKey(CatalogProperties.ENCRYPTION_KMS_IMPL)) { | ||
| this.keyManagementClient = EncryptionUtil.createKmsClient(mergedProps); | ||
| this.closeables.addCloseable(this.keyManagementClient); | ||
| } | ||
|
|
||
| this.namespaceSeparator = | ||
| PropertyUtil.propertyAsString( | ||
| mergedProps, | ||
|
|
@@ -575,6 +584,7 @@ private Supplier<BaseTable> createTableSupplier( | |
| Map::of, | ||
| mutationHeaders, | ||
| tableFileIO(context, tableConf, credentials), | ||
| keyManagementClient, | ||
| tableMetadata, | ||
| endpoints); | ||
|
|
||
|
|
@@ -674,6 +684,7 @@ public Table registerTable( | |
| Map::of, | ||
| mutationHeaders, | ||
| tableFileIO(context, tableConf, response.credentials()), | ||
| keyManagementClient, | ||
| response.tableMetadata(), | ||
| endpoints); | ||
|
|
||
|
|
@@ -943,6 +954,7 @@ public Table create() { | |
| Map::of, | ||
| mutationHeaders, | ||
| tableFileIO(context, tableConf, response.credentials()), | ||
| keyManagementClient, | ||
| response.tableMetadata(), | ||
| endpoints); | ||
|
|
||
|
|
@@ -976,6 +988,7 @@ public Transaction createTransaction() { | |
| Map::of, | ||
| mutationHeaders, | ||
| tableFileIO(context, tableConf, response.credentials()), | ||
| keyManagementClient, | ||
| RESTTableOperations.UpdateType.CREATE, | ||
| createChanges(meta), | ||
| meta, | ||
|
|
@@ -1041,6 +1054,7 @@ public Transaction replaceTransaction() { | |
| Map::of, | ||
| mutationHeaders, | ||
| tableFileIO(context, tableConf, response.credentials()), | ||
| keyManagementClient, | ||
| RESTTableOperations.UpdateType.REPLACE, | ||
| changes.build(), | ||
| base, | ||
|
|
@@ -1181,6 +1195,7 @@ private FileIO tableFileIO( | |
| * @param mutationHeaderSupplier a supplier for additional HTTP headers to include in mutation | ||
| * requests (POST/DELETE) | ||
| * @param fileIO the FileIO implementation for reading and writing table metadata and data files | ||
| * @param kmsClient the {@link KeyManagementClient} for encrypted tables | ||
|
Contributor
Author
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. |
||
| * @param current the current table metadata | ||
| * @param supportedEndpoints the set of supported REST endpoints | ||
| * @return a new RESTTableOperations instance | ||
|
|
@@ -1191,10 +1206,18 @@ protected RESTTableOperations newTableOps( | |
| Supplier<Map<String, String>> readHeaders, | ||
| Supplier<Map<String, String>> mutationHeaderSupplier, | ||
| FileIO fileIO, | ||
| KeyManagementClient kmsClient, | ||
| TableMetadata current, | ||
| Set<Endpoint> supportedEndpoints) { | ||
| return new RESTTableOperations( | ||
| restClient, path, readHeaders, mutationHeaderSupplier, fileIO, current, supportedEndpoints); | ||
| restClient, | ||
| path, | ||
| readHeaders, | ||
| mutationHeaderSupplier, | ||
| fileIO, | ||
| kmsClient, | ||
| current, | ||
| supportedEndpoints); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1211,6 +1234,7 @@ protected RESTTableOperations newTableOps( | |
| * @param mutationHeaderSupplier a supplier for additional HTTP headers to include in mutation | ||
| * requests (POST/DELETE) | ||
| * @param fileIO the FileIO implementation for reading and writing table metadata and data files | ||
| * @param kmsClient the {@link KeyManagementClient} for encrypted tables | ||
| * @param updateType the {@link RESTTableOperations.UpdateType} being performed | ||
| * @param createChanges the list of metadata updates to apply during table creation or replacement | ||
| * @param current the current table metadata (may be null for CREATE operations) | ||
|
|
@@ -1223,6 +1247,7 @@ protected RESTTableOperations newTableOps( | |
| Supplier<Map<String, String>> readHeaders, | ||
| Supplier<Map<String, String>> mutationHeaderSupplier, | ||
| FileIO fileIO, | ||
| KeyManagementClient kmsClient, | ||
| RESTTableOperations.UpdateType updateType, | ||
| List<MetadataUpdate> createChanges, | ||
| TableMetadata current, | ||
|
|
@@ -1233,6 +1258,7 @@ protected RESTTableOperations newTableOps( | |
| readHeaders, | ||
| mutationHeaderSupplier, | ||
| fileIO, | ||
| kmsClient, | ||
| updateType, | ||
| createChanges, | ||
| current, | ||
|
|
||
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.
have you all thought about the IRC remote scan planning and it integration with encryption ?
do we have test for the same.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks for bringing this up!
Don't have all the context here, but some initial thoughts:
key-metadatais part of theContentFileschema in the REST speciceberg/open-api/rest-catalog-open-api.yaml
Line 4493 in f865bac
FileScanTasksreturned by server-side scan planning can carry theencryption metadata needed for clients to decrypt data files. See debugging from [POC] JDBC encryption to test encrypted scan planning #15603:
This does require that REST implementations obtain the key metadata for data files that clients have written, which due to the nature of enveloping encryption may limit custom server-side optimisations
fileIOForPlanIdcatches my eyeiceberg/core/src/main/java/org/apache/iceberg/rest/RESTTableScan.java
Line 215 in f865bac
SerializableTablewhich maybe feels odd if so. WDYT?I think testing is a bit involved as it requires the server-side catalog to support encryption (or some custom interception to return key metadata in scan tasks). I think it's doable though and tests should pass without changes - see [POC] JDBC encryption to test encrypted scan planning #15603 (
TestRemoteScanPlanningWithEncryption) for a proof of concept passing test suite (I threw together JDBC encryption for the POC).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.
Would suggest us moving forwards with this PR as is for now to keep it concise, and it feels no regret to do so? Curious for thoughts on that and the above 🙏
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.
Ah sorry on (3) I see maybe #15448 addresses this and https://github.com/apache/iceberg/pull/15448/changes#diff-3e1df3e550b23bbdfd41f0cdbfe1923fe26755e8954aab0f78cfb288fbb6e08fR94 looks good