registry.h 3.1 KB

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