Skip to content

Conversation

@aajtodd
Copy link
Contributor

@aajtodd aajtodd commented Dec 15, 2021

Issue #

N/A

Description of changes

  • Reimplement KMP compatible ECS provider based on SDK runtime primitives
  • Adds a CDK test app that can be used to test out the provider (or really any ECS related task) going forward

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

@aajtodd aajtodd requested a review from a team as a code owner December 15, 2021 21:40
@aajtodd aajtodd requested review from ianbotsf and kggilmer December 15, 2021 21:40
@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-feat-ecs-provider

Copy link
Contributor

@kggilmer kggilmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive work


public constructor() : this(Platform, CrtHttpEngine())

private val retryMiddleware = run {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice


if (url.scheme == Protocol.HTTPS) return url

// TODO - validate loopback via DNS resolution instead of fixed set. Custom host names (including localhost) that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

will this require some KMP work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's why it isn't implemented. We need the ability to actually resolve a host to something like List<InetAddress> and verify that each one is in fact the loopback device (e.g. InetAddres.isLoopBackDevice(): Boolean).

ECS itself only uses the relative URI, this only comes into play when the full URI is set (and not using https). I believe greengrass is the primary user of this for something but I don't recall what. Seems safe to wait until it's needed. I created #476 to track it.

internal class EcsCredentialsRetryPolicy : RetryPolicy<Any?> {
override fun evaluate(result: Result<Any?>): RetryDirective = when {
result.isSuccess -> RetryDirective.TerminateAndSucceed
else -> evaluate(result.exceptionOrNull()!!)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

it seems a little weird to call an ...orNull() function and then !! it. Is there a reason this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I agree it's a little weird but there is no function on Result that provides the exception or throws. The success case has functions like getOrThrow() but nothing like that for the error case. No smart casting to be had either :(

Seems like something is missing from Result to me but this should be safe since we know it's the error case.

@@ -0,0 +1,70 @@
# CDK stack for ECS credentials provider testing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow nice

@@ -0,0 +1,34 @@
plugins {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

pull the version strings out property references (log4j, coroutines)

import { EcsCredentialsStack } from '../lib/ecs-credentials-stack';

const app = new cdk.App();
new EcsCredentialsStack(app, 'EcsCredentialsStack', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

does this reference any cloud things that may change over time that we may need to manage? I'm not familiar with CDK myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CDK is just a wrapper around cloudformation templates. To answer your question though no there is nothing to manage here. The expected usage of this is for one off testing. Developers would deploy, run whatever tests they need, and tear down the stack when they are done.


const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {
memoryLimitMiB: 512,
cpu: 256,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

is this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's a bit of an odd one but it's correct. 256 maps to .25 vCPU

See docs here

@@ -0,0 +1,17 @@
// import * as cdk from 'aws-cdk-lib';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

is most of this commented out for a reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be deleted, it's part of cdk init scaffolding 🤷

@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-feat-ecs-provider

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 4 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-feat-ecs-provider

@aajtodd aajtodd merged commit b9945d3 into feat-cred-providers Dec 20, 2021
@aajtodd aajtodd deleted the feat-ecs-provider branch December 20, 2021 14:56
aajtodd added a commit that referenced this pull request Feb 17, 2022
…ible (#469)

Refactor credential providers to remove CRT dependency and make them KMP compatible. Added SSO provider to default chain. Lots of misc cleanup and improvements.


* feat(rt): standalone sso credentials provider (#462)
* refactor(rt)!: generated sts and sts web identity credential providers (#470)
* refactor(rt)!: implement kmp ecs provider (#475)
* feat(rt)!: implement kmp profile credentials provider (#478)
* feat(rt)!: kmp default credentials provider chain (#491)
* fix: work around machine-specific Gradle bug with aws-config variants (#496)
* fix: credentials provider ownership (#498)

Co-authored-by: Ian Botsford <83236726+ianbotsf@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants