go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cipd/appengine/impl/cas/acled.go (about) 1 // Copyright 2017 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cas 16 17 import ( 18 "context" 19 20 "google.golang.org/grpc/codes" 21 "google.golang.org/grpc/status" 22 23 api "go.chromium.org/luci/cipd/api/cipd/v1" 24 "go.chromium.org/luci/cipd/appengine/impl/rpcacl" 25 ) 26 27 // Public returns publicly exposed implementation of cipd.Storage service that 28 // wraps the given internal implementation with ACLs. 29 func Public(internal api.StorageServer) api.StorageServer { 30 return &acledStorage{internal: internal} 31 } 32 33 type acledStorage struct { 34 // We want the compilation to fail when new methods are added. 35 api.UnsafeStorageServer 36 37 internal api.StorageServer 38 } 39 40 func (s *acledStorage) GetObjectURL(ctx context.Context, req *api.GetObjectURLRequest) (*api.ObjectURL, error) { 41 if err := rpcacl.CheckAdmin(ctx); err != nil { 42 return nil, err 43 } 44 return s.internal.GetObjectURL(ctx, req) 45 } 46 47 func (s *acledStorage) BeginUpload(ctx context.Context, req *api.BeginUploadRequest) (*api.UploadOperation, error) { 48 if err := rpcacl.CheckAdmin(ctx); err != nil { 49 return nil, err 50 } 51 return s.internal.BeginUpload(ctx, req) 52 } 53 54 // Upload operations are initiated by the backend, but finalized by whoever 55 // uploads the data, thus 'FinishUpload' and 'CancelUpload' is accessible to 56 // anyone (the authorization happens through upload operation IDs which should 57 // be treated as secrets). Except we don't trust external API users to assign 58 // hashes, so usage of 'force_hash' field is forbidden. 59 60 func (s *acledStorage) FinishUpload(ctx context.Context, req *api.FinishUploadRequest) (*api.UploadOperation, error) { 61 if req.ForceHash != nil { 62 return nil, status.Errorf(codes.PermissionDenied, "usage of 'force_hash' is forbidden") 63 } 64 return s.internal.FinishUpload(ctx, req) 65 } 66 67 func (s *acledStorage) CancelUpload(ctx context.Context, req *api.CancelUploadRequest) (*api.UploadOperation, error) { 68 return s.internal.CancelUpload(ctx, req) 69 }