]> git.proxmox.com Git - pmg-api.git/commitdiff
PMG/HTTPServer.pm: add safety check for master node
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 6 Apr 2017 05:17:55 +0000 (07:17 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 6 Apr 2017 05:17:55 +0000 (07:17 +0200)
We want to verify that we are on the master node.

PMG/HTTPServer.pm
PMG/RESTEnvironment.pm

index ed2849138c81f684b6a3bb05820f66e0bdb8839a..26a2015c516db26e6627b326ac6acc480977d196 100755 (executable)
@@ -112,8 +112,7 @@ sub rest_handler {
        # check access permissions
        PMG::AccessControl::check_api2_permissions($info->{permissions}, $auth->{userid});
 
-       if ($info->{proxyto}) {
-           my $pn = $info->{proxyto};
+       if (my $pn = $info->{proxyto}) {
 
            my $node;
            if ($pn eq 'master') {
@@ -137,6 +136,12 @@ sub rest_handler {
            return;
        }
 
+       if (my $pn = $info->{proxyto}) {
+           if ($pn eq 'master') {
+               $rpcenv->check_node_is_master();
+           }
+       }
+
        $resp = {
            data => $handler->handle($info, $uri_param),
            info => $info, # useful to format output
index cde486dbc4bd7ffe323c967d772232be7d4ef5b3..b25d62a97cc1c5325dd54cd515014877c2d2ed58 100644 (file)
@@ -3,12 +3,16 @@ package PMG::RESTEnvironment;
 use strict;
 use warnings;
 
+use PVE::INotify;
 use PVE::RESTEnvironment;
 
+use PMG::Cluster;
 use PMG::ClusterConfig;
 
 use base qw(PVE::RESTEnvironment);
 
+my $nodename = PVE::INotify::nodename();
+
 # initialize environment - must be called once at program startup
 sub init {
     my ($class, $type, %params) = @_;
@@ -31,4 +35,16 @@ sub init_request {
     $self->{cinfo} = PVE::INotify::read_file("cluster.conf");
 }
 
+sub check_node_is_master {
+    my ($self, $noerr);
+
+    my $master = PMG::Cluster::get_master_node($self->{cinfo});
+
+    return 1 if $master eq 'localhost' || $master eq $nodename;
+
+    return undef if $noerr;
+
+    die "this node ('$nodename') is not the master node\n";
+}
+
 1;