@@ -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 {
@@ -48,7 +45,6 @@ func NewGRPCServer(server *Server) proto.GitserverServiceServer {
48
45
logger : server .logger ,
49
46
db : server .db ,
50
47
hostname : server .hostname ,
51
- subRepoChecker : authz .DefaultSubRepoPermsChecker ,
52
48
locker : server .locker ,
53
49
getBackendFunc : server .getBackendFunc ,
54
50
svc : server ,
@@ -60,7 +56,6 @@ type grpcServer struct {
60
56
logger log.Logger
61
57
db database.DB
62
58
hostname string
63
- subRepoChecker authz.SubRepoPermissionChecker
64
59
locker RepositoryLocker
65
60
getBackendFunc Backender
66
61
fs gitserverfs.FS
@@ -269,15 +264,6 @@ func (gs *grpcServer) Archive(req *proto.ArchiveRequest, ss proto.GitserverServi
269
264
return err
270
265
}
271
266
272
- if ! actor .FromContext (ctx ).IsInternal () {
273
- if enabled , err := gs .subRepoChecker .EnabledForRepo (ctx , repoName ); err != nil {
274
- return errors .Wrap (err , "sub-repo permissions check" )
275
- } else if enabled {
276
- s := status .New (codes .Unimplemented , "archiveReader invoked for a repo with sub-repo permissions" )
277
- return s .Err ()
278
- }
279
- }
280
-
281
267
// This is a long time, but this never blocks a user request for this
282
268
// long. Even repos that are not that large can take a long time, for
283
269
// example a search over all repos in an organization may have several
@@ -788,14 +774,9 @@ func (gs *grpcServer) GetCommit(ctx context.Context, req *proto.GetCommitRequest
788
774
return nil , err
789
775
}
790
776
791
- subRepoPermsEnabled , err := authz .SubRepoEnabledForRepo (ctx , gs .subRepoChecker , repoName )
792
- if err != nil {
793
- return nil , err
794
- }
795
-
796
777
backend := gs .getBackendFunc (repoDir , repoName )
797
778
798
- commit , err := backend .GetCommit (ctx , api .CommitID (req .GetCommit ()), subRepoPermsEnabled )
779
+ commit , err := backend .GetCommit (ctx , api .CommitID (req .GetCommit ()), req . GetIncludeModifiedFiles () )
799
780
if err != nil {
800
781
var e * gitdomain.RevisionNotFoundError
801
782
if errors .As (err , & e ) {
@@ -813,24 +794,14 @@ func (gs *grpcServer) GetCommit(ctx context.Context, req *proto.GetCommitRequest
813
794
return nil , err
814
795
}
815
796
816
- hasAccess , err := hasAccessToCommit (ctx , repoName , commit .ModifiedFiles , gs .subRepoChecker )
817
- if err != nil {
818
- return nil , err
819
- }
820
-
821
- if ! hasAccess {
822
- s , err := status .New (codes .NotFound , "revision not found" ).WithDetails (& proto.RevisionNotFoundPayload {
823
- Repo : req .GetRepoName (),
824
- Spec : req .GetCommit (),
825
- })
826
- if err != nil {
827
- return nil , err
828
- }
829
- return nil , s .Err ()
797
+ modifiedFiles := make ([][]byte , len (commit .ModifiedFiles ))
798
+ for i , f := range commit .ModifiedFiles {
799
+ modifiedFiles [i ] = []byte (f )
830
800
}
831
801
832
802
return & proto.GetCommitResponse {
833
- Commit : commit .ToProto (),
803
+ Commit : commit .ToProto (),
804
+ ModifiedFiles : modifiedFiles ,
834
805
}, nil
835
806
}
836
807
@@ -863,26 +834,6 @@ func (gs *grpcServer) Blame(req *proto.BlameRequest, ss proto.GitserverService_B
863
834
return err
864
835
}
865
836
866
- // First, verify that the actor has access to the given path.
867
- hasAccess , err := authz .FilterActorPath (ctx , gs .subRepoChecker , actor .FromContext (ctx ), repoName , req .GetPath ())
868
- if err != nil {
869
- return err
870
- }
871
- if ! hasAccess {
872
- up := & proto.UnauthorizedPayload {
873
- RepoName : req .GetRepoName (),
874
- Commit : pointers .Ptr (req .GetCommit ()),
875
- Path : pointers .Ptr (req .GetPath ()),
876
- }
877
-
878
- s , marshalErr := status .New (codes .PermissionDenied , "no access to path" ).WithDetails (up )
879
- if marshalErr != nil {
880
- gs .logger .Error ("failed to marshal error" , log .Error (marshalErr ))
881
- return err
882
- }
883
- return s .Err ()
884
- }
885
-
886
837
backend := gs .getBackendFunc (repoDir , repoName )
887
838
888
839
opts := git.BlameOptions {
@@ -1023,27 +974,6 @@ func (gs *grpcServer) ReadFile(req *proto.ReadFileRequest, ss proto.GitserverSer
1023
974
return err
1024
975
}
1025
976
1026
- // First, verify that the actor has access to the given path.
1027
- hasAccess , err := authz .FilterActorPath (ctx , gs .subRepoChecker , actor .FromContext (ctx ), repoName , req .GetPath ())
1028
- if err != nil {
1029
- return err
1030
- }
1031
- if ! hasAccess {
1032
- up := & proto.UnauthorizedPayload {
1033
- RepoName : req .GetRepoName (),
1034
- Path : pointers .Ptr (req .GetPath ()),
1035
- }
1036
- if c := req .GetCommit (); c != "" {
1037
- up .Commit = & c
1038
- }
1039
- s , marshalErr := status .New (codes .PermissionDenied , "no access to path" ).WithDetails (up )
1040
- if marshalErr != nil {
1041
- gs .logger .Error ("failed to marshal error" , log .Error (marshalErr ))
1042
- return err
1043
- }
1044
- return s .Err ()
1045
- }
1046
-
1047
977
backend := gs .getBackendFunc (repoDir , repoName )
1048
978
1049
979
r , err := backend .ReadFile (ctx , api .CommitID (req .GetCommit ()), req .GetPath ())
@@ -1430,29 +1360,6 @@ func (gs *grpcServer) checkRepoExists(ctx context.Context, repo api.RepoName) er
1430
1360
return newRepoNotFoundError (repo , cloneInProgress , cloneProgress )
1431
1361
}
1432
1362
1433
- func hasAccessToCommit (ctx context.Context , repoName api.RepoName , files []string , checker authz.SubRepoPermissionChecker ) (bool , error ) {
1434
- if len (files ) == 0 {
1435
- return true , nil // If commit has no files, assume user has access to view the commit.
1436
- }
1437
-
1438
- if enabled , err := authz .SubRepoEnabledForRepo (ctx , checker , repoName ); err != nil {
1439
- return false , err
1440
- } else if ! enabled {
1441
- return true , nil
1442
- }
1443
-
1444
- a := actor .FromContext (ctx )
1445
- for _ , fileName := range files {
1446
- if hasAccess , err := authz .FilterActorPath (ctx , checker , a , repoName , fileName ); err != nil {
1447
- return false , err
1448
- } else if hasAccess {
1449
- // if the user has access to one file modified in the commit, they have access to view the commit
1450
- return true , nil
1451
- }
1452
- }
1453
- return false , nil
1454
- }
1455
-
1456
1363
func newRepoNotFoundError (repo api.RepoName , cloneInProgress bool , cloneProgress string ) error {
1457
1364
s , err := status .New (codes .NotFound , "repo not found" ).WithDetails (& proto.RepoNotFoundPayload {
1458
1365
CloneInProgress : cloneInProgress ,
0 commit comments