Skip to content

Commit

Permalink
[CORE-1231] pass pachctl args to server for audit logging (#8356)
Browse files Browse the repository at this point in the history
* send args in metadata

* log user commands
  • Loading branch information
Armaan Varadaraj committed Dec 8, 2022
1 parent 360e5fb commit 84daafc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ func (c *APIClient) AddMetadata(ctx context.Context) context.Context {
clientData["userid"] = c.metricsUserID
clientData["prefix"] = c.metricsPrefix
}
if len(os.Args) > 1 && os.Args[0] != "/pachd" {
clientData["command"] = strings.Join(os.Args, " ")
}

// Rescue any metadata pairs already in 'ctx' (otherwise
// metadata.NewOutgoingContext() would drop them). Note that this is similar
Expand Down
7 changes: 7 additions & 0 deletions src/internal/middleware/logging/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"reflect"
"strings"
"time"

"github.com/gogo/protobuf/types"
Expand Down Expand Up @@ -382,6 +383,12 @@ func (li *LoggingInterceptor) UnaryServerInterceptor(ctx context.Context, req in
logReq = config.transformRequest(req)
}

md, ok := metadata.FromIncomingContext(ctx)
if ok && len(md.Get("command")) > 0 {
command := md.Get("command")
li.logger.Logf(logrus.InfoLevel, "user command: %s", strings.Join(command, ""))
}

li.logUnaryBefore(ctx, level, logReq, info.FullMethod, start)
defer func() {
level := defaultLevel(retErr)
Expand Down

0 comments on commit 84daafc

Please sign in to comment.