Repository navigation
feat(encryption): add EncryptionManager and StandardEncryptionManager #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
Open
shangxinli
wants to merge
6
commits into
apache:main
Choose a base branch
from
shangxinli:pr-enc06-encryption-manager
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.
+1,870
−12
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4e75611
feat: add EncryptionManager and StandardEncryptionManager
shangxinli 47af1f3
fix: use designated initializers for CachedKek
shangxinli f3fe388
fix(encryption): install missing public headers and guard timestamp o…
shangxinli 5e89b4a
test(encryption): remove unused manifest/data fixture files
shangxinli 1f5785f
refactor(encryption): align class hierarchy with Java EncryptionManag…
shangxinli 330e3ca
fix(encryption): follow Java two-path contract for native key metadat…
shangxinli 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| * 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 <utility> | ||
|
|
||
| #include "iceberg/encryption/encryption_key_metadata.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 Give up the still-encrypted raw input file. | ||
| virtual std::unique_ptr<InputFile> ReleaseInputFile() = 0; | ||
|
|
||
| /// \brief The key metadata needed to decrypt this file. | ||
| virtual const EncryptionKeyMetadata& key_metadata() const = 0; | ||
| }; | ||
|
|
||
| /// \brief EncryptedInputFile backed by a plain InputFile and opaque key metadata. | ||
| class ICEBERG_EXPORT BaseEncryptedInputFile : public EncryptedInputFile { | ||
| public: | ||
| BaseEncryptedInputFile(std::unique_ptr<InputFile> encrypted_file, | ||
| std::shared_ptr<EncryptionKeyMetadata> key_metadata) | ||
| : encrypted_file_(std::move(encrypted_file)), | ||
| key_metadata_(std::move(key_metadata)) {} | ||
|
|
||
| std::unique_ptr<InputFile> ReleaseInputFile() override { | ||
| return std::move(encrypted_file_); | ||
| } | ||
|
|
||
| const EncryptionKeyMetadata& key_metadata() const override { return *key_metadata_; } | ||
|
|
||
| private: | ||
| std::unique_ptr<InputFile> encrypted_file_; | ||
| std::shared_ptr<EncryptionKeyMetadata> key_metadata_; | ||
| }; | ||
|
|
||
| /// \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: | ||
| /// ReleaseInputFile() gives the still-encrypted raw file and key_metadata() gives the | ||
| /// key parameters (and AAD prefix) the native reader needs. | ||
| /// - 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; | ||
| }; | ||
|
|
||
| /// \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 The output file that writers should use. | ||
| /// | ||
| /// Unlike EncryptedInputFile::ReleaseInputFile, this is a non-consuming accessor: | ||
| /// implementations may need to keep ownership to finalize encryption on Close. | ||
| 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 EncryptedOutputFile backed by a plain OutputFile and opaque key metadata. | ||
| class ICEBERG_EXPORT BaseEncryptedOutputFile : public EncryptedOutputFile { | ||
| public: | ||
| BaseEncryptedOutputFile(std::unique_ptr<OutputFile> output_file, | ||
| std::shared_ptr<EncryptionKeyMetadata> key_metadata) | ||
| : output_file_(std::move(output_file)), key_metadata_(std::move(key_metadata)) {} | ||
|
|
||
| OutputFile& encrypting_output_file() const override { return *output_file_; } | ||
| const EncryptionKeyMetadata& key_metadata() const override { return *key_metadata_; } | ||
|
|
||
| private: | ||
| std::unique_ptr<OutputFile> output_file_; | ||
| std::shared_ptr<EncryptionKeyMetadata> key_metadata_; | ||
| }; | ||
|
|
||
| /// \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 |
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,40 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| #include "iceberg/encryption/encrypted_files.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| std::unique_ptr<EncryptedInputFile> EncryptedFiles::Encrypted( | ||
| std::unique_ptr<InputFile> encrypted_file, | ||
| std::shared_ptr<EncryptionKeyMetadata> key_metadata) { | ||
| return std::make_unique<BaseEncryptedInputFile>(std::move(encrypted_file), | ||
| std::move(key_metadata)); | ||
| } | ||
|
|
||
| std::unique_ptr<EncryptedOutputFile> EncryptedFiles::Encrypted( | ||
| std::unique_ptr<OutputFile> output_file, | ||
| std::shared_ptr<EncryptionKeyMetadata> key_metadata) { | ||
| return std::make_unique<BaseEncryptedOutputFile>(std::move(output_file), | ||
| std::move(key_metadata)); | ||
| } | ||
|
|
||
| } // namespace iceberg |
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,50 @@ | ||
| /* | ||
| * 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_files.h | ||
| /// Builds the generic EncryptedInputFile / EncryptedOutputFile wrappers that | ||
| /// EncryptionManager consumes and produces, mirroring Java's EncryptedFiles. | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "iceberg/encryption/encrypted_file.h" | ||
| #include "iceberg/iceberg_export.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief Builds EncryptedInputFile / EncryptedOutputFile wrappers around a plain file | ||
| /// and its key metadata, for callers that do not need the native (modular) encryption | ||
| /// wrappers. | ||
| class ICEBERG_EXPORT EncryptedFiles { | ||
| public: | ||
| /// \brief Wrap a still-encrypted input file together with its key metadata. | ||
| static std::unique_ptr<EncryptedInputFile> Encrypted( | ||
| std::unique_ptr<InputFile> encrypted_file, | ||
| std::shared_ptr<EncryptionKeyMetadata> key_metadata); | ||
|
|
||
| /// \brief Wrap a plaintext output file together with the key metadata used (or to be | ||
| /// used) to encrypt it. | ||
| static std::unique_ptr<EncryptedOutputFile> Encrypted( | ||
| std::unique_ptr<OutputFile> output_file, | ||
| std::shared_ptr<EncryptionKeyMetadata> key_metadata); | ||
| }; | ||
|
|
||
| } // 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.