@@ -18,9 +18,7 @@ import (
18
18
"github.com/sourcegraph/sourcegraph/cmd/gitserver/internal/git/gitcli"
19
19
"github.com/sourcegraph/sourcegraph/cmd/gitserver/internal/gitserverfs"
20
20
"github.com/sourcegraph/sourcegraph/cmd/gitserver/internal/perforce"
21
- "github.com/sourcegraph/sourcegraph/internal/actor"
22
21
"github.com/sourcegraph/sourcegraph/internal/api"
23
- "github.com/sourcegraph/sourcegraph/internal/authz"
24
22
"github.com/sourcegraph/sourcegraph/internal/conf"
25
23
"github.com/sourcegraph/sourcegraph/internal/database"
26
24
"github.com/sourcegraph/sourcegraph/internal/dotcom"
@@ -32,7 +30,6 @@ import (
32
30
"github.com/sourcegraph/sourcegraph/internal/repoupdater"
33
31
"github.com/sourcegraph/sourcegraph/internal/trace"
34
32
"github.com/sourcegraph/sourcegraph/lib/errors"
35
- "github.com/sourcegraph/sourcegraph/lib/pointers"
36
33
)
37
34
38
35
type service interface {
@@ -52,7 +49,6 @@ func NewGRPCServer(server *Server, config *GRPCServerConfig) proto.GitserverServ
52
49
logger : server .logger ,
53
50
db : server .db ,
54
51
hostname : server .hostname ,
55
- subRepoChecker : authz .DefaultSubRepoPermsChecker ,
56
52
locker : server .locker ,
57
53
getBackendFunc : server .getBackendFunc ,
58
54
svc : server ,
@@ -75,7 +71,6 @@ type grpcServer struct {
75
71
logger log.Logger
76
72
db database.DB
77
73
hostname string
78
- subRepoChecker authz.SubRepoPermissionChecker
79
74
locker RepositoryLocker
80
75
getBackendFunc Backender
81
76
fs gitserverfs.FS
@@ -284,15 +279,6 @@ func (gs *grpcServer) Archive(req *proto.ArchiveRequest, ss proto.GitserverServi
284
279
return err
285
280
}
286
281
287
- if ! actor .FromContext (ctx ).IsInternal () {
288
- if enabled , err := gs .subRepoChecker .EnabledForRepo (ctx , repoName ); err != nil {
289
- return errors .Wrap (err , "sub-repo permissions check" )
290
- } else if enabled {
291
- s := status .New (codes .Unimplemented , "archiveReader invoked for a repo with sub-repo permissions" )
292
- return s .Err ()
293
- }
294
- }
295
-
296
282
// This is a long time, but this never blocks a user request for this
297
283
// long. Even repos that are not that large can take a long time, for
298
284
// example a search over all repos in an organization may have several
@@ -803,14 +789,9 @@ func (gs *grpcServer) GetCommit(ctx context.Context, req *proto.GetCommitRequest
803
789
return nil , err
804
790
}
805
791
806
- subRepoPermsEnabled , err := authz .SubRepoEnabledForRepo (ctx , gs .subRepoChecker , repoName )
807
- if err != nil {
808
- return nil , err
809
- }
810
-
811
792
backend := gs .getBackendFunc (repoDir , repoName )
812
793
813
- commit , err := backend .GetCommit (ctx , api .CommitID (req .GetCommit ()), subRepoPermsEnabled )
794
+ commit , err := backend .GetCommit (ctx , api .CommitID (req .GetCommit ()), req . GetIncludeModifiedFiles () )
814
795
if err != nil {
815
796
var e * gitdomain.RevisionNotFoundError
816
797
if errors .As (err , & e ) {
@@ -828,24 +809,14 @@ func (gs *grpcServer) GetCommit(ctx context.Context, req *proto.GetCommitRequest
828
809
return nil , err
829
810
}
830
811
831
- hasAccess , err := hasAccessToCommit (ctx , repoName , commit .ModifiedFiles , gs .subRepoChecker )
832
- if err != nil {
833
- return nil , err
834
- }
835
-
836
- if ! hasAccess {
837
- s , err := status .New (codes .NotFound , "revision not found" ).WithDetails (& proto.RevisionNotFoundPayload {
838
- Repo : req .GetRepoName (),
839
- Spec : req .GetCommit (),
840
- })
841
- if err != nil {
842
- return nil , err
843
- }
844
- return nil , s .Err ()
812
+ modifiedFiles := make ([][]byte , len (commit .ModifiedFiles ))
813
+ for i , f := range commit .ModifiedFiles {
814
+ modifiedFiles [i ] = []byte (f )
845
815
}
846
816
847
817
return & proto.GetCommitResponse {
848
- Commit : commit .ToProto (),
818
+ Commit : commit .ToProto (),
819
+ ModifiedFiles : modifiedFiles ,
849
820
}, nil
850
821
}
851
822
@@ -878,26 +849,6 @@ func (gs *grpcServer) Blame(req *proto.BlameRequest, ss proto.GitserverService_B
878
849
return err
879
850
}
880
851
881
- // First, verify that the actor has access to the given path.
882
- hasAccess , err := authz .FilterActorPath (ctx , gs .subRepoChecker , actor .FromContext (ctx ), repoName , req .GetPath ())
883
- if err != nil {
884
- return err
885
- }
886
- if ! hasAccess {
887
- up := & proto.UnauthorizedPayload {
888
- RepoName : req .GetRepoName (),
889
- Commit : pointers .Ptr (req .GetCommit ()),
890
- Path : pointers .Ptr (req .GetPath ()),
891
- }
892
-
893
- s , marshalErr := status .New (codes .PermissionDenied , "no access to path" ).WithDetails (up )
894
- if marshalErr != nil {
895
- gs .logger .Error ("failed to marshal error" , log .Error (marshalErr ))
896
- return err
897
- }
898
- return s .Err ()
899
- }
900
-
901
852
backend := gs .getBackendFunc (repoDir , repoName )
902
853
903
854
opts := git.BlameOptions {
@@ -1038,27 +989,6 @@ func (gs *grpcServer) ReadFile(req *proto.ReadFileRequest, ss proto.GitserverSer
1038
989
return err
1039
990
}
1040
991
1041
- // First, verify that the actor has access to the given path.
1042
- hasAccess , err := authz .FilterActorPath (ctx , gs .subRepoChecker , actor .FromContext (ctx ), repoName , req .GetPath ())
1043
- if err != nil {
1044
- return err
1045
- }
1046
- if ! hasAccess {
1047
- up := & proto.UnauthorizedPayload {
1048
- RepoName : req .GetRepoName (),
1049
- Path : pointers .Ptr (req .GetPath ()),
1050
- }
1051
- if c := req .GetCommit (); c != "" {
1052
- up .Commit = & c
1053
- }
1054
- s , marshalErr := status .New (codes .PermissionDenied , "no access to path" ).WithDetails (up )
1055
- if marshalErr != nil {
1056
- gs .logger .Error ("failed to marshal error" , log .Error (marshalErr ))
1057
- return err
1058
- }
1059
- return s .Err ()
1060
- }
1061
-
1062
992
backend := gs .getBackendFunc (repoDir , repoName )
1063
993
1064
994
r , err := backend .ReadFile (ctx , api .CommitID (req .GetCommit ()), req .GetPath ())
@@ -1445,29 +1375,6 @@ func (gs *grpcServer) checkRepoExists(ctx context.Context, repo api.RepoName) er
1445
1375
return newRepoNotFoundError (repo , cloneInProgress , cloneProgress )
1446
1376
}
1447
1377
1448
- func hasAccessToCommit (ctx context.Context , repoName api.RepoName , files []string , checker authz.SubRepoPermissionChecker ) (bool , error ) {
1449
- if len (files ) == 0 {
1450
- return true , nil // If commit has no files, assume user has access to view the commit.
1451
- }
1452
-
1453
- if enabled , err := authz .SubRepoEnabledForRepo (ctx , checker , repoName ); err != nil {
1454
- return false , err
1455
- } else if ! enabled {
1456
- return true , nil
1457
- }
1458
-
1459
- a := actor .FromContext (ctx )
1460
- for _ , fileName := range files {
1461
- if hasAccess , err := authz .FilterActorPath (ctx , checker , a , repoName , fileName ); err != nil {
1462
- return false , err
1463
- } else if hasAccess {
1464
- // if the user has access to one file modified in the commit, they have access to view the commit
1465
- return true , nil
1466
- }
1467
- }
1468
- return false , nil
1469
- }
1470
-
1471
1378
func newRepoNotFoundError (repo api.RepoName , cloneInProgress bool , cloneProgress string ) error {
1472
1379
s , err := status .New (codes .NotFound , "repo not found" ).WithDetails (& proto.RepoNotFoundPayload {
1473
1380
CloneInProgress : cloneInProgress ,
0 commit comments