Skip to content

Symfony 4.4 secrets management system #12958

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

Merged
merged 3 commits into from
Jan 27, 2020

Conversation

weaverryan
Copy link
Member

Hi!

This completes #11396

I also made some changes to the section in configuration.rst about environment variables to make sure that it read well with the secrets stuff.

Thanks to @jderusse for doing the vast majority of the work.

Cheers!

Use Secret for Sensitive Information
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When your application has sensitive configuration - like an API key - you should
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use a database password instead of an api key for the example
99% of project have a db :)
Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see your point. But on some systems (Heroku, SymfonyCloud), the database credentials are provided to you by your platform and are not something you need to store in a vault.


.. code-block:: bash

# .env
DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name"

This file should be committed to your repository and (due to that fact) should
only contain "default" values that are good for local development. This file
should not contain production values.
Copy link
Contributor

@94noni 94noni Jan 19, 2020

Choose a reason for hiding this comment

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

I would use sensitives values
As on a preproduction, there are also such values

Copy link
Member

Choose a reason for hiding this comment

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

sensitive value should not be committed and therefore should not be stored in .env file which contains default public values.

I'd rather use secrets to store "pre-prodction" sensitive value and change the secret location (see section configuration) according to an env variable that define the stage.
ie.

framework:
  secrets:
    vault_directory: '%kernel.project_dir%/config/secrets/%kernel.environment%/%app_stage'
parameters:
  app_stage: '%env(STAGE)%'
$ STAGE=PRE-PRODCTION APP_ENV=PROD bin/console secrets:set DATABASE_PASSWORD

Copy link
Member Author

Choose a reason for hiding this comment

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

This might be a nice example to add to the config section after this PR is merged :)

The Secrets management was introduced in Symfony 4.4.

:ref:`Environment variables <config-env-vars>` are the best way to store configuration
that depends on where the application is run - for example, some API key that
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Copy link
Member

@wouterj wouterj left a comment

Choose a reason for hiding this comment

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

Nice work!

Beware that dumping the contents of the ``$_SERVER`` and ``$_ENV`` variables
or outputting the ``phpinfo()`` contents will display the values of the
environment variables, exposing sensitive information such as the database
credentials.
Copy link
Member

Choose a reason for hiding this comment

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

Even more, they are exposed in the system (for instance, when requesting details about PHP-fpm processes or services). I think we maybe should be more explicit that plaintext sensitive information should not be in an env var

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true... but only true when users are setting "real" env vars (not using .env), right? In general, I hope we can now (with secrets) really push people to use that system. This warning already is starting to look misplaced to me: we should (in the document in general) be telling people to instantly use the secrets management for sensitive stuff.

@weaverryan
Copy link
Member Author

This should be ready now!

# config/packages/doctrine.yaml
doctrine:
dbal:
password: '%env(DATABASE_PASSWORD)%'
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be %env(secret:DATABASE_PASSWORD) ?

Copy link
Member

@jderusse jderusse Jan 27, 2020

Choose a reason for hiding this comment

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

there is no secret env processor, the documentation is right here, to access secret, you should use %env(DATABASE_PASSWORD)%. this is explain in the paragraph above (line 104).

@weaverryan
Copy link
Member Author

Thanks to @jderusse for helping with this great feature and writing most of the docs. Sorry for the delay - but I wanted to get the first draft right :)

weaverryan added a commit that referenced this pull request Jan 27, 2020
…rryan)

This PR was merged into the 4.4 branch.

Discussion
----------

Symfony 4.4 secrets management system

Hi!

This completes #11396

I also made some changes to the section in `configuration.rst` about environment variables to make sure that it read well with the secrets stuff.

Thanks to @jderusse for doing the vast majority of the work.

Cheers!

Commits
-------

cd066cc tweaks thanks to review
75e5ae6 finishing the secrets documentation
82d2058 Add the secret documentation
@weaverryan weaverryan merged commit cd066cc into symfony:4.4 Jan 27, 2020
@weaverryan weaverryan deleted the jderusse-secrets branch January 27, 2020 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants