I am deploying my laravel application to AWS Elastic Beanstalk and I'm encountering the problem of persisting the oauth keys for laravel passport.
I went through this and this. While the S3 option sounds reasonable, I still wanted a more secure way and wanted to checkout secret manager from AWS.
Since laravel passport provides the option to load keys from a custom folder, I figured I could use the AWS PHP SDK to retrieve a secret key and write it to storage/app/oauth-public.key
and storage/app/oauth-private.key
and have passport load it from there.
This approach is working fine after deployment to beanstalk but is the storage/app
folder a safe location to generate the oauth.*.key
files? or is there a better way/safer place?
The following is my boot function in Providers/AuthServiceProvider.php
public function boot()
{
$this->registerPolicies();
Passport::routes();
Passport::tokensExpireIn(now()->addDays(5));
// load keys from aws secret manager if they don't exist
if(!file_exists(storage_path().'/app/oauth-public.key') && !file_exists(storage_path().'/app/oauth-private.key')) {
$keys = json_decode($this->getPassportKeys());
$public_key = implode("\n", explode('\n', $keys->PASSPORT_PUBLIC_KEY));
Storage::put('oauth-public.key', $public_key);
$private_key = implode("\n", explode('\n', $keys->PASSPORT_PRIVATE_KEY));
Storage::put('oauth-private.key', $private_key);
}
Passport::loadKeysFrom(storage_path().'/app');
}