Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

CI/CD Improvements (#770)

Rich Turner55b085254f08
diff --git a/.ci_cd/aws/cloudformation-create-ec2.yml b/.ci_cd/aws/cloudformation-create-ec2.yml
index 56716549c..8d119780f 100644
--- a/.ci_cd/aws/cloudformation-create-ec2.yml
+++ b/.ci_cd/aws/cloudformation-create-ec2.yml
@@ -30,13 +30,26 @@ Parameters:
Type: String
#AllowedPattern: "^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9\-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$"
Default: ""
+ VpcId:
+ Description: VPC ID
+ Type: String
+ SubnetId:
+ Description: Subnet ID
+ Type: String
+ SSHSecurityGroupId:
+ Description: SSH Security Group ID
+ Type: String
+ ImageId:
+ Description: AMI ID
+ Type: String
+ Default: "ami-0a6b5206d1730bdce"
InstanceType:
Description: EC2 instance type (don't change it unless you know what you are doing)
Type: String
# AWS Compute Optimizer reports that this instance type is under-provisioned and advise
# more than double the price instance. As the requirements vary massively depending on the actual project
# then we need to be flexible here and bear in mind use case and acceptable cost.
- Default: t4g.small
+ Default: t4g.medium
AllowedValues:
- t4g.micro
- t4g.small
@@ -106,7 +119,7 @@ Resources:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "Access OpenRemote stack services"
- GroupName: !Ref Host
+ VpcId: !Ref VpcId
Tags:
- Key: Name
Value: !Ref Host
@@ -441,7 +454,7 @@ Resources:
args = parser.parse_args()
print(calculate_key(args.secret, args.region))
-
+
if __name__ == '__main__':
main()
owner: ec2-user
@@ -467,7 +480,7 @@ Resources:
fi
02_efs_dns:
command: !Sub |
- # Look for EFS filesystem called osts-filesystem and
+ # Look for EFS filesystem called hosts-filesystem and create env variable for it
FILESYSTEMID=$(aws efs describe-file-systems --query "FileSystems[?Name=='hosts-filesystem'].FileSystemId" --output text --region ${AWS::Region})
if [ -n "$FILESYSTEMID" ]; then
@@ -548,11 +561,12 @@ Resources:
Ref: InstanceType
KeyName:
"developers"
- ImageId:
- "ami-0042fede24cb86d5c"
- SecurityGroups:
- - "ssh-access"
+ ImageId: !Ref ImageId
+ SubnetId: !Ref SubnetId
+ SecurityGroupIds:
+ - Ref: SSHSecurityGroupId
- Ref: StandardSecurityGroup
+
Ipv6AddressCount: 1
Tags:
- Key: Name
@@ -594,8 +608,8 @@ Resources:
Properties:
InstanceId: !Ref EC2Instance
EIP: !Ref IPAddress
-
-# Telemetry and Alarms
+
+ # Telemetry and Alarms
EmailSubscription:
Type: AWS::SNS::Subscription
@@ -620,13 +634,13 @@ Resources:
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- - !Sub "arn:aws:automate:${AWS::Region}:ec2:recover"
- - !Ref SnsTopic
+ - !Sub "arn:aws:automate:${AWS::Region}:ec2:recover"
+ - !Ref SnsTopic
OKActions:
- - !Ref SnsTopic
+ - !Ref SnsTopic
Dimensions:
- - Name: InstanceId
- Value: !Ref EC2Instance
+ - Name: InstanceId
+ Value: !Ref EC2Instance
InstanceStatusAlarm:
Type: AWS::CloudWatch::Alarm
@@ -639,13 +653,13 @@ Resources:
ComparisonOperator: GreaterThanThreshold
Threshold: 0
AlarmActions:
- - !Sub "arn:aws:automate:${AWS::Region}:ec2:reboot"
- - !Ref SnsTopic
+ - !Sub "arn:aws:automate:${AWS::Region}:ec2:reboot"
+ - !Ref SnsTopic
OKActions:
- - !Ref SnsTopic
+ - !Ref SnsTopic
Dimensions:
- - Name: InstanceId
- Value: !Ref EC2Instance
+ - Name: InstanceId
+ Value: !Ref EC2Instance
CPUUtilizationAlarm:
Type: AWS::CloudWatch::Alarm
@@ -658,13 +672,13 @@ Resources:
ComparisonOperator: GreaterThanThreshold
Threshold: 90
AlarmActions:
- - !Sub "arn:aws:automate:${AWS::Region}:ec2:reboot"
- - !Ref SnsTopic
+ - !Sub "arn:aws:automate:${AWS::Region}:ec2:reboot"
+ - !Ref SnsTopic
OKActions:
- - !Ref SnsTopic
+ - !Ref SnsTopic
Dimensions:
- - Name: InstanceId
- Value: !Ref EC2Instance
+ - Name: InstanceId
+ Value: !Ref EC2Instance
HealthCheckAlarm:
Type: AWS::CloudWatch::Alarm
@@ -677,12 +691,12 @@ Resources:
ComparisonOperator: LessThanThreshold
Threshold: 1
AlarmActions:
- - !Ref SnsTopic
+ - !Ref SnsTopic
OKActions:
- - !Ref SnsTopic
+ - !Ref SnsTopic
Dimensions:
- - Name: HealthCheckId
- Value: !Ref HealthCheck
+ - Name: HealthCheckId
+ Value: !Ref HealthCheck
HealthCheck:
Type: AWS::Route53::HealthCheck
@@ -696,6 +710,6 @@ Resources:
RequestInterval: 30
FailureThreshold: 10
HealthCheckTags:
- - Key: Name
- Value: !Sub ${Host}
+ - Key: Name
+ Value: !Sub ${Host}
diff --git a/.ci_cd/aws/cloudformation-create-vpc.yml b/.ci_cd/aws/cloudformation-create-vpc.yml
new file mode 100644
index 000000000..05f293f2c
--- /dev/null
+++ b/.ci_cd/aws/cloudformation-create-vpc.yml
@@ -0,0 +1,132 @@
+# ---------------------------------------------------------------------------------------------------------------------
+# Create standard OpenRemote VPC with 2 public and 2 private subnets
+# ---------------------------------------------------------------------------------------------------------------------
+
+AWSTemplateFormatVersion: 2010-09-09
+Description: 'Creates standard OR VPC, subnets, route tables and IGW'
+
+Parameters:
+ IPV4CIDR:
+ Description: IPV4CIDR for VPC
+ Type: String
+
+Resources:
+ ## VPC
+ Vpc:
+ Type: AWS::EC2::VPC
+ Properties:
+ CidrBlock: !Ref IPV4CIDR
+ EnableDnsHostnames: true
+ EnableDnsSupport: true
+ InstanceTenancy: default
+ Tags:
+ - Key: Name
+ Value: or-vpc
+
+ VpcCidrBlockIpv6:
+ Type: AWS::EC2::VPCCidrBlock
+ Properties:
+ VpcId: !Ref Vpc
+ AmazonProvidedIpv6CidrBlock: true
+
+ SecurityGroup:
+ Type: AWS::EC2::SecurityGroup
+ Properties:
+ GroupDescription: "SSH access whitelist"
+ VpcId: !Ref Vpc
+ Tags:
+ - Key: Name
+ Value: ssh-access
+
+ ## SUBNETS
+ PublicSubnet1:
+ Type: AWS::EC2::Subnet
+ DependsOn: VpcCidrBlockIpv6
+ Properties:
+ VpcId: !Ref Vpc
+ AvailabilityZone: !Select [ 0, !GetAZs '' ]
+ CidrBlock: !Select [ 0, !Cidr [!Ref IPV4CIDR, 6, 8]]
+ Ipv6CidrBlock: !Select [1, !Cidr [!Select [0, !GetAtt 'Vpc.Ipv6CidrBlocks'], 7, 64]]
+ AssignIpv6AddressOnCreation: true
+ MapPublicIpOnLaunch: true
+ Tags:
+ - Key: Name
+ Value: or-subnet-public-1
+
+ PublicSubnet2:
+ Type: AWS::EC2::Subnet
+ DependsOn: VpcCidrBlockIpv6
+ Properties:
+ VpcId: !Ref Vpc
+ AvailabilityZone: !Select [ 1, !GetAZs '' ]
+ CidrBlock: !Select [ 1, !Cidr [!Ref IPV4CIDR, 6, 8]]
+ Ipv6CidrBlock: !Select [2, !Cidr [!Select [0, !GetAtt 'Vpc.Ipv6CidrBlocks'], 7, 64]]
+ AssignIpv6AddressOnCreation: true
+ MapPublicIpOnLaunch: true
+ Tags:
+ - Key: Name
+ Value: or-subnet-public-2
+
+ PrivateSubnet1:
+ Type: AWS::EC2::Subnet
+ DependsOn: VpcCidrBlockIpv6
+ Properties:
+ VpcId: !Ref Vpc
+ AvailabilityZone: !Select [ 0, !GetAZs '' ]
+ CidrBlock: !Select [ 2, !Cidr [!Ref IPV4CIDR, 6, 8]]
+ Ipv6CidrBlock: !Select [3, !Cidr [!Select [0, !GetAtt 'Vpc.Ipv6CidrBlocks'], 7, 64]]
+ AssignIpv6AddressOnCreation: true
+ MapPublicIpOnLaunch: false
+ Tags:
+ - Key: Name
+ Value: or-subnet-private-1
+
+ PrivateSubnet2:
+ Type: AWS::EC2::Subnet
+ DependsOn: VpcCidrBlockIpv6
+ Properties:
+ VpcId: !Ref Vpc
+ AvailabilityZone: !Select [ 1, !GetAZs '' ]
+ CidrBlock: !Select [ 3, !Cidr [!Ref IPV4CIDR, 6, 8]]
+ Ipv6CidrBlock: !Select [4, !Cidr [!Select [0, !GetAtt 'Vpc.Ipv6CidrBlocks'], 7, 64]]
+ AssignIpv6AddressOnCreation: true
+ MapPublicIpOnLaunch: false
+ Tags:
+ - Key: Name
+ Value: or-subnet-private-2
+
+ ## INTERNET GATEWAY
+ InternetGateway:
+ Type: AWS::EC2::InternetGateway
+
+ GatewayToInternet:
+ Type: AWS::EC2::VPCGatewayAttachment
+ Properties:
+ VpcId: !Ref Vpc
+ InternetGatewayId: !Ref InternetGateway
+
+ ## PUBLIC ROUTING
+ PublicRouteTable:
+ Type: AWS::EC2::RouteTable
+ Properties:
+ VpcId: !Ref Vpc
+
+ PublicRoute:
+ Type: AWS::EC2::Route
+ DependsOn: GatewayToInternet
+ Properties:
+ RouteTableId: !Ref PublicRouteTable
+ DestinationCidrBlock: 0.0.0.0/0
+ GatewayId: !Ref InternetGateway
+
+ PublicSubnet1RouteTableAssociation:
+ Type: AWS::EC2::SubnetRouteTableAssociation
+ Properties:
+ SubnetId: !Ref PublicSubnet1
+ RouteTableId: !Ref PublicRouteTable
+
+ PublicSubnet2RouteTableAssociation:
+ Type: AWS::EC2::SubnetRouteTableAssociation
+ Properties:
+ SubnetId: !Ref PublicSubnet2
+ RouteTableId: !Ref PublicRouteTable
diff --git a/.ci_cd/aws/provision_account.sh b/.ci_cd/aws/provision_account.sh
index ecb4472fb..a25b2caec 100644
--- a/.ci_cd/aws/provision_account.sh
+++ b/.ci_cd/aws/provision_account.sh
@@ -139,59 +139,59 @@ fi
# Update aws github-da profile with this account
source "${awsDir}set_github-da_account_arn.sh"
-# Re-instate default VPC (Control Tower removes it)
-VPCID=$(aws ec2 describe-vpcs --filters Name=is-default,Values=true --query "Vpcs[0].VpcId" --output text $ACCOUNT_PROFILE 2>/dev/null)
+# Check/Create VPC
+VPCID=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].VpcId" --output text $ACCOUNT_PROFILE 2>/dev/null)
if [ "$VPCID" == 'None' ]; then
- echo "Provisioning default VPC"
- VPCID=$(aws ec2 create-default-vpc --query "Vpc.VpcId" --output text $ACCOUNT_PROFILE)
-
- # Add IPv6 CIDR
- aws ec2 associate-vpc-cidr-block --amazon-provided-ipv6-cidr-block --ipv6-cidr-block-network-border-group $AWS_REGION --vpc-id $VPCID $ACCOUNT_PROFILE
- # Wait a short while for it to be provisioned
- sleep 10
- IPV6CIDR=$(aws ec2 describe-vpcs --vpc-ids $VPCID --query "Vpcs[0].Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock" --output text $ACCOUNT_PROFILE)
-
- # Add IPv6 CIDR to each subnet and add IPv6 route for internet gateway
- SUBNETID1=$(aws ec2 describe-subnets --filter "Name=vpc-id,Values=$VPCID" --query "Subnets[0].[SubnetId]" --output text $ACCOUNT_PROFILE)
- SUBNETID2=$(aws ec2 describe-subnets --filter "Name=vpc-id,Values=$VPCID" --query "Subnets[1].[SubnetId]" --output text $ACCOUNT_PROFILE)
- SUBNETID3=$(aws ec2 describe-subnets --filter "Name=vpc-id,Values=$VPCID" --query "Subnets[2].[SubnetId]" --output text $ACCOUNT_PROFILE)
- ROUTETABLEID=$(aws ec2 describe-route-tables --filters "Name=vpc-id,Values=$VPCID" --query "RouteTables[0].RouteTableId" --output text $ACCOUNT_PROFILE)
- IGWID=$(aws ec2 describe-internet-gateways --filters "Name=attachment.vpc-id,Values=$VPCID" --query "InternetGateways[0].InternetGatewayId" --output text $ACCOUNT_PROFILE)
- if [ -n "$SUBNETID1" ] && [ "$SUBNETID1" != 'None' ] && [ "$SUBNETID1" != 'none' ]; then
- echo "Adding IPv6 support to subnet '$SUBNETID1'"
- aws ec2 associate-subnet-cidr-block --ipv6-cidr-block ${IPV6CIDR%0::/56}1::/64 --subnet-id $SUBNETID1 $ACCOUNT_PROFILE
- aws ec2 modify-subnet-attribute --assign-ipv6-address-on-creation --subnet-id "$SUBNETID1" $ACCOUNT_PROFILE
- fi
- if [ -n "$SUBNETID2" ] && [ "$SUBNETID2" != 'None' ] && [ "$SUBNETID2" != 'none' ]; then
- echo "Adding IPv6 support to subnet '$SUBNETID3'"
- aws ec2 associate-subnet-cidr-block --ipv6-cidr-block ${IPV6CIDR%0::/56}2::/64 --subnet-id $SUBNETID2 $ACCOUNT_PROFILE
- aws ec2 modify-subnet-attribute --assign-ipv6-address-on-creation --subnet-id "$SUBNETID2" $ACCOUNT_PROFILE
- fi
- if [ -n "$SUBNETID3" ] && [ "$SUBNETID3" != 'None' ] && [ "$SUBNETID3" != 'none' ]; then
- echo "Adding IPv6 support to subnet '$SUBNETID3'"
- aws ec2 associate-subnet-cidr-block --ipv6-cidr-block ${IPV6CIDR%0::/56}3::/64 --subnet-id $SUBNETID3 $ACCOUNT_PROFILE
- aws ec2 modify-subnet-attribute --assign-ipv6-address-on-creation --subnet-id "$SUBNETID3" $ACCOUNT_PROFILE
+ echo "Provisioning OR VPC Stack"
+ # Create a new VPC with random IPv4 CIDR (so we can easily create peer connections between accounts)
+ OCTET1=$(( $RANDOM % 255 ))
+ OCTET2=$(( 5 * ($RANDOM % 51) ))
+ VPCIP4CIDR="10.$OCTET1.$OCTET2.0/20"
+
+ if [ -f "${awsDir}cloudformation-create-vpc.yml" ]; then
+ TEMPLATE_PATH="${awsDir}cloudformation-create-vpc.yml"
+ elif [ -f ".ci_cd/aws/cloudformation-create-vpc.yml" ]; then
+ TEMPLATE_PATH=".ci_cd/aws/cloudformation-create-vpc.yml"
+ elif [ -f "openremote/.ci_cd/aws/cloudformation-create-vpc.yml" ]; then
+ TEMPLATE_PATH="openremote/.ci_cd/aws/cloudformation-create-vpc.yml"
+ else
+ echo "Cannot determine location of cloudformation-create-vpc.yml"
+ exit 1
fi
- aws ec2 create-route --destination-ipv6-cidr-block ::/0 --route-table-id $ROUTETABLEID --gateway-id $IGWID $ACCOUNT_PROFILE
-else
- echo "Default VPC already exists"
-fi
+ STACK_NAME=or-vpc
+ #Configure parameters
+ PARAMS="ParameterKey=IPV4CIDR,ParameterValue='$VPCIP4CIDR'"
+
+ # Create standard stack resources in specified account
+ STACK_ID=$(aws cloudformation create-stack --stack-name $STACK_NAME --template-body file://$TEMPLATE_PATH --parameters $PARAMS --output text)
-# Create ssh-access security group
-SGID=$(aws ec2 describe-security-groups --filters Name=vpc-id,Values=$VPCID --group-names 'ssh-access' --query "SecurityGroups[0].GroupId" --output text $ACCOUNT_PROFILE 2>/dev/null)
-if [ -z "$SGID" ]; then
- echo "Provisioning ssh-access security group"
- SGID=$(aws ec2 create-security-group --description "SSH access for all EC2 instances" --group-name "ssh-access" --query "GroupId" --output text $ACCOUNT_PROFILE)
+ # Wait for cloud formation stack status to be CREATE_*
+ echo "Waiting for stack to be created"
+ STATUS=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[?StackId=='$STACK_ID'].StackStatus" --output text $ACCOUNT_PROFILE 2>/dev/null)
- if [ -z "$SGID" ]; then
- echo "Failed to provision ssh-access security group"
+ while [[ "$STATUS" == 'CREATE_IN_PROGRESS' ]]; do
+ echo "Stack creation is still in progress .. Sleeping 30 seconds"
+ sleep 30
+ STATUS=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[?StackId=='$STACK_ID'].StackStatus" --output text $ACCOUNT_PROFILE 2>/dev/null)
+ done
+
+ if [ "$STATUS" != 'CREATE_COMPLETE' ] && [ "$STATUS" != 'UPDATE_COMPLETE' ]; then
+ echo "Stack creation has failed status is '$STATUS'"
+ exit 1
+ else
+ echo "Stack creation is complete"
fi
+
else
- echo "ssh-access security group already exists '$SGID'"
+ echo "OR VPC already exists"
fi
+# Get SSH Access security group ID
+echo "Getting ssh-access security group ID"
+SGID=$(aws ec2 describe-security-groups --filters Name=tag:Name,Values=ssh-access --query "SecurityGroups[0].GroupId" --output text $ACCOUNT_PROFILE 2>/dev/null)
+
# Get developers SSH public key from Parameter Store /SSH-Key/ and store as ~/.ssh/developers.pub
echo "Getting developers SSH public key"
mkdir ~/.ssh &>/dev/null
@@ -288,8 +288,8 @@ if [ "$PROVISION_EFS" != 'false' ]; then
else
# Find Default VPC security group and IP CIDRs
- VPCIP4CIDR=$(aws ec2 describe-vpcs --filters Name=is-default,Values=true --query "Vpcs[0].CidrBlockAssociationSet[0].CidrBlock" --output text $ACCOUNT_PROFILE 2>/dev/null)
- VPCIP6CIDR=$(aws ec2 describe-vpcs --filters Name=is-default,Values=true --query "Vpcs[0].Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock" --output text $ACCOUNT_PROFILE 2>/dev/null)
+ VPCIP4CIDR=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].CidrBlockAssociationSet[0].CidrBlock" --output text $ACCOUNT_PROFILE 2>/dev/null)
+ VPCIP6CIDR=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].Ipv6CidrBlockAssociationSet[0].Ipv6CidrBlock" --output text $ACCOUNT_PROFILE 2>/dev/null)
if [ "$VPCIP4CIDR" == 'None' ]; then
unset VPCIP4CIDR
@@ -299,19 +299,19 @@ if [ "$PROVISION_EFS" != 'false' ]; then
fi
if [ -z "$VPCIP4CIDR" ] && [ -z "$VPCIP6CIDR" ]; then
- echo "Default VPC not found"
+ echo "OR VPC not found"
else
SGID=$(aws ec2 describe-security-groups --filters Name=vpc-id,Values=$VPCID --group-names 'default' --query "SecurityGroups[0].GroupId" --output text $ACCOUNT_PROFILE 2>/dev/null)
if [ -z "$SGID" ]; then
- echo "Security group for default VPC not found"
+ echo "Security group for OR VPC not found"
exit 1
else
SUBNETIDS=$(aws ec2 describe-subnets --filters Name=vpc-id,Values=$VPCID --query "Subnets[*].SubnetId" --output text $ACCOUNT_PROFILE 2>/dev/null)
if [ -z "$SUBNETIDS" ]; then
- echo "Subnets for default VPC not found"
+ echo "Subnets for OR VPC not found"
else
PARAMS="ParameterKey=SecurityGroupID,ParameterValue=$SGID"
diff --git a/.ci_cd/aws/provision_host.sh b/.ci_cd/aws/provision_host.sh
index 1a99be283..ddeb04aaf 100644
--- a/.ci_cd/aws/provision_host.sh
+++ b/.ci_cd/aws/provision_host.sh
@@ -193,6 +193,15 @@ EOF
if [ -n "$DNSHostedZoneRoleArn" ]; then
PARAMS="$PARAMS ParameterKey=DNSHostedZoneRoleArn,ParameterValue=$DNSHostedZoneRoleArn"
fi
+
+ # Get OR VPC ID, Subnet ID and SSH Security Group ID
+ VPCID=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values=or-vpc --query "Vpcs[0].VpcId" --output text $ACCOUNT_PROFILE 2>/dev/null)
+ SUBNETNAME="or-subnet-public-$(( $RANDOM % 2 + 1 ))"
+ SUBNETID=$(aws ec2 describe-subnets --filters Name=tag:Name,Values=$SUBNETNAME --query "Subnets[0].SubnetId" --output text $ACCOUNT_PROFILE 2>/dev/null)
+ SGID=$(aws ec2 describe-security-groups --filters Name=tag:Name,Values=ssh-access --query "SecurityGroups[0].GroupId" --output text $ACCOUNT_PROFILE 2>/dev/null)
+ PARAMS="$PARAMS ParameterKey=VpcId,ParameterValue=$VPCID"
+ PARAMS="$PARAMS ParameterKey=SSHSecurityGroupId,ParameterValue=$SGID"
+ PARAMS="$PARAMS ParameterKey=SubnetId,ParameterValue=$SUBNETID"
# Create standard stack resources in specified account
STACK_ID=$(aws cloudformation create-stack --capabilities CAPABILITY_NAMED_IAM --stack-name $STACK_NAME --template-body file://$TEMPLATE_PATH --parameters $PARAMS --output text $ACCOUNT_PROFILE)
diff --git a/.ci_cd/aws/refresh_ssh_whitelist.sh b/.ci_cd/aws/refresh_ssh_whitelist.sh
index b7ee7b3ef..48cf4c93a 100644
--- a/.ci_cd/aws/refresh_ssh_whitelist.sh
+++ b/.ci_cd/aws/refresh_ssh_whitelist.sh
@@ -63,9 +63,10 @@ for AWS_ACCOUNT_ID in $AWS_ACCOUNT_IDS; do
source "${awsDir}set_github-da_account_arn.sh"
echo "Revoking existing SSH Whitelist for Account '$AWS_ACCOUNT_ID'"
- LIST=$(aws ec2 describe-security-groups --filters Name=ip-permission.from-port,Values=22 Name=group-name,Values=ssh-access --query 'SecurityGroups[0].IpPermissions[?(IpProtocol==`tcp` && FromPort==`22`)]' --output json $ACCOUNT_PROFILE)
+ SGID=$(aws ec2 describe-security-groups --filters Name=tag:Name,Values=ssh-access --query "SecurityGroups[0].GroupId" --output text $ACCOUNT_PROFILE 2>/dev/null)
+ LIST=$(aws ec2 describe-security-groups --group-ids $SGID --filters Name=ip-permission.from-port,Values=22 --query 'SecurityGroups[0].IpPermissions[?(IpProtocol==`tcp` && FromPort==`22`)]' --output json $ACCOUNT_PROFILE)
if [ -n "$LIST" ] && [ "$LIST" != "null" ]; then
- aws ec2 revoke-security-group-ingress --group-name ssh-access --ip-permissions "$LIST" $ACCOUNT_PROFILE
+ aws ec2 revoke-security-group-ingress --group-id $SGID --ip-permissions "$LIST" $ACCOUNT_PROFILE
fi
if [ -n "$SSH_LIST" ]; then
diff --git a/.ci_cd/aws/ssh_revoke.sh b/.ci_cd/aws/ssh_revoke.sh
index 591114da2..d332bceba 100644
--- a/.ci_cd/aws/ssh_revoke.sh
+++ b/.ci_cd/aws/ssh_revoke.sh
@@ -21,9 +21,16 @@ fi
if [ -n "$CIDR" ]; then
echo "Revoking SSH access for CIDR '$CIDR' on AWS"
- aws ec2 revoke-security-group-ingress --group-name ssh-access --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,Ipv6Ranges=[{CidrIpv6=$CIDR}] $PROFILE
+ SGID=$(aws ec2 describe-security-groups --filters Name=tag:Name,Values=ssh-access --query "SecurityGroups[0].GroupId" --output text $PROFILE)
+
+ if [ $? -ne 0 ]; then
+ echo "Failed to find ssh-access security group"
+ exit 1
+ fi
+
+ aws ec2 revoke-security-group-ingress --group-id $SGID --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,Ipv6Ranges=[{CidrIpv6=$CIDR}] $PROFILE 2>/dev/null
v6Result=$?
- aws ec2 revoke-security-group-ingress --group-name ssh-access --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges=[{CidrIp=$CIDR}] $PROFILE
+ aws ec2 revoke-security-group-ingress --group-id $SGID --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges=[{CidrIp=$CIDR}] $PROFILE 2>/dev/null
v4Result=$?
if [ $v6Result -ne 0 ] && [ $v4Result -ne 0 ]; then
diff --git a/.ci_cd/aws/ssh_whitelist.sh b/.ci_cd/aws/ssh_whitelist.sh
index b5adda355..c9d7267ff 100644
--- a/.ci_cd/aws/ssh_whitelist.sh
+++ b/.ci_cd/aws/ssh_whitelist.sh
@@ -24,7 +24,14 @@ fi
if [ -n "$CIDR" ]; then
echo "Granting SSH access for CIDR '$CIDR' on AWS"
- aws ec2 authorize-security-group-ingress --group-name ssh-access --ip-permissions "IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges=[{CidrIp=$CIDR,Description=$DESCRIPTION}]" $PROFILE
+ SGID=$(aws ec2 describe-security-groups --filters Name=tag:Name,Values=ssh-access --query "SecurityGroups[0].GroupId" --output text $PROFILE)
+
+ if [ $? -ne 0 ]; then
+ echo "Failed to find ssh-access security group"
+ exit 1
+ fi
+
+ aws ec2 authorize-security-group-ingress --group-id $SGID --ip-permissions "IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges=[{CidrIp=$CIDR,Description=$DESCRIPTION}]" $PROFILE
if [ $? -ne 0 ]; then
echo "SSH Access failed might not be able to SSH into host(s)"
diff --git a/.ci_cd/deploy.sh b/.ci_cd/deploy.sh
index ebcd4dbaa..f2fcdf038 100644
--- a/.ci_cd/deploy.sh
+++ b/.ci_cd/deploy.sh
@@ -470,8 +470,11 @@ while [[ $response -ne 200 ]] && [ $count -lt 12 ]; do
done
if [ $response -ne 200 ]; then
+ echo "Manager web server is unreachable https://$OR_HOSTNAME..."
revoke_ssh
exit 1
+else
+ echo "Manager web server now reachable https://$OR_HOSTNAME..."
fi
revoke_ssh