iceberg-cpp
Loading...
Searching...
No Matches
key_management_client.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
25
26#include <cstdint>
27#include <functional>
28#include <memory>
29#include <span>
30#include <string>
31#include <string_view>
32#include <unordered_map>
33#include <vector>
34
36#include "iceberg/result.h"
37
38namespace iceberg {
39
45class ICEBERG_EXPORT KeyManagementClient {
46 public:
48 struct GeneratedKey {
49 std::vector<uint8_t> key;
50 std::vector<uint8_t> wrapped_key;
51 };
52
53 virtual ~KeyManagementClient() = default;
54
57 const std::unordered_map<std::string, std::string>& /*properties*/) {
58 return {};
59 }
60
64 virtual Result<std::vector<uint8_t>> WrapKey(std::span<const uint8_t> key,
65 std::string_view wrapping_key_id) = 0;
66
68 virtual Result<std::vector<uint8_t>> UnwrapKey(std::span<const uint8_t> wrapped_key,
69 std::string_view wrapping_key_id) = 0;
70
72 virtual bool SupportsKeyGeneration() const { return false; }
73
75 virtual Result<GeneratedKey> GenerateKey(std::string_view /*wrapping_key_id*/) {
76 return NotSupported("Key generation is not supported by this KMS client");
77 }
78};
79
93class ICEBERG_EXPORT KmsRegistry {
94 public:
95 static constexpr std::string_view kKmsType = "encryption.kms-type";
96 static constexpr std::string_view kKmsImpl = "encryption.kms-impl";
97 static constexpr std::string_view kKmsTypeAws = "aws";
98 static constexpr std::string_view kKmsTypeGcp = "gcp";
99 static constexpr std::string_view kKmsTypeAzure = "azure";
100
101 using Properties = std::unordered_map<std::string, std::string>;
102 using Factory = std::function<Result<std::unique_ptr<KeyManagementClient>>()>;
103
108 static void Register(std::string name, Factory factory);
109
112 const Properties& properties);
113
119 const Properties& properties);
120};
121
122} // namespace iceberg
Wraps and unwraps secret keys with master keys kept in a KMS.
Definition key_management_client.h:45
virtual bool SupportsKeyGeneration() const
Whether the KMS can generate keys (GenerateKey).
Definition key_management_client.h:72
virtual Result< GeneratedKey > GenerateKey(std::string_view)
Generate a new key in the KMS, returned in plain and wrapped form.
Definition key_management_client.h:75
virtual Status Initialize(const std::unordered_map< std::string, std::string > &)
Initialize the client with the catalog properties.
Definition key_management_client.h:56
virtual Result< std::vector< uint8_t > > UnwrapKey(std::span< const uint8_t > wrapped_key, std::string_view wrapping_key_id)=0
Unwrap a key returned by WrapKey.
virtual Result< std::vector< uint8_t > > WrapKey(std::span< const uint8_t > key, std::string_view wrapping_key_id)=0
Wrap (encrypt) a secret key with the master key wrapping_key_id.
Creates KMS clients by name.
Definition key_management_client.h:93
static Result< std::shared_ptr< KeyManagementClient > > Load(std::string_view name, const Properties &properties)
Create and initialize the client registered under name.
static void Register(std::string name, Factory factory)
Register a client factory under name, replacing any previous one.
static Result< std::shared_ptr< KeyManagementClient > > FromCatalogProperties(const Properties &properties)
Create the KMS client configured by catalog properties.
Definition expected.h:1199
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
Define Result, Status, and error helpers.
A generated key and its wrapped form.
Definition key_management_client.h:48