diff options
author | Paul Katsoulakis <34388743+paulkatsoulakis@users.noreply.github.com> | 2019-03-01 07:56:36 +0000 |
---|---|---|
committer | Chris Akritidis <43294513+cakrit@users.noreply.github.com> | 2019-03-01 08:56:36 +0100 |
commit | c05954cf0537da81e24eb698fe0a60fa088848f5 (patch) | |
tree | 1863c384aa8760bbed77b24de3833c168f2d4ccf /streaming | |
parent | 54dae3f2f011ca55361c9dbeaa753b97b7a259bb (diff) |
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
Diffstat (limited to 'streaming')
-rw-r--r-- | streaming/rrdpush.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/streaming/rrdpush.c b/streaming/rrdpush.c index d1626db708..b98d0b3dc6 100644 --- a/streaming/rrdpush.c +++ b/streaming/rrdpush.c @@ -868,8 +868,12 @@ static int rrdpush_receive(int fd tags = appconfig_set_default(&stream_config, machine_guid, "host tags", (tags)?tags:""); if(tags && !*tags) tags = NULL; - if(!strcmp(machine_guid, "localhost")) - host = localhost; + if (strcmp(machine_guid, localhost->machine_guid) == 0) { + log_stream_connection(client_ip, client_port, key, machine_guid, hostname, "DENIED - ATTEMPT TO RECEIVE METRICS FROM MACHINE_GUID IDENTICAL TO MASTER"); + 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); + close(fd); + return 1; + } else host = rrdhost_find_or_create( hostname @@ -1050,24 +1054,24 @@ static void rrdpush_receiver_thread_cleanup(void *ptr) { static void *rrdpush_receiver_thread(void *ptr) { netdata_thread_cleanup_push(rrdpush_receiver_thread_cleanup, ptr); - struct rrdpush_thread *rpt = (struct rrdpush_thread *)ptr; - info("STREAM %s [%s]:%s: receive thread created (task id %d)", rpt->hostname, rpt->client_ip, rpt->client_port, gettid()); - - rrdpush_receive( - rpt->fd - , rpt->key - , rpt->hostname - , rpt->registry_hostname - , rpt->machine_guid - , rpt->os - , rpt->timezone - , rpt->tags - , rpt->program_name - , rpt->program_version - , rpt->update_every - , rpt->client_ip - , rpt->client_port - ); + struct rrdpush_thread *rpt = (struct rrdpush_thread *)ptr; + info("STREAM %s [%s]:%s: receive thread created (task id %d)", rpt->hostname, rpt->client_ip, rpt->client_port, gettid()); + + rrdpush_receive( + rpt->fd + , rpt->key + , rpt->hostname + , rpt->registry_hostname + , rpt->machine_guid + , rpt->os + , rpt->timezone + , rpt->tags + , rpt->program_name + , rpt->program_version + , rpt->update_every + , rpt->client_ip + , rpt->client_port + ); netdata_thread_cleanup_pop(1); return NULL; |