Skip to content

With the default config APP_SECRET is required for cache warmup #51255

Closed
@gorbunovav

Description

@gorbunovav

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

  1. Create a default Symfony 5 application
  2. Remove APP_SECRET variable from the .env file
  3. Try to execute php bin/console cache:warmup
  4. Check output for warnings

Possible Solution

Options:

  1. Make APP_SECRET not required for the cache warmup command.
  2. 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"
]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions