VM::EC...yGroup(3pm)
π VM::EC2::SecurityGroup β the perl manual, but make it cute π
okay bestie, gather round, because this is the VM::EC2::SecurityGroup page from the User Contributed Perl Documentation, and it's literally all about describing an Amazon EC2 security group. it's giving firewall rules, but make it β¨documentationβ¨.
πΈ NAME πΈ
VM::EC2::SecurityGroup β an object that describes an Amazon EC2 security group π‘οΈ
β¨ SYNOPSIS β¨
here's the whole vibe, copy it exactly, no cap:
use VM::EC2;
$ec2 = VM::EC2->new(...);
@sg = $ec2->describe_security_groups;
for my $sg (@sg) {
$name = $sg->groupName;
$id = $sg->groupId;
$desc = $sg->groupDescription;
$tags = $sg->tags;
@inbound_permissions = $sg->ipPermissions;
@outbound_permissions = $sg->ipPermissionsEgress;
for $i (@inbound_permissions) {
$protocol = $i->ipProtocol;
$fromPort = $i->fromPort;
$toPort = $i->toPort;
@ranges = $i->ipRanges;
}
}
$sg = $sg[0];
# Add a new security rule
$sg->authorize_incoming(-protocol => 'tcp',
-port => 80,
-source_ip => ['192.168.2.0/24','192.168.2.1/24']);
# write it to AWS.
$sg->update();
π¦ DESCRIPTION π¦
so this object is the whole personality of an Amazon EC2 security group π
. you get one back from VM::EC2->describe_security_groups(). you can ALSO get one by calling an Instance object's groups() method, and then invoking one of the group's permissions() method. see VM::EC2::Group for that one, bestie.
π METHODS π
the following object methods are supported, and yes, every single one slays:
ownerIdβ Owner of this security groupgroupIdβ ID of this security groupgroupNameβ Name of this security groupgroupDescriptionβ Description of this groupvpcIdβ Virtual Private Cloud ID, if applicableipPermissionsβ A list of rules that govern incoming connections to instances running under this security group. Each rule is aVM::EC2::SecurityGroup::IpPermissionobject.ipPermissionsEgressβ A list of rules that govern outgoing connections from instances running under this security group. Each rule is aVM::EC2::SecurityGroup::IpPermissionobject. This field is only valid for VPC groups.tagsβ Hashref containing tags associated with this group. SeeVM::EC2::Generic.
and for convenience, these aliases are provided for the commonly used methods (iconic behaviour tbh):
inbound_permissionsβ same asipPermissions()outbound_permissionsβ same asipPermissionsEgress()nameβ same asgroupName()
see VM::EC2::SecurityGroup::IpPermission for the deets on accessing port numbers, IP ranges and other fields associated with incoming and outgoing firewall rules π§
π₯ MODIFYING FIREWALL RULES π₯
to add or revoke firewall rules, call the authorize_incoming, authorize_outgoing, revoke_incoming or revoke_outgoing() methods one or more times. each of these methods either adds or removes a single firewall rule, so don't be surprised. after adding or revoking the desired rules, call update() to write the modified group back to Amazon. the object will change to reflect the new permissions. periodt.
π $permission = $group->authorize_incoming(%args)
add a rule for incoming firewall traffic. the arguments are as follows:
-protocolβ The protocol, either a string (tcp,udp,icmp) or the corresponding protocol number (6,17,1). Use-1to indicate all protocols. (required)-port, -portsβ The port or port range. When referring to a single port, you may use either the port number or the service name (e.g."ssh"). For this to work the service name must be located in/etc/services. When specifying a port range, use"start..end"as in"8000..9000". Note that this is a string that contains two dots, and not two numbers separated by the perl range operator. For theicmpprotocol, this argument corresponds to the ICMP type number. (required)-group, -groupsβ Security groups to authorize. Instances that belong to the named security groups will be allowed access. You may specify either a single group or a list of groups as an arrayref. The following syntaxes are recognized:"sg-12345"β authorize group with this groupId"12345/my group"β authorize group named"my group"owned by user12345"my group"β authorize group named"my group"owned by yourself
-source, -source_ipβ Authorize incoming traffic from an IP address, IP address range, or set of such ranges. IP addresses use the CIDR notation ofa.b.c.d/mask, as described inhttp://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing. Pass an arrayref to simultaneously authorize multiple CIDR ranges.
the result of this call is a VM::EC2::SecurityGroup::IpPermission object corresponding to the rule you defined. note that the rule is not written to Amazon until you call update() π
here are some examples, bestie, use them well:
$sg->authorize_incoming(-protocol => 'tcp',
-port => 80,
-source_ip => ['192.168.2.0/24','192.168.2.1/24']);
# TCP on ports 22 and 23 from anyone
$sg->authorize_incoming(-protocol => 'tcp',
-port => '22..23',
-source_ip => '0.0.0.0/0');
# ICMP on echo (ping) port from anyone
$sg->authorize_incoming(-protocol => 'icmp',
-port => -1,
-source_ip => '0.0.0.0/0');
# TCP to port 25 (mail) from instances belonging to
# the "Mail relay" group belonging to user 12345678.
$sg->authorize_incoming(-protocol => 'tcp',
-port => 25,
-group => '12345678/Mail relay');
π $permission = $group->authorize_outgoing(%args)
this is identical to authorize_incoming() except that the rule applies to outbound traffic. only VPC security groups can define outgoing firewall rules, so keep that in mind π
π $permission = $group->revoke_incoming($rule) / $permission = $group->revoke_incoming(%args)
this method revokes an incoming firewall rule. you can call it with a single argument consisting of a VM::EC2::SecurityGroup::IpPermission object in order to revoke that rule. alternatively, when called with the named arguments listed for authorize_incoming(), it will attempt to match an existing rule to the provided arguments and queue it for deletion.
here's an example of revoking all rules that allow ssh (port 22) access:
@ssh_rules = grep {$_->fromPort == 22} $group->ipPermissions;
$group->revoke_incoming($_) foreach @ssh_rules;
$group->update();
π $boolean = $group->update()
this method will write all queued rule authorizations and revocations to Amazon, and return a true value if successful. the method will return false if any of the rule updates failed π. you can examine the VM::EC2 object's error_str() method to determine what went wrong, and check the group object's ipPermissions() method to see what firewall rules are currently defined.
β $boolean = $group->write()
an alias for update(). same energy, shorter name π
π«Ά $group->refresh()
this method refreshes the group information from Amazon. it is called automatically by update().
π§ STRING OVERLOADING π§
when used in a string context, this object will interpolate the groupId.
π« SEE ALSO π«
VM::EC2 VM::EC2::Generic VM::EC2::Instance VM::EC2::Group VM::EC2::SecurityGroup::IpPermission
π AUTHOR π
Lincoln Stein <lincoln.stein@gmail.com>.
Copyright (c) 2011 Ontario Institute for Cancer Research
This package and its accompanying libraries is free software; you can redistribute it and/or modify it under the terms of the GPL (either version 1, or at your option, any later version) or the Artistic License 2.0. Refer to LICENSE for the full license text. In addition, please see DISCLAIMER.txt for disclaimers of warranty.
and that's the whole page, bestie π no cap, every single flag and fact is in there. this was perl v5.38.2, dated 2024-08-10, and it's the VM::EC2::SecurityGroup page from the User Contributed Perl Documentation. mwah, go secure those groups π
β¨π¦
π¦ where this page comes from
- debian trixie: libvm-ec2-perl 1.28-5 Β· Artistic-2.0 OR GPL-1.0-or-later
- ubuntu resolute: libvm-ec2-perl 1.28-5 Β· Artistic-2.0 OR GPL-1.0-or-later
- ubuntu stonking: libvm-ec2-perl 1.28-5 Β· Artistic-2.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms