...
1 package server
2
3 import (
4 "context"
5 "fmt"
6
7 apb "golang.conradwood.net/apis/auth"
8 "golang.conradwood.net/go-easyops/auth"
9
10
11 "golang.conradwood.net/go-easyops/cmdline"
12
13 "sync"
14
15 "golang.conradwood.net/go-easyops/errors"
16 "golang.conradwood.net/go-easyops/rpc"
17 "golang.conradwood.net/go-easyops/utils"
18 "google.golang.org/grpc/peer"
19 )
20
21 var (
22 debuglock sync.Mutex
23 gettingrpc = false
24 rpclock sync.Mutex
25
26
27 )
28
29
34
35 func (sd *serverDef) checkAccess(octx context.Context, rc *rpccall) error {
36 if sd.noAuth || cmdline.IsStandalone() {
37 return nil
38 }
39 if auth.GetUser(octx) == nil && auth.GetService(octx) == nil {
40 fmt.Printf("[go-easyops] access denied to %s/%s for no-user and no-service to service with auth requirement (caller:%s)\n", rc.ServiceName, rc.MethodName, utils.CallingFunction())
41 return errors.Unauthenticated(octx, "denied for access with no user and no service to rpc with auth requirement")
42 }
43 return nil
44 }
45
46
47 func Authenticate(ictx context.Context, cs *rpc.CallState) error {
48 panic("obsolete codepath")
49 }
50
51
72 func peerFromContext(ctx context.Context) string {
73 s := ""
74 t, ok := peer.FromContext(ctx)
75 if ok && t != nil && t.Addr != nil {
76 s = t.Addr.String()
77 }
78 return s
79 }
80
81 func username(user *apb.User) string {
82 if user == nil {
83 return "[nouser]"
84 }
85 return fmt.Sprintf("[#%s %s]", user.ID, user.Email)
86 }
87
View as plain text