Prevent data corruption upon GUID duplication between master and slave netdata instances (#5511)
* Do a GUID comparison between slave and receiver to avoid conflicts in processing when the GUID is mistakenly set same on both We found this issue while creating a container, set it up with netdata and then clone it to get another one up and running with the same setup. We need this check to prevent data conflicts as the GUID is considered to be unique across the universe. TODO: I dont have enough visibility over the rates that this string comparison will be executed, we might need to reconsider another faster approach to compare the GUIDs * Dont forget to cleanup resources properly upon early exit * Remove mysterious string compare, fix indentation in other part of the code
Paul Katsoulakis committed
Mar 1, 2019 at 07:56 UTC
c05954cf0537da81e24eb698fe0a60fa088848f5
1 file changed
+24
-20
streaming/rrdpush.c
+24
-20
@@ -868,8 +868,12 @@ static int rrdpush_receive(int fd
868
tags = appconfig_set_default(&stream_config, machine_guid, "host tags", (tags)?tags:"");
869
if(tags && !*tags) tags = NULL;
870
871
- if(!strcmp(machine_guid, "localhost"))
872
- host = localhost;
871
+ if (strcmp(machine_guid, localhost->machine_guid) == 0) {
872
+ log_stream_connection(client_ip, client_port, key, machine_guid, hostname, "DENIED - ATTEMPT TO RECEIVE METRICS FROM MACHINE_GUID IDENTICAL TO MASTER");
873
+ error("STREAM %s [receive from %s:%s]: denied to receive metrics, machine GUID [%s] is my own. Did you copy the master/proxy machine guid to a slave?", hostname, client_ip, client_port, machine_guid);
874
+ close(fd);
875
+ return 1;
876
+ }
877
else
878
host = rrdhost_find_or_create(
879
hostname
@@ -1050,24 +1054,24 @@ static void rrdpush_receiver_thread_cleanup(void *ptr) {
1054
static void *rrdpush_receiver_thread(void *ptr) {
1055
netdata_thread_cleanup_push(rrdpush_receiver_thread_cleanup, ptr);
1056
1053
- struct rrdpush_thread *rpt = (struct rrdpush_thread *)ptr;
1054
- info("STREAM %s [%s]:%s: receive thread created (task id %d)", rpt->hostname, rpt->client_ip, rpt->client_port, gettid());
1055
-
1056
- rrdpush_receive(
1057
- rpt->fd
1058
- , rpt->key
1059
- , rpt->hostname
1060
- , rpt->registry_hostname
1061
- , rpt->machine_guid
1062
- , rpt->os
1063
- , rpt->timezone
1064
- , rpt->tags
1065
- , rpt->program_name
1066
- , rpt->program_version
1067
- , rpt->update_every
1068
- , rpt->client_ip
1069
- , rpt->client_port
1070
- );
1057
+ struct rrdpush_thread *rpt = (struct rrdpush_thread *)ptr;
1058
+ info("STREAM %s [%s]:%s: receive thread created (task id %d)", rpt->hostname, rpt->client_ip, rpt->client_port, gettid());
1059
+
1060
+ rrdpush_receive(
1061
+ rpt->fd
1062
+ , rpt->key
1063
+ , rpt->hostname
1064
+ , rpt->registry_hostname
1065
+ , rpt->machine_guid
1066
+ , rpt->os
1067
+ , rpt->timezone
1068
+ , rpt->tags
1069
+ , rpt->program_name
1070
+ , rpt->program_version
1071
+ , rpt->update_every
1072
+ , rpt->client_ip
1073
+ , rpt->client_port
1074
+ );
1075
1076
netdata_thread_cleanup_pop(1);
1077
return NULL;