Skip to content

Commit

Permalink
Better logging
Browse files Browse the repository at this point in the history
- Add more logging to our macaroon discharger
- Reduce logging on our model proxy
  • Loading branch information
kian99 committed Sep 7, 2023
1 parent 48fff0e commit 6425f16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions internal/rpc/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (p *clientProxy) start(ctx context.Context) error {
zapctx.Debug(ctx, "Reading on client connection")
msg := new(message)
if err := p.src.readJson(&msg); err != nil {
zapctx.Error(ctx, "clientProxy error reading from src", zap.Error(err))
// Error reading on the socket implies it is closed, simply return.
return err
}
zapctx.Debug(ctx, "Read message from client", zap.Any("message", msg))
Expand Down Expand Up @@ -286,7 +286,6 @@ func (p *controllerProxy) start(ctx context.Context) error {
zapctx.Debug(ctx, "Reading on controller connection")
msg := new(message)
if err := p.src.readJson(msg); err != nil {
zapctx.Error(ctx, "controllerProxy error reading from src", zap.Error(err))
// Error reading on the socket implies it is closed, simply return.
return err
}
Expand Down
7 changes: 7 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,28 +598,33 @@ func (s *Service) thirdPartyCaveatCheckerFunction(ofgaClient *openfga.OFGAClient
return func(ctx context.Context, req *http.Request, cavInfo *bakery.ThirdPartyCaveatInfo, _ *httpbakery.DischargeToken) ([]checkers.Caveat, error) {
caveatTokens := strings.Split(string(cavInfo.Condition), " ")
if len(caveatTokens) != 3 {
zapctx.Error(ctx, "caveat token length incorrect", zap.Int("length", len(caveatTokens)))
return nil, checkers.ErrCaveatNotRecognized
}
relationString := caveatTokens[0]
userTagString := caveatTokens[1]
objectTagString := caveatTokens[2]

if !strings.HasPrefix(relationString, "is-") {
zapctx.Error(ctx, "caveat token relation string missing prefix")
return nil, checkers.ErrCaveatNotRecognized
}
relationString = strings.TrimPrefix(relationString, "is-")
relation, err := ofganames.ParseRelation(relationString)
if err != nil {
zapctx.Error(ctx, "caveat token relation invalid", zap.Error(err))
return nil, checkers.ErrCaveatNotRecognized
}

userTag, err := names.ParseUserTag(userTagString)
if err != nil {
zapctx.Error(ctx, "failed to parse caveat user tag", zap.Error(err))
return nil, checkers.ErrCaveatNotRecognized
}

objectTag, err := jimmnames.ParseTag(objectTagString)
if err != nil {
zapctx.Error(ctx, "failed to parse caveat object tag", zap.Error(err))
return nil, checkers.ErrCaveatNotRecognized
}

Expand All @@ -632,6 +637,7 @@ func (s *Service) thirdPartyCaveatCheckerFunction(ofgaClient *openfga.OFGAClient

allowed, err := openfga.CheckRelation(ctx, user, objectTag, relation)
if err != nil {
zapctx.Error(ctx, "failed to check request caveat relation", zap.Error(err))
return nil, errors.E(err)
}

Expand All @@ -640,6 +646,7 @@ func (s *Service) thirdPartyCaveatCheckerFunction(ofgaClient *openfga.OFGAClient
checkers.TimeBeforeCaveat(time.Now().Add(defaultDischargeExpiry)),
}, nil
}
zapctx.Debug(ctx, "macaroon dishcharge denied", zap.String("user", user.Username), zap.String("object", objectTag.Id()))
return nil, httpbakery.ErrPermissionDenied
}
}

0 comments on commit 6425f16

Please sign in to comment.