iControl Perl - Authentication
Another thing that each of these iControl Perl scripts is going to need to do is to authenticate with the BigIP ltm. Since you are connecting using https, you are going to be using Basic Authentication. Below are a couple of options for setting authentication up.
The first method, which seems to be the most popular, is to insert the userid and password into SOAP::Lite's get_basic_credentials method, which would get set prior to creating your soap request. For example:
my $host = "the_bigip_hostname_or_ipaddr" my $port = "443"; my $uid = "some_user_id"; my $pwd = "some_password"; sub SOAP::Transport::HTTP::Client::get_basic_credentials { return "$uid" => "$pwd"; } # This is the base request my $req = SOAP::Lite -> uri('urn:iControl:LocalLB/Pool') -> proxy("https://$host:$port/iControl/iControlPortal.cgi");
Using this method, the request will get sent to your bigip, the bigip will respond with a 401 Unauthorized status code, and then the request will be retried with the UserID and password. If you want to skip the initial authentication failure, add the following code after the code which creates the request. This will add an Authorization header with your encoded userid and password on every request:
# Add authorization header; Otherwise the # initial request will fail eval { $req->transport->http_request->header ( 'Authorization' => 'Basic ' . MIME::Base64::encode("$uid:$pwd", '')); };
The second method employs a similar technique to what you would employ if you were setting an ftp_proxy environment variable in your .bashrc—insert the userid and password separated by a colon and then separate the password from the URL with an @ symbol. For example:
export ftp_proxy=$USERID:[email protected]
With iControl, you would modify the proxy parameter in your request to use the same syntax:
my $host = "the_bigip_hostname_or_ipaddr" my $port = "443"; my $uid = "some_user_id"; my $pwd = "some_password"; my $req = SOAP::Lite -> uri('urn:iControl:LocalLB/Pool') -> proxy("https://$uid:$pwd@$host:$port/iControl/iControlPortal.cgi");
Other Posts in This Series
<< Previous iControl Perl - User Accounts