The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Firewall::PaloAlto - Interact with a Palo Alto firewall's API through Perl.

VERSION

Version 0.03

SYNOPSIS

The Firewall::PaloAlto module provides interfaces into the XML API of a Palo Alto firewall.

    use Firewall::PaloAlto;

    my $fw = Firewall::PaloAlto->new(host => 'pa.local', username => 'admin', password => 'admin');
    $fw->connect();

    #Add a new virtual system
    $fw->address('set', vsys_id => 6, 'display-name' => "Script_Tenant");

    #Add a virtual router to the chassis
    $fw->virtual_router('set', vr_name => 'NEW_VR', interface => [ 'ae1.65', 'ae1.66' ]);

    #Add a new address - if the vsys is not specified it defaults to vsys1.
    #This works for devices such as the VM series, which only have a vsys1. 
    $fw->address('set', name => 'Google_DNS', ip-netmask => '8.8.8.8/32');

    #Get the configuration for the newly created address:
    my $address_config = $fw->address('get', name => 'Google_DNS');

    #Delete the newly created address
    $fw->address('delete', name => 'Google_DNS);

A list of functions that can be exported. You can delete this section if you don't export anything, such as for a purely object-oriented module.

CLASS METHODS

new(%parameters)

The constructor generates a new object to interact with a specific firewall.

The host, username and password parameters are mandatory. If not specified, SSL is used, but it can be disabled using the argument ssl => 0

Detailed debugging can be turned on using the debug => 1 argument. It is off by default.

This method is inherited from the Firewall::PaloAlto::Common role.

    my $palo = Firewall::PaloAlto->new(host => 'paloalto.local', username => 'admin', password => 'admin', ssl => 0, debug => 1);

Parameters

  • host - the hostname or IP of the firewall to connect to.

  • username - a username to connect to the firewall.

  • password - a password to connect to the firewall.

  • ssl (optional, default: 1) - use SSL to connect to the firewall.

  • debug (optional, default: 0) - print debugging messages.

CONFIGURATION METHODS

connect()

The connect functions connects to the Palo Alto, validates and saves the API key. It has no parameters and is inherited from the Firewall::PaloAlto::Common role.

    $pa->connect();

commit(%parameters)

The commit function commits the current candidate configuration to the Palo Alto firewall.

    $pa_firewall->commit(vsys_id => 10, poll => 10);

Parameters

  • vsys_id (optional) - if supplied, performs a partial commit on the vsys specified. If not provided, performs a full commit on the device.

  • poll (optional, default: 5 seconds) - defines the interval (seconds) that the method will poll the device to get the current status of the commit job.

vsys($action, %parameters)

The vsys function creates a new virtual system.

 $pa->vsys('set', vsys_id => 4, display-name => "Tenant 4");

Parameters

  • $action - perform an action: ['get' | 'set' | 'delete']

  • vsys_id - the ID of the virtual system to perform the action on.

  • display-name - sets the display name of the virtual system.

vsys_import($action, %parameters);

The vsys_import function imports interfaces and virtual-routers into a virtual system.

    $pa_firewall->vsys_import('set', vsys_id => 4, interface => [ ethernet1/1, ethernet1/2 ], virtual-router => [ default ]);

Parameters

  • $action - perform an action: ['get' | 'set' | 'delete']

  • vsys_id - the ID of the virtual system to perform the action on.

  • interface - an anonymous array of one or more interfaces to add to the virtual system.

  • virtual-router - an anonymous array of one or more virtual routers to add to the virtual system.

l3_subinterface($action, %parameters)

This function creates a new layer 3 subinterface underneath a parent interface.

    $pa->l3_subinterface('set', parent => 'ethernet1/1', tag => 5, description => 'Tenant x untrust interface');

Parameters

  • $action - perform an action: ['get' | 'set' | 'delete']

  • parent - the parent interface of the new subinterface

  • tag - the VLAN tag to use on the sub-interface. This is also used as the logical sub-interface identifier.

  • description - a description to add to the sub-interface.

virtual_router($action, %parameters)

Parameters

  • $action - perform an action: ['get' | 'set' | 'delete']

  • vr_name - the name of the virtual router to perform the action on.

  • interface - an anonymous array of one or more interfaces to add to the virtual router.

zone($action, %parameters)

Parameters

  • $action - perform an action: ['get' | 'set' | 'delete']

  • vsys_id - the virtual system ID to which the zone is/should be a member of.

  • zone - the name of the zone to create/update/delete.

  • layer3 - an anonymous array of one or more interfaces to add to the zone.

ipv4_static_route($action, %parameters)

Parameters

  • $action - perform an action: ['get' | 'set' | 'delete']

  • vr_name - the name of the virtual router in which the static route resides.

  • route_name - the name of the route to perform the action on.

  • destination - the IPv4 destination of the route (IP/prefix)

  • nexthop - an anonymous hash specifying the next hop

  • ip-address - the next hop IP address

  • interface - the next hop interface

ipv6_static_route($action, %parameters)

Parameters

  • $action - perform an action: ['get' | 'set' | 'delete']

  • vr_name - the name of the virtual router in which the static route resides.

  • route_name - the name of the route to perform the action on.

  • destination - the IPv6 destination of the route (IP/prefix)

  • nexthop - an anonymous hash specifying the next hop

  • ipv6-address - the next hop IPv6 address

  • interface - the next hop interface

address($action, %parameters)

Parameters

  • vsys_id - the vsys ID in which the resides/shall reside.

  • name - the name of the address.

  • ip-netmask - the IP/netmask combination which defines the address.

  • ip-range - an IP address range (format: 'IPstart-IPend')

address_group($action, %parameters)

Parameters

  • $action - perform an action: ['get' | 'set' | 'delete']

  • vsys_id - the vsys ID in which the address group resides/shall reside.A

  • name - the name of the address group.

  • member - an anonymous array of one or more addresses. These can be either address entries created with address(), or explicit IP/netmasks (e.g. 9.8.8.8/32)

security_rule($action, %parameters)

Parameters

  • $action - perform an action: ['get' | 'set' | 'delete']

  • vsys_id - the virtual system ID of the vsys in which the security rule resides/will reside. Defaults to 1 if not supplied.

  • name - the name of the rule.

  • from - the source zone, defaults to 'any' if not supplied.

  • to - the destination zone, defaults to 'any' if not supplied.

  • source - an anonymous array of source addresses - can be addresses, address groups or explicit IP/netmask entries. Defaults to 'any' if not supplied.

  • destination - an anonymous array of destination addresses - can be addresses, address groups or explicit IP/netmask entries. Defaults to 'any' if not supplied.

  • service - an anonymous array of one or more services. Defaults to 'application-default' if not supplied.

  • appplication - an anonymous array of one or more Palo Alto applications. Defaults to 'any' if not supplied.

  • source-user - an anonymous array of one or more Palo Alto source user mappings. Defaults to 'any' if not supplied.

  • hip-profile - an anonymous array of Host Information Profiles. defaults to 'any' if not supplied.

  • action - an action for the rule, either 'allow', 'deny' or 'drop'. Defaults to 'allow' if not supplied.

OPERATIONAL METHODS

get_system_info()

Returns a HASHREF containing information about the system.

get_routing_table()

Retrieves the routing table of a particular router. If no virtual router is specified, defaults to the 'default' virtual router.

The return value is an object of type Firewall::PaloAlto::Routes.

AUTHOR

Greg Foletta, <greg at foletta.org>

BUGS

Please report any bugs or feature requests to bug-firewall-paloalto at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Firewall-PaloAlto. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Firewall::PaloAlto

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2015 Greg Foletta.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.