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

Add ability to generate secrets for the application #602

Merged
merged 6 commits into from
May 26, 2024
Merged

Conversation

lorenyu
Copy link
Contributor

@lorenyu lorenyu commented May 22, 2024

Ticket

Resolves #562

Changes

⚠️ breaking change (change to way secrets are defined in app-config in environment-variables.tf).
secrets are now defined as a map:

secrets = {
  ENV_VAR_NAME = {
    manage_method     = "code" or "manual"
    secret_store_path = "/ssm/param/name"
  }
}

It was previously defined as a list:

secrets = [
  {
    name = "ENV_VAR_NAME",
    ssm_param_name = "/ssm/param/name"
  }
]
  • Add new module modules/secret for generating new secrets or referencing existing secrets
  • Refactor interface

To migrate:

  • In app-config's environment-variables.tf, update secret definitions to use the new format.
  • For secrets managed outside of the project's codebase, set manage_method = "manual"
  • For secrets created within the project's codebase but defined elsewhere, move (using terraform mv) the aws_ssm_parameter to module.secret[ENV_VAR_NAME].aws_ssm_parameter.secret

Context for reviewers

This is the work for #562

The CI failures for trivy and anchor aren't related to this PR.

Testing

Developed and tested in platform-test in this PR: navapbc/platform-test#95

Rollout notes

After the template-infra PR is merged, we should update the platform-test PR from main and then merge it rather than closing it, since it'll have changes to app-config and the app that wouldn't have been pulled over from the template CD.

Future work

In the future we should add the ability to rotate the randomly generated secret by adding version numbers: #601

Copy link
Contributor

@rocketnova rocketnova left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! Left some feedback on naming, only one of which isn't a nit.

docs/infra/environment-variables-and-secrets.md Outdated Show resolved Hide resolved
infra/modules/secret/variables.tf Outdated Show resolved Hide resolved
infra/modules/secret/variables.tf Outdated Show resolved Hide resolved
@lorenyu lorenyu merged commit 85830e5 into main May 26, 2024
12 of 14 checks passed
@lorenyu lorenyu deleted the lorenyu/secrets branch May 26, 2024 17:54
coilysiren added a commit to HHS/simpler-grants-gov that referenced this pull request Oct 10, 2024
## Summary

Fixes #1656

### Time to review: __10 ~ 30 mins__

## Changes proposed

- Deploys an opensearch domain
- Configures the opensearch domain to be high availability in prod, and
as cheap as possible (while still being similarly configured) elsewhere.
Prod is currently turned off, though.
- Adds opensearch secrets to the API service

## Context for reviewers

Opensearch takes about 20 minutes to deploy, similarly to RDS Postgres

Generating the password was a pain in the butt

This style of this infra code is similar to the style of platform code,
so I'm going to post it in our platform channel for other people to see

This PR tangentially includes the updated secrets handling from
navapbc/template-infra#602. I added that because
I'm adding a bunch of secrets, and I don't want them to conflict with
#2351.

## Additional information

Opensearch deployment:

(staging has since been torn down)

<img width="396" alt="image"
src="https://github.com/user-attachments/assets/ab78b649-8e9c-460c-b9e8-3d0b823d8d5e">

The terraform diff for the API service layer:

```
                    {
                        Action = "ssm:GetParameters"
                        Effect = "Allow"
                      ~ Resource = "arn:aws:ssm:*:*:parameter/api/dev/api-auth-token" -> [
                          + "arn:aws:ssm:us-east-1:315341936575:parameter/search/dev/username"
                          + "arn:aws:ssm:us-east-1:315341936575:parameter/search/dev/password"
                          + "arn:aws:ssm:us-east-1:315341936575:parameter/search/dev/endpoint"
                          + "arn:aws:ssm:us-east-1:315341936575:parameter/api/dev/api-auth-token"
                        ]
                        Sid = "SecretsAccess"
                    }
                ]
```

```
                    secrets = [
                        {
                        }
                      + {
                          + name = "SEARCH_ENDPOINT"
                          + valueFrom = "arn:aws:ssm:us-east-1:315341936575:parameter/search/dev/endpoint"
                        }
                      + {
                          + name = "SEARCH_PASSWORD"
                          + valueFrom = "arn:aws:ssm:us-east-1:315341936575:parameter/search/dev/password"
                        }
                      + {
                          + name = "SEARCH_USERNAME"
                          + valueFrom = "arn:aws:ssm:us-east-1:315341936575:parameter/search/dev/username"
                        }
                    ]
```
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.

Add ability to generate secrets for the application
2 participants