laravel-aws-secrets-manager icon indicating copy to clipboard operation
laravel-aws-secrets-manager copied to clipboard

putenv() and use of ServiceProvider "boot" method

Open audunru opened this issue 3 years ago • 4 comments

Hi, thanks for making this package. It's exactly what I was looking for. Two things I noticed that may or may not be a problem:

  1. In LaravelAwsSecretsManager putenv() is used and later env(). I think this only works if the env variables do not exist in the .env file. In my testing, if the .env file contains the line MAIL_PASSWORD= I can't update the password with values from AWS. A call to config() to update the config value will work, though.

  2. I tried to set the REDIS_PASSWORD from AWS, and discovered this problem. The framework's RedisServiceProvider reads the config in register(), whichs runs before LaravelAwsSecretsManagerServiceProvider's boot(). So when the Redis password is retrieved, the config is the original config, with no values from AWS yet. And if Redis requires a password, it fails.

audunru avatar Apr 05 '21 21:04 audunru

@audunru, @swilla, I also have this problem, the putenv() params can't be used in config/database.php which uses the .env DB params, do you have any ideas about how to resolve this issue?

You can see the below screenshot to check the loading orders

FYI: image

xingtianyoulong avatar Nov 04 '21 00:11 xingtianyoulong

@xingtianyoulong One solution for this package would be to load the secrets earlier in the process, for instance in bootstrap/app.php. If you are trying to store any kind of secret in AWS which is needed by a service that loads before LaravelAwsSecretsManagerServiceProvider, you can run into problems. RedisServiceProvider is one such example.

audunru avatar Nov 04 '21 19:11 audunru

If we load secrets in boostrap/app.php so we can use them in database.php for example, we can't store them in cache since in boostrap/app.php Cache is not already available, right?

mistre833 avatar Nov 25 '21 16:11 mistre833

Guys, Anyone find the solution for that. I have tried the package for load db and all credential from aws secret manager, it fails to load db details. It will very helpful if anyone solution / package for that

mmani0507 avatar Feb 28 '22 07:02 mmani0507