Description
Symfony version(s) affected
5 and up
Description
The default framework package config contains the following lines:
framework:
secret: '%env(APP_SECRET)%'
Starting from Symfony 5 attempt to warmup the cache (php bin/console cache:warmup
) without the environmental variable APP_SECRET
present leads to a warning:
WARNING [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension.
which was not the case before.
We are building docker images for the production deployment, so we don't want any sensitive information to be present in the image itself, but we want the image with the cache initialized for a better spin up time.
Right now it is not clear if the APP_SECRET
value is really required or is it safe to pass e.g. an empty string during the cache warmup step.
How to reproduce
- Create a default Symfony 5 application
- Remove
APP_SECRET
variable from the.env
file - Try to execute
php bin/console cache:warmup
- Check output for warnings
Possible Solution
Options:
- Make
APP_SECRET
not required for the cache warmup command. - Document if you can pass a random value for the cache warmup
Additional Context
Full warning output:
WARNING [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension.
[
"exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ {
#message: "Environment variable not found: "APP_SECRET"."
#code: 0
#file: "./vendor/symfony/dependency-injection/EnvVarProcessor.php"
#line: 172
trace: {
./vendor/symfony/dependency-injection/EnvVarProcessor.php:172 { …}
./vendor/symfony/dependency-injection/Container.php:396 { …}
./var/cache/prod/ContainerLDkvRXT/App_KernelProdContainer.php:1538 {
ContainerLDkvRXT\App_KernelProdContainer->getDynamicParameter(string $name)^
› case 'authorization_service_port': $value = $this->getEnv('AUTHORIZATION_SERVICE_PORT'); break;
› case 'kernel.secret': $value = $this->getEnv('APP_SECRET'); break;
› case 'session.save_path': $value = ($this->targetDir.''.'/sessions'); break;
arguments: {
$name: "APP_SECRET"
}
}
./var/cache/prod/ContainerLDkvRXT/App_KernelProdContainer.php:1499 { …}
./vendor/symfony/framework-bundle/CacheWarmer/ConfigBuilderCacheWarmer.php:74 { …}
./vendor/symfony/framework-bundle/CacheWarmer/ConfigBuilderCacheWarmer.php:56 { …}
./vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php:98 { …}
./vendor/symfony/framework-bundle/Command/CacheWarmupCommand.php:82 { …}
./vendor/symfony/console/Command/Command.php:299 { …}
./vendor/symfony/console/Application.php:996 { …}
./vendor/symfony/framework-bundle/Console/Application.php:96 { …}
./vendor/symfony/console/Application.php:295 { …}
./vendor/symfony/framework-bundle/Console/Application.php:82 { …}
./vendor/symfony/console/Application.php:167 { …}
./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:56 { …}
./vendor/autoload_runtime.php:35 { …}
./bin/console:11 { …}
}
},
"extensionClass" => "Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension"
]