Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
check that user IP is contained in director security group cidrs
Browse files Browse the repository at this point in the history
this allows for CIDRs in the security group other than /32

Signed-off-by: Colin Simmons <[email protected]>
  • Loading branch information
Panagiotis Xynos authored and crsimmons committed Jan 11, 2019
1 parent 471fc76 commit e6f6af6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions iaas/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package iaas

import (
"fmt"
"net"
"strings"
"time"

Expand Down Expand Up @@ -112,7 +113,7 @@ func (a *AWSProvider) listZones() ([]string, error) {
// CheckForWhitelistedIP checks if the specified IP is whitelisted in the security group
func (a *AWSProvider) CheckForWhitelistedIP(ip, securityGroup string) (bool, error) {

cidr := fmt.Sprintf("%s/32", ip)
parsedIP := net.ParseIP(ip)

ec2Client := ec2.New(a.sess)

Expand All @@ -130,7 +131,11 @@ func (a *AWSProvider) CheckForWhitelistedIP(ip, securityGroup string) (bool, err
port22, port6868, port25555 := false, false, false
for _, entry := range ingressPermissions {
for _, sgIP := range entry.IpRanges {
checkPorts(*sgIP.CidrIp, cidr, &port22, &port6868, &port25555, *entry.FromPort)
_, parsedCIDR, err := net.ParseCIDR(*sgIP.CidrIp)
if err != nil {
return false, err
}
checkPorts(parsedCIDR, parsedIP, &port22, &port6868, &port25555, *entry.FromPort)
}
}

Expand All @@ -141,8 +146,8 @@ func (a *AWSProvider) CheckForWhitelistedIP(ip, securityGroup string) (bool, err
return false, nil
}

func checkPorts(sgCidr, cidr string, port22, port6868, port25555 *bool, fromPort int64) {
if sgCidr == cidr {
func checkPorts(cidr *net.IPNet, ip net.IP, port22, port6868, port25555 *bool, fromPort int64) {
if cidr.Contains(ip) {
switch fromPort {
case 22:
*port22 = true
Expand Down

0 comments on commit e6f6af6

Please sign in to comment.