Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ecs-patterns): allow setting TLS listener for NLB patterns #6988

Closed

Conversation

iamhopaul123
Copy link
Contributor

fix #6263


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@iamhopaul123 iamhopaul123 changed the title chore(ecs-patterns): allow setting TLS listener forr NLB patterns chore(ecs-patterns): allow setting TLS listener for NLB patterns Mar 24, 2020
@iamhopaul123 iamhopaul123 force-pushed the ecs-pattern/tls-listener-for-nlb branch from 48fb160 to ab32b36 Compare March 24, 2020 23:48
@SoManyHs SoManyHs added @aws-cdk/aws-ecs Related to Amazon Elastic Container @aws-cdk/aws-ecs-patterns Related to ecs-patterns library labels Apr 6, 2020
@piradeepk
Copy link
Contributor

Should this also be updated for the NLBService?

@iamhopaul123 iamhopaul123 force-pushed the ecs-pattern/tls-listener-for-nlb branch from ab32b36 to 2281220 Compare April 29, 2020 19:53
@mergify mergify bot dismissed piradeepk’s stale review April 29, 2020 19:53

Pull request has been modified.

@piradeepk piradeepk assigned piradeepk and unassigned uttarasridhar Apr 29, 2020
@piradeepk
Copy link
Contributor

The PR looks great! I think this is more of a feature than a chore, so you’ll need to add an example to the README.

@piradeepk piradeepk changed the title chore(ecs-patterns): allow setting TLS listener for NLB patterns fix(ecs-patterns): allow setting TLS listener for NLB patterns May 5, 2020
@piradeepk piradeepk changed the title fix(ecs-patterns): allow setting TLS listener for NLB patterns feat(ecs-patterns): allow setting TLS listener for NLB patterns May 5, 2020
@dejonghe
Copy link

Is this only blocked by a readme?
Is this the right README? https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-ecs-patterns
ALB's support this functionality but there's nothing in the README about it. I'd be more than happy to write something up but do not under stand the direction.
This is a critical feature for any non HTTP app that need public TLS by default.

@iamhopaul123
Copy link
Contributor Author

Is this only blocked by a readme?
Is this the right README? https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-ecs-patterns
ALB's support this functionality but there's nothing in the README about it. I'd be more than happy to write something up but do not under stand the direction.
This is a critical feature for any non HTTP app that need public TLS by default.

No this is blocked because public TLS listener with domain still won't work with this PR.

@dejonghe
Copy link

dejonghe commented Aug 13, 2020

Is this only blocked by a readme?
Is this the right README? https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-ecs-patterns
ALB's support this functionality but there's nothing in the README about it. I'd be more than happy to write something up but do not under stand the direction.
This is a critical feature for any non HTTP app that need public TLS by default.

No this is blocked because public TLS listener with domain still won't work with this PR.

Understood. Thanks for the response.

@gitpod-io
Copy link

gitpod-io bot commented Nov 13, 2020

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: a58bd97
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@iamhopaul123
Copy link
Contributor Author

won't be able to work on it for a while. close for now.

@dannyalan
Copy link

Following. This has just tripped me up too. Is there anything we can do to help move this along?

@js-timbirkett
Copy link

js-timbirkett commented Apr 29, 2022

For anyone who finds this... I made use of the ECS patterns as they're really useful, and got TLS termination working like this:

.....

    const tlsCertificate = new DnsValidatedCertificate(this, 'SFTPWebCert', {
      domainName: `sftp.${props.zone.zoneName}`,
      hostedZone: props.zone,
    });
    
    const cluster = new ecs.Cluster(this, 'SFTPCluster', { vpc: props.vpc });

    const sftpService = new ecsPatterns.NetworkMultipleTargetGroupsFargateService(this, 'SFTPService', {
      cluster,
      serviceName: 'sftpgo',
      desiredCount: 1,
      cpu: 256,
      memoryLimitMiB: 512,
      taskImageOptions: {
        containerName: 'sftpgo',
        image: ecs.ContainerImage.fromRegistry("ghcr.io/drakkan/sftpgo:v2.2.2"),
      },
      loadBalancers: [
        {
          name: 'sftpgo',
          domainName: `sftp.${props.zone.zoneName}.`,
          domainZone: props.zone,
          publicLoadBalancer: true,
          listeners: [
            {
              name: 'sftp',
              port: 2022,
            },
          ],
        }
      ],
      targetGroups: [
        {
          containerPort: 2022,
          listener: 'sftp',
        },
      ],
    });
    
    // As it isn't possible to configure TLS through the listeners in above,
    // we must resort to configuring them manually.
     
    const container = sftpService.taskDefinition.findContainer('sftpgo');
    
    container.addPortMappings({
      containerPort: 8080,
    });

    const webListener = sftpService.loadBalancer.addListener('web', {
      port: 443,
      certificates: [ { certificateArn: tlsCertificate.certificateArn } ],
      sslPolicy: elbv2.SslPolicy.RECOMMENDED,
      alpnPolicy: elbv2.AlpnPolicy.HTTP1_ONLY,
    });
    
    sftpService.service.registerLoadBalancerTargets({
      containerName: 'sftpgo',
      containerPort: 8080,
      newTargetGroupId: 'sftpgo-web',
      listener: ecs.ListenerConfig.networkListener(webListener, {
        port: 8080,
        protocol: 'TCP',
      }),
    });
    
    // Although this opens ports to everywhere, the Fargate container is not
    // exposed directly to the outside world. All traffic is handled by the NLBs.
    sftpService.service.connections.allowFromAnyIpv4(ec2.Port.tcp(2022), 'SSH/SFTP');
    sftpService.service.connections.allowFromAnyIpv4(ec2.Port.tcp(8080), 'Web UI');
    
    .....

I pass in the Route53 zone and VPC from other stacks. The main thing here is that I make use of NetworkMultipleTargetGroupsFargateService, but only configure one port for TCP forwarding. I then use available functions to configure the TLS listener, expose ports, attach to target groups etc... this took me about 6 hours to work out 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container @aws-cdk/aws-ecs-patterns Related to ecs-patterns library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unclear how to use ecs-patterns NetworkMultipleTargetGroupsEc2Service
9 participants