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

Feature/nar 1545 app setup keygen #139

Merged
merged 9 commits into from
Mar 4, 2024

Conversation

mattschoch
Copy link
Contributor

No description provided.

Copy link

linear bot commented Feb 28, 2024

apps/policy-engine/src/policy-engine.config.ts Outdated Show resolved Hide resolved
apps/policy-engine/src/keyring/core/keyring.service.ts Outdated Show resolved Hide resolved
apps/policy-engine/src/keyring/core/keyring.service.ts Outdated Show resolved Hide resolved
apps/policy-engine/src/keyring/core/keyring.service.ts Outdated Show resolved Hide resolved
apps/policy-engine/src/keyring/core/keyring.service.ts Outdated Show resolved Hide resolved
apps/policy-engine/src/keyring/core/keyring.service.ts Outdated Show resolved Hide resolved
apps/policy-engine/Makefile Outdated Show resolved Hide resolved
@mattschoch mattschoch force-pushed the feature/nar-1545-app-setup-keygen branch 5 times, most recently from 12d6773 to 51bd555 Compare March 1, 2024 20:15
@mattschoch
Copy link
Contributor Author

mattschoch commented Mar 1, 2024

@wcalderipe Pushed some updated

  • encrypt and decrypt work correctly now.
  • If you set env variables for KMS, it supports a AWS KMS keyring, otherwise it will generate a masterKey & encrypted based on a masterPassword config.
  • I don't do ANYTHING related to api key anymore.
  • I think the Engine & API key config or whatever should be set up elsewhere; I'm inserting to the engine table if needed but I believe the EncryptionService should only bootstrap the encryption encryption keyrings.

Other things to note / give feedback on

  • I don't have tests on the KMS keyring...I tried it locally, but don't love the idea of using a real key in tests. wdyt? Maybe that'd be good, we can make a totally open key policy just for tests so we do actually do an e2e test on it? Should that go in e2e though or unit since everything else is the same as the unit test?
  • Look at my jest.setup.ts, I removed the .env file completely rather than overwriting it; I really don't like that you have to look at multiple files to know the env of the tests, much prefer to have to explicitly define the whole environment.

LMK any thoughts you have, I believe this can be merged & is stable; it may continue to evolve a bit, but the core functions are working now & have basic tests. Do you see places you'd suggest additional tests?

Comment on lines 22 to 26
for (const prop in process.env) {
if (Object.prototype.hasOwnProperty.call(process.env, prop)) {
delete process.env[prop]
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder why not delete process.env directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think you want/should delete the whole process.env object, not sure what happens there...tbh I just copy/pasted a snippet

@wcalderipe
Copy link
Collaborator

wcalderipe commented Mar 4, 2024

@mattschoch

I don't do ANYTHING related to api key anymore.
I think the Engine & API key config or whatever should be set up elsewhere; I'm inserting to the engine table if needed but I believe the EncryptionService should only bootstrap the encryption encryption keyrings.

Cool.

I've been thinking about the pattern of using the OnApplicationBootstrap interface on multiple services for provisioning setup, and I feel we could improve by centralizing the engine provisioning logic into a single service. This way, you'd know exactly where to look if you need to change the engine's provision.

The provision would involve other services like encryption:

  • Provisioning the encryption keys
  • Provisioning the admin API key
  • Anything else needed (e.g., diagnostics on the network, checking if the database is using the latest version)

It doesn't have to be done in your PR; it's just an idea I'm exploring. What do you think?

I don't have tests on the KMS keyring...I tried it locally, but don't love the idea of using a real key in tests. wdyt? Maybe that'd be good, we can make a totally open key policy just for tests so we do actually do an e2e test on it? Should that go in e2e though or unit since everything else is the same as the unit test?

I believe we're good to merge. However, since KMS is critical to the application's logic and security model, I would definitely include an integration test for it.

Moreover, I think we should be able to run the application connected to any dependency to easily debug it. I've used LocalStack in the past to simulate AWS services (S3, DynamoDB, Kinesis, and Lambda). They offer a version of KMS, which you can find at LocalStack KMS documentation.

Aside from a standalone application, they also distribute it as a Docker image, available at LocalStack Docker images that you can simply drop in the docker-compose.yml or in the GitHub Action workflow definition.

Look at my jest.setup.ts, I removed the .env file completely rather than overwriting it; I really don't like that you have to look at multiple files to know the env of the tests, much prefer to have to explicitly define the whole environment.

Copy that. Do you think you can set up the Armory project to do the same? I'd prefer that we have a consistent way of handling cross-functional tasks like environment management.

describe('EncryptionService', () => {
let service: EncryptionService

nock.enableNetConnect('kms.us-east-2.amazonaws.com:443')
Copy link
Collaborator

Choose a reason for hiding this comment

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

I left you a comment about using localstack #139 (comment) instead of connecting to AWS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re: testing KMS --
let me push that to "I'll add integration test on this separately, solving that problem on it's own"
I believe for KMS I probably prefer the solution of just actually using KMS directly, not localstack, since it's probably easier to have a single real key we're using. I just need to set up reasonable policies & credentials to do it, but we'd have to run A LOT of ci/cd to make it a cost-issue so I actually don't think there's a concern using KMS directly from local or ci/cd.

I definitely agree with your point that any dependency should be easy to set up / debug against. This has been a severe bottleneck in the past.

@mattschoch mattschoch force-pushed the feature/nar-1545-app-setup-keygen branch from 1f47778 to 3e4d6ab Compare March 4, 2024 14:03
@mattschoch mattschoch merged commit da72887 into main Mar 4, 2024
3 checks passed
@mattschoch mattschoch deleted the feature/nar-1545-app-setup-keygen branch March 4, 2024 14:11
mattschoch added a commit that referenced this pull request Jun 19, 2024
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