Skip to content

POC Localstack for local integration testing#2

Open
cazlo wants to merge 14 commits into
mainfrom
localstack
Open

POC Localstack for local integration testing#2
cazlo wants to merge 14 commits into
mainfrom
localstack

Conversation

@cazlo

@cazlo cazlo commented Jun 5, 2024

Copy link
Copy Markdown
Owner

What

  • Add localstack to local docker deployment cluster to serve as local emulation of most AWS services
    • Requires app level changes to inject the localstack endpoint URL into core svc DynamoDB and (mostly fixing a few todos in the code about this)
    • Done in a way which is re-usable in a production context, specifically for the runtime override of VPC endpoint URLs.
  • Provision most necessary application infrastructure in localstack using terraform
    • Organized into set of re-usable modules, so we can deploy nearly the same stack to an actual AWS env

Why

Refactor most of the logic contained within the installer stack into a localstack + terraform test-able platform.

Dependency Tree

The below diagram details the local deployment dependency diagram, however can likely be extended with minimal modification to the production deployment context.

graph LR
  dcv-broker
  dcv-gateway
  config-bootstrapper --> cluster-manager
  config-bootstrapper --> virtual-desktop-controller

  subgraph Emulated-AWS-Resources
    localstack --> terraform
    terraform -. Creates .-> config-db[(Config DB)]
    terraform -. Creates .-> config-secrets[(Config Secrets DB)]
    terraform -. Creates .-> sqs[/Task Queues/]
    terraform --> config-bootstrapper -. WritesTo .-> config-db

  end
Loading

@cazlo cazlo changed the title Localstack support Draft: Localstack support Jun 5, 2024
@cazlo cazlo changed the title Draft: Localstack support POC Localstack for local integration testing Jun 10, 2024
return InitiateAuthResult(
challenge_name="challenge_name",
session="session",
auth={

@cazlo cazlo Jun 10, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

this is a total hack not mean to be any kind of production worthy anything. it's just enough to get past the login without cognito. it's a very basic jwt from jwt.io with only an added kid claim.

while enough to bypass auth initially, later calls which happen on the page are still failing apparently due to trying to call out to {kid}/.well-known/jwks.json.

more effort will need to be done to bypass the tight coupling with cognito.

we could probably setup some kind of dependency injection for the identity provider used in the auth layer and inject something other than cognito optionally.

otherwise cognito is locked behind paywall in localstack which is something like 20 bucks per dev per month

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The good news is this does break 5 unit tests:

FAILED tests/unit/idea-cluster-manager/test_accounts.py::test_accounts_initiate_auth_user_password_auth_flow - AssertionError: assert 'role' == 'admin'
FAILED tests/unit/idea-cluster-manager/test_accounts.py::test_accounts_initiate_auth_user_password_auth_flow_fail - Failed: DID NOT RAISE <class 'containres.ideadatamodel.exceptions.exceptions.SocaException'>
FAILED tests/unit/idea-cluster-manager/test_accounts.py::test_accounts_initiate_auth_refresh_token_auth_flow - Failed: DID NOT RAISE <class 'containres.ideadatamodel.exceptions.exceptions.SocaException'>
FAILED tests/unit/idea-cluster-manager/test_accounts.py::test_accounts_initiate_sso_auth_flow - Failed: DID NOT RAISE <class 'containres.ideadatamodel.exceptions.exceptions.SocaException'>
FAILED tests/unit/idea-cluster-manager/test_accounts.py::test_accounts_initiate_sso_refresh_auth_flow - Failed: DID NOT RAISE <class 'containres.ideadatamodel.exceptions.exceptions.SocaException'>

self.apply_sanic_extensions(self._unix_app)

if self.options.enable_metrics:
if False: # todo self.options.enable_metrics:

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

should probably revert this and find some better solution around this.

in tracing through how this is used, it is apparently a UUID which can be used as an auth token to the metrics/healthcheck endpoint.

this makes sense in certain context such as exposing loadbalancer and/or synthetic healthchecks

Comment thread containres/ideavirtualdesktopcontroller/app/app_main.py Outdated
Comment thread Makefile
.PHONY: build-webapp
build-webapp:
docker build -f infra/webapp.Dockerfile -t containres-webapp webapp
#.PHONY: build-webapp

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

in this iteration of the build this is merged in with the python webapp backend to facilitate the current CORS setup of the app


def get_use_vpc_endpoints(self) -> bool:
return Utils.get_value_as_bool('use_vpc_endpoints', self.user_values, False)
return Utils.get_value_as_bool('use_vpc_endpoints', self.user_values, True)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

As VPC endpoints represents the generally more secure approach for communication between nodes and AWS services, I desire the app to use VPC endpoints by default.

This additionally facilitates local override of these endpoints facilitating local integration testing using localstack

@@ -0,0 +1,56 @@
#!/bin/bash

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

note: this is very similar conceptually to the installer's config bootstrapping process

I also added most of the config items which were previously places by the CDK sub-stacks that get invoked by the installer stack

Comment thread infra/cluster-config-setup.sh Outdated

# Install dependencies
COPY webapp/package.json webapp/yarn.lock ./
RUN yarn install

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

should be using lockfile here

cazlo added 10 commits June 16, 2024 09:36
note in unit tests now the AWSProvider is monkey patched with mock endpoints, rather than using dependency injection at the app level to inject the mock.

if we instead used dependency injection, we could probably get better test coverage by using it in basic integration tests run in pytest
at this point it is mostly butting up against a few restriction with free localstack (no cognito-idp svc avail in free version, no ec2 svc ail in free version)
add dockerignore to remove need to change build context and sometimes unnecessarily trigger rebuild when these files change

plain progress builds to reduce flicker during build
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.

1 participant