@@ -84,6 +84,7 @@ func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
84
84
p := & rpcProxy {
85
85
cfg : cfg ,
86
86
basicAuth : basicAuth ,
87
+ permissionMap : permissionMap ,
87
88
macValidator : validator ,
88
89
superMacValidator : superMacValidator ,
89
90
bufListener : bufListener ,
@@ -92,12 +93,8 @@ func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
92
93
// From the grpxProxy doc: This codec is *crucial* to the
93
94
// functioning of the proxy.
94
95
grpc .CustomCodec (grpcProxy .Codec ()), // nolint:staticcheck
95
- grpc .ChainStreamInterceptor (p .StreamServerInterceptor (
96
- permissionMap ,
97
- )),
98
- grpc .ChainUnaryInterceptor (p .UnaryServerInterceptor (
99
- permissionMap ,
100
- )),
96
+ grpc .ChainStreamInterceptor (p .StreamServerInterceptor ),
97
+ grpc .ChainUnaryInterceptor (p .UnaryServerInterceptor ),
101
98
grpc .UnknownServiceHandler (
102
99
grpcProxy .TransparentHandler (p .director ),
103
100
),
@@ -156,8 +153,9 @@ func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
156
153
// +---------------------+
157
154
//
158
155
type rpcProxy struct {
159
- cfg * Config
160
- basicAuth string
156
+ cfg * Config
157
+ basicAuth string
158
+ permissionMap map [string ][]bakery.Op
161
159
162
160
macValidator macaroons.MacaroonValidator
163
161
superMacValidator session.SuperMacaroonValidator
@@ -346,93 +344,86 @@ func (p *rpcProxy) director(ctx context.Context,
346
344
347
345
// UnaryServerInterceptor is a gRPC interceptor that checks whether the
348
346
// request is authorized by the included macaroons.
349
- func (p * rpcProxy ) UnaryServerInterceptor (
350
- permissionMap map [string ][]bakery.Op ) grpc.UnaryServerInterceptor {
347
+ func (p * rpcProxy ) UnaryServerInterceptor (ctx context.Context , req interface {},
348
+ info * grpc.UnaryServerInfo , handler grpc.UnaryHandler ) (interface {},
349
+ error ) {
351
350
352
- return func (ctx context.Context , req interface {},
353
- info * grpc.UnaryServerInfo ,
354
- handler grpc.UnaryHandler ) (interface {}, error ) {
355
-
356
- uriPermissions , ok := permissionMap [info .FullMethod ]
357
- if ! ok {
358
- return nil , fmt .Errorf ("%s: unknown permissions " +
359
- "required for method" , info .FullMethod )
360
- }
351
+ uriPermissions , ok := p .permissionMap [info .FullMethod ]
352
+ if ! ok {
353
+ return nil , fmt .Errorf ("%s: unknown permissions " +
354
+ "required for method" , info .FullMethod )
355
+ }
361
356
362
- // For now, basic authentication is just a quick fix until we
363
- // have proper macaroon support implemented in the UI. We allow
364
- // gRPC web requests to have it and "convert" the auth into a
365
- // proper macaroon now.
366
- newCtx , err := p .convertBasicAuth (ctx , info .FullMethod , nil )
367
- if err != nil {
368
- // Make sure we handle the case where the super macaroon
369
- // is still empty on startup.
370
- if pErr , ok := err .(* proxyErr ); ok &&
371
- pErr .proxyContext == "supermacaroon" {
357
+ // For now, basic authentication is just a quick fix until we
358
+ // have proper macaroon support implemented in the UI. We allow
359
+ // gRPC web requests to have it and "convert" the auth into a
360
+ // proper macaroon now.
361
+ newCtx , err := p .convertBasicAuth (ctx , info .FullMethod , nil )
362
+ if err != nil {
363
+ // Make sure we handle the case where the super macaroon
364
+ // is still empty on startup.
365
+ if pErr , ok := err .(* proxyErr ); ok &&
366
+ pErr .proxyContext == "supermacaroon" {
372
367
373
- return nil , fmt .Errorf ("super macaroon error: " +
374
- "%v" , pErr )
375
- }
376
- return nil , err
377
- }
378
-
379
- // With the basic auth converted to a macaroon if necessary,
380
- // let's now validate the macaroon.
381
- err = p .macValidator .ValidateMacaroon (
382
- newCtx , uriPermissions , info .FullMethod ,
383
- )
384
- if err != nil {
385
- return nil , err
368
+ return nil , fmt .Errorf ("super macaroon error: " +
369
+ "%v" , pErr )
386
370
}
371
+ return nil , err
372
+ }
387
373
388
- return handler (ctx , req )
374
+ // With the basic auth converted to a macaroon if necessary,
375
+ // let's now validate the macaroon.
376
+ err = p .macValidator .ValidateMacaroon (
377
+ newCtx , uriPermissions , info .FullMethod ,
378
+ )
379
+ if err != nil {
380
+ return nil , err
389
381
}
382
+
383
+ return handler (ctx , req )
390
384
}
391
385
392
386
// StreamServerInterceptor is a GRPC interceptor that checks whether the
393
387
// request is authorized by the included macaroons.
394
- func (p * rpcProxy ) StreamServerInterceptor (
395
- permissionMap map [string ][]bakery.Op ) grpc.StreamServerInterceptor {
396
-
397
- return func (srv interface {}, ss grpc.ServerStream ,
398
- info * grpc.StreamServerInfo , handler grpc.StreamHandler ) error {
399
-
400
- uriPermissions , ok := permissionMap [info .FullMethod ]
401
- if ! ok {
402
- return fmt .Errorf ("%s: unknown permissions required " +
403
- "for method" , info .FullMethod )
404
- }
388
+ func (p * rpcProxy ) StreamServerInterceptor (srv interface {},
389
+ ss grpc.ServerStream , info * grpc.StreamServerInfo ,
390
+ handler grpc.StreamHandler ) error {
405
391
406
- // For now, basic authentication is just a quick fix until we
407
- // have proper macaroon support implemented in the UI. We allow
408
- // gRPC web requests to have it and "convert" the auth into a
409
- // proper macaroon now.
410
- ctx , err := p .convertBasicAuth (
411
- ss .Context (), info .FullMethod , nil ,
412
- )
413
- if err != nil {
414
- // Make sure we handle the case where the super macaroon
415
- // is still empty on startup.
416
- if pErr , ok := err .(* proxyErr ); ok &&
417
- pErr .proxyContext == "supermacaroon" {
392
+ uriPermissions , ok := p .permissionMap [info .FullMethod ]
393
+ if ! ok {
394
+ return fmt .Errorf ("%s: unknown permissions required " +
395
+ "for method" , info .FullMethod )
396
+ }
418
397
419
- return fmt .Errorf ("super macaroon error: " +
420
- "%v" , pErr )
421
- }
422
- return err
423
- }
398
+ // For now, basic authentication is just a quick fix until we
399
+ // have proper macaroon support implemented in the UI. We allow
400
+ // gRPC web requests to have it and "convert" the auth into a
401
+ // proper macaroon now.
402
+ ctx , err := p .convertBasicAuth (
403
+ ss .Context (), info .FullMethod , nil ,
404
+ )
405
+ if err != nil {
406
+ // Make sure we handle the case where the super macaroon
407
+ // is still empty on startup.
408
+ if pErr , ok := err .(* proxyErr ); ok &&
409
+ pErr .proxyContext == "supermacaroon" {
424
410
425
- // With the basic auth converted to a macaroon if necessary,
426
- // let's now validate the macaroon.
427
- err = p .macValidator .ValidateMacaroon (
428
- ctx , uriPermissions , info .FullMethod ,
429
- )
430
- if err != nil {
431
- return err
411
+ return fmt .Errorf ("super macaroon error: " +
412
+ "%v" , pErr )
432
413
}
414
+ return err
415
+ }
433
416
434
- return handler (srv , ss )
417
+ // With the basic auth converted to a macaroon if necessary,
418
+ // let's now validate the macaroon.
419
+ err = p .macValidator .ValidateMacaroon (
420
+ ctx , uriPermissions , info .FullMethod ,
421
+ )
422
+ if err != nil {
423
+ return err
435
424
}
425
+
426
+ return handler (srv , ss )
436
427
}
437
428
438
429
// convertBasicAuth tries to convert the HTTP authorization header into a
0 commit comments