TappNetwork / laravel-aws-secrets-manager

Manage environment secrets using AWS Secrets Manager.
MIT License
33 stars 20 forks source link

putenv() and use of ServiceProvider "boot" method #12

Closed audunru closed 8 months ago

audunru commented 3 years ago

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.

xingtianyoulong commented 2 years ago

@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

audunru commented 2 years ago

@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.

mistre833 commented 2 years ago

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?

mmani0507 commented 2 years ago

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