Skip to content

Commit

Permalink
Cloud Sign-In (netdata#5095)
Browse files Browse the repository at this point in the history
* Manually merged changes from old hub-support branch, tracking netdata#131

Call claim url netdata#4771
Claim ui improvements netdata#4771
Cleanup
Implement Sign Out
Introduced sign-in modal netdata#3990
Added sign-in button
More work on the iframe trick
More work
More work on the logic, removed old obsolete stuff
Close modal
Implement account menu
Minor rename
Renamed my-netdata to My Agents
Show migrate button
Collect known agents
Work on migrateRegistryDidClick
Minor
Actually show agents from netdata cloud in the menu
Some cleanup
Keep all the alternate_urls for each agent
Fix for tooltips over SignIn/AccountMenu

* Actually use NETDATA.registry.cloudBaseURL

Tricky!

* Hide switch identity when signed-in netdata#153

* Manually merged changes from old hub-support branch, tracking netdata#131

Call claim url netdata#4771
Claim ui improvements netdata#4771
Cleanup
Implement Sign Out
Introduced sign-in modal netdata#3990
Added sign-in button
More work on the iframe trick
More work
More work on the logic, removed old obsolete stuff
Close modal
Implement account menu
Minor rename
Renamed my-netdata to My Agents
Show migrate button
Collect known agents
Work on migrateRegistryDidClick
Minor
Actually show agents from netdata cloud in the menu
Some cleanup
Keep all the alternate_urls for each agent
Fix for tooltips over SignIn/AccountMenu

* Actually use NETDATA.registry.cloudBaseURL

Tricky!

* Hide switch identity when signed-in netdata#153

* Cleanup

* Refresh menu on sign-in

* Disable cloud functionality if cloud base url is not set.

This wll allow the merging of the branch into master, so we can avoid nasty rebases.

* Updated to use the latest API endpoints

* Fixed a couple of LGTM warnings

* Improved migration algorithm, some cleanup.

* Update My-Netdata menu on sign-out

* Minor

* Replaced modal with window

* Update the My-Agents menu after migration, cleanup

* Make the agent work after switching cloudBaseURL, cleanup

* Introduced event tracing for analytics

* Minor

* Removed GA

* Fixed error reported by LGTM

* Only send the diff when syncing agents to ameliorate the load on the backend, cleanup

* Reverted My-Netdata name, added some logging

* Add Netdata Cloud menu item

* Minor

* Use the merge: false option and a fix

* Added loading message in my-netdata menu

* Show error if we cannot connect to netdata.cloud

* Minor

* Implemented deleteCloudKnownAgentURL api call, use it in my-netdata menu.

* Removed menu entry

* Disable my-netdata menu if user is not signed-in and using the global registry

* Stop accessing the registry if it's not used.

* Mask the agent url if the registry is in 'disabled' mode

* Filter masked urls

* Improved filtering of masked urls

* Try to eagerly initialize the account ui to improve perceived performance

* Minor

* Don't search for other people's urls in cloud-enabled mode.

* Added basic my-netdata filtering

* Filter streamed host, aesthetic fixes

* Minor

* Some improvements of the filter ui

* Removed What is this

* Added placeholder to input, other fixes netdata#240

* Show message if no databases match filter criteria

* Fixed bug where agent lists where not merged

* Minor

* Hide modal if it redirects to self.

* autocomplete off for filter input

* Enable delete for custom registries, don't show error if delete fails

* Filter agents without urls

* Fix LGTM warning

* Minor

* Concatenate at client side, used the faster merge: false path

* Added a clear button to the filter for extra usability

* Minor

* Minor

* Improvements for small screens (more needed)

* Combined  my-netdata menu and hostname

* Re-enabled registry masking

* Show agent-filter only when signed-in

* Improved syncAgents

* Don't mask if using custom registry

* Reject agents with empty urls

* Filter valid agents

* Fixed a couple of bugs

* Applied Chris' fixes

* Fix in registry.c

* Cleanup

* Only sync once

* Implemented forceSync

* Added what is this

* sso, wip

* Working SSO sign-in/sign-out, cleanup

* Added Chris' patch

* Added a modal that explains what synchronize is doing

* Use sso-agent

* Use origin as query param in sign-in

* iframe -> origin

* Pass machine_guid to sso

* Make sure that the current netdata agent is synchronized hub#262

* Normalize originURL

* Reenable tryFastInitCloud()

* Updated to the latest endpoints

* Support synchronizing to multiple cloud accounts

* Set default cloud base url to netdata.cloud

* Fix filter issues with Firefox

* Fix for double tooltip on sign-in

* Show known servers in console for debugging purposes

* Don't block on errors to delete from registry when signed in

* Disable tryFastInitCloud

* Improved styling for filter input

* Improved styling in my-netdata menu

* Display the registry url in the sync-registry modal

* agents -> nodes in texts

* Support for sso-precheck

* Do not implicitly synchronize custom registries.

* Improvement to syncAgents (more coming)

* More fixes

* Don't sign in users with private registries if they don't consent on the sync

* Set netdataRegistryAfterMs = 0

* Don't pass url to sso-agent

* Added Chris' patch to alarm-notify

* Refactored syncAgent/mergeAgents, make sure current Agent is synced on sign-in.

* Fix for LGTM warning

* Minor

* Fix for a XSS warning

* Extra check for dataLayer
  • Loading branch information
gmosx authored and kiku-jw committed Mar 4, 2019
1 parent 8f90197 commit 187eff5
Show file tree
Hide file tree
Showing 11 changed files with 1,004 additions and 111 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,6 @@ python.d/python-modules-installer.sh
docs/generator/src
docs/generator/build
docs/generator/mkdocs.yml

netdata-updater.sh
.environment.sh
22 changes: 21 additions & 1 deletion health/notifications/alarm-notify.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,27 @@ urlencode "${args_host}" >/dev/null; url_host="${REPLY}"
urlencode "${chart}" >/dev/null; url_chart="${REPLY}"
urlencode "${family}" >/dev/null; url_family="${REPLY}"
urlencode "${name}" >/dev/null; url_name="${REPLY}"
goto_url="${NETDATA_REGISTRY_URL}/goto-host-from-alarm.html?host=${url_host}&chart=${url_chart}&family=${url_family}&alarm=${url_name}&alarm_unique_id=${unique_id}&alarm_id=${alarm_id}&alarm_event_id=${event_id}"

redirect_params="host=${url_host}&chart=${url_chart}&family=${url_family}&alarm=${url_name}&alarm_unique_id=${unique_id}&alarm_id=${alarm_id}&alarm_event_id=${event_id}"
GOTOCLOUD=0

if [ "${NETDATA_REGISTRY_URL}" == "https://registry.my-netdata.io" ] ; then
if [ -z "${NETDATA_REGISTRY_UNIQUE_ID}" ] ; then
if [ -f "@registrydir_POST@/netdata.public.unique.id" ]; then
NETDATA_REGISTRY_UNIQUE_ID="$(cat "@registrydir_POST@/netdata.public.unique.id")"
fi
fi
if [ ! -z "${NETDATA_REGISTRY_UNIQUE_ID}" ] ; then
GOTOCLOUD=1
fi
fi

if [ ${GOTOCLOUD} -eq 0 ] ; then
goto_url="${NETDATA_REGISTRY_URL}/goto-host-from-alarm.html?${redirect_params}"
else
urlencode "${NETDATA_REGISTRY_URL}/goto-host-from-alarm.html" >/dev/null; url_registrypath="${REPLY}"
goto_url="https://netdata.cloud/alarms/redirect?agentID=${NETDATA_REGISTRY_UNIQUE_ID}&registrypath=${url_registrypath}&${redirect_params}"
fi

# the severity of the alarm
severity="${status}"
Expand Down
4 changes: 4 additions & 0 deletions registry/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static int registry_json_person_url_callback(void *entry, void *data) {
struct registry_json_walk_person_urls_callback *c = (struct registry_json_walk_person_urls_callback *)data;
struct web_client *w = c->w;

if (!strcmp(pu->url->url,"***")) return 0;

if(unlikely(c->count++))
buffer_strcat(w->response.data, ",");

Expand All @@ -97,6 +99,8 @@ static int registry_json_machine_url_callback(void *entry, void *data) {
struct web_client *w = c->w;
REGISTRY_MACHINE *m = c->m;

if (!strcmp(mu->url->url,"***")) return 1;

if(unlikely(c->count++))
buffer_strcat(w->response.data, ",");

Expand Down
4 changes: 3 additions & 1 deletion registry/registry_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ int registry_init(void) {
registry.persons_expiration = config_get_number(CONFIG_SECTION_REGISTRY, "registry expire idle persons days", 365) * 86400;
registry.registry_domain = config_get(CONFIG_SECTION_REGISTRY, "registry domain", "");
registry.registry_to_announce = config_get(CONFIG_SECTION_REGISTRY, "registry to announce", "https://registry.my-netdata.io");
registry.cloud_base_url = config_get(CONFIG_SECTION_CLOUD, "cloud base url", "https://netdata.cloud");
registry.hostname = config_get(CONFIG_SECTION_REGISTRY, "registry hostname", netdata_configured_hostname);
registry.verify_cookies_redirects = config_get_boolean(CONFIG_SECTION_REGISTRY, "verify browser cookies support", 1);

// netdata.cloud configuration, if cloud_base_url == "", cloud functionality is disabled.
registry.cloud_base_url = config_get(CONFIG_SECTION_CLOUD, "cloud base url", "https://netdata.cloud");

setenv("NETDATA_REGISTRY_HOSTNAME", registry.hostname, 1);
setenv("NETDATA_REGISTRY_URL", registry.registry_to_announce, 1);

Expand Down
49 changes: 39 additions & 10 deletions web/gui/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ if (typeof netdataShowAlarms === 'undefined') {
}

if (typeof netdataRegistryAfterMs !== 'number' || netdataRegistryAfterMs < 0) {
netdataRegistryAfterMs = 1500;
netdataRegistryAfterMs = 0; // 1500;
}

if (typeof netdataRegistry === 'undefined') {
Expand Down Expand Up @@ -9677,6 +9677,7 @@ NETDATA.alarms = {

NETDATA.registry = {
server: null, // the netdata registry server
isCloudEnabled: false,// is netdata.cloud functionality enabled?
cloudBaseURL: null, // the netdata cloud base url
person_guid: null, // the unique ID of this browser / user
machine_guid: null, // the unique ID the netdata server that served dashboard.js
Expand All @@ -9685,8 +9686,17 @@ NETDATA.registry = {
machines_array: null, // the user's other URLs in an array
person_urls: null,

MASKED_DATA: "***",

isUsingGlobalRegistry: function() {
return NETDATA.registry.server == "https://registry.my-netdata.io";
},

isRegistryEnabled: function() {
return !(NETDATA.registry.isUsingGlobalRegistry() || isSignedIn())
},

parsePersonUrls: function (person_urls) {
// console.log(person_urls);
NETDATA.registry.person_urls = person_urls;

if (person_urls) {
Expand Down Expand Up @@ -9739,14 +9749,21 @@ NETDATA.registry = {
NETDATA.registry.hello(NETDATA.serverDefault, function (data) {
if (data) {
NETDATA.registry.server = data.registry;
NETDATA.registry.cloudBaseURL = data.cloud_base_url;
if (data.cloud_base_url != "") {
NETDATA.registry.isCloudEnabled = true;
NETDATA.registry.cloudBaseURL = data.cloud_base_url;
} else {
NETDATA.registry.isCloudEnabled = false;
NETDATA.registry.cloudBaseURL = "";
}
NETDATA.registry.machine_guid = data.machine_guid;
NETDATA.registry.hostname = data.hostname;
if (data.anonymous_statistics) dataLayer.push({"anonymous_statistics" : "true", "machine_guid" : data.machine_guid});
if (dataLayer) {
if (data.anonymous_statistics) dataLayer.push({"anonymous_statistics" : "true", "machine_guid" : data.machine_guid});
}
NETDATA.registry.access(2, function (person_urls) {
NETDATA.registry.parsePersonUrls(person_urls);

});
});
}
});
},
Expand Down Expand Up @@ -9789,13 +9806,25 @@ NETDATA.registry = {
},

access: function (max_redirects, callback) {
let name = NETDATA.registry.MASKED_DATA;
let url = NETDATA.registry.MASKED_DATA;

if (!NETDATA.registry.isUsingGlobalRegistry()) {
// If the user is using a private registry keep sending identifiable
// data.
name = NETDATA.registry.hostname;
url = NETDATA.serverDefault;
}

console.log("ACCESS", name, url);

// send ACCESS to a netdata registry:
// 1. it lets it know we are accessing a netdata server (its machine GUID and its URL)
// 2. it responds with a list of netdata servers we know
// the registry identifies us using a cookie it sets the first time we access it
// the registry may respond with a redirect URL to send us to another registry
$.ajax({
url: NETDATA.registry.server + '/api/v1/registry?action=access&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(NETDATA.registry.hostname) + '&url=' + encodeURIComponent(NETDATA.serverDefault), // + '&visible_url=' + encodeURIComponent(document.location),
url: NETDATA.registry.server + '/api/v1/registry?action=access&machine=' + NETDATA.registry.machine_guid + '&name=' + encodeURIComponent(name) + '&url=' + encodeURIComponent(url), // + '&visible_url=' + encodeURIComponent(document.location),
async: true,
cache: false,
headers: {
Expand Down Expand Up @@ -9827,14 +9856,14 @@ NETDATA.registry = {
return callback(null);
}
}
}
else {
} else {
if (typeof data.person_guid === 'string') {
NETDATA.registry.person_guid = data.person_guid;
}

if (typeof callback === 'function') {
return callback(data.urls);
const urls = data.urls.filter((u) => u[1] !== NETDATA.registry.MASKED_DATA);
return callback(urls);
}
}
})
Expand Down
9 changes: 7 additions & 2 deletions web/gui/goto-host-from-alarm.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
<html lang="en">
<head>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-N6CBMJD');
dataLayer.push({"anonymous_statistics" : "false"});
</script>
<title>Goto a host you know...</title>
<meta name="application-name" content="netdata">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

</head>
<script>
var netdataRegistry = true;
Expand Down
Loading

0 comments on commit 187eff5

Please sign in to comment.