| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | /* |
| 3 | * netdata registry |
| 4 | * |
| 5 | * this header file describes the public interface |
| 6 | * to the netdata registry |
| 7 | * |
| 8 | * only these high level functions are exposed |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | // ---------------------------------------------------------------------------- |
| 13 | // TODO |
| 14 | // |
| 15 | // 1. the default tracking cookie expires in 1 year, but the persons are not |
| 16 | // removed from the db - this means the database only grows - ideally the |
| 17 | // database should be cleaned in registry_db_save() for both on-disk and |
| 18 | // on-memory entries. |
| 19 | // |
| 20 | // Cleanup: |
| 21 | // i. Find all the PERSONs that have expired cookie |
| 22 | // ii. For each of their PERSON_URLs: |
| 23 | // - decrement the linked MACHINE links |
| 24 | // - if the linked MACHINE has no other links, remove the linked MACHINE too |
| 25 | // - remove the PERSON_URL |
| 26 | // |
| 27 | // 2. add protection to prevent abusing the registry by flooding it with |
| 28 | // requests to fill the memory and crash it. |
| 29 | // |
| 30 | // Possible protections: |
| 31 | // - limit the number of URLs per person |
| 32 | // - limit the number of URLs per machine |
| 33 | // - limit the number of persons |
| 34 | // - limit the number of machines |
| 35 | // - [DONE] limit the size of URLs |
| 36 | // - [DONE] limit the size of PERSON_URL names |
| 37 | // - limit the number of requests that add data to the registry, |
| 38 | // per client IP per hour |
| 39 | // |
| 40 | // 3. lower memory requirements |
| 41 | // |
| 42 | // - embed avl structures directly into registry objects, instead of DICTIONARY |
| 43 | // [DONE for PERSON_URLs, PENDING for MACHINE_URLs] |
| 44 | // - store GUIDs in memory as UUID instead of char * |
| 45 | // - do not track persons using the demo machines only |
| 46 | // (i.e. start tracking them only when they access a non-demo machine) |
| 47 | // - [DONE] do not track custom dashboards by default |
| 48 | |
| 49 | #ifndef NETDATA_REGISTRY_H |
| 50 | #define NETDATA_REGISTRY_H 1 |
| 51 | |
| 52 | #include "database/rrd.h" |
| 53 | |
| 54 | #define NETDATA_REGISTRY_COOKIE_NAME "netdata_registry_id" |
| 55 | |
| 56 | // initialize the registry |
| 57 | // should only happen when netdata starts |
| 58 | void netdata_conf_section_registry(void); |
| 59 | void registry_init(void); |
| 60 | bool registry_load(void); |
| 61 | |
| 62 | // free all data held by the registry |
| 63 | // should only happen when netdata exits |
| 64 | void registry_free(void); |
| 65 | |
| 66 | // HTTP requests handled by the registry |
| 67 | int registry_request_access_json(RRDHOST *host, struct web_client *w, char *person_guid, char *machine_guid, char *url, char *name, time_t when); |
| 68 | int registry_request_delete_json(RRDHOST *host, struct web_client *w, char *person_guid, char *machine_guid, char *url, char *delete_url, time_t when); |
| 69 | int registry_request_search_json(RRDHOST *host, struct web_client *w, char *person_guid, char *request_machine); |
| 70 | int registry_request_switch_json(RRDHOST *host, struct web_client *w, char *person_guid, char *machine_guid, char *url, char *new_person_guid, time_t when); |
| 71 | int registry_request_hello_json(RRDHOST *host, struct web_client *w, bool do_not_track); |
| 72 | |
| 73 | // update the registry config |
| 74 | void registry_update_cloud_base_url(); |
| 75 | |
| 76 | // update the registry monitoring charts |
| 77 | void registry_statistics(void); |
| 78 | |
| 79 | char *registry_get_mgmt_api_key(void); |
| 80 | const char *registry_get_this_machine_hostname(void); |
| 81 | |
| 82 | int regenerate_guid(const char *guid, char *result); |
| 83 | |
| 84 | #endif /* NETDATA_REGISTRY_H */ |