Why do you need to encrypt the .env file ? By default it is inaccessible.
Best practice for deploying encrypted .env files to Vapor via GitHub Actions?
Hi everyone,
I have been using Vapor for years now with an encrypted environment file .env.production.encrypted. This has worked great when deploying from local, but I'm currently putting together a CI/CD pipeline through GitHub Actions, and I'm unsure of the best practice to deploy the encrypted .env file.
Up until now I have never committed the .env.production.encrypted to source control, and had written a local deploy script to encrypt my .env.production, update the LARAVEL_ENV_ENCRYPTION_KEY in Vapor's env, then run vapor deploy production. However the only way I can really think of doing this through CI/CD is to encrypt the file locally, then commit the encrypted .env to source control. The repo is private and only myself and one other developer has access to it.
Is this bad practice? How does everyone else do this? Any thoughts?
Thanks!
@evan-55 If that’s the case, then you can commit the encrypted .env file to your repository. Just so long as you don’t also encrypt the actual decryption key as well. If someone does get access to your repository, then they just have the encrypted file’s contents and can’t read the original contents.
You’ll then need to set your encryption key as a secret in your repository (https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository). Your GitHub Actions workflow can then use the key to decrypt the encryption .env file just like you would when deploying or whatever.
Please or to participate in this conversation.