Repository navigation
feat(encryption): add EncryptionManager with plaintext and standard implementations #1071
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
Merged
+2,452
−141
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d8b10d1
feat: add EncryptionManager and StandardEncryptionManager
shangxinli 76106ce
fix: use designated initializers for CachedKek
shangxinli a0dbb57
fix(encryption): install missing public headers and guard timestamp o…
shangxinli b25d647
test(encryption): remove unused manifest/data fixture files
shangxinli ed7a7e8
refactor(encryption): align class hierarchy with Java EncryptionManag…
shangxinli 6723b0f
fix(encryption): follow Java two-path contract for native key metadat…
shangxinli 9523992
follow up on the encryption manager review
wgtmac 01169a2
test(encryption): tighten AGS1 and key cache regression tests
wgtmac fcfe747
test(encryption): use std::array for DEK length cases
wgtmac 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
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
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| /// \file iceberg/encryption/encrypted_file.h | ||
| /// Pairs a file handle with its key metadata, mirroring Java's | ||
| /// EncryptedInputFile / EncryptedOutputFile. | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "iceberg/encryption/encryption_key_metadata.h" | ||
| #include "iceberg/encryption/type_fwd.h" | ||
| #include "iceberg/file_io.h" | ||
| #include "iceberg/iceberg_export.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief An encrypted input file together with the key metadata needed to decrypt it. | ||
| class ICEBERG_EXPORT EncryptedInputFile { | ||
| public: | ||
| virtual ~EncryptedInputFile() = default; | ||
|
|
||
| /// \brief Take ownership of a native wrapper, or leave encrypted intact and return | ||
| /// null. | ||
| static std::unique_ptr<NativeEncryptionInputFile> AsNative( | ||
| std::unique_ptr<EncryptedInputFile>& encrypted); | ||
|
|
||
| /// \brief Transfer ownership of the still-encrypted raw input file. | ||
| /// | ||
| /// Returns nullptr if the wrapper has no file. Use the returned handle for file access | ||
| /// after detaching. | ||
| virtual std::unique_ptr<InputFile> DetachInputFile() && = 0; | ||
|
|
||
| /// \brief The key metadata needed to decrypt this file. | ||
| virtual const EncryptionKeyMetadata& key_metadata() const = 0; | ||
|
|
||
| private: | ||
| virtual NativeEncryptionInputFile* native_input_file() noexcept { return nullptr; } | ||
| }; | ||
|
|
||
| /// \brief An encrypted input file that supports both read paths of Java's | ||
| /// NativeEncryptionInputFile. | ||
| /// | ||
| /// - Native path, for formats such as Parquet that perform their own modular decryption: | ||
| /// key_metadata() gives the key parameters (and AAD prefix) the native reader needs. | ||
| /// DetachInputFile() then transfers the still-encrypted raw file. | ||
| /// - Stream path: the InputFile methods read the file as an AES GCM stream (AGS1), | ||
| /// decrypting it, and require the encrypted file length in the key metadata. | ||
| /// | ||
| /// Implementations may defer building the stream reader until the InputFile methods are | ||
| /// first used, so native-only callers are not subject to the stream path's requirements. | ||
| class ICEBERG_EXPORT NativeEncryptionInputFile : public EncryptedInputFile, | ||
| public InputFile { | ||
| public: | ||
| const NativeEncryptionKeyMetadata& key_metadata() const override = 0; | ||
|
|
||
| private: | ||
| NativeEncryptionInputFile* native_input_file() noexcept final { return this; } | ||
| }; | ||
|
|
||
| /// \brief An encrypting output file together with the key metadata that was used (or | ||
| /// will be used) to encrypt it. | ||
| class ICEBERG_EXPORT EncryptedOutputFile { | ||
| public: | ||
| virtual ~EncryptedOutputFile() = default; | ||
|
|
||
| /// \brief Borrow the encrypting output file from this wrapper. | ||
| virtual OutputFile& encrypting_output_file() const = 0; | ||
|
|
||
| /// \brief The key metadata that was used to encrypt this file. | ||
| virtual const EncryptionKeyMetadata& key_metadata() const = 0; | ||
| }; | ||
|
|
||
| /// \brief An encrypting output file that supports both write paths of Java's | ||
| /// NativeEncryptionOutputFile. | ||
| /// | ||
| /// - Native path, for formats such as Parquet that perform their own modular encryption: | ||
| /// plain_output_file() gives the file to write the (already encrypted) bytes to and | ||
| /// key_metadata() gives the key parameters (and AAD prefix) the native writer needs. | ||
| /// - Stream path: encrypting_output_file(), and the OutputFile methods that delegate to | ||
| /// it, write the file as an AES GCM stream (AGS1). | ||
| class ICEBERG_EXPORT NativeEncryptionOutputFile : public EncryptedOutputFile, | ||
| public OutputFile { | ||
| public: | ||
| /// \brief The underlying plain output file, for native writers. | ||
| virtual OutputFile& plain_output_file() const = 0; | ||
|
|
||
| const NativeEncryptionKeyMetadata& key_metadata() const override = 0; | ||
|
|
||
| // OutputFile, delegating to the stream path. | ||
| std::string_view location() const override { | ||
| return encrypting_output_file().location(); | ||
| } | ||
|
|
||
| Result<std::unique_ptr<PositionOutputStream>> Create() override { | ||
| return encrypting_output_file().Create(); | ||
| } | ||
|
|
||
| Result<std::unique_ptr<PositionOutputStream>> CreateOrOverwrite() override { | ||
| return encrypting_output_file().CreateOrOverwrite(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace iceberg |
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.
The new public headers are missing from the explicit install lists:
encryption_manager.h,encryption_register.handstandard_encryption_manager.h. Please add them to the core, bundle and encryption groups respectively and regenerate the public-header coverage. Installed consumers currently cannot include these APIs; the registration header should remain available when the bundle is built with encryption disabled.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.
Added the three missing headers to the install lists — encryption_manager.h as core, encryption_register.h tagged ICEBERG_PUBLIC_HEADERS_BUNDLE so it stays available with encryption disabled, and standard_encryption_manager.h in the existing encryption group — and regenerated cpp20_compatibility_internal.h.