9
vendor/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/envelope.go
generated
vendored
9
vendor/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/envelope.go
generated
vendored
@@ -94,13 +94,17 @@ func (t *envelopeTransformer) TransformFromStorage(data []byte, context value.Co
|
||||
value.RecordCacheMiss()
|
||||
key, err := t.envelopeService.Decrypt(encKey)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while decrypting key: %q", err)
|
||||
// Do NOT wrap this err using fmt.Errorf() or similar functions
|
||||
// because this gRPC status error has useful error code when
|
||||
// record the metric.
|
||||
return nil, false, err
|
||||
}
|
||||
transformer, err = t.addTransformer(encKey, key)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
return transformer.TransformFromStorage(encData, context)
|
||||
}
|
||||
|
||||
@@ -113,6 +117,9 @@ func (t *envelopeTransformer) TransformToStorage(data []byte, context value.Cont
|
||||
|
||||
encKey, err := t.envelopeService.Encrypt(newKey)
|
||||
if err != nil {
|
||||
// Do NOT wrap this err using fmt.Errorf() or similar functions
|
||||
// because this gRPC status error has useful error code when
|
||||
// record the metric.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
62
vendor/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/grpc_service.go
generated
vendored
62
vendor/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/grpc_service.go
generated
vendored
@@ -61,28 +61,31 @@ func NewGRPCService(endpoint string, callTimeout time.Duration) (Service, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
connection, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithDefaultCallOptions(grpc.FailFast(false)), grpc.WithDialer(
|
||||
func(string, time.Duration) (net.Conn, error) {
|
||||
// Ignoring addr and timeout arguments:
|
||||
// addr - comes from the closure
|
||||
// timeout - is ignored since we are connecting in a non-blocking configuration
|
||||
c, err := net.DialTimeout(unixProtocol, addr, 0)
|
||||
if err != nil {
|
||||
klog.Errorf("failed to create connection to unix socket: %s, error: %v", addr, err)
|
||||
}
|
||||
return c, err
|
||||
}))
|
||||
s := &gRPCService{callTimeout: callTimeout}
|
||||
s.connection, err = grpc.Dial(
|
||||
addr,
|
||||
grpc.WithInsecure(),
|
||||
grpc.WithUnaryInterceptor(s.interceptor),
|
||||
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
|
||||
grpc.WithContextDialer(
|
||||
func(context.Context, string) (net.Conn, error) {
|
||||
// Ignoring addr and timeout arguments:
|
||||
// addr - comes from the closure
|
||||
c, err := net.DialUnix(unixProtocol, nil, &net.UnixAddr{Name: addr})
|
||||
if err != nil {
|
||||
klog.Errorf("failed to create connection to unix socket: %s, error: %v", addr, err)
|
||||
} else {
|
||||
klog.V(4).Infof("Successfully dialed Unix socket %v", addr)
|
||||
}
|
||||
return c, err
|
||||
}))
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create connection to %s, error: %v", endpoint, err)
|
||||
}
|
||||
|
||||
kmsClient := kmsapi.NewKeyManagementServiceClient(connection)
|
||||
return &gRPCService{
|
||||
kmsClient: kmsClient,
|
||||
connection: connection,
|
||||
callTimeout: callTimeout,
|
||||
}, nil
|
||||
s.kmsClient = kmsapi.NewKeyManagementServiceClient(s.connection)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Parse the endpoint to extract schema, host or path.
|
||||
@@ -138,10 +141,6 @@ func (g *gRPCService) Decrypt(cipher []byte) ([]byte, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), g.callTimeout)
|
||||
defer cancel()
|
||||
|
||||
if err := g.checkAPIVersion(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
request := &kmsapi.DecryptRequest{Cipher: cipher, Version: kmsapiVersion}
|
||||
response, err := g.kmsClient.Decrypt(ctx, request)
|
||||
if err != nil {
|
||||
@@ -154,9 +153,6 @@ func (g *gRPCService) Decrypt(cipher []byte) ([]byte, error) {
|
||||
func (g *gRPCService) Encrypt(plain []byte) ([]byte, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), g.callTimeout)
|
||||
defer cancel()
|
||||
if err := g.checkAPIVersion(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
request := &kmsapi.EncryptRequest{Plain: plain, Version: kmsapiVersion}
|
||||
response, err := g.kmsClient.Encrypt(ctx, request)
|
||||
@@ -165,3 +161,21 @@ func (g *gRPCService) Encrypt(plain []byte) ([]byte, error) {
|
||||
}
|
||||
return response.Cipher, nil
|
||||
}
|
||||
|
||||
func (g *gRPCService) interceptor(
|
||||
ctx context.Context,
|
||||
method string,
|
||||
req interface{},
|
||||
reply interface{},
|
||||
cc *grpc.ClientConn,
|
||||
invoker grpc.UnaryInvoker,
|
||||
opts ...grpc.CallOption,
|
||||
) error {
|
||||
if !kmsapi.IsVersionCheckMethod(method) {
|
||||
if err := g.checkAPIVersion(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
}
|
||||
|
||||
23
vendor/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/v1beta1/v1beta1.go
generated
vendored
Normal file
23
vendor/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/v1beta1/v1beta1.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed 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.
|
||||
*/
|
||||
|
||||
// Package v1beta1 contains definition of kms-plugin's gRPC service.
|
||||
package v1beta1
|
||||
|
||||
// IsVersionCheckMethod determines whether the supplied method is a version check against kms-plugin.
|
||||
func IsVersionCheckMethod(method string) bool {
|
||||
return method == "/v1beta1.KeyManagementService/Version"
|
||||
}
|
||||
36
vendor/k8s.io/apiserver/pkg/storage/value/metrics.go
generated
vendored
36
vendor/k8s.io/apiserver/pkg/storage/value/metrics.go
generated
vendored
@@ -20,7 +20,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"k8s.io/component-base/metrics"
|
||||
@@ -49,7 +48,7 @@ var (
|
||||
Help: "Latencies in seconds of value transformation operations.",
|
||||
// In-process transformations (ex. AES CBC) complete on the order of 20 microseconds. However, when
|
||||
// external KMS is involved latencies may climb into milliseconds.
|
||||
Buckets: prometheus.ExponentialBuckets(5e-6, 2, 14),
|
||||
Buckets: metrics.ExponentialBuckets(5e-6, 2, 14),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
[]string{"transformation_type"},
|
||||
@@ -59,11 +58,12 @@ var (
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "transformation_latencies_microseconds",
|
||||
Help: "(Deprecated) Latencies in microseconds of value transformation operations.",
|
||||
Help: "Latencies in microseconds of value transformation operations.",
|
||||
// In-process transformations (ex. AES CBC) complete on the order of 20 microseconds. However, when
|
||||
// external KMS is involved latencies may climb into milliseconds.
|
||||
Buckets: prometheus.ExponentialBuckets(5, 2, 14),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
Buckets: metrics.ExponentialBuckets(5, 2, 14),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
DeprecatedVersion: "1.14.0",
|
||||
},
|
||||
[]string{"transformation_type"},
|
||||
)
|
||||
@@ -81,11 +81,12 @@ var (
|
||||
|
||||
deprecatedTransformerFailuresTotal = metrics.NewCounterVec(
|
||||
&metrics.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "transformation_failures_total",
|
||||
Help: "(Deprecated) Total number of failed transformation operations.",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "transformation_failures_total",
|
||||
Help: "Total number of failed transformation operations.",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
DeprecatedVersion: "1.15.0",
|
||||
},
|
||||
[]string{"transformation_type"},
|
||||
)
|
||||
@@ -106,18 +107,19 @@ var (
|
||||
Subsystem: subsystem,
|
||||
Name: "data_key_generation_duration_seconds",
|
||||
Help: "Latencies in seconds of data encryption key(DEK) generation operations.",
|
||||
Buckets: prometheus.ExponentialBuckets(5e-6, 2, 14),
|
||||
Buckets: metrics.ExponentialBuckets(5e-6, 2, 14),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
deprecatedDataKeyGenerationLatencies = metrics.NewHistogram(
|
||||
&metrics.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "data_key_generation_latencies_microseconds",
|
||||
Help: "(Deprecated) Latencies in microseconds of data encryption key(DEK) generation operations.",
|
||||
Buckets: prometheus.ExponentialBuckets(5, 2, 14),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "data_key_generation_latencies_microseconds",
|
||||
Help: "Latencies in microseconds of data encryption key(DEK) generation operations.",
|
||||
Buckets: metrics.ExponentialBuckets(5, 2, 14),
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
DeprecatedVersion: "1.14.0",
|
||||
},
|
||||
)
|
||||
dataKeyGenerationFailuresTotal = metrics.NewCounter(
|
||||
|
||||
Reference in New Issue
Block a user