-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Add secrets:*
commands and %env(secret:...)%
processor to deal with secrets seamlessly
#33997
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
Conversation
How does the management of the secret key would work on Saas hosting like Heroku or Symfony Cloud ? I don't think they let us inject some files on the filesystem. |
7bd4631
to
495909e
Compare
495909e
to
e089bec
Compare
All PaaS providers have a build and/or deploy step so this file could be dealt with there. For SFCloud at least there are many possible solutions. I think it's the same for all hosting providers. Since the key file is a PHP file, it's also possible to dump e.g a reference to an env var if that's what one wants to do: |
hmm, this is what I missed. I thought it was the key file itself. |
src/Symfony/Bundle/FrameworkBundle/Command/SecretsSetCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Command/SecretsListCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Command/SecretsSetCommand.php
Outdated
Show resolved
Hide resolved
I've been playing with this feature inside the Symfony Demo application. First, thanks Nicolas for working on this. I don't know if this could disappoint some who expected a more complex feature (not only filesystem-based, etc.) ... but to me it was perfect and it didn't fall short at anything I needed. I love it ❤️ Now, let's comment some details.
I guess it would be complicated to change this ... but just a comment in case we could do some effort.
Maybe we can improve the output to add more information about the successful message? E.g.: which files have been generated and in which file. Also, a basic info explaining what to do: commit the public key but not the private key, etc.
We could improve it explaining that even keys already exist, you can rotate them with the
Before:
After:
Or:
Same for the names of the encrypted values: do we need to include the env name?
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1426528957000",
"Effect": "Allow",
"Action": ["ec2:*"],
"Resource": ["*"]
}
]
} In Hashicorp Vault I can do this:
|
Thanks for the feedback @javiereguiluz
updated
using more fancy chars is anyway incompatible with
You can store only strings. Store the empty one if you want to (using STDIN as input as the interactive mode doesn't allow empty strings. I don't think that's useful enough to fix.)
emoji removed
I'm not sure we can, because commands don't know anything about where keys are put (the vault is a black box to them.)
maybe the above message is enough a hint? if you have a suggestion, I'm listening.
that's a dangerous hint as ppl may erase the existing keys by mistake. I'd better have them check the help (or read the doc) to discover how to get past this.
yes, we do: if for any reason a file is moved out of the directory where it is, then you'd suddenly lose all context to know what this is about. With these, you're a bit safer. Same for s 8000 ecrets' files. The word sodium provides some possible future extensibility.
Addressed by adding an additional command-line argument which is a file where to read the secret from ( |
73bcdf8
to
1c0fbb7
Compare
BTW: public/private are generic terms, encrypt/decrypt are more accurate because we do have more context about the use case. |
Hiya! I agree with Javier - this is fun to use! After kicking the tires, here's my feedback FWIW A) For local dev workflow, fallback to env vars There's a workflow problem currently for local development. If the app requires 10 "secrets", does the user need to create their own I think the workflow should look like this:
** B) Smaller Stuff**
That path -
|
IMHO you should never commit the private key. If you don't care about the secret and want an easy way to share the key, then those are not secrets and you don't have to use the "secrets feature". Symfony is flexible enough to use different ways to configure 2 environments.
# /config/packages/database.yaml
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
password: 'root' # yes, you can provide both DSN (without password) and password attribute
# /config/packages/prod/database.yaml
doctrine:
dbal:
password: '%env(secret:DATABASE_PASSWORD)%'
# .env
DATABASE_URL=mysql://db_user@127.0.0.1:3306/db_name
# /config/packages/database.yaml
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
password: '%env(default:empty_database_password:secret:DATABASE_PASSWORD)%'
parameters:
empty_database_password: '%env(DATABASE_PASSWORD)%'
# /config/packages/messenger.yaml
framework:
messenger:
transports:
async: '%env(resolve:MESSENGER_TRANSPORT_DSN)%'
parameters:
amqp_password: '%env(secret:AMQP_PASSWORD)'
# .env
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# .env.prod
MESSENGER_TRANSPORT_DSN=amqp://guest:%amqp_password%@localhost:5672/%2f/messages note: I personnaly would loved to use # /config/packages/messenger.yaml
framework:
messenger:
transports:
async: '%env(resolve:MESSENGER_TRANSPORT_DSN)%'
# .env
MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# .env.prod
MESSENGER_TRANSPORT_DSN=amqp://guest:%env(secret:AMQP_PASSWORD)%@localhost:5672/%2f/messages |
b6f3784
to
be8b267
Compare
3846ce4
to
78af50f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 from me! Excellent work
Now with two new commands:
and |
78af50f
to
2aaf715
Compare
src/Symfony/Bundle/FrameworkBundle/Command/SecretsDecryptToLocalCommand.php
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Command/SecretsEncryptFromLocalCommand.php
Outdated
Show resolved
Hide resolved
2aaf715
to
8efe31e
Compare
8efe31e
to
785e25b
Compare
785e25b
to
d9aec9a
Compare
d9aec9a
to
c4653e1
Compare
Thank you @nicolas-grekas. |
…ecret:...)%` processor to deal with secrets seamlessly (Tobion, jderusse, nicolas-grekas) This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle] Add `secrets:*` commands and `%env(secret:...)%` processor to deal with secrets seamlessly | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #27351 | License | MIT | Doc PR | symfony/symfony-docs/pull/11396 This PR continues #31101, please see there for previous discussions. The attached patch has been fine-tuned on nicolas-grekas#33 with @jderusse. This PR is more opinionated and thus a lot simpler than #31101: only Sodium is supported to encrypt/decrypt (polyfill possible), and only local filesystem is available as a storage, with little to no extension point. That's on purpose: the goal here is to provide an experience, not software building blocks. In 5.1, this might be extended and might lead to a new component, but we'd first need reports from real-world needs. Having this straight-to-the-point in 4.4 will allow gathering these needs (if they exist) and will immediately provide a nice workflow for the need we do want to solve now: forwarding secrets from dev to prod using git in a secure way. The workflow this will allow is the following: - public/private key pairs are generated in the `config/secrets/%kernel.environment%/` folder using `bin/console secrets:generate-keys` - for the prod env, the corresponding private key should be deployed to the server using whatever means the hosting provider allows - this key MUST NOT be committed - the public key is used to encrypt secrets and thus *may* be committed in the git repository to allow anyone *that can commit* to add secrets - this is done using `bin/console secrets:set` DI configuration can reference secrets using `%env(secret:...)%` in e.g `services.yaml`. There is also `bin/console secrets:remove` and `bin/console debug:secrets` to complete the toolbox. In terms of design, vs #31101, this groups the dual "encoder" + "storage" concepts in a single "vault" one. That's part of what makes this PR simpler. That's all folks :) Commits ------- c4653e1 Restrict secrets management to sodium+filesystem 02b5d74 Add secrets management 8c8f623 Proof of concept for encrypted secrets
This PR continues #31101, please see there for previous discussions. The attached patch has been fine-tuned on nicolas-grekas#33 with @jderusse.
This PR is more opinionated and thus a lot simpler than #31101: only Sodium is supported to encrypt/decrypt (polyfill possible), and only local filesystem is available as a storage, with little to no extension point. That's on purpose: the goal here is to provide an experience, not software building blocks. In 5.1, this might be extended and might lead to a new component, but we'd first need reports from real-world needs. Having this straight-to-the-point in 4.4 will allow gathering these needs (if they exist) and will immediately provide a nice workflow for the need we do want to solve now: forwarding secrets from dev to prod using git in a secure way.
The workflow this will allow is the following:
config/secrets/%kernel.environment%/
folder usingbin/console secrets:generate-keys
bin/console secrets:set
DI configuration can reference secrets using
%env(secret:...)%
in e.gservices.yaml
.There is also
bin/console secrets:remove
andbin/console debug:secrets
to complete the toolbox.In terms of design, vs #31101, this groups the dual "encoder" + "storage" concepts in a single "vault" one. That's part of what makes this PR simpler.
That's all folks :)