Recently I’ve talked about the new cPanel feature – Security Policies – and there is no way to restrict root logins only to valid or allowed ip addresses until now.
The cPanel’s Security Policy is a framework which let you improve you security or practices. For example take the test server tnt.ruyrocha.com and its root password 3Y6Nn5CW44bY0F?5F}gHoWDy:KFzAGtp Go ahead and try to access it: https://tnt.ruyrocha.com:2087/login/?user=root&pass=3Y6Nn5CW44bY0F?5F}gHoWDy:KFzAGtp
TNT will be available until next Friday, 02/09, so feel free to give it a try. I don’t want anyone being able to access it from home, just from office’s ip address. The RestrictRoot security policy module must be included in /usr/local/cpanel/Cpanel/SecurityPolicy as follows:
package Cpanel::SecurityPolicy::RestrictRoot; # cpanel - Cpanel/SecurityPolicy/RestrictRoot.pm # # Copyright (c) 2011 Ruy Rocha # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in the # Software without restriction, including without limitation the rights to use, copy, # modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, subject to the # following conditions: # # The above copyright notice and this permission notice shall be included in all copies # or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE # USE OR OTHER DEALINGS IN THE SOFTWARE. # my $priority = 20; sub check { my ( $acctref, $sec_ctxt, $cpconf_ref, $cookie_ref ) = @_; if ( $sec_ctxt->{'appname'} eq 'whostmgrd' && $acctref->{'user'} eq 'root' ) { return _ip_passes($sec_ctxt->{'remoteip'}); } return 0; } # Return true if this address is valid, false otherwise. sub _ip_passes { my $remote_ip = shift; my @allowed_ips = ('187.x.x.x', '17.x.x.x'); if ( !$remote_ip ) { Carp::confess("I am missing the users remote ip. Security Policy requires exec termination."); } return $priority if !grep(/$remote_ip$/, @allowed_ips); return 0; } 1;
Save the code to /usr/local/cpanel/Cpanel/SecurityPolicy/RestrictRoot.pm and activate the module on WHM.





how exactly do you install this and activate
I created the /usr/local/cpanel/Cpanel/SecurityPolicy/RestrictRoot.pm file, but see no where to ‘activate this’ in whm. Under Security policies i see 3 check boxes for the other 3 standard cpanel security policy checkboxes, but nothing about this one visible.
Could you elbaorate briefly on that, as this looks like a great idea!
11 de setembro de 2011Ruy Rocha
Did you restart cPanel after put the module there?
16 de setembro de 2011