Skip to content

Commit

Permalink
Changes to audit the log for infra proxy (#6622)
Browse files Browse the repository at this point in the history
* added changes for infra proxy audit log

* added reflect codes

Signed-off-by: Kallol Roy <karoy@progress.com>

* added changes for the audit logs for infra

Signed-off-by: Vinay Sharma <vsharma@chef.io>

* removed commented code

Signed-off-by: Vinay Sharma <vsharma@chef.io>

* added some minor changes

Signed-off-by: Vinay Sharma <vsharma@chef.io>

Co-authored-by: Kallol Roy <karoy@progress.com>
  • Loading branch information
vinay033 and kalroy authored Jan 25, 2022
1 parent 889b918 commit 0985f26
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions components/automate-gateway/gateway/middleware/auth_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/pem"
"errors"
"net/url"
"reflect"
"strings"

"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/chef/automate/api/interservice/authn"
"github.com/chef/automate/lib/grpc/auth_context"
"github.com/chef/automate/lib/grpc/service_authn"
"github.com/chef/automate/lib/logger"
)

// NewAuthInterceptor returns an AuthInterceptor that performs
Expand Down Expand Up @@ -77,6 +79,7 @@ func (a *authInterceptor) combinedAuth(ctxIn context.Context, req interface{}) (
log.Debugf("error authenticating request: %s", err)
return nil, err
}

authCtx = context.WithValue(authCtx, "requestorID", authResponse.Requestor)
subs = append(authResponse.Teams, authResponse.Subject)
}
Expand Down Expand Up @@ -109,10 +112,32 @@ func (a *authInterceptor) UnaryServerInterceptor() grpc.UnaryServerInterceptor {
return nil, err
}

a.logInfraProxyLogData(ctxForDownstream, req)

return handler(ctxForDownstream, req)
}
}

func (a *authInterceptor) logInfraProxyLogData(ctx context.Context, req interface{}) {

log := ctxlogrus.Extract(ctx)
logData := log.Data

if logData["grpc.service"] == "chef.automate.api.infra_proxy.InfraProxy" {
interfaceValue := reflect.ValueOf(req)

// TODO: We need to improve the audit log information for infra proxy
log.Logger.WithFields(logger.KV{
"User::": logData["auth.subjects"],
"GrpcMethod::": logData["grpc.method"],
"Service::": logData["grpc.service"],
"API info::": logData["auth.action"],
"Time::": logData["grpc.start_time"],
"API params::": interfaceValue.Interface(),
}).Info("Infra proxy server API logs")
}
}

// interceptedServerStream wraps a grpc.ServerStream in order to allow an
// updated context to be given to the handler. The auth process updates the
// context with auth metadata which should be passed along to the domain
Expand Down

0 comments on commit 0985f26

Please sign in to comment.