Symfony can't find secret environment variable

穿精又带淫゛_ 提交于 2020-04-13 10:06:10

问题


I am trying to set up a secret manager in Symfony 5. I followed this Secrets Management Setup course and How to Keep Sensitive Information Secret documentation.

My app is now triggering :

Fatal Error: Maximum execution time of 30 seconds exceeded
Environment variable not found: "DATABASE_URL".

As the documentation says, I dropped DATABASE_URL from my .env and used php bin/console secrets:set DATABASE_URL which output :

 [OK] Sodium keys have been generated at "config/secrets/dev/dev.*.public/private.php".


 !
 ! [CAUTION] DO NOT COMMIT THE DECRYPTION KEY FOR THE PROD ENVIRONMENT⚠️
 !


 [OK] Secret "DATABASE_URL" encrypted in "config/secrets/dev/"; you can commit it.

Here is the result of php bin/console secrets:list :

 // Use "%env(<name>)%" to reference a secret in a config file.
 ------------------- -------- -------------
  Secret              Value    Local Value
 ------------------- -------- -------------
  DATABASE_URL        ******
 ------------------- -------- -------------

Here how I use %env% in config/packages/doctrine.yaml :

doctrine:
    dbal:
        # ...
        url: '%env(DATABASE_URL)%'
        # ...

I'm using PHP 7.2.21 and following the documentation :

The Secrets system requires the sodium PHP extension that is bundled with PHP 7.2. If you're using an earlier PHP version, you can install the libsodium PHP extension or use the paragonie/sodium_compat package.

The Symfony console asked me anyway to install paragonie/sodium_compat polyfill, what I did.

My application isn't working anymore. What am I missing ?

Update #1

It turns out that the problem is from the paragonie/sodium_compat package. The last debug message before Fatal Error: Maximum execution time of 30 seconds exceeded is :

timeParagonIE_Sodium_Core_Util::mul() vendor/paragonie/sodium_compat/src/Core/Curve25519.php:756

So Symfony isn't able to get the environment variable and trigger the error.

I tried then to decrypt secrets and store them in .env.dev.local to avoid decrypting them at each request using this command :

 php bin/console secrets:decrypt-to-local --force

But Symfony keeps decrypting it and doesn't use .env.dev.local.

来源:https://stackoverflow.com/questions/61016442/symfony-cant-find-secret-environment-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!