diff --git a/apps/dashboard/src/main/java/com/akto/action/quick_start/QuickStartAction.java b/apps/dashboard/src/main/java/com/akto/action/quick_start/QuickStartAction.java index 26ba7dca67..b8ccb88a14 100644 --- a/apps/dashboard/src/main/java/com/akto/action/quick_start/QuickStartAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/quick_start/QuickStartAction.java @@ -154,14 +154,11 @@ public String saveLoadBalancers() { if (!AwsStack.getInstance().checkIfStackExists(MirroringStackDetails.getStackName())) { this.isFirstSetup = true; try { - Map parameters = new HashMap() { - { - put("MongoIp", System.getenv("AKTO_MONGO_CONN")); - put("KeyPair", System.getenv("EC2_KEY_PAIR")); - put("SourceLBs", extractLBs()); - put("SubnetId", System.getenv("EC2_SUBNET_ID")); - } - }; + Map parameters = new HashMap<>(); + parameters.put("MongoIp", System.getenv("AKTO_MONGO_CONN")); + parameters.put("KeyPair", System.getenv("EC2_KEY_PAIR")); + parameters.put("SourceLBs", extractLBs()); + parameters.put("SubnetId", System.getenv("EC2_SUBNET_ID")); String template = convertStreamToString(AwsStack.class .getResourceAsStream("/cloud_formation_templates/akto_aws_mirroring.template")); List tags = Utils.fetchTags(DashboardStackDetails.getStackName()); @@ -174,11 +171,8 @@ public String saveLoadBalancers() { } else { this.isFirstSetup = false; try { - Map updatedEnvVars = new HashMap() { - { - put("ELB_NAMES", extractLBs()); - } - }; + Map updatedEnvVars = new HashMap<>(); + updatedEnvVars.put("ELB_NAMES", extractLBs()); String functionName = AwsStack.getInstance().fetchResourcePhysicalIdByLogicalId(MirroringStackDetails.getStackName(), MirroringStackDetails.CREATE_MIRROR_SESSION_LAMBDA); UpdateFunctionRequest ufr = new UpdateFunctionRequest(updatedEnvVars); Lambda.getInstance().updateFunctionConfiguration(functionName, ufr); diff --git a/apps/dashboard/src/main/resources/cloud_formation_templates/akto_aws_mirroring.template b/apps/dashboard/src/main/resources/cloud_formation_templates/akto_aws_mirroring.template index 66dd5bc4e7..85e111e540 100644 --- a/apps/dashboard/src/main/resources/cloud_formation_templates/akto_aws_mirroring.template +++ b/apps/dashboard/src/main/resources/cloud_formation_templates/akto_aws_mirroring.template @@ -1 +1 @@ -{"AWSTemplateFormatVersion":"2010-09-09","Description":"This template does a simple setup for all Akto modules. It sets up all modules on a single instance. If you want a scalable and flexible setup, please contact support@akto.io.","Parameters":{"SubnetId":{"Type":"AWS::EC2::Subnet::Id"},"KeyPair":{"Type":"AWS::EC2::KeyPair::KeyName"},"SourceLBs":{"Type":"CommaDelimitedList"},"MongoIp":{"Type":"String"}},"Mappings":{"RegionMap":{"af-south-1":{"AMI":"ami-0adee70ff4394e3d5"},"eu-north-1":{"AMI":"ami-04e8b0e36ed3403dc"},"ap-south-1":{"AMI":"ami-09de362f44ba0a166"},"eu-west-3":{"AMI":"ami-0614433a16ab15878"},"eu-west-2":{"AMI":"ami-030770b178fa9d374"},"eu-south-1":{"AMI":"ami-0432f14b68c3e0273"},"eu-west-1":{"AMI":"ami-0bba0a4cb75835f71"},"ap-northeast-3":{"AMI":"ami-0253beba286f3e848"},"ap-northeast-2":{"AMI":"ami-0e1d09d8b7c751816"},"me-south-1":{"AMI":"ami-07a68e42e669daed0"},"ap-northeast-1":{"AMI":"ami-06ce6680729711877"},"sa-east-1":{"AMI":"ami-0656df2cc0dfd150a"},"ca-central-1":{"AMI":"ami-04c12937e87474def"},"ap-east-1":{"AMI":"ami-0b751f901b93720a5"},"ap-southeast-1":{"AMI":"ami-0adf622550366ea53"},"ap-southeast-2":{"AMI":"ami-03b836d87d294e89e"},"eu-central-1":{"AMI":"ami-094c442a8e9a67935"},"ap-southeast-3":{"AMI":"ami-0483d92a8124da6c9"},"us-east-1":{"AMI":"ami-065efef2c739d613b"},"us-east-2":{"AMI":"ami-07251f912d2a831a3"},"us-west-1":{"AMI":"ami-09b2f6d85764ec71b"},"us-west-2":{"AMI":"ami-0d08ef957f0e4722b"}}},"Resources":{"TrafficMirrorTarget":{"Type":"AWS::EC2::TrafficMirrorTarget","Properties":{"Description":"Traffic Mirror target set to network interface of Akto EC2 instance","Tags":[{"Key":"Name","Value":{"Fn::Join":["",[{"Ref":"AWS::StackName"},"-","Target"]]}},{"Key":"Deployment","Value":"Akto-CloudFormation"}],"NetworkLoadBalancerArn":{"Ref":"AktoNLB"}}},"LBTrafficMirrorFilter":{"Type":"AWS::EC2::TrafficMirrorFilter","Properties":{"Description":"Traffic mirror filter for LBs and Target Groups","NetworkServices":["amazon-dns"],"Tags":[{"Key":"Name","Value":{"Fn::Join":["",[{"Ref":"AWS::StackName"},"-","Filter"]]}},{"Key":"Deployment","Value":"Akto-CloudFormation"}]}},"LambdaLogGroup":{"Type":"AWS::Logs::LogGroup","Properties":{"LogGroupName":{"Fn::Sub":"/aws/lambda/${CreateMirrorSession}"},"RetentionInDays":7}},"LambdaBasicExecutionRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]},"Path":"/","Policies":[{"PolicyName":"LBCreateTrafficMirrorSession","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ec2:DescribeNetworkInterfaces","ec2:DescribeTrafficMirrorSessions","ec2:DescribeInstances","ec2:DescribeVpcs","elasticloadbalancing:DescribeLoadBalancers","elasticloadbalancing:DescribeTargetGroups","elasticloadbalancing:DescribeTargetHealth","ec2:DescribeTrafficMirrorFilters","ec2:DeleteTrafficMirrorFilterRule","ec2:CreateTrafficMirrorFilterRule","lambda:InvokeFunction"],"Resource":"*"},{"Effect":"Allow","Action":["ec2:CreateTrafficMirrorSession"],"Resource":["arn:aws:ec2:*:*:traffic-mirror-session/*","arn:aws:ec2:*:*:network-interface/*",{"Fn::Join":["",["arn:aws:ec2:*:*:traffic-mirror-target/",{"Ref":"TrafficMirrorTarget"}]]},{"Fn::Join":["",["arn:aws:ec2:*:*:traffic-mirror-filter/*"]]}]},{"Effect":"Allow","Action":["ec2:DeleteTrafficMirrorSession"],"Resource":["arn:aws:ec2:*:*:traffic-mirror-session/*"]}]}}]}},"GetAktoSetupDetailsLambdaBasicExecutionRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]},"Path":"/","Policies":[{"PolicyName":"GetAktoSetupDetailsExecuteLambda","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ec2:DescribeNetworkInterfaces","ec2:DescribeTrafficMirrorSessions","ec2:DescribeInstances","ec2:DescribeVpcs","elasticloadbalancing:DescribeLoadBalancers","elasticloadbalancing:DescribeTargetGroups","elasticloadbalancing:DescribeTargetHealth"],"Resource":"*"}]}}]}},"LambdaLogPermissions":{"Type":"AWS::IAM::Policy","Properties":{"Roles":[{"Ref":"LambdaBasicExecutionRole"}],"PolicyName":{"Fn::Sub":"${AWS::Region}-LambdaLogGroup"},"PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["logs:CreateLogStream","logs:PutLogEvents"],"Resource":[{"Fn::Sub":"arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${CreateMirrorSession}"},{"Fn::Sub":"arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${CreateMirrorSession}:*"},{"Fn::Sub":"arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${CreateMirrorSession}:*:*"}]}]}}},"GetAktoSetupDetails":{"Type":"AWS::Lambda::Function","Properties":{"Runtime":"nodejs12.x","Timeout":60,"Role":{"Fn::GetAtt":["GetAktoSetupDetailsLambdaBasicExecutionRole","Arn"]},"Handler":"index.handler","Environment":{"Variables":{"TARGET_LB":{"Ref":"AktoNLB"}}},"Code":{"S3Bucket":{"Fn::Sub":"akto-setup-${AWS::Region}"},"S3Key":"templates/get-akto-setup-details.zip"}}},"CustomSourceAktoSetupDetails":{"Type":"AWS::CloudFormation::CustomResource","Properties":{"ServiceToken":{"Fn::GetAtt":["GetAktoSetupDetails","Arn"]}}},"CreateMirrorSession":{"Type":"AWS::Lambda::Function","Properties":{"Runtime":"nodejs12.x","Timeout":60,"Role":{"Fn::GetAtt":["LambdaBasicExecutionRole","Arn"]},"Handler":"index.handler","Environment":{"Variables":{"ELB_NAMES":{"Fn::Join":[",",{"Ref":"SourceLBs"}]},"TRAFFIC_MIRROR_FILTER_ID":{"Ref":"LBTrafficMirrorFilter"},"TRAFFIC_MIRROR_TARGET_ID":{"Ref":"TrafficMirrorTarget"},"TARGET_LB":{"Ref":"AktoNLB"},"SAVE_COLLECTION_NAMES_LAMBDA_ARN":{"Fn::GetAtt":["SaveCollectionNames","Arn"]}}},"Code":{"S3Bucket":{"Fn::Sub":"akto-setup-${AWS::Region}"},"S3Key":"templates/create-mirror-session.zip"},"Description":"Auto create mirroring configuration","TracingConfig":{"Mode":"Active"}}},"PeriodicEventRule":{"Type":"AWS::Events::Rule","Properties":{"Description":"Generate an event periodically","Name":{"Fn::Join":["",[{"Ref":"AWS::StackName"},"-","PeriodicRule"]]},"ScheduleExpression":"rate(15 minutes)","State":"ENABLED","Targets":[{"Arn":{"Fn::GetAtt":["CreateMirrorSession","Arn"]},"Id":{"Ref":"CreateMirrorSession"}}]}},"PeriodicEventPermission":{"Type":"AWS::Lambda::Permission","Properties":{"FunctionName":{"Fn::GetAtt":["CreateMirrorSession","Arn"]},"Action":"lambda:InvokeFunction","Principal":"events.amazonaws.com","SourceAccount":{"Ref":"AWS::AccountId"},"SourceArn":{"Fn::GetAtt":["PeriodicEventRule","Arn"]}}},"LambdaVPCAccessRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]},"Path":"/","Policies":[{"PolicyName":"LambdaBasicAccessVPCPolicy","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ec2:DescribeNetworkInterfaces","ec2:DescribeInstances","ec2:CreateNetworkInterface","ec2:DeleteNetworkInterface","ec2:AttachNetworkInterface"],"Resource":"*"}]}}]}},"LambdaSecurityGroupVPC":{"Type":"AWS::EC2::SecurityGroup","Properties":{"VpcId":{"Fn::GetAtt":["CustomSourceAktoSetupDetails","VpcId"]},"GroupDescription":"Security group is required to create a lambda inside a VPC","SecurityGroupEgress":[{"IpProtocol":"tcp","FromPort":9092,"ToPort":9092,"CidrIp":"0.0.0.0/0"}]}},"SaveCollectionNames":{"Type":"AWS::Lambda::Function","Properties":{"Runtime":"nodejs12.x","Timeout":60,"Role":{"Fn::GetAtt":["LambdaVPCAccessRole","Arn"]},"Handler":"nodejs/index.handler","VpcConfig":{"SecurityGroupIds":[{"Fn::GetAtt":["LambdaSecurityGroupVPC","GroupId"]}],"SubnetIds":{"Fn::GetAtt":["CustomSourceAktoSetupDetails","SubnetId"]}},"Environment":{"Variables":{"PRIVATE_IP":{"Fn::GetAtt":["CustomSourceAktoSetupDetails","kafkaIp"]},"SUCCESS_ENIS":{"Fn::GetAtt":["CustomSourceAktoSetupDetails","successEnis"]}}},"Code":{"S3Bucket":{"Fn::Sub":"akto-setup-${AWS::Region}"},"S3Key":"templates/mirroring-collections-split.zip"},"Description":"Send collection name to id mapping to Akto modules","TracingConfig":{"Mode":"Active"}}},"GetVpcDetailsLambdaRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["lambda.amazonaws.com"]},"Action":["sts:AssumeRole"]}]},"Path":"/","Policies":[{"PolicyName":"DescribeAssetsPolicy","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ec2:DescribeVpcs","ec2:DescribeSubnets"],"Resource":"*"}]}}]}},"GetVpcDetailsLambda":{"Type":"AWS::Lambda::Function","Properties":{"Description":"Look up info from a VPC","Handler":"index.handler","Runtime":"nodejs12.x","Timeout":30,"Role":{"Fn::GetAtt":["GetVpcDetailsLambdaRole","Arn"]},"Environment":{"Variables":{"SUBNET_ID":{"Ref":"SubnetId"}}},"Code":{"ZipFile":"var SUBNET_ID = process.env.SUBNET_ID; var aws = require('aws-sdk'); var response = require('cfn-response'); var ec2 = new aws.EC2(); exports.handler = async function(event, context) {\n if (event.RequestType == 'Delete') {\n await response.send(event, context, 'SUCCESS');\n return;\n }\n var params = {\n SubnetIds: [SUBNET_ID] \n };\n var subnets = await ec2.describeSubnets(params).promise().catch(err => {\n console.error(err);\n });\n var vpcId = subnets['Subnets'][0]['VpcId'];\n var vpcs = await ec2.describeVpcs({VpcIds: [vpcId]}).promise().catch(err => {\n console.error(err);\n });\n await response.send(event, context, 'SUCCESS', {CidrBlock: vpcs['Vpcs'][0]['CidrBlock'], VpcId: vpcId})\n};\n"}}},"CustomSourceGetVpcDetails":{"Type":"AWS::CloudFormation::CustomResource","Properties":{"ServiceToken":{"Fn::GetAtt":["GetVpcDetailsLambda","Arn"]}}},"IamInstanceProfile":{"Type":"AWS::IAM::InstanceProfile","Properties":{"Path":"/","Roles":[{"Ref":"RefreshHandlerLambdaBasicExecutionRole"}]}},"AktoContextAnalyzerSecurityGroup":{"Type":"AWS::EC2::SecurityGroup","Properties":{"VpcId":{"Fn::GetAtt":["CustomSourceGetVpcDetails","VpcId"]},"GroupDescription":"Enable the ports Akto requires (22, 9092)","SecurityGroupIngress":[{"IpProtocol":"tcp","FromPort":22,"ToPort":22,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}},{"IpProtocol":"tcp","FromPort":9092,"ToPort":9092,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}}],"SecurityGroupEgress":[]}},"AktoContextAnalyzerASGLaunchConfiguration":{"Type":"AWS::AutoScaling::LaunchConfiguration","Properties":{"ImageId":{"Fn::FindInMap":["RegionMap",{"Ref":"AWS::Region"},"AMI"]},"InstanceType":"m5a.xlarge","KeyName":{"Ref":"KeyPair"},"AssociatePublicIpAddress":"false","SecurityGroups":[{"Ref":"AktoContextAnalyzerSecurityGroup"}],"BlockDeviceMappings":[{"DeviceName":"/dev/xvda","Ebs":{"VolumeType":"gp2","DeleteOnTermination":"true","VolumeSize":"50","Encrypted":true}}],"MetadataOptions":{"HttpTokens":"required"},"UserData":{"Fn::Base64":{"Fn::Join":["\n",["#!/bin/bash -xe",{"Fn::Sub":"export AKTO_MONGO_CONN='${MongoIp}'"},"touch /tmp/hello.txt","touch ~/hello.txt","sudo yum update -y","sudo yum install -y python python-setuptools","sudo yum install -y docker","sudo dockerd&","sudo mkdir -p /opt/aws/bin","export COMPOSE_FILE=docker-compose-context-analyser.yml","sudo wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz","sudo python -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-latest.tar.gz","curl -fsSL 'https://raw.githubusercontent.com/akto-api-security/infra/feature/segregation_2/cf-deploy-akto' > cf-deploy-akto","sudo chmod 700 cf-deploy-akto","./cf-deploy-akto < <(echo 'test')","sudo echo >> ~/akto/infra/docker-context-analyser.env","sudo echo AKTO_MONGO_CONN=$AKTO_MONGO_CONN >> ~/akto/infra/docker-context-analyser.env","export TOKEN=$(curl -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 600')",{"Fn::Join":[":",["export AKTO_CURRENT_INSTANCE_IP=$(curl -H \"X-aws-ec2-metadata-token","$TOKEN\" -v http://169.254.169.254/latest/meta-data/local-ipv4)"]]},"echo AKTO_CURRENT_INSTANCE_IP=$AKTO_CURRENT_INSTANCE_IP >> ~/akto/infra/docker-context-analyser.env","curl -fsSL 'https://raw.githubusercontent.com/akto-api-security/infra/feature/segregation_2/cf-deploy-akto-start' > cf-deploy-akto-start","sudo chmod 700 cf-deploy-akto-start","./cf-deploy-akto-start < <(echo 'test')"]]}}}},"AktoContextAnalyzerAutoScalingGroup":{"Type":"AWS::AutoScaling::AutoScalingGroup","Properties":{"LaunchConfigurationName":{"Ref":"AktoContextAnalyzerASGLaunchConfiguration"},"VPCZoneIdentifier":[{"Ref":"SubnetId"}],"MaxSize":"1","MinSize":"1"}},"AktoContextAnalyzerInstanceRefreshHandler":{"Type":"AWS::Lambda::Function","Properties":{"Handler":"index.handler","Runtime":"nodejs12.x","Timeout":30,"Role":{"Fn::GetAtt":["InstanceRefreshHandlerLambdaRole","Arn"]},"Code":{"ZipFile":"var aws = require('aws-sdk'); var autoscaling = new aws.AutoScaling(); exports.handler = function(event, context) {\n var params = {\n AutoScalingGroupName: 'AktoContextAnalyzerAutoScalingGroup', \n Preferences: {\n InstanceWarmup: 200, \n MinHealthyPercentage: 0\n }\n };\n \n autoscaling.startInstanceRefresh(params, function(err, data) {\n if(err) { console.log(err) }\n else { console.log(data) }\n })\n}; \n"}}},"RefreshHandlerLambdaBasicExecutionRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"ec2.amazonaws.com"},"Action":"sts:AssumeRole"}]},"Policies":[{"PolicyName":"InvokeLambdaPolicy","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Resource":[{"Fn::GetAtt":["DashboardInstanceRefreshHandler","Arn"]},{"Fn::GetAtt":["TrafficMirroringInstanceRefreshHandler","Arn"]},{"Fn::GetAtt":["AktoContextAnalyzerInstanceRefreshHandler","Arn"]}],"Action":"lambda:InvokeFunction"}]}}]}},"AktoSecurityGroup":{"Type":"AWS::EC2::SecurityGroup","Properties":{"VpcId":{"Fn::GetAtt":["CustomSourceGetVpcDetails","VpcId"]},"GroupDescription":"Enable the ports Akto requires (22, 4789, 8000, 9092)","SecurityGroupIngress":[{"IpProtocol":"tcp","FromPort":22,"ToPort":22,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}},{"IpProtocol":"tcp","FromPort":9092,"ToPort":9092,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}},{"IpProtocol":"udp","FromPort":4789,"ToPort":4789,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}},{"IpProtocol":"tcp","FromPort":8000,"ToPort":8000,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}}],"SecurityGroupEgress":[]}},"AktoASGLaunchConfiguration":{"Type":"AWS::AutoScaling::LaunchConfiguration","DependsOn":["AktoNLB"],"Properties":{"ImageId":{"Fn::FindInMap":["RegionMap",{"Ref":"AWS::Region"},"AMI"]},"InstanceType":"m5a.xlarge","KeyName":{"Ref":"KeyPair"},"AssociatePublicIpAddress":"false","IamInstanceProfile":{"Ref":"IamInstanceProfile"},"SecurityGroups":[{"Ref":"AktoSecurityGroup"}],"BlockDeviceMappings":[{"DeviceName":"/dev/xvda","Ebs":{"VolumeType":"gp2","DeleteOnTermination":"true","VolumeSize":"50","Encrypted":true}}],"MetadataOptions":{"HttpTokens":"required"},"UserData":{"Fn::Base64":{"Fn::Join":["\n",["#!/bin/bash -xe",{"Fn::Sub":"export AKTO_MONGO_CONN='${MongoIp}'"},{"Fn::Sub":"export AKTO_KAFKA_IP='${AktoNLB.DNSName}'"},"touch /tmp/hello.txt","touch ~/hello.txt","sudo yum update -y","sudo yum install -y python python-setuptools","sudo yum install -y docker","sudo dockerd&","sudo mkdir -p /opt/aws/bin","export COMPOSE_FILE=docker-compose-runtime.yml","sudo wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz","sudo python -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-latest.tar.gz","curl -fsSL 'https://raw.githubusercontent.com/akto-api-security/infra/feature/segregation_2/cf-deploy-akto' > cf-deploy-akto","sudo chmod 700 cf-deploy-akto","./cf-deploy-akto < <(echo 'test')","sudo echo >> ~/akto/infra/docker-runtime.env","sudo echo AKTO_MONGO_CONN=$AKTO_MONGO_CONN >> ~/akto/infra/docker-runtime.env","sudo echo AKTO_KAFKA_IP=$AKTO_KAFKA_IP >> ~/akto/infra/.env","curl -fsSL 'https://raw.githubusercontent.com/akto-api-security/infra/feature/segregation_2/cf-deploy-akto-start' > cf-deploy-akto-start","sudo chmod 700 cf-deploy-akto-start","./cf-deploy-akto-start < <(echo 'test')"]]}}}},"AktoAutoScalingGroup":{"Type":"AWS::AutoScaling::AutoScalingGroup","Properties":{"LaunchConfigurationName":{"Ref":"AktoASGLaunchConfiguration"},"VPCZoneIdentifier":[{"Ref":"SubnetId"}],"TargetGroupARNs":[{"Ref":"AktoTrafficMirroringTargetGroup"},{"Ref":"AktoKafkaTargetGroup"}],"MaxSize":"10","MinSize":"1"}},"AktoTargetTrackingNetworkPolicy":{"Type":"AWS::AutoScaling::ScalingPolicy","Properties":{"PolicyType":"TargetTrackingScaling","AutoScalingGroupName":{"Ref":"AktoAutoScalingGroup"},"EstimatedInstanceWarmup":30,"TargetTrackingConfiguration":{"PredefinedMetricSpecification":{"PredefinedMetricType":"ASGAverageNetworkIn"},"TargetValue":200000000}}},"AktoNLB":{"Type":"AWS::ElasticLoadBalancingV2::LoadBalancer","Properties":{"Type":"network","Scheme":"internal","IpAddressType":"ipv4","Subnets":[{"Ref":"SubnetId"}],"LoadBalancerAttributes":[{"Key":"load_balancing.cross_zone.enabled","Value":"true"}]}},"AktoTrafficMirroringTargetGroup":{"Type":"AWS::ElasticLoadBalancingV2::TargetGroup","Properties":{"Port":"4789","Protocol":"UDP","HealthCheckEnabled":"true","HealthCheckIntervalSeconds":10,"HealthCheckPath":"/metrics","HealthCheckPort":"8000","HealthCheckProtocol":"HTTP","HealthCheckTimeoutSeconds":6,"HealthyThresholdCount":2,"UnhealthyThresholdCount":2,"TargetType":"instance","VpcId":{"Fn::GetAtt":["CustomSourceGetVpcDetails","VpcId"]},"Targets":[]}},"AktoTrafficMirroringListener":{"Type":"AWS::ElasticLoadBalancingV2::Listener","Properties":{"LoadBalancerArn":{"Ref":"AktoNLB"},"Port":"4789","Protocol":"UDP","DefaultActions":[{"Type":"forward","TargetGroupArn":{"Ref":"AktoTrafficMirroringTargetGroup"}}]}},"AktoKafkaTargetGroup":{"Type":"AWS::ElasticLoadBalancingV2::TargetGroup","Properties":{"Port":"9092","Protocol":"TCP","TargetType":"instance","HealthCheckEnabled":"true","HealthCheckIntervalSeconds":10,"HealthCheckPath":"/metrics","HealthCheckPort":"8000","HealthCheckProtocol":"HTTP","HealthCheckTimeoutSeconds":6,"HealthyThresholdCount":2,"UnhealthyThresholdCount":2,"VpcId":{"Fn::GetAtt":["CustomSourceGetVpcDetails","VpcId"]},"Targets":[]}},"AktoKafkaListener":{"Type":"AWS::ElasticLoadBalancingV2::Listener","Properties":{"LoadBalancerArn":{"Ref":"AktoNLB"},"Port":"9092","Protocol":"TCP","DefaultActions":[{"Type":"forward","TargetGroupArn":{"Ref":"AktoKafkaTargetGroup"}}]}},"DashboardInstanceRefreshHandler":{"Type":"AWS::Lambda::Function","Properties":{"Handler":"index.handler","Runtime":"nodejs12.x","Timeout":30,"Role":{"Fn::GetAtt":["InstanceRefreshHandlerLambdaRole","Arn"]},"Code":{"ZipFile":"var aws = require('aws-sdk'); var autoscaling = new aws.AutoScaling(); exports.handler = function(event, context) {\n var params = {\n AutoScalingGroupName: 'AktoDashboardAutoScalingGroup', \n Preferences: {\n InstanceWarmup: 200, \n MinHealthyPercentage: 0\n }\n };\n \n autoscaling.startInstanceRefresh(params, function(err, data) {\n if(err) { console.log(err) }\n else { console.log(data) }\n })\n};\n"}}},"TrafficMirroringInstanceRefreshHandler":{"Type":"AWS::Lambda::Function","Properties":{"Handler":"index.handler","Runtime":"nodejs12.x","Timeout":30,"Role":{"Fn::GetAtt":["InstanceRefreshHandlerLambdaRole","Arn"]},"Code":{"ZipFile":"var aws = require('aws-sdk'); var autoscaling = new aws.AutoScaling(); exports.handler = function(event, context) {\n var params = {\n AutoScalingGroupName: 'AktoAutoScalingGroup', \n Preferences: {\n InstanceWarmup: 200, \n MinHealthyPercentage: 0\n }\n };\n \n autoscaling.startInstanceRefresh(params, function(err, data) {\n if(err) { console.log(err) }\n else { console.log(data) }\n })\n};\n"}}},"InstanceRefreshHandlerLambdaRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["lambda.amazonaws.com"]},"Action":["sts:AssumeRole"]}]},"Path":"/service-role/","Policies":[{"PolicyName":"lambdaExecution-DashboardInstanceRefreshHandler","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["logs:CreateLogGroup"],"Resource":"*"},{"Effect":"Allow","Action":["logs:CreateLogStream","logs:PutLogEvents"],"Resource":"*"},{"Effect":"Allow","Action":["autoscaling:StartInstanceRefresh","autoscaling:Describe*","autoscaling:UpdateAutoScalingGroup","ec2:CreateLaunchTemplateVersion","ec2:DescribeLaunchTemplates","ec2:RunInstances"],"Resource":"*"}]}}]}}},"Outputs":{"AktoNLB":{"Value":{"Ref":"AktoNLB"},"Description":"Arn of Akto Network Load Balancer"}}} \ No newline at end of file +{"AWSTemplateFormatVersion":"2010-09-09","Description":"This template does a simple setup for all Akto modules. It sets up all modules on a single instance. If you want a scalable and flexible setup, please contact support@akto.io.","Parameters":{"SubnetId":{"Type":"AWS::EC2::Subnet::Id"},"KeyPair":{"Type":"AWS::EC2::KeyPair::KeyName"},"SourceLBs":{"Type":"CommaDelimitedList"},"MongoIp":{"Type":"String"}},"Mappings":{"RegionMap":{"af-south-1":{"AMI":"ami-0adee70ff4394e3d5"},"eu-north-1":{"AMI":"ami-04e8b0e36ed3403dc"},"ap-south-1":{"AMI":"ami-09de362f44ba0a166"},"eu-west-3":{"AMI":"ami-0614433a16ab15878"},"eu-west-2":{"AMI":"ami-030770b178fa9d374"},"eu-south-1":{"AMI":"ami-0432f14b68c3e0273"},"eu-west-1":{"AMI":"ami-0bba0a4cb75835f71"},"ap-northeast-3":{"AMI":"ami-0253beba286f3e848"},"ap-northeast-2":{"AMI":"ami-0e1d09d8b7c751816"},"me-south-1":{"AMI":"ami-07a68e42e669daed0"},"ap-northeast-1":{"AMI":"ami-06ce6680729711877"},"sa-east-1":{"AMI":"ami-0656df2cc0dfd150a"},"ca-central-1":{"AMI":"ami-04c12937e87474def"},"ap-east-1":{"AMI":"ami-0b751f901b93720a5"},"ap-southeast-1":{"AMI":"ami-0adf622550366ea53"},"ap-southeast-2":{"AMI":"ami-03b836d87d294e89e"},"eu-central-1":{"AMI":"ami-094c442a8e9a67935"},"ap-southeast-3":{"AMI":"ami-0483d92a8124da6c9"},"us-east-1":{"AMI":"ami-065efef2c739d613b"},"us-east-2":{"AMI":"ami-07251f912d2a831a3"},"us-west-1":{"AMI":"ami-09b2f6d85764ec71b"},"us-west-2":{"AMI":"ami-0d08ef957f0e4722b"}}},"Resources":{"TrafficMirrorTarget":{"Type":"AWS::EC2::TrafficMirrorTarget","Properties":{"Description":"Traffic Mirror target set to network interface of Akto EC2 instance","Tags":[{"Key":"Name","Value":{"Fn::Join":["",[{"Ref":"AWS::StackName"},"-","Target"]]}},{"Key":"Deployment","Value":"Akto-CloudFormation"}],"NetworkLoadBalancerArn":{"Ref":"AktoNLB"}}},"LBTrafficMirrorFilter":{"Type":"AWS::EC2::TrafficMirrorFilter","Properties":{"Description":"Traffic mirror filter for LBs and Target Groups","NetworkServices":["amazon-dns"],"Tags":[{"Key":"Name","Value":{"Fn::Join":["",[{"Ref":"AWS::StackName"},"-","Filter"]]}},{"Key":"Deployment","Value":"Akto-CloudFormation"}]}},"LambdaLogGroup":{"Type":"AWS::Logs::LogGroup","Properties":{"LogGroupName":{"Fn::Sub":"/aws/lambda/${CreateMirrorSession}"},"RetentionInDays":7}},"LambdaBasicExecutionRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]},"Path":"/","Policies":[{"PolicyName":"LBCreateTrafficMirrorSession","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ec2:DescribeNetworkInterfaces","ec2:DescribeTrafficMirrorSessions","ec2:DescribeInstances","ec2:DescribeVpcs","elasticloadbalancing:DescribeLoadBalancers","elasticloadbalancing:DescribeTargetGroups","elasticloadbalancing:DescribeTargetHealth","ec2:DescribeTrafficMirrorFilters","ec2:DeleteTrafficMirrorFilterRule","ec2:CreateTrafficMirrorFilterRule","lambda:InvokeFunction"],"Resource":"*"},{"Effect":"Allow","Action":["ec2:CreateTrafficMirrorSession"],"Resource":["arn:aws:ec2:*:*:traffic-mirror-session/*","arn:aws:ec2:*:*:network-interface/*",{"Fn::Join":["",["arn:aws:ec2:*:*:traffic-mirror-target/",{"Ref":"TrafficMirrorTarget"}]]},{"Fn::Join":["",["arn:aws:ec2:*:*:traffic-mirror-filter/*"]]}]},{"Effect":"Allow","Action":["ec2:DeleteTrafficMirrorSession"],"Resource":["arn:aws:ec2:*:*:traffic-mirror-session/*"]}]}}]}},"GetAktoSetupDetailsLambdaBasicExecutionRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]},"Path":"/","Policies":[{"PolicyName":"GetAktoSetupDetailsExecuteLambda","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ec2:DescribeNetworkInterfaces","ec2:DescribeTrafficMirrorSessions","ec2:DescribeInstances","ec2:DescribeVpcs","elasticloadbalancing:DescribeLoadBalancers","elasticloadbalancing:DescribeTargetGroups","elasticloadbalancing:DescribeTargetHealth"],"Resource":"*"}]}}]}},"LambdaLogPermissions":{"Type":"AWS::IAM::Policy","Properties":{"Roles":[{"Ref":"LambdaBasicExecutionRole"}],"PolicyName":{"Fn::Sub":"${AWS::Region}-LambdaLogGroup"},"PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["logs:CreateLogStream","logs:PutLogEvents"],"Resource":[{"Fn::Sub":"arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${CreateMirrorSession}"},{"Fn::Sub":"arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${CreateMirrorSession}:*"},{"Fn::Sub":"arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${CreateMirrorSession}:*:*"}]}]}}},"GetAktoSetupDetails":{"Type":"AWS::Lambda::Function","Properties":{"Runtime":"nodejs12.x","Timeout":60,"Role":{"Fn::GetAtt":["GetAktoSetupDetailsLambdaBasicExecutionRole","Arn"]},"Handler":"index.handler","Environment":{"Variables":{"TARGET_LB":{"Ref":"AktoNLB"}}},"Code":{"S3Bucket":{"Fn::Sub":"akto-setup-${AWS::Region}"},"S3Key":"templates/get-akto-setup-details.zip"}}},"CustomSourceAktoSetupDetails":{"Type":"AWS::CloudFormation::CustomResource","Properties":{"ServiceToken":{"Fn::GetAtt":["GetAktoSetupDetails","Arn"]}}},"CreateMirrorSession":{"Type":"AWS::Lambda::Function","Properties":{"Runtime":"nodejs12.x","Timeout":300,"Role":{"Fn::GetAtt":["LambdaBasicExecutionRole","Arn"]},"Handler":"index.handler","Environment":{"Variables":{"ELB_NAMES":{"Fn::Join":[",",{"Ref":"SourceLBs"}]},"TRAFFIC_MIRROR_FILTER_ID":{"Ref":"LBTrafficMirrorFilter"},"TRAFFIC_MIRROR_TARGET_ID":{"Ref":"TrafficMirrorTarget"},"TARGET_LB":{"Ref":"AktoNLB"},"SAVE_COLLECTION_NAMES_LAMBDA_ARN":{"Fn::GetAtt":["SaveCollectionNames","Arn"]}}},"Code":{"S3Bucket":{"Fn::Sub":"akto-setup-${AWS::Region}"},"S3Key":"templates/create-mirror-session.zip"},"Description":"Auto create mirroring configuration","TracingConfig":{"Mode":"Active"}}},"PeriodicEventRule":{"Type":"AWS::Events::Rule","Properties":{"Description":"Generate an event periodically","Name":{"Fn::Join":["",[{"Ref":"AWS::StackName"},"-","PeriodicRule"]]},"ScheduleExpression":"rate(15 minutes)","State":"ENABLED","Targets":[{"Arn":{"Fn::GetAtt":["CreateMirrorSession","Arn"]},"Id":{"Ref":"CreateMirrorSession"}}]}},"PeriodicEventPermission":{"Type":"AWS::Lambda::Permission","Properties":{"FunctionName":{"Fn::GetAtt":["CreateMirrorSession","Arn"]},"Action":"lambda:InvokeFunction","Principal":"events.amazonaws.com","SourceAccount":{"Ref":"AWS::AccountId"},"SourceArn":{"Fn::GetAtt":["PeriodicEventRule","Arn"]}}},"LambdaVPCAccessRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]},"Path":"/","Policies":[{"PolicyName":"LambdaBasicAccessVPCPolicy","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ec2:DescribeNetworkInterfaces","ec2:DescribeInstances","ec2:CreateNetworkInterface","ec2:DeleteNetworkInterface","ec2:AttachNetworkInterface"],"Resource":"*"}]}}]}},"LambdaSecurityGroupVPC":{"Type":"AWS::EC2::SecurityGroup","Properties":{"VpcId":{"Fn::GetAtt":["CustomSourceAktoSetupDetails","VpcId"]},"GroupDescription":"Security group is required to create a lambda inside a VPC","SecurityGroupEgress":[{"IpProtocol":"tcp","FromPort":9092,"ToPort":9092,"CidrIp":"0.0.0.0/0"}]}},"SaveCollectionNames":{"Type":"AWS::Lambda::Function","Properties":{"Runtime":"nodejs12.x","Timeout":60,"Role":{"Fn::GetAtt":["LambdaVPCAccessRole","Arn"]},"Handler":"nodejs/index.handler","VpcConfig":{"SecurityGroupIds":[{"Fn::GetAtt":["LambdaSecurityGroupVPC","GroupId"]}],"SubnetIds":{"Fn::GetAtt":["CustomSourceAktoSetupDetails","SubnetId"]}},"Environment":{"Variables":{"PRIVATE_IP":{"Fn::GetAtt":["CustomSourceAktoSetupDetails","kafkaIp"]},"SUCCESS_ENIS":{"Fn::GetAtt":["CustomSourceAktoSetupDetails","successEnis"]}}},"Code":{"S3Bucket":{"Fn::Sub":"akto-setup-${AWS::Region}"},"S3Key":"templates/mirroring-collections-split.zip"},"Description":"Send collection name to id mapping to Akto modules","TracingConfig":{"Mode":"Active"}}},"GetVpcDetailsLambdaRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["lambda.amazonaws.com"]},"Action":["sts:AssumeRole"]}]},"Path":"/","Policies":[{"PolicyName":"DescribeAssetsPolicy","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ec2:DescribeVpcs","ec2:DescribeSubnets"],"Resource":"*"}]}}]}},"GetVpcDetailsLambda":{"Type":"AWS::Lambda::Function","Properties":{"Description":"Look up info from a VPC","Handler":"index.handler","Runtime":"nodejs12.x","Timeout":30,"Role":{"Fn::GetAtt":["GetVpcDetailsLambdaRole","Arn"]},"Environment":{"Variables":{"SUBNET_ID":{"Ref":"SubnetId"}}},"Code":{"ZipFile":"var SUBNET_ID = process.env.SUBNET_ID; var aws = require('aws-sdk'); var response = require('cfn-response'); var ec2 = new aws.EC2(); exports.handler = async function(event, context) {\n if (event.RequestType == 'Delete') {\n await response.send(event, context, 'SUCCESS');\n return;\n }\n var params = {\n SubnetIds: [SUBNET_ID] \n };\n var subnets = await ec2.describeSubnets(params).promise().catch(err => {\n console.error(err);\n });\n var vpcId = subnets['Subnets'][0]['VpcId'];\n var vpcs = await ec2.describeVpcs({VpcIds: [vpcId]}).promise().catch(err => {\n console.error(err);\n });\n await response.send(event, context, 'SUCCESS', {CidrBlock: vpcs['Vpcs'][0]['CidrBlock'], VpcId: vpcId})\n};\n"}}},"CustomSourceGetVpcDetails":{"Type":"AWS::CloudFormation::CustomResource","Properties":{"ServiceToken":{"Fn::GetAtt":["GetVpcDetailsLambda","Arn"]}}},"IamInstanceProfile":{"Type":"AWS::IAM::InstanceProfile","Properties":{"Path":"/","Roles":[{"Ref":"RefreshHandlerLambdaBasicExecutionRole"}]}},"AktoContextAnalyzerSecurityGroup":{"Type":"AWS::EC2::SecurityGroup","Properties":{"VpcId":{"Fn::GetAtt":["CustomSourceGetVpcDetails","VpcId"]},"GroupDescription":"Enable the ports Akto requires (22, 9092)","SecurityGroupIngress":[{"IpProtocol":"tcp","FromPort":22,"ToPort":22,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}},{"IpProtocol":"tcp","FromPort":9092,"ToPort":9092,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}}],"SecurityGroupEgress":[]}},"AktoContextAnalyzerASGLaunchConfiguration":{"Type":"AWS::AutoScaling::LaunchConfiguration","Properties":{"ImageId":{"Fn::FindInMap":["RegionMap",{"Ref":"AWS::Region"},"AMI"]},"InstanceType":"m5a.xlarge","KeyName":{"Ref":"KeyPair"},"AssociatePublicIpAddress":"false","SecurityGroups":[{"Ref":"AktoContextAnalyzerSecurityGroup"}],"BlockDeviceMappings":[{"DeviceName":"/dev/xvda","Ebs":{"VolumeType":"gp2","DeleteOnTermination":"true","VolumeSize":"50","Encrypted":true}}],"MetadataOptions":{"HttpTokens":"required"},"UserData":{"Fn::Base64":{"Fn::Join":["\n",["#!/bin/bash -xe",{"Fn::Sub":"export AKTO_MONGO_CONN='${MongoIp}'"},"touch /tmp/hello.txt","touch ~/hello.txt","sudo yum update -y","sudo yum install -y python python-setuptools","sudo yum install -y docker","sudo dockerd&","sudo mkdir -p /opt/aws/bin","export COMPOSE_FILE=docker-compose-context-analyser.yml","sudo wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz","sudo python -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-latest.tar.gz","curl -fsSL 'https://raw.githubusercontent.com/akto-api-security/infra/feature/segregation_2/cf-deploy-akto' > cf-deploy-akto","sudo chmod 700 cf-deploy-akto","./cf-deploy-akto < <(echo 'test')","sudo echo >> ~/akto/infra/docker-context-analyser.env","sudo echo AKTO_MONGO_CONN=$AKTO_MONGO_CONN >> ~/akto/infra/docker-context-analyser.env","export TOKEN=$(curl -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 600')",{"Fn::Join":[":",["export AKTO_CURRENT_INSTANCE_IP=$(curl -H \"X-aws-ec2-metadata-token","$TOKEN\" -v http://169.254.169.254/latest/meta-data/local-ipv4)"]]},"echo AKTO_CURRENT_INSTANCE_IP=$AKTO_CURRENT_INSTANCE_IP >> ~/akto/infra/docker-context-analyser.env","curl -fsSL 'https://raw.githubusercontent.com/akto-api-security/infra/feature/segregation_2/cf-deploy-akto-start' > cf-deploy-akto-start","sudo chmod 700 cf-deploy-akto-start","./cf-deploy-akto-start < <(echo 'test')"]]}}}},"AktoContextAnalyzerAutoScalingGroup":{"Type":"AWS::AutoScaling::AutoScalingGroup","Properties":{"LaunchConfigurationName":{"Ref":"AktoContextAnalyzerASGLaunchConfiguration"},"VPCZoneIdentifier":[{"Ref":"SubnetId"}],"MaxSize":"1","MinSize":"1"}},"AktoContextAnalyzerInstanceRefreshHandler":{"Type":"AWS::Lambda::Function","Properties":{"Handler":"index.handler","Runtime":"nodejs12.x","Timeout":30,"Role":{"Fn::GetAtt":["InstanceRefreshHandlerLambdaRole","Arn"]},"Code":{"ZipFile":"var aws = require('aws-sdk'); var autoscaling = new aws.AutoScaling(); exports.handler = function(event, context) {\n var params = {\n AutoScalingGroupName: 'AktoContextAnalyzerAutoScalingGroup', \n Preferences: {\n InstanceWarmup: 200, \n MinHealthyPercentage: 0\n }\n };\n \n autoscaling.startInstanceRefresh(params, function(err, data) {\n if(err) { console.log(err) }\n else { console.log(data) }\n })\n}; \n"}}},"RefreshHandlerLambdaBasicExecutionRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"ec2.amazonaws.com"},"Action":"sts:AssumeRole"}]},"Policies":[{"PolicyName":"InvokeLambdaPolicy","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Resource":[{"Fn::GetAtt":["DashboardInstanceRefreshHandler","Arn"]},{"Fn::GetAtt":["TrafficMirroringInstanceRefreshHandler","Arn"]},{"Fn::GetAtt":["AktoContextAnalyzerInstanceRefreshHandler","Arn"]}],"Action":"lambda:InvokeFunction"}]}}]}},"AktoSecurityGroup":{"Type":"AWS::EC2::SecurityGroup","Properties":{"VpcId":{"Fn::GetAtt":["CustomSourceGetVpcDetails","VpcId"]},"GroupDescription":"Enable the ports Akto requires (22, 4789, 8000, 9092)","SecurityGroupIngress":[{"IpProtocol":"tcp","FromPort":22,"ToPort":22,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}},{"IpProtocol":"tcp","FromPort":9092,"ToPort":9092,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}},{"IpProtocol":"udp","FromPort":4789,"ToPort":4789,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}},{"IpProtocol":"tcp","FromPort":8000,"ToPort":8000,"CidrIp":{"Fn::GetAtt":["CustomSourceGetVpcDetails","CidrBlock"]}}],"SecurityGroupEgress":[]}},"AktoASGLaunchConfiguration":{"Type":"AWS::AutoScaling::LaunchConfiguration","DependsOn":["AktoNLB"],"Properties":{"ImageId":{"Fn::FindInMap":["RegionMap",{"Ref":"AWS::Region"},"AMI"]},"InstanceType":"m5a.xlarge","KeyName":{"Ref":"KeyPair"},"AssociatePublicIpAddress":"false","IamInstanceProfile":{"Ref":"IamInstanceProfile"},"SecurityGroups":[{"Ref":"AktoSecurityGroup"}],"BlockDeviceMappings":[{"DeviceName":"/dev/xvda","Ebs":{"VolumeType":"gp2","DeleteOnTermination":"true","VolumeSize":"50","Encrypted":true}}],"MetadataOptions":{"HttpTokens":"required"},"UserData":{"Fn::Base64":{"Fn::Join":["\n",["#!/bin/bash -xe",{"Fn::Sub":"export AKTO_MONGO_CONN='${MongoIp}'"},{"Fn::Sub":"export AKTO_KAFKA_IP='${AktoNLB.DNSName}'"},"touch /tmp/hello.txt","touch ~/hello.txt","sudo yum update -y","sudo yum install -y python python-setuptools","sudo yum install -y docker","sudo dockerd&","sudo mkdir -p /opt/aws/bin","export COMPOSE_FILE=docker-compose-runtime.yml","sudo wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz","sudo python -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-latest.tar.gz","curl -fsSL 'https://raw.githubusercontent.com/akto-api-security/infra/feature/segregation_2/cf-deploy-akto' > cf-deploy-akto","sudo chmod 700 cf-deploy-akto","./cf-deploy-akto < <(echo 'test')","sudo echo >> ~/akto/infra/docker-runtime.env","sudo echo AKTO_MONGO_CONN=$AKTO_MONGO_CONN >> ~/akto/infra/docker-runtime.env","sudo echo AKTO_KAFKA_IP=$AKTO_KAFKA_IP >> ~/akto/infra/.env","curl -fsSL 'https://raw.githubusercontent.com/akto-api-security/infra/feature/segregation_2/cf-deploy-akto-start' > cf-deploy-akto-start","sudo chmod 700 cf-deploy-akto-start","./cf-deploy-akto-start < <(echo 'test')"]]}}}},"AktoAutoScalingGroup":{"Type":"AWS::AutoScaling::AutoScalingGroup","Properties":{"LaunchConfigurationName":{"Ref":"AktoASGLaunchConfiguration"},"VPCZoneIdentifier":[{"Ref":"SubnetId"}],"TargetGroupARNs":[{"Ref":"AktoTrafficMirroringTargetGroup"},{"Ref":"AktoKafkaTargetGroup"}],"MaxSize":"10","MinSize":"1"}},"AktoTargetTrackingNetworkPolicy":{"Type":"AWS::AutoScaling::ScalingPolicy","Properties":{"PolicyType":"TargetTrackingScaling","AutoScalingGroupName":{"Ref":"AktoAutoScalingGroup"},"EstimatedInstanceWarmup":30,"TargetTrackingConfiguration":{"PredefinedMetricSpecification":{"PredefinedMetricType":"ASGAverageNetworkIn"},"TargetValue":200000000}}},"AktoNLB":{"Type":"AWS::ElasticLoadBalancingV2::LoadBalancer","Properties":{"Type":"network","Scheme":"internal","IpAddressType":"ipv4","Subnets":[{"Ref":"SubnetId"}],"LoadBalancerAttributes":[{"Key":"load_balancing.cross_zone.enabled","Value":"true"}]}},"AktoTrafficMirroringTargetGroup":{"Type":"AWS::ElasticLoadBalancingV2::TargetGroup","Properties":{"Port":"4789","Protocol":"UDP","HealthCheckEnabled":"true","HealthCheckIntervalSeconds":10,"HealthCheckPath":"/metrics","HealthCheckPort":"8000","HealthCheckProtocol":"HTTP","HealthCheckTimeoutSeconds":6,"HealthyThresholdCount":2,"UnhealthyThresholdCount":2,"TargetType":"instance","VpcId":{"Fn::GetAtt":["CustomSourceGetVpcDetails","VpcId"]},"Targets":[]}},"AktoTrafficMirroringListener":{"Type":"AWS::ElasticLoadBalancingV2::Listener","Properties":{"LoadBalancerArn":{"Ref":"AktoNLB"},"Port":"4789","Protocol":"UDP","DefaultActions":[{"Type":"forward","TargetGroupArn":{"Ref":"AktoTrafficMirroringTargetGroup"}}]}},"AktoKafkaTargetGroup":{"Type":"AWS::ElasticLoadBalancingV2::TargetGroup","Properties":{"Port":"9092","Protocol":"TCP","TargetType":"instance","HealthCheckEnabled":"true","HealthCheckIntervalSeconds":10,"HealthCheckPath":"/metrics","HealthCheckPort":"8000","HealthCheckProtocol":"HTTP","HealthCheckTimeoutSeconds":6,"HealthyThresholdCount":2,"UnhealthyThresholdCount":2,"VpcId":{"Fn::GetAtt":["CustomSourceGetVpcDetails","VpcId"]},"Targets":[]}},"AktoKafkaListener":{"Type":"AWS::ElasticLoadBalancingV2::Listener","Properties":{"LoadBalancerArn":{"Ref":"AktoNLB"},"Port":"9092","Protocol":"TCP","DefaultActions":[{"Type":"forward","TargetGroupArn":{"Ref":"AktoKafkaTargetGroup"}}]}},"DashboardInstanceRefreshHandler":{"Type":"AWS::Lambda::Function","Properties":{"Handler":"index.handler","Runtime":"nodejs12.x","Timeout":30,"Role":{"Fn::GetAtt":["InstanceRefreshHandlerLambdaRole","Arn"]},"Code":{"ZipFile":"var aws = require('aws-sdk'); var autoscaling = new aws.AutoScaling(); exports.handler = function(event, context) {\n var params = {\n AutoScalingGroupName: 'AktoDashboardAutoScalingGroup', \n Preferences: {\n InstanceWarmup: 200, \n MinHealthyPercentage: 0\n }\n };\n \n autoscaling.startInstanceRefresh(params, function(err, data) {\n if(err) { console.log(err) }\n else { console.log(data) }\n })\n};\n"}}},"TrafficMirroringInstanceRefreshHandler":{"Type":"AWS::Lambda::Function","Properties":{"Handler":"index.handler","Runtime":"nodejs12.x","Timeout":30,"Role":{"Fn::GetAtt":["InstanceRefreshHandlerLambdaRole","Arn"]},"Code":{"ZipFile":"var aws = require('aws-sdk'); var autoscaling = new aws.AutoScaling(); exports.handler = function(event, context) {\n var params = {\n AutoScalingGroupName: 'AktoAutoScalingGroup', \n Preferences: {\n InstanceWarmup: 200, \n MinHealthyPercentage: 0\n }\n };\n \n autoscaling.startInstanceRefresh(params, function(err, data) {\n if(err) { console.log(err) }\n else { console.log(data) }\n })\n};\n"}}},"InstanceRefreshHandlerLambdaRole":{"Type":"AWS::IAM::Role","Properties":{"AssumeRolePolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["lambda.amazonaws.com"]},"Action":["sts:AssumeRole"]}]},"Path":"/service-role/","Policies":[{"PolicyName":"lambdaExecution-DashboardInstanceRefreshHandler","PolicyDocument":{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["logs:CreateLogGroup"],"Resource":"*"},{"Effect":"Allow","Action":["logs:CreateLogStream","logs:PutLogEvents"],"Resource":"*"},{"Effect":"Allow","Action":["autoscaling:StartInstanceRefresh","autoscaling:Describe*","autoscaling:UpdateAutoScalingGroup","ec2:CreateLaunchTemplateVersion","ec2:DescribeLaunchTemplates","ec2:RunInstances"],"Resource":"*"}]}}]}}},"Outputs":{"AktoNLB":{"Value":{"Ref":"AktoNLB"},"Description":"Arn of Akto Network Load Balancer"}}} \ No newline at end of file diff --git a/apps/dashboard/web/src/apps/dashboard/layouts/LayoutWithTabs.vue b/apps/dashboard/web/src/apps/dashboard/layouts/LayoutWithTabs.vue index 2ed10ec395..e7b1018d93 100644 --- a/apps/dashboard/web/src/apps/dashboard/layouts/LayoutWithTabs.vue +++ b/apps/dashboard/web/src/apps/dashboard/layouts/LayoutWithTabs.vue @@ -57,11 +57,12 @@ tabs: obj.arrR, description: obj.strN, defaultTabName: obj.strN, - tabsContent: obj.objN + tabsContent: obj.objN, + tab: obj.strN }, data () { return { - tabName: null + tabName: parseInt(this.tab) || null } }, methods: { diff --git a/apps/dashboard/web/src/apps/dashboard/views/observe/inventory/components/TestsSelector.vue b/apps/dashboard/web/src/apps/dashboard/views/observe/inventory/components/TestsSelector.vue index 1454385de6..c15a5f8d43 100644 --- a/apps/dashboard/web/src/apps/dashboard/views/observe/inventory/components/TestsSelector.vue +++ b/apps/dashboard/web/src/apps/dashboard/views/observe/inventory/components/TestsSelector.vue @@ -2,7 +2,11 @@
-
+
+ Please set an authentication mechanism here before you test any APIs. +
+
+
Name:
@@ -58,7 +62,7 @@
- +
@@ -67,6 +71,7 @@ import marketplaceApi from '../../../marketplace/api' import issuesApi from '../../../issues/api' +import testingApi from '../../../testing/api' import Spinner from '@/apps/dashboard/shared/components/Spinner' import ScheduleBox from '@/apps/dashboard/shared/components/ScheduleBox' import func from '@/util/func' @@ -96,7 +101,9 @@ export default { startTimestamp: func.timeNow(), selectedCategory: null, globalCheckbox: false, - testName: "" + testName: "", + authPresent: false, + disableLinkClass: 'disable-div' } }, mounted() { @@ -111,7 +118,12 @@ export default { _this.mapCategoryToSubcategory = _this.populateMapCategoryToSubcategory() }) }) - + testingApi.fetchAuthMechanismData().then(resp => { + if(resp.authMechanism){ + this.authPresent = true; + this.disableLinkClass = '' + } + }) }, methods: { @@ -246,4 +258,11 @@ export default { margin: auto 8px auto 0 font-size: 14px font-weight: 500 + +.clickable-link + color: #6200ea !important + +.disable-div + pointer-events: none + opacity: 0.4 \ No newline at end of file diff --git a/apps/dashboard/web/src/apps/dashboard/views/testing/PageTesting.vue b/apps/dashboard/web/src/apps/dashboard/views/testing/PageTesting.vue index d05bae22da..975b68ff52 100644 --- a/apps/dashboard/web/src/apps/dashboard/views/testing/PageTesting.vue +++ b/apps/dashboard/web/src/apps/dashboard/views/testing/PageTesting.vue @@ -1,5 +1,5 @@