Skip to content

Unauthorized agents should be recorded into logs #5725

Closed

Description

@bmfmancini

If you dont have a reverse DNS or IP set for the remote poller to verify the main poller
an error reporting you are not authorized to use this service should appear

However I am seeing it does not

here is the function

	if (get_nfilter_request_var('action') == 'runquery') {
		db_force_remote_cnn();
	}

	$poller_db_cnn_id = $remote_db_cnn_id;
} else {
	$poller_db_cnn_id = false;
}

if (!remote_client_authorized()) {
	print 'FATAL: Client authorization failed.  You are not authorized to use this service';
	exit;
}

set_default_action();


function remote_client_authorized() {
	global $config, $poller_db_cnn_id;

	/* don't allow to run from the command line */
	$client_addr = get_client_addr();
	if ($client_addr === false) {
		return false;
	}

	if (!filter_var($client_addr, FILTER_VALIDATE_IP)) {
		cacti_log('ERROR: Invalid remote agent client IP Address.  Exiting');
		return false;
	}

	$client_name = gethostbyaddr($client_addr);

	if ($client_name == $client_addr) {
		cacti_log('NOTE: Unable to resolve hostname from address ' . $client_addr, false, 'WEBUI', POLLER_VERBOSITY_MEDIUM);
	} else {
		$client_name = remote_agent_strip_domain($client_name);
	}

	$pollers = db_fetch_assoc('SELECT * FROM poller WHERE disabled = ""', true, $poller_db_cnn_id);

	if (cacti_sizeof($pollers) > 1) {
		foreach($pollers as $poller) {
			if (remote_agent_strip_domain($poller['hostname']) == $client_name) {
				return true;
			} elseif ($poller['hostname'] == $client_addr) {
				return true;
			}
		}
	}

	cacti_log("Unauthorized remote agent access attempt from $client_name ($client_addr)");

	return false;
}

``

Activity

  1. bmfmancini commented on Apr 13, 2024

    @bmfmancini
    MemberAuthor

    image

    Viewing device on Master that is located on remote

    image

    Remote Poller Log does not record the access attempt

    2024-04-13 11:36:05 - SYSTEM MAINT STATS: Time:0.01
    2024-04-13 11:36:04 - SYSTEM STATS: Time:1.1237 Method:spine Processes:1 Threads:1 Hosts:1 HostsPerProcess:1 DataSources:1 RRDsProcessed:0
    2024-04-13 11:35:05 - SYSTEM MAINT STATS: Time:0.02
    2024-04-13 11:35:04 - SYSTEM STATS: Time:1.1288 Method:spine Processes:1 Threads:1 Hosts:1 HostsPerProcess:1 DataSources:1 RRDsProcessed:0
    2024-04-13 11:34:05 - SYSTEM MAINT STATS: Time:0.02
    2024-04-13 11:34:04 - SYSTEM STATS: Time:1.1233 Method:spine Processes:1 Threads:1 Hosts:1 HostsPerProcess:1 DataSources:1 RRDsProcessed:0
    

    Main poller does not record the error as a unauthorized user but records

    024-04-13 11:37:04 - SYSTEM STATS: Time:1.2344 Method:spine Processes:1 Threads:1 Hosts:1 HostsPerProcess:1 DataSources:5 RRDsProcessed:0
    2024-04-13 11:36:18 - CMDPHP PHP ERROR WARNING Backtrace: (/host.php[143]:api_device_ping_device(), /lib/api_device.php[1504]:file_get_contents(), CactiErrorHandler())
    2024-04-13 11:36:18 - ERROR PHP WARNING: file_get_contents(http://foo.bar.com/cacti/remote_agent.php?action=ping&host_id=2): Failed to open stream: HTTP request failed! in file: /var/www/html/cacti/lib/api_device.php on line: 1504
    
  2. changed the title [-][1.2.27] - Remote Agent is not recording not authorized agent in log[/-] [+][1.2.27] - [QA] - Remote Agent is not recording not authorized agent in log[/+] on Apr 13, 2024
  3. TheWitness commented on Apr 13, 2024

    @TheWitness
    Member

    Can you do a pull request @bmfmancini ?

  4. bmfmancini commented on Apr 13, 2024

    @bmfmancini
    MemberAuthor

    That function is what already there
    I'll do some debug haven't spent much time on it yet

  5. TheWitness commented on Apr 14, 2024

    @TheWitness
    Member

    Can the remote data collector even reach foo.bar.com? If it can not reach it, of course it will error out and the main data collector will never log an issue.

  6. bmfmancini commented on Apr 14, 2024

    @bmfmancini
    MemberAuthor

    the poller IP is correct but the hostname is differnt
    So the main can reach the remote but it will not be authorized to admin any devices on it

  7. TheWitness commented on Apr 14, 2024

    @TheWitness
    Member

    So, the warning should be at the remote or at the main?

  8. bmfmancini commented on Apr 14, 2024

    @bmfmancini
    MemberAuthor
  9. bmfmancini commented on Apr 14, 2024

    @bmfmancini
    MemberAuthor
  10. TheWitness commented on Apr 14, 2024

    @TheWitness
    Member

    So, the current error is not good enough?

  11. TheWitness commented on Apr 14, 2024

    @TheWitness
    Member

    Or would you like it more meaningful? I would want to de-bounce notification for something like this for sure.

  12. bmfmancini commented on Apr 14, 2024

    @bmfmancini
    MemberAuthor

    It seems to be a regression

    Usually the remote would log that an error has occurred and the main would display an authorization failure not thag it cannot connect to the poller

  13. changed the title [-][1.2.27] - [QA] - Remote Agent is not recording not authorized agent in log[/-] [+]Remote Agent is not recording not authorized agent in log[/+] on Apr 14, 2024
  14. added
    confirmedBug is confirm by dev team
    and removed
    unverifiedSome days we don't have a clue
    on Apr 14, 2024
  15. added a commit that references this issue on Apr 14, 2024
  16. added this to the 1.2.27 milestone on Apr 14, 2024
  17. bmfmancini commented on Apr 14, 2024

    @bmfmancini
    MemberAuthor

    This is good now 👍

  18. added a commit that references this issue on Apr 15, 2024
  19. changed the title [-]Remote Agent is not recording not authorized agent in log[/-] [+]Unauthorized agents should be recorded into logs[/+] on Apr 28, 2024
  20. locked and limited conversation to collaborators on Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUndesired behaviourconfirmedBug is confirm by dev teamresolvedA fixed issuestatus:confirmedNamespaced Cacti workflow labeltype:bugNamespaced Cacti workflow label

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions