From a1e38245fb0e0d4d316b7148a685826fc3e72527 Mon Sep 17 00:00:00 2001 From: Michael Cohen Date: Mon, 15 Jul 2019 02:41:23 +0000 Subject: [PATCH] Fixed bug in hunts paths. The aff4 prefix is just confusing - we need to drop it everywhere. --- bin/inspect.go | 20 ++++++++++---------- constants/constants.go | 9 ++++----- constants/paths.go | 13 +++++++++++++ flows/hunts.go | 4 ++-- services/hunt_dispatcher.go | 6 +++--- services/hunt_manager.go | 2 +- 6 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 constants/paths.go diff --git a/bin/inspect.go b/bin/inspect.go index 96cb4a2ec9c..e8ea06abafd 100644 --- a/bin/inspect.go +++ b/bin/inspect.go @@ -42,16 +42,16 @@ import ( ) var classifiers = map[string]proto.Message{ - "aff4:/clients/C.[^/]+$": &actions_proto.ClientInfo{}, - "aff4:/clients/C.[^/]+/ping$": &actions_proto.ClientInfo{}, - "aff4:/clients/C.[^/]+/key$": &crypto_proto.PublicKey{}, - "aff4:/clients/C.[^/]+/vfs/.+": &actions_proto.VQLResponse{}, - "aff4:/clients/C.[^/]+/flows/F\\.[^/]+$": &flows_proto.AFF4FlowObject{}, - "aff4:/clients/C.[^/]+/flows/F\\.[^/]+/results/.+$": &crypto_proto.GrrMessage{}, - "aff4:/clients/C.[^/]+/tasks/[^/]+$": &crypto_proto.GrrMessage{}, - constants.HUNTS_URN + "H.[^/]+$": &api_proto.Hunt{}, - "aff4:/users/[^/]+$": &api_proto.VelociraptorUser{}, - "aff4:/users/[^/]+/notifications/.+$": &api_proto.UserNotification{}, + "/clients/C.[^/]+$": &actions_proto.ClientInfo{}, + "/clients/C.[^/]+/ping$": &actions_proto.ClientInfo{}, + "/clients/C.[^/]+/key$": &crypto_proto.PublicKey{}, + "/clients/C.[^/]+/vfs/.+": &actions_proto.VQLResponse{}, + "/clients/C.[^/]+/flows/F\\.[^/]+$": &flows_proto.AFF4FlowObject{}, + "/clients/C.[^/]+/flows/F\\.[^/]+/results/.+$": &crypto_proto.GrrMessage{}, + "/clients/C.[^/]+/tasks/[^/]+$": &crypto_proto.GrrMessage{}, + constants.HUNTS_URN + "H.[^/]+$": &api_proto.Hunt{}, + "/users/[^/]+$": &api_proto.VelociraptorUser{}, + "/users/[^/]+/notifications/.+$": &api_proto.UserNotification{}, } var ( diff --git a/constants/constants.go b/constants/constants.go index 0a8d8d3c51e..22927e2e872 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -29,13 +29,12 @@ const ( FLOW_PREFIX = "F." FOREMAN_WELL_KNOWN_FLOW = "aff4:/flows/E.Foreman" - HUNTS_URN = "aff4:/hunts/" HUNT_PREFIX = "H." // The GUI uses this as the client index. - CLIENT_INDEX_URN = "aff4:/client_index/" + CLIENT_INDEX_URN = "/client_index/" - USER_URN = "aff4:/users/" + USER_URN = "/users/" // Well known flows - Request ID: LOG_SINK uint64 = 980 @@ -57,8 +56,8 @@ const ( // These store configuration for the server and client // monitoring artifacts. - ServerMonitoringFlowURN = "aff4:/config/server_monitoring.json" - ClientMonitoringFlowURN = "aff4:/config/client_monitoring.json" + ServerMonitoringFlowURN = "/config/server_monitoring.json" + ClientMonitoringFlowURN = "/config/client_monitoring.json" ) var ( diff --git a/constants/paths.go b/constants/paths.go new file mode 100644 index 00000000000..adf5c99a041 --- /dev/null +++ b/constants/paths.go @@ -0,0 +1,13 @@ +package constants + +const ( + HUNTS_URN = "/hunts/" +) + +func GetHuntURN(hunt_id string) string { + return HUNTS_URN + hunt_id +} + +func GetHuntStatsPath(hunt_id string) string { + return HUNTS_URN + hunt_id + "/stats" +} diff --git a/flows/hunts.go b/flows/hunts.go index 8d2058d9b20..7522ae5008e 100644 --- a/flows/hunts.go +++ b/flows/hunts.go @@ -122,7 +122,7 @@ func CreateHunt( }) } - err = db.SetSubject(config_obj, constants.HUNTS_URN+hunt.HuntId, hunt) + err = db.SetSubject(config_obj, constants.GetHuntURN(hunt.HuntId), hunt) if err != nil { return nil, err } @@ -233,7 +233,7 @@ func ModifyHunt(config_obj *api_proto.Config, hunt_modification *api_proto.Hunt) err = db.SetSubject( config_obj, - constants.HUNTS_URN+hunt.HuntId, hunt) + constants.GetHuntURN(hunt.HuntId), hunt) if err != nil { return err } diff --git a/services/hunt_dispatcher.go b/services/hunt_dispatcher.go index e8a8d774bfb..12699f9aece 100644 --- a/services/hunt_dispatcher.go +++ b/services/hunt_dispatcher.go @@ -138,7 +138,7 @@ func (self *HuntDispatcher) _flush_stats() error { for _, hunt_obj := range self.hunts { err = db.SetSubject( self.config_obj, - constants.HUNTS_URN+hunt_obj.HuntId+"/stats", hunt_obj.Stats) + constants.GetHuntStatsPath(hunt_obj.HuntId), hunt_obj.Stats) if err != nil { logger := logging.GetLogger(self.config_obj, &logging.FrontendComponent) logger.Error("Flushing %s to disk: %v", hunt_obj.HuntId, err) @@ -203,7 +203,7 @@ func (self *HuntDispatcher) Refresh() error { hunt_obj := &api_proto.Hunt{} err = db.GetSubject( self.config_obj, - constants.HUNTS_URN+hunt_id, hunt_obj) + constants.GetHuntURN(hunt_id), hunt_obj) if err != nil { continue } @@ -211,7 +211,7 @@ func (self *HuntDispatcher) Refresh() error { // Re-read the stats into the hunt object. hunt_stats := &api_proto.HuntStats{} err := db.GetSubject(self.config_obj, - constants.HUNTS_URN+hunt_id+"/stats", hunt_stats) + constants.GetHuntStatsPath(hunt_id), hunt_stats) if err == nil { hunt_obj.Stats = hunt_stats } diff --git a/services/hunt_manager.go b/services/hunt_manager.go index b3a0a8ced5e..64b70202a7d 100644 --- a/services/hunt_manager.go +++ b/services/hunt_manager.go @@ -144,7 +144,7 @@ func (self *HuntManager) ProcessRow( // Hold references to all the writers for the life of // the manager. fd, err := file_store_factory.WriteFile( - constants.HUNTS_URN + participation_row.HuntId + ".csv") + constants.GetHuntURN(participation_row.HuntId) + ".csv") if err != nil { return }