Debian Codegraph @

pkg/apis/apiserver/types_encryption.go

raw
1 /*
2 Copyright 2018 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package apiserver
18
19 import (
20 "fmt"
21
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23 )
24
25 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
26
27 /*
28 EncryptionConfiguration stores the complete configuration for encryption providers.
29 It also allows the use of wildcards to specify the resources that should be encrypted.
30 Use '*.<group>' to encrypt all resources within a group or '*.*' to encrypt all resources.
31 '*.' can be used to encrypt all resource in the core group. '*.*' will encrypt all
32 resources, even custom resources that are added after API server start.
33 Use of wildcards that overlap within the same resource list or across multiple
34 entries are not allowed since part of the configuration would be ineffective.
35 Resource lists are processed in order, with earlier lists taking precedence.
36
37 Example:
38
39 kind: EncryptionConfiguration
40 apiVersion: apiserver.config.k8s.io/v1
41 resources:
42 - resources:
43 - events
44 providers:
45 - identity: {} # do not encrypt events even though *.* is specified below
46 - resources:
47 - secrets
48 - configmaps
49 - pandas.awesome.bears.example
50 providers:
51 - aescbc:
52 keys:
53 - name: key1
54 secret: c2VjcmV0IGlzIHNlY3VyZQ==
55 - resources:
56 - '*.apps'
57 providers:
58 - aescbc:
59 keys:
60 - name: key2
61 secret: c2VjcmV0IGlzIHNlY3VyZSwgb3IgaXMgaXQ/Cg==
62 - resources:
63 - '*.*'
64 providers:
65 - aescbc:
66 keys:
67 - name: key3
68 secret: c2VjcmV0IGlzIHNlY3VyZSwgSSB0aGluaw==
69 */
70 type EncryptionConfiguration struct {
71 metav1.TypeMeta
72 // resources is a list containing resources, and their corresponding encryption providers.
73 Resources []ResourceConfiguration
74 }
75
76 // ResourceConfiguration stores per resource configuration.
77 type ResourceConfiguration struct {
78 // resources is a list of kubernetes resources which have to be encrypted. The resource names are derived from `resource` or `resource.group` of the group/version/resource.
79 // eg: pandas.awesome.bears.example is a custom resource with 'group': awesome.bears.example, 'resource': pandas.
80 // Use '*.*' to encrypt all resources and '*.<group>' to encrypt all resources in a specific group.
81 // eg: '*.awesome.bears.example' will encrypt all resources in the group 'awesome.bears.example'.
82 // eg: '*.' will encrypt all resources in the core group (such as pods, configmaps, etc).
83 Resources []string
84 // providers is a list of transformers to be used for reading and writing the resources to disk.
85 // eg: aesgcm, aescbc, secretbox, identity, kms.
86 Providers []ProviderConfiguration
87 }
88
89 // ProviderConfiguration stores the provided configuration for an encryption provider.
90 type ProviderConfiguration struct {
91 // aesgcm is the configuration for the AES-GCM transformer.
92 AESGCM *AESConfiguration
93 // aescbc is the configuration for the AES-CBC transformer.
94 AESCBC *AESConfiguration
95 // secretbox is the configuration for the Secretbox based transformer.
96 Secretbox *SecretboxConfiguration
97 // identity is the (empty) configuration for the identity transformer.
98 Identity *IdentityConfiguration
99 // kms contains the name, cache size and path to configuration file for a KMS based envelope transformer.
100 KMS *KMSConfiguration
101 }
102
103 // AESConfiguration contains the API configuration for an AES transformer.
104 type AESConfiguration struct {
105 // keys is a list of keys to be used for creating the AES transformer.
106 // Each key has to be 32 bytes long for AES-CBC and 16, 24 or 32 bytes for AES-GCM.
107 Keys []Key
108 }
109
110 // SecretboxConfiguration contains the API configuration for an Secretbox transformer.
111 type SecretboxConfiguration struct {
112 // keys is a list of keys to be used for creating the Secretbox transformer.
113 // Each key has to be 32 bytes long.
114 Keys []Key
115 }
116
117 // Key contains name and secret of the provided key for a transformer.
118 type Key struct {
119 // name is the name of the key to be used while storing data to disk.
120 Name string
121 // secret is the actual key, encoded in base64.
122 Secret string
123 }
124
125 // String implements Stringer interface in a log safe way.
126 func (k Key) String() string {
127 return fmt.Sprintf("Name: %s, Secret: [REDACTED]", k.Name)
128 }
129
130 // IdentityConfiguration is an empty struct to allow identity transformer in provider configuration.
131 type IdentityConfiguration struct{}
132
133 // KMSConfiguration contains the name, cache size and path to configuration file for a KMS based envelope transformer.
134 type KMSConfiguration struct {
135 // apiVersion of KeyManagementService
136 // +optional
137 APIVersion string
138 // name is the name of the KMS plugin to be used.
139 Name string
140 // cachesize is the maximum number of secrets which are cached in memory. The default value is 1000.
141 // Set to a negative value to disable caching. This field is only allowed for KMS v1 providers.
142 // +optional
143 CacheSize *int32
144 // endpoint is the gRPC server listening address, for example "unix:///var/run/kms-provider.sock".
145 Endpoint string
146 // timeout for gRPC calls to kms-plugin (ex. 5s). The default is 3 seconds.
147 // +optional
148 Timeout *metav1.Duration
149 }