Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ set(ICEBERG_SOURCES
deletes/position_delete_index.cc
deletes/position_delete_range_consumer.cc
deletes/roaring_position_bitmap.cc
encryption/encrypted_files.cc
encryption/encryption_manager.cc

Copy link
Copy Markdown
Member

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.h and standard_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.

Copy link
Copy Markdown
Contributor Author

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.

encryption/key_management_client.cc
encryption/standard_key_metadata.cc
expression/aggregate.cc
Expand Down Expand Up @@ -325,6 +327,7 @@ if(ICEBERG_BUILD_BUNDLE)
avro/avro_register.cc
avro/avro_schema_util.cc
avro/avro_stream_internal.cc
encryption/encryption_register.cc
parquet/parquet_data_util.cc
parquet/parquet_metrics.cc
parquet/parquet_metrics_row_group_filter.cc
Expand All @@ -339,7 +342,9 @@ if(ICEBERG_BUILD_BUNDLE)
ICEBERG_BUNDLE_SOURCES
encryption/aes_gcm.cc
encryption/aes_gcm_stream.cc
encryption/in_memory_kms.cc)
encryption/encryption_util.cc
encryption/in_memory_kms.cc
encryption/standard_encryption_manager.cc)
endif()

# Libraries to link with exported libiceberg_bundle.{so,a}.
Expand Down Expand Up @@ -414,6 +419,11 @@ if(ICEBERG_BUILD_BUNDLE)

foreach(target iceberg_bundle_static iceberg_bundle_shared)
if(TARGET ${target})
if(ICEBERG_ENCRYPTION)
target_compile_definitions(${target} PRIVATE ICEBERG_ENCRYPTION_ENABLED=1)
else()
target_compile_definitions(${target} PRIVATE ICEBERG_ENCRYPTION_ENABLED=0)
endif()
if(ICEBERG_S3)
target_compile_definitions(${target}
PUBLIC "$<BUILD_INTERFACE:ICEBERG_S3_ENABLED=1>")
Expand Down
7 changes: 7 additions & 0 deletions src/iceberg/cpp20_compatibility_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
#include "iceberg/deletes/position_delete_index.h"
#include "iceberg/deletes/position_delete_range_consumer.h"
#include "iceberg/deletes/roaring_position_bitmap.h"
#include "iceberg/encryption/encrypted_file.h"
#include "iceberg/encryption/encrypted_files.h"
#include "iceberg/encryption/encrypted_key.h"
#include "iceberg/encryption/encryption_key_metadata.h"
#include "iceberg/encryption/encryption_manager.h"
#include "iceberg/encryption/key_management_client.h"
#include "iceberg/encryption/standard_key_metadata.h"
#include "iceberg/exception.h"
Expand Down Expand Up @@ -217,14 +221,17 @@
# include "iceberg/avro/avro_reader.h"
# include "iceberg/avro/avro_register.h"
# include "iceberg/avro/avro_writer.h"
# include "iceberg/encryption/encryption_register.h"
# include "iceberg/parquet/parquet_reader.h"
# include "iceberg/parquet/parquet_register.h"
# include "iceberg/parquet/parquet_writer.h"
#endif // ICEBERG_PUBLIC_HEADERS_BUNDLE

#ifdef ICEBERG_PUBLIC_HEADERS_ENCRYPTION
# include "iceberg/encryption/aes_gcm_stream.h"
# include "iceberg/encryption/encryption_util.h"
# include "iceberg/encryption/in_memory_kms.h"
# include "iceberg/encryption/standard_encryption_manager.h"
#endif // ICEBERG_PUBLIC_HEADERS_ENCRYPTION

#ifdef ICEBERG_PUBLIC_HEADERS_HIVE
Expand Down
21 changes: 17 additions & 4 deletions src/iceberg/encryption/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,27 @@

iceberg_install_all_headers(iceberg/encryption
PATTERN
encrypted_file.h
encrypted_files.h
encrypted_key.h
encryption_key_metadata.h
encryption_manager.h
key_management_client.h
standard_key_metadata.h)
if(ICEBERG_BUILD_BUNDLE AND ICEBERG_ENCRYPTION)
if(ICEBERG_BUILD_BUNDLE)
iceberg_install_all_headers(iceberg/encryption
PATTERN
aes_gcm_stream.h
in_memory_kms.h
encryption_register.h
HEADER_GROUP
ICEBERG_PUBLIC_HEADERS_ENCRYPTION)
ICEBERG_PUBLIC_HEADERS_BUNDLE)
if(ICEBERG_ENCRYPTION)
iceberg_install_all_headers(iceberg/encryption
PATTERN
aes_gcm_stream.h
encryption_util.h
in_memory_kms.h
standard_encryption_manager.h
HEADER_GROUP
ICEBERG_PUBLIC_HEADERS_ENCRYPTION)
endif()
endif()
142 changes: 142 additions & 0 deletions src/iceberg/encryption/encrypted_file.h
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
40 changes: 40 additions & 0 deletions src/iceberg/encryption/encrypted_files.cc
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
50 changes: 50 additions & 0 deletions src/iceberg/encryption/encrypted_files.h
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
Loading
Loading