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

Update push_secrets.sh to use hcp instead of vlt #31

Merged
merged 3 commits into from
Sep 30, 2024

Conversation

kenzysoror
Copy link
Contributor

@kenzysoror kenzysoror commented Sep 22, 2024

Notion ticket link

Modify push_secrets.sh to use hcp instead of vlt

Implementation description

  • Updated all vlt commands to hcp commands

Steps to test

  1. Create a test key/value secret within the .env file
  2. Run ./push_secrets.sh
  3. Check HashiCorp to ensure the secret was created
  4. Change the value of the test key/value secret within the .env file
  5. Run ./push_secrets.sh
  6. Check Hashicorp to ensure the secret was deleted and re-created with the changed value
  7. Remove the test key/value secret within the .env file
  8. Run ./push_secrets.sh
  9. Check Hashicorp to ensure the secret was deleted

Checklist

  • My PR name is descriptive and in imperative tense
  • My commit messages are descriptive and in imperative tense. My commits are atomic and trivial commits are squashed or fixup'd into non-trivial commits
  • I have requested a review from the PL, as well as other devs who have background knowledge on this PR or who will be building on top of this PR

Copy link

vercel bot commented Sep 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sistema ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 29, 2024 11:57pm

Copy link
Member

@ChinemeremChigbo ChinemeremChigbo left a comment

Choose a reason for hiding this comment

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

Did an initial walk through and it looks good so far. Do you mind adding adding instructions for running the push_secrets script to the README similar to those that exist in https://github.com/uwblueprint/sistema?tab=readme-ov-file#secrets . Under the secrets header please add 2 subheaders, one for copying the secrets (./setup_secrets.sh) and the other for your command. Thanks!

@ChinemeremChigbo
Copy link
Member

Also please remove the unused secrets from vlt lol/

@kenzysoror
Copy link
Contributor Author

Of course, just deleted the 2 test keys I was using from HashiCorp itself! Is that what you're referring to?

@ChinemeremChigbo
Copy link
Member

Of course, just deleted the 2 test keys I was using from HashiCorp itself! Is that what you're referring to?

yup!

Copy link
Member

@ChinemeremChigbo ChinemeremChigbo left a comment

Choose a reason for hiding this comment

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

Deletion is not working as intended. Hashicorp has a limit of 5 secrets so the original script deletes and then recreates all of the secrets so they are new each time and don't reach the limit. You can note that the deletion is not working as intended because some secrets reach the maximum number of secret versions reached. You should ensure that SECRET_KEYS=$(hcp vault-secrets secrets list --format=json | grep -Eo '"([^"]*)"\s*:\s*"([^"]*)"' | sed -E 's/^"([^"]*)"\s*:\s*"([^"]*)"$/\1=\2/' | grep "^name=" | grep -v "@" | sed 's/^name=//') is working as intended. I suspect that it's not, because if you echo $SECRET_KEYS; it is empty. I would run hcp vault-secrets secrets list --format=json and make sure that $SECRET_KEYS is a list of each secrets name. Feel free to ask GPT or myself for some help!

✓ App with name "sistema" selected
Fetching and deleting all existing secrets...
ERROR: failed to create secret with name "AUTH_GOOGLE_ID": [POST
/secrets/2023-06-13/organizations/{location.organization_id}/projects/{location.project_id}/apps/{app_name}/kv][429]
CreateAppKVSecret default  &{Code:8 Details:[] Message:maximum number of secret versions reached}
Failed to create secret for AUTH_GOOGLE_ID.

ERROR: failed to create secret with name "AUTH_GOOGLE_SECRET": [POST
/secrets/2023-06-13/organizations/{location.organization_id}/projects/{location.project_id}/apps/{app_name}/kv][429]
CreateAppKVSecret default  &{Code:8 Details:[] Message:maximum number of secret versions reached}
Failed to create secret for AUTH_GOOGLE_SECRET.

Secret Name               Created At                 Latest Version
AUTH_REDIRECT_PROXY_URL   2024-09-25T01:34:55.188Z   4             

✓ Successfully created secret with name "AUTH_REDIRECT_PROXY_URL"

@kenzysoror
Copy link
Contributor Author

Thank you for catching that! It looks like hcp vault-secrets secrets list --format=json required the --app=sistema flag at the end since now:

echo $SECRET_KEYS; :

AUTH_GOOGLE_ID AUTH_GOOGLE_SECRET AUTH_REDIRECT_PROXY_URL AUTH_SECRET DATABASE_URL EMAIL_PASS EMAIL_SERVICE EMAIL_USER GDRIVE_CLIENT_EMAIL GDRIVE_CLIENT_ID GDRIVE_PRIVATE_KEY GDRIVE_PROJECT_ID POSTGRES_DATABASE POSTGRES_PASSWORD POSTGRES_PORT POSTGRES_USER SISTEMA_PASSWORD

./push_secrets.sh:

...
Fetching and deleting all existing secrets...
Deleting secret with name AUTH_GOOGLE_ID
✓ Successfully deleted secret with name "AUTH_GOOGLE_ID"

Deleting secret with name AUTH_GOOGLE_SECRET
✓ Successfully deleted secret with name "AUTH_GOOGLE_SECRET"

Deleting secret with name AUTH_REDIRECT_PROXY_URL
✓ Successfully deleted secret with name "AUTH_REDIRECT_PROXY_URL"

Deleting secret with name AUTH_SECRET
✓ Successfully deleted secret with name "AUTH_SECRET"

Deleting secret with name DATABASE_URL
✓ Successfully deleted secret with name "DATABASE_URL"

Deleting secret with name EMAIL_PASS
✓ Successfully deleted secret with name "EMAIL_PASS"

Deleting secret with name EMAIL_SERVICE
✓ Successfully deleted secret with name "EMAIL_SERVICE"

Deleting secret with name EMAIL_USER
✓ Successfully deleted secret with name "EMAIL_USER"

Deleting secret with name GDRIVE_CLIENT_EMAIL
✓ Successfully deleted secret with name "GDRIVE_CLIENT_EMAIL"

Deleting secret with name GDRIVE_CLIENT_ID
✓ Successfully deleted secret with name "GDRIVE_CLIENT_ID"

Deleting secret with name GDRIVE_PRIVATE_KEY
✓ Successfully deleted secret with name "GDRIVE_PRIVATE_KEY"

Deleting secret with name GDRIVE_PROJECT_ID
✓ Successfully deleted secret with name "GDRIVE_PROJECT_ID"

Deleting secret with name POSTGRES_DATABASE
✓ Successfully deleted secret with name "POSTGRES_DATABASE"

Deleting secret with name POSTGRES_PASSWORD
✓ Successfully deleted secret with name "POSTGRES_PASSWORD"

Deleting secret with name POSTGRES_PORT
✓ Successfully deleted secret with name "POSTGRES_PORT"

Deleting secret with name POSTGRES_USER
✓ Successfully deleted secret with name "POSTGRES_USER"

Deleting secret with name SISTEMA_PASSWORD
✓ Successfully deleted secret with name "SISTEMA_PASSWORD"
...

Copy link
Member

@ChinemeremChigbo ChinemeremChigbo left a comment

Choose a reason for hiding this comment

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

Very weird. I am guessing this is a Windows vs Linux vs Mac difference with the binary? When you run:

hcp vault-secrets secrets list --format=json --app=sistema | grep -Eo '"([^"]*)"\s*:\s*"([^"]*)"' | sed -E 's/^"([^"]*)"\s*:\s*"([^"]*)"$/\1=\2/' | grep '^\(name=\|"name":\)'| grep -v "@"

in your CLI are your secrets like:
"name": "SECRET_NAME"
or are they like:
name=SECRET_NAME
Mine are like the former, but I am guessing that yours are like the latter. Does the change I suggested on line 24 of the push_secrets.sh file work for you?

push_secrets.sh Outdated Show resolved Hide resolved
@kenzysoror
Copy link
Contributor Author

Definitely very weird! My secrets are indeed name=SECRET_NAME, which seems to have been the previous default since I didn't make any changes to the grep when I went from vlt to hcp. This change works for me too!

By the way, when I run hcp version I get hcp v0.5.0 (410604f643303ece1593db5d7601a3c4f3a9dd40) go1.22.2 amd64 - could that be different from yours?

Copy link
Member

@ChinemeremChigbo ChinemeremChigbo left a comment

Choose a reason for hiding this comment

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

LGTM!

@ChinemeremChigbo ChinemeremChigbo merged commit 4b7ab20 into main Sep 30, 2024
3 checks passed
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