【发布时间】:2021-04-25 04:43:14
【问题描述】:
我正在将我的 laravel 应用程序部署到 AWS Elastic Beanstalk,我遇到了持久化 laravel 护照的 oauth 密钥的问题。
我经历了this 和this。虽然 S3 选项听起来很合理,但我仍然想要一种更安全的方式,并希望从 AWS 中签出 Secret Manager。
由于 laravel 护照 provides the option to load keys from a custom folder,我想我可以使用 AWS PHP SDK to retrieve a secret key 并将其写入 storage/app/oauth-public.key 和 storage/app/oauth-private.key 并从那里加载护照。
这种方法在部署到 beanstalk 后运行良好,但 storage/app 文件夹是生成 oauth.*.key 文件的安全位置吗?还是有更好的方法/更安全的地方?
以下是我在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');
}
【问题讨论】:
标签: php laravel amazon-web-services amazon-elastic-beanstalk laravel-passport