AWS code-library documentation change
Summary
Added PowerShell V5 examples for Grant-EC2SecurityGroupIngress with specific port restrictions and security group references
Security assessment
Documents proper ingress rule configuration which is security-related, but no indication of fixing a specific vulnerability
Diff
diff --git a/code-library/latest/ug/ec2_example_ec2_AuthorizeSecurityGroupIngress_section.md b/code-library/latest/ug/ec2_example_ec2_AuthorizeSecurityGroupIngress_section.md index aad8d4392..46820cd93 100644 --- a//code-library/latest/ug/ec2_example_ec2_AuthorizeSecurityGroupIngress_section.md +++ b//code-library/latest/ug/ec2_example_ec2_AuthorizeSecurityGroupIngress_section.md @@ -889,0 +890,86 @@ PowerShell +**Tools for PowerShell V5** + + +**Example 1: This example defines ingress rules for a security group for EC2-VPC. These rules grant access to a specific IP address for SSH (port 22) and RDC (port 3389). Note that you must identify security groups for EC2-VPC using the security group ID not the security group name. The syntax used by this example requires PowerShell version 3 or higher.** + + + $ip1 = @{ IpProtocol="tcp"; FromPort="22"; ToPort="22"; IpRanges="203.0.113.25/32" } + $ip2 = @{ IpProtocol="tcp"; FromPort="3389"; ToPort="3389"; IpRanges="203.0.113.25/32" } + + Grant-EC2SecurityGroupIngress -GroupId sg-12345678 -IpPermission @( $ip1, $ip2 ) + + +**Example 2: With PowerShell version 2, you must use New-Object to create the IpPermission objects.** + + + $ip1 = New-Object Amazon.EC2.Model.IpPermission + $ip1.IpProtocol = "tcp" + $ip1.FromPort = 22 + $ip1.ToPort = 22 + $ip1.IpRanges.Add("203.0.113.25/32") + + $ip2 = new-object Amazon.EC2.Model.IpPermission + $ip2.IpProtocol = "tcp" + $ip2.FromPort = 3389 + $ip2.ToPort = 3389 + $ip2.IpRanges.Add("203.0.113.25/32") + + Grant-EC2SecurityGroupIngress -GroupId sg-12345678 -IpPermission @( $ip1, $ip2 ) + + +**Example 3: This example defines ingress rules for a security group for EC2-Classic. These rules grant access to a specific IP address for SSH (port 22) and RDC (port 3389). The syntax used by this example requires PowerShell version 3 or higher.** + + + $ip1 = @{ IpProtocol="tcp"; FromPort="22"; ToPort="22"; IpRanges="203.0.113.25/32" } + $ip2 = @{ IpProtocol="tcp"; FromPort="3389"; ToPort="3389"; IpRanges="203.0.113.25/32" } + + Grant-EC2SecurityGroupIngress -GroupName "my-security-group" -IpPermission @( $ip1, $ip2 ) + + +**Example 4: With PowerShell version 2, you must use New-Object to create the IpPermission objects.** + + + $ip1 = New-Object Amazon.EC2.Model.IpPermission + $ip1.IpProtocol = "tcp" + $ip1.FromPort = 22 + $ip1.ToPort = 22 + $ip1.IpRanges.Add("203.0.113.25/32") + + $ip2 = new-object Amazon.EC2.Model.IpPermission + $ip2.IpProtocol = "tcp" + $ip2.FromPort = 3389 + $ip2.ToPort = 3389 + $ip2.IpRanges.Add("203.0.113.25/32") + + Grant-EC2SecurityGroupIngress -GroupName "my-security-group" -IpPermission @( $ip1, $ip2 ) + + +**Example 5: This example grants TCP port 8081 access from the specified source security group (sg-1a2b3c4d) to the specified security group (sg-12345678).** + + + $ug = New-Object Amazon.EC2.Model.UserIdGroupPair + $ug.GroupId = "sg-1a2b3c4d" + $ug.UserId = "123456789012" + + Grant-EC2SecurityGroupIngress -GroupId sg-12345678 -IpPermission @( @{ IpProtocol="tcp"; FromPort="8081"; ToPort="8081"; UserIdGroupPairs=$ug } ) + + +**Example 6: This example adds the CIDR 5.5.5.5/32 to the Ingress rules of security Group sg-1234abcd for TCP port 22 traffic with a description.** + + + $IpRange = New-Object -TypeName Amazon.EC2.Model.IpRange + $IpRange.CidrIp = "5.5.5.5/32" + $IpRange.Description = "SSH from Office" + $IpPermission = New-Object Amazon.EC2.Model.IpPermission + $IpPermission.IpProtocol = "tcp" + $IpPermission.ToPort = 22 + $IpPermission.FromPort = 22 + $IpPermission.Ipv4Ranges = $IpRange + Grant-EC2SecurityGroupIngress -GroupId sg-1234abcd -IpPermission $IpPermission + + + * For API details, see [AuthorizeSecurityGroupIngress](https://docs.aws.amazon.com/powershell/v5/reference) in _AWS Tools for PowerShell Cmdlet Reference (V5)_. + + + +