-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Manifest list encryption #7770
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
Manifest list encryption #7770
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * 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.iceberg; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import org.apache.iceberg.encryption.EncryptionManager; | ||
|
|
||
| public interface ManifestListFile { | ||
|
|
||
| /** Location of manifest list file. */ | ||
| String location(); | ||
|
|
||
| /** The manifest list key metadata can be encrypted. Returns ID of encryption key */ | ||
| String encryptionKeyID(); | ||
|
|
||
| /** Decrypt and return the manifest list key metadata */ | ||
| ByteBuffer decryptKeyMetadata(EncryptionManager em); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * 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.iceberg; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.nio.ByteBuffer; | ||
| import org.apache.iceberg.encryption.EncryptionManager; | ||
| import org.apache.iceberg.encryption.EncryptionUtil; | ||
|
|
||
| class BaseManifestListFile implements ManifestListFile, Serializable { | ||
| private final String location; | ||
| private final String encryptionKeyID; | ||
|
|
||
| BaseManifestListFile(String location, String encryptionKeyID) { | ||
| this.location = location; | ||
| this.encryptionKeyID = encryptionKeyID; | ||
| } | ||
|
|
||
| @Override | ||
| public String location() { | ||
| return location; | ||
| } | ||
|
|
||
| @Override | ||
| public String encryptionKeyID() { | ||
| return encryptionKeyID; | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuffer decryptKeyMetadata(EncryptionManager em) { | ||
|
Contributor
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. When was this added? I don't think this should be here because it just calls a method on
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. It was added in PR11 (these lines: interface, implementation ). I think the main is reason is, the class
Contributor
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. Yeah I'm not sure if there's an alternative to passing the EncryptionManager at least with the current design of EncryptingFileIO |
||
| return EncryptionUtil.decryptManifestListKeyMetadata(this, em); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,10 @@ | |
| import java.io.IOException; | ||
| import java.util.Iterator; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.encryption.EncryptionManager; | ||
| import org.apache.iceberg.encryption.NativeEncryptionKeyMetadata; | ||
| import org.apache.iceberg.encryption.NativeEncryptionOutputFile; | ||
| import org.apache.iceberg.encryption.StandardEncryptionManager; | ||
| import org.apache.iceberg.exceptions.RuntimeIOException; | ||
| import org.apache.iceberg.io.FileAppender; | ||
| import org.apache.iceberg.io.OutputFile; | ||
|
|
@@ -29,9 +33,25 @@ | |
|
|
||
| abstract class ManifestListWriter implements FileAppender<ManifestFile> { | ||
| private final FileAppender<ManifestFile> writer; | ||
| private final StandardEncryptionManager standardEncryptionManager; | ||
| private final NativeEncryptionKeyMetadata manifestListKeyMetadata; | ||
| private final OutputFile outputFile; | ||
|
|
||
| private ManifestListWriter( | ||
| OutputFile file, EncryptionManager encryptionManager, Map<String, String> meta) { | ||
| if (encryptionManager instanceof StandardEncryptionManager) { | ||
| // ability to encrypt the manifest list key is introduced for standard encryption. | ||
| this.standardEncryptionManager = (StandardEncryptionManager) encryptionManager; | ||
| NativeEncryptionOutputFile encryptedFile = this.standardEncryptionManager.encrypt(file); | ||
|
Member
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. I was very confused by this when I was working on Parquet Manifests, it's a little weird that the method returns NativeEncyrptionOutputFile but it's actually a StandardEncryptionOuputFile. Maybe it's too late but I wonder if we should change the names of those classes. We can save this for another PR though. The base class being Native just is confusing to me because the subclass obviously isn't
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. I agree this naming can be confusing. Since both classes are merged, lets indeed handle this in another PR. |
||
| this.outputFile = encryptedFile.encryptingOutputFile(); | ||
| this.manifestListKeyMetadata = encryptedFile.keyMetadata(); | ||
| } else { | ||
| this.standardEncryptionManager = null; | ||
| this.outputFile = file; | ||
| this.manifestListKeyMetadata = null; | ||
| } | ||
|
|
||
| private ManifestListWriter(OutputFile file, Map<String, String> meta) { | ||
| this.writer = newAppender(file, meta); | ||
| this.writer = newAppender(outputFile, meta); | ||
| } | ||
|
|
||
| protected abstract ManifestFile prepare(ManifestFile manifest); | ||
|
|
@@ -73,18 +93,31 @@ public Long nextRowId() { | |
| return null; | ||
| } | ||
|
|
||
| public ManifestListFile toManifestListFile() { | ||
| if (manifestListKeyMetadata != null && manifestListKeyMetadata.encryptionKey() != null) { | ||
| manifestListKeyMetadata.copyWithLength(writer.length()); | ||
| String manifestListKeyID = | ||
| standardEncryptionManager.addManifestListKeyMetadata(manifestListKeyMetadata); | ||
| return new BaseManifestListFile(outputFile.location(), manifestListKeyID); | ||
| } else { | ||
| return new BaseManifestListFile(outputFile.location(), null); | ||
| } | ||
| } | ||
|
|
||
| static class V4Writer extends ManifestListWriter { | ||
| private final V4Metadata.ManifestFileWrapper wrapper; | ||
| private Long nextRowId; | ||
|
|
||
| V4Writer( | ||
| OutputFile snapshotFile, | ||
| EncryptionManager encryptionManager, | ||
| long snapshotId, | ||
| Long parentSnapshotId, | ||
| long sequenceNumber, | ||
| long firstRowId) { | ||
| super( | ||
| snapshotFile, | ||
| encryptionManager, | ||
| ImmutableMap.of( | ||
| "snapshot-id", String.valueOf(snapshotId), | ||
| "parent-snapshot-id", String.valueOf(parentSnapshotId), | ||
|
|
@@ -137,12 +170,14 @@ static class V3Writer extends ManifestListWriter { | |
|
|
||
| V3Writer( | ||
| OutputFile snapshotFile, | ||
| EncryptionManager encryptionManager, | ||
| long snapshotId, | ||
| Long parentSnapshotId, | ||
| long sequenceNumber, | ||
| long firstRowId) { | ||
| super( | ||
| snapshotFile, | ||
| encryptionManager, | ||
| ImmutableMap.of( | ||
| "snapshot-id", String.valueOf(snapshotId), | ||
| "parent-snapshot-id", String.valueOf(parentSnapshotId), | ||
|
|
@@ -192,9 +227,15 @@ public Long nextRowId() { | |
| static class V2Writer extends ManifestListWriter { | ||
| private final V2Metadata.ManifestFileWrapper wrapper; | ||
|
|
||
| V2Writer(OutputFile snapshotFile, long snapshotId, Long parentSnapshotId, long sequenceNumber) { | ||
| V2Writer( | ||
| OutputFile snapshotFile, | ||
| EncryptionManager encryptionManager, | ||
| long snapshotId, | ||
| Long parentSnapshotId, | ||
| long sequenceNumber) { | ||
| super( | ||
| snapshotFile, | ||
| encryptionManager, | ||
| ImmutableMap.of( | ||
| "snapshot-id", String.valueOf(snapshotId), | ||
| "parent-snapshot-id", String.valueOf(parentSnapshotId), | ||
|
|
@@ -228,9 +269,14 @@ protected FileAppender<ManifestFile> newAppender(OutputFile file, Map<String, St | |
| static class V1Writer extends ManifestListWriter { | ||
| private final V1Metadata.ManifestFileWrapper wrapper = new V1Metadata.ManifestFileWrapper(); | ||
|
|
||
| V1Writer(OutputFile snapshotFile, long snapshotId, Long parentSnapshotId) { | ||
| V1Writer( | ||
| OutputFile snapshotFile, | ||
| EncryptionManager encryptionManager, | ||
| long snapshotId, | ||
| Long parentSnapshotId) { | ||
| super( | ||
| snapshotFile, | ||
| encryptionManager, | ||
| ImmutableMap.of( | ||
| "snapshot-id", String.valueOf(snapshotId), | ||
| "parent-snapshot-id", String.valueOf(parentSnapshotId), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.