diff --git a/README.md b/README.md index a1dad551ba7dd0e30546f3f3acd5e71bf80ae8f2..518115b31b6b86774aa006a235b860a0f3717b48 100644 --- a/README.md +++ b/README.md @@ -131,9 +131,15 @@ can be passed as a Terraform variable for `image_name`, see below for an example in `infaagent.ini` using `InfaAgent.GroupName=aws-interop`). * Terraform state files are stored in shared S3 buckets `test-interop-terraform-state` and `prod-interop-terraform-state`. +### Informatica User +Credentials for Informatica User (for test and prod instances) are stored in parameter store (in regions `us-east-1` and +`us-east-2` respectively) and expected to be available with the following names: +* username - `/iics/cicd_username`. +* password - `/iics/cicd_password`. + ### Credentials in Terraform * It's recommended to define all variables values in a `*.tfvars` file and pass that to terraform using `-var-file` argument. - This will avoid having Informatica credentials in bash history. + This will avoid having any sensitive parameters in bash history. ```shell script $ cd terraform @@ -155,8 +161,6 @@ $ terraform validate # create `secure_agent.tfvars` with required variables. $ cat secure_agent.tfvars -informatica_username="<informatica-username>" -informatica_password="<informatica-password>" image_name="265723766240.dkr.ecr.us-east-1.amazonaws.com/enterprise-integrations/iics_secure_agent:git-8f6f0d24" $ terraform plan -out agent.tfplan -var-file=<path>/<to>/secure_agent.tfvars @@ -164,7 +168,7 @@ $ terraform apply "agent.tfplan" ``` ### Memory and CPU for Secure Agent -* By default, Secure Agent is deployed on to a `t2.large` instance and container is given an 5GB of memory. `instance_type` +* By default, Secure Agent is deployed on to a `t2.xlarge` instance and container is given an 15GB of memory. `instance_type` and `container_memory` variables can be used to adjust these values. See [variables.tf](./terraform/variables.tf) for details. ### EFS Mounting, Accessing Secure Agent Configurations, Logs and Additional Debugging diff --git a/terraform/autoscaling-group.tf b/terraform/autoscaling-group.tf index 6dfc20387d8280455caa741ababcdf2ff8a00bf4..e5e0931d73372622636251e00c4be4b2e9ad0647 100644 --- a/terraform/autoscaling-group.tf +++ b/terraform/autoscaling-group.tf @@ -18,19 +18,13 @@ resource "aws_autoscaling_group" "secure-agent-autoscaling-group" { } } -data "aws_ami" "ecs-optimized" { - most_recent = true - owners = ["amazon"] - - filter { - name = "name" - values = ["*-amazon-ecs-optimized"] - } +data "aws_ssm_parameter" "ecs-optimized" { + name = "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id" } resource "aws_launch_configuration" "secure-agent-launch-config" { name = "secure-agnet-launch-configuration" - image_id = data.aws_ami.ecs-optimized.image_id + image_id = data.aws_ssm_parameter.ecs-optimized.value enable_monitoring = false iam_instance_profile = aws_iam_instance_profile.ecs-instance-profile.name @@ -38,7 +32,6 @@ resource "aws_launch_configuration" "secure-agent-launch-config" { user_data = <<EOF #!/bin/bash echo ECS_CLUSTER=${var.ecs_cluster_name} >> /etc/ecs/ecs.config - sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm EOF instance_type = var.instance_type root_block_device { diff --git a/terraform/ecs.tf b/terraform/ecs.tf index f5b522de9f2b65847bc71b92afeeeae94c39f55d..aab9b33453965247f37b8c756954d8a30e2fdc87 100644 --- a/terraform/ecs.tf +++ b/terraform/ecs.tf @@ -1,26 +1,84 @@ +data "aws_ssm_parameter" "informatica-username" { + name = "/iics/cicd_username" +} + +data "aws_ssm_parameter" "informatica-password" { + name = "/iics/cicd_password" +} + data "template_file" "container" { template = file("./templates/container-definitions.tpl") vars = { - container_name = var.container_name - image_name = var.image_name - container_memory = var.container_memory - container_hostname = var.container_hostname - app_port1 = var.container_app_port[0] - app_port2 = var.container_app_port[1] - app_port3 = var.container_app_port[2] - informatica_username = var.informatica_username - informatica_password = var.informatica_password + container_name = var.container_name + image_name = var.image_name + container_memory = var.container_memory + container_hostname = var.container_hostname + app_port1 = var.container_app_port[0] + app_port2 = var.container_app_port[1] + app_port3 = var.container_app_port[2] + informatica_username = data.aws_ssm_parameter.informatica-username.arn + informatica_password = data.aws_ssm_parameter.informatica-password.arn secure_agent_mount_path = var.secure_agent_mount_path } } -data "aws_iam_role" "ecs-task-execution" { - name = "ecsTaskExecutionRole" +resource "aws_iam_role" "ecs-task-execution" { + name = var.ecs_execution_role + assume_role_policy = <<EOF +{ + "Version": "2012-10-17", + "Statement": [ + { + "Action": "sts:AssumeRole", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + }, + "Effect":"Allow" + } + ] +} +EOF + tags = { + Name = "iics-ecs-execution-role" + } +} + +# grant role permission for ECS task execution +resource "aws_iam_role_policy_attachment" "ecs-task-execution" { + role = aws_iam_role.ecs-task-execution.name + policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy" +} + +# grant access for SSM for credentails look up +resource "aws_iam_policy" "iics-ssm-policy" { + name = var.iics_secret_access_policy + policy = <<EOF +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "ssm:GetParameters" + ], + "Resource": [ + "${data.aws_ssm_parameter.informatica-username.arn}", + "${data.aws_ssm_parameter.informatica-password.arn}" + ] + } + ] +} +EOF +} + +resource "aws_iam_role_policy_attachment" "credentails" { + role = aws_iam_role.ecs-task-execution.name + policy_arn = aws_iam_policy.iics-ssm-policy.arn } resource "aws_ecs_task_definition" "task" { family = var.ecs_task_name - execution_role_arn = data.aws_iam_role.ecs-task-execution.arn + execution_role_arn = aws_iam_role.ecs-task-execution.arn network_mode = var.container_network_mode requires_compatibilities = [ "EC2"] diff --git a/terraform/iam.tf b/terraform/iam.tf index 20c2cc27fb6f80b38907b802618ff491f6676ea2..a37eeca7cbc09ac1726242b8f5ddef19549c4562 100644 --- a/terraform/iam.tf +++ b/terraform/iam.tf @@ -6,7 +6,8 @@ data "aws_iam_policy_document" "ecs-agent" { principals { type = "Service" identifiers = [ - "ec2.amazonaws.com"] + "ec2.amazonaws.com", + "ecs-tasks.amazonaws.com"] } } } diff --git a/terraform/security.tf b/terraform/security.tf index 900795e78d0b640f17be5bffdccf7c9126e502fc..c854a311ecd4db83cc23ba5cb0a50c2a87755a7b 100644 --- a/terraform/security.tf +++ b/terraform/security.tf @@ -5,7 +5,7 @@ data "aws_security_group" "sec-group" { data "aws_security_group" "default" { vpc_id = data.aws_vpc.vpc.id - name = "default" + name = "default" } // open port 2049 for NFSv4 diff --git a/terraform/templates/container-definitions.tpl b/terraform/templates/container-definitions.tpl index 0102cd9e2c16e202e713cd937ce2400b58bf3c68..a736e8e7ca6c0bdf8de25e4f4a89dba11c052704 100644 --- a/terraform/templates/container-definitions.tpl +++ b/terraform/templates/container-definitions.tpl @@ -18,21 +18,21 @@ "hostPort": ${app_port3} } ], - "environment": [ - { - "name": "INFORMATICA_USER", - "value": "${informatica_username}" - }, - { - "name": "INFORMATICA_PASSWORD", - "value": "${informatica_password}" - } - ], "mountPoints": [ { "containerPath": "${secure_agent_mount_path}", "sourceVolume": "agent-configs-path" } + ], + "secrets":[ + { + "name":"INFORMATICA_USER", + "valueFrom":"${informatica_username}" + }, + { + "name":"INFORMATICA_PASSWORD", + "valueFrom":"${informatica_password}" + } ] } ] \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf index 687c45728e12ed89d0fed80e455fcee38d677bb1..5e88ecfac37c49521c4d92923a5e9aba7079a93a 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -1,6 +1,3 @@ -variable "informatica_username" {} -variable "informatica_password" {} - variable "aws_profile" { default = "default" } @@ -65,7 +62,7 @@ variable "container_memory" { } variable "instance_ebs_size" { - default = 40 # 40GB + default = 250 # 250GB } # see Secure Agent system requirements, before changing instance type, see the @@ -93,6 +90,10 @@ variable "ecs_iam_role" { default = "iics-secure-agent-iam-role-test" } +variable "ecs_execution_role" { + default = "iics-secure-agent-ecs-execution-role-test" +} + variable "ecs_cluster_name" { default = "iics-agent-cluster" } @@ -130,7 +131,7 @@ variable "efs_tags" { } variable "secure_agent_mount_path" { - default = "/home/agent/infaagent/" + default = "/home/agent/infaagent/apps/agentcore/" } variable "secure_agent_sg_tags" { @@ -146,4 +147,8 @@ variable "iam_instance_profile" { variable "secure_agent_efs_sg" { default = "secure-agent-efs-sg" +} + +variable "iics_secret_access_policy" { + default = "iics-secret-access-policy-test" } \ No newline at end of file