Skip to content

Commit 933881b

Browse files
Enable encryption in the cache proxy by experiment
1 parent 5f9dc06 commit 933881b

File tree

7 files changed

+45
-13
lines changed

7 files changed

+45
-13
lines changed

enterprise/server/action_cache_server_proxy/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ go_library(
88
importpath = "github.com/buildbuddy-io/buildbuddy/enterprise/server/action_cache_server_proxy",
99
visibility = ["//visibility:public"],
1010
deps = [
11+
"//enterprise/server/remote_crypter",
1112
"//enterprise/server/util/proxy_util",
1213
"//proto:remote_execution_go_proto",
1314
"//proto:resource_go_proto",

enterprise/server/action_cache_server_proxy/action_cache_server_proxy.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77

8+
"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_crypter"
89
"github.com/buildbuddy-io/buildbuddy/enterprise/server/util/proxy_util"
910
"github.com/buildbuddy-io/buildbuddy/server/environment"
1011
"github.com/buildbuddy-io/buildbuddy/server/interfaces"
@@ -30,7 +31,7 @@ var (
3031
)
3132

3233
type ActionCacheServerProxy struct {
33-
supportsEncryption bool
34+
supportsEncryption func(context.Context) bool
3435
env environment.Env
3536
authenticator interfaces.Authenticator
3637
localCache interfaces.Cache
@@ -52,8 +53,14 @@ func NewActionCacheServerProxy(env environment.Env) (*ActionCacheServerProxy, er
5253
if remoteCache == nil {
5354
return nil, fmt.Errorf("An ActionCacheClient is required to enable the ActionCacheServerProxy")
5455
}
56+
supportsEncryption := func(ctx context.Context) bool {
57+
if env.GetCrypter() == nil {
58+
return false
59+
}
60+
return remote_crypter.Enabled(ctx, env.GetExperimentFlagProvider())
61+
}
5562
return &ActionCacheServerProxy{
56-
supportsEncryption: env.GetCrypter() != nil,
63+
supportsEncryption: supportsEncryption,
5764
env: env,
5865
authenticator: env.GetAuthenticator(),
5966
localCache: env.GetCache(),
@@ -134,7 +141,7 @@ func (s *ActionCacheServerProxy) cacheActionResultToLocalCAS(ctx context.Context
134141
// request to the authoritative cache, but send a hash of the last value we
135142
// received to avoid transferring data on unmodified actions.
136143
func (s *ActionCacheServerProxy) GetActionResult(ctx context.Context, req *repb.GetActionResultRequest) (*repb.ActionResult, error) {
137-
if authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption {
144+
if authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption(ctx) {
138145
resp, err := s.remoteACClient.GetActionResult(ctx, req)
139146
labels := prometheus.Labels{
140147
metrics.StatusLabel: fmt.Sprintf("%d", gstatus.Code(err)),
@@ -222,7 +229,7 @@ func (s *ActionCacheServerProxy) GetActionResult(ctx context.Context, req *repb.
222229

223230
func (s *ActionCacheServerProxy) UpdateActionResult(ctx context.Context, req *repb.UpdateActionResultRequest) (*repb.ActionResult, error) {
224231
// Only if it's explicitly requested do we cache AC results locally.
225-
if proxy_util.SkipRemote(ctx) && (!authutil.EncryptionEnabled(ctx, s.authenticator) || s.supportsEncryption) {
232+
if proxy_util.SkipRemote(ctx) && (!authutil.EncryptionEnabled(ctx, s.authenticator) || s.supportsEncryption(ctx)) {
226233
resp, err := s.localACServer.UpdateActionResult(ctx, req)
227234

228235
labels := prometheus.Labels{

enterprise/server/byte_stream_server_proxy/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ go_library(
88
importpath = "github.com/buildbuddy-io/buildbuddy/enterprise/server/byte_stream_server_proxy",
99
visibility = ["//visibility:public"],
1010
deps = [
11+
"//enterprise/server/remote_crypter",
1112
"//enterprise/server/util/proxy_util",
1213
"//server/environment",
1314
"//server/interfaces",

enterprise/server/byte_stream_server_proxy/byte_stream_server_proxy.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"strconv"
88

9+
"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_crypter"
910
"github.com/buildbuddy-io/buildbuddy/enterprise/server/util/proxy_util"
1011
"github.com/buildbuddy-io/buildbuddy/server/environment"
1112
"github.com/buildbuddy-io/buildbuddy/server/interfaces"
@@ -23,7 +24,7 @@ import (
2324
)
2425

2526
type ByteStreamServerProxy struct {
26-
supportsEncryption bool
27+
supportsEncryption func(context.Context) bool
2728
atimeUpdater interfaces.AtimeUpdater
2829
authenticator interfaces.Authenticator
2930
local interfaces.ByteStreamServer
@@ -56,8 +57,14 @@ func New(env environment.Env) (*ByteStreamServerProxy, error) {
5657
if local == nil {
5758
return nil, fmt.Errorf("A local ByteStreamServer is required to enable ByteStreamServerProxy")
5859
}
60+
supportsEncryption := func(ctx context.Context) bool {
61+
if env.GetCrypter() == nil {
62+
return false
63+
}
64+
return remote_crypter.Enabled(ctx, env.GetExperimentFlagProvider())
65+
}
5966
return &ByteStreamServerProxy{
60-
supportsEncryption: env.GetCrypter() != nil,
67+
supportsEncryption: supportsEncryption,
6168
atimeUpdater: atimeUpdater,
6269
authenticator: authenticator,
6370
local: local,
@@ -92,7 +99,7 @@ func (s *ByteStreamServerProxy) Read(req *bspb.ReadRequest, stream bspb.ByteStre
9299
}
93100

94101
func (s *ByteStreamServerProxy) read(ctx context.Context, req *bspb.ReadRequest, stream *meteredReadServerStream) (string, error) {
95-
if authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption {
102+
if authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption(ctx) {
96103
return metrics.UncacheableStatusLabel, s.readRemoteOnly(ctx, req, stream)
97104
}
98105

@@ -289,7 +296,7 @@ func (s *ByteStreamServerProxy) Write(stream bspb.ByteStream_WriteServer) error
289296
meteredStream := &meteredServerSideClientStream{ByteStream_WriteServer: stream}
290297
stream = meteredStream
291298
var err error
292-
if authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption {
299+
if authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption(ctx) {
293300
err = s.writeRemoteOnly(ctx, stream)
294301
} else if proxy_util.SkipRemote(ctx) {
295302
err = s.writeLocalOnly(stream)

enterprise/server/content_addressable_storage_server_proxy/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ go_library(
88
importpath = "github.com/buildbuddy-io/buildbuddy/enterprise/server/content_addressable_storage_server_proxy",
99
visibility = ["//visibility:public"],
1010
deps = [
11+
"//enterprise/server/remote_crypter",
1112
"//enterprise/server/util/proxy_util",
1213
"//proto:remote_execution_go_proto",
1314
"//server/environment",

enterprise/server/content_addressable_storage_server_proxy/content_addressable_storage_server_proxy.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"strconv"
99

10+
"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_crypter"
1011
"github.com/buildbuddy-io/buildbuddy/enterprise/server/util/proxy_util"
1112
"github.com/buildbuddy-io/buildbuddy/server/environment"
1213
"github.com/buildbuddy-io/buildbuddy/server/interfaces"
@@ -29,7 +30,7 @@ import (
2930
var enableGetTreeCaching = flag.Bool("cache_proxy.enable_get_tree_caching", false, "If true, the Cache Proxy attempts to serve GetTree requests out of the local cache. If false, GetTree requests are always proxied to the remote, authoritative cache.")
3031

3132
type CASServerProxy struct {
32-
supportsEncryption bool
33+
supportsEncryption func(context.Context) bool
3334
atimeUpdater interfaces.AtimeUpdater
3435
authenticator interfaces.Authenticator
3536
local repb.ContentAddressableStorageServer
@@ -62,8 +63,14 @@ func New(env environment.Env) (*CASServerProxy, error) {
6263
if remote == nil {
6364
return nil, fmt.Errorf("A remote ContentAddressableStorageClient is required to enable the ContentAddressableStorageServerProxy")
6465
}
66+
supportsEncryption := func(ctx context.Context) bool {
67+
if env.GetCrypter() == nil {
68+
return false
69+
}
70+
return remote_crypter.Enabled(ctx, env.GetExperimentFlagProvider())
71+
}
6572
proxy := CASServerProxy{
66-
supportsEncryption: env.GetCrypter() != nil,
73+
supportsEncryption: supportsEncryption,
6774
atimeUpdater: atimeUpdater,
6875
authenticator: authenticator,
6976
local: local,
@@ -123,7 +130,7 @@ func (s *CASServerProxy) BatchUpdateBlobs(ctx context.Context, req *repb.BatchUp
123130
map[string]int{metrics.MissStatusLabel: bytesInRequest(req)},
124131
)
125132

126-
if authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption {
133+
if authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption(ctx) {
127134
return s.remote.BatchUpdateBlobs(ctx, req)
128135
}
129136

@@ -172,7 +179,7 @@ func (s *CASServerProxy) BatchReadBlobs(ctx context.Context, req *repb.BatchRead
172179
mergedResp := repb.BatchReadBlobsResponse{}
173180
mergedDigests := []*repb.Digest{}
174181
localResp := &repb.BatchReadBlobsResponse{}
175-
remoteOnly := authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption
182+
remoteOnly := authutil.EncryptionEnabled(ctx, s.authenticator) && !s.supportsEncryption(ctx)
176183
if !remoteOnly {
177184
resp, err := s.local.BatchReadBlobs(ctx, req)
178185
if err != nil {
@@ -290,7 +297,7 @@ func (s *CASServerProxy) batchReadBlobsRemote(ctx context.Context, readReq *repb
290297
Compressor: response.Compressor,
291298
})
292299
}
293-
if !authutil.EncryptionEnabled(ctx, s.authenticator) || s.supportsEncryption {
300+
if !authutil.EncryptionEnabled(ctx, s.authenticator) || s.supportsEncryption(ctx) {
294301
if _, err := s.local.BatchUpdateBlobs(ctx, &updateReq); err != nil {
295302
log.CtxWarningf(ctx, "Error locally updating blobs: %s", err)
296303
}

enterprise/server/remote_crypter/remote_crypter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121
sgpb "github.com/buildbuddy-io/buildbuddy/proto/storage"
2222
)
2323

24+
const (
25+
remoteEncryptionEnabled = "crypter.remote_encryption_enabled"
26+
)
27+
2428
var (
2529
target = flag.String("crypter.remote_target", "", "The gRPC target of the remote encryption API.")
2630
)
@@ -32,6 +36,10 @@ type RemoteCrypter struct {
3236
clientIdentityService interfaces.ClientIdentityService
3337
}
3438

39+
func Enabled(ctx context.Context, experiments interfaces.ExperimentFlagProvider) bool {
40+
return experiments.Boolean(ctx, remoteEncryptionEnabled, false)
41+
}
42+
3543
func Register(env *real_environment.RealEnv) error {
3644
if *target == "" {
3745
return nil

0 commit comments

Comments
 (0)