Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -901,6 +902,17 @@ func (self *ApiServer) Query(
principal, permissions))
}

peer, ok := peer.FromContext(stream.Context())
if !ok {
return status.Error(codes.PermissionDenied, "No peer")
}

_ = users.SetUserStats(stream.Context(), org_config_obj, principal,
&api_proto.UserStats{
LastActiveTime: utils.GetTime().Now().Unix(),
LastIpAddress: peer.Addr.String(),
})

return streamQuery(stream.Context(), org_config_obj, in, stream, principal)
}

Expand Down
10 changes: 8 additions & 2 deletions api/authenticators/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"www.velocidex.com/golang/velociraptor/acls"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
api_utils "www.velocidex.com/golang/velociraptor/api/utils"
utils "www.velocidex.com/golang/velociraptor/api/utils"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
"www.velocidex.com/golang/velociraptor/constants"
"www.velocidex.com/golang/velociraptor/json"
"www.velocidex.com/golang/velociraptor/logging"
"www.velocidex.com/golang/velociraptor/services"
utils "www.velocidex.com/golang/velociraptor/utils"
)

// Implement basic authentication.
Expand Down Expand Up @@ -44,7 +44,7 @@ func (self *BasicAuthenticator) AddLogoff(mux *api_utils.ServeMux) error {
old_username, ok := params["username"]
if ok && len(old_username) == 1 && old_username[0] != username {
// Authenticated as someone else.
http.Redirect(w, r, utils.Homepage(self.config_obj),
http.Redirect(w, r, api_utils.Homepage(self.config_obj),
http.StatusTemporaryRedirect)
return
}
Expand Down Expand Up @@ -158,6 +158,12 @@ func (self *BasicAuthenticator) AuthenticateUserHandler(
ctx := context.WithValue(
r.Context(), constants.GRPC_USER_CONTEXT, string(serialized))

_ = users_manager.SetUserStats(r.Context(), self.config_obj, username,
&api_proto.UserStats{
LastActiveTime: utils.GetTime().Now().Unix(),
LastIpAddress: r.RemoteAddr,
})

// Need to call logging after auth so it can access
// the USER value in the context.
logger.ServeHTTP(w, r.WithContext(ctx))
Expand Down
6 changes: 6 additions & 0 deletions api/authenticators/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func authenticateUserHandle(
ctx := context.WithValue(
r.Context(), constants.GRPC_USER_CONTEXT, string(serialized))

_ = users.SetUserStats(r.Context(), config_obj, username,
&api_proto.UserStats{
LastActiveTime: utils.GetTime().Now().Unix(),
LastIpAddress: r.RemoteAddr,
})

// Need to call logging after auth so it can access
// the contextKeyUser value in the context.
logger.ServeHTTP(w, r.WithContext(ctx))
Expand Down
Loading
Loading