预签名的S3 url在过期后有效



从SDK文档(链接:https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.S3Client.html#_createPresignedRequest)CCD_ 1参数应当表示URL应当到期的时间。

因此,如果我指定2分钟作为过期时间,那么2分钟后URL将无效。我的代码看起来像这个

<?php
$s3 = $this->cloudProvider->getClient(); // S3 client
$cmd = $s3->getCommand(
'GetObject',
[
'Bucket' => $this->getSdkBucket(), // Bucket name
'Key' => "$s3Name",
]
);
$urlReq = $s3->createPresignedRequest($cmd, $expirationTime); // $expirationTime is a Unix timestamp

我得到了具有正确到期时间的url(在我的情况下,客户端希望它是会话到期时间,会话时间为4小时(

X-Amz-Content-Sha256=UNSIGNED-PAYLOAD
&X-Amz-Security-Token=long_string_goes_here
&X-Amz-Algorithm=AWS4-HMAC-SHA256
&X-Amz-Credential=another_string_goes_here
&X-Amz-Date=20200907T110127Z
&X-Amz-SignedHeaders=host
&X-Amz-Expires=14400 // This decreases depending on how long the user is logged in - max 4hrs
&X-Amz-Signature=another_string_here

问题是这个网址将在4小时后有效。

根据我在这个答案中读到的关于到期时间的内容(https://stackoverflow.com/a/57792699/629127),URL的有效期为6小时至7天,具体取决于用于生成它的凭据。

我正在使用IAM凭据(ECS提供商(。

那么,这是否意味着,无论我在到期变量中输入什么值,我都无法使链接在该时间段内有效?

S3检查过期时间,如果浏览器或代理(例如,如果您使用CloudFront(缓存了文件,则请求不会到达S3。如果它被缓存在浏览器中,那么不用担心,这意味着同一用户只能在过期后访问URL。

您可以使用浏览器开发工具来检查这一点。在"网络"选项卡上,找到对已签名URL的请求,您可以查看它是否从缓存(从内存/磁盘缓存(返回。

最新更新