在Postgresql RDS/Amazon Aurora中签名S3 URL
DB(PostgreSQL RDS/Amazon Aurora)返回了很多图像文件。我们需要签署URL。当前,用户定义的函数或视图返回记录。
我正在寻找一种将S3 URL直接在SQL中签名的方法,作为用户定义的功能。不幸的是,除了在用户定义的函数中使用Python语言外,似乎没有其他方法,而Python在PostgreSQL/Aurora中不支持Python。
有人知道我们可以直接签署URL作为SQL查询的一部分而在Postgresql RDS/Amazon Aurora中直接签名的方法?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这是可能的,我已经做到了。
首先,让我们看看AWS SDK是如何做到的。在JavaScript AWS SDK中,我们调用
getsignedurlpromise
获取签名的URL。从 aws.signers.presign.presign.presign() 我们可以看到
签名发生在 signedurlsigner 对于v3,
签名
来自标题['授权']
,但是授权
设置在哪里?它设置为 aws.signers.s3 .addauthorization
sign
函数正在使用sha1 with base64摘要和
stringtosign
有点令人困惑,但是在我的实验中,结果是上述信息,我们可以轻松地轻松编写一个postgres函数
结果是
并添加您的S3主机
https://my_bucket.s3.us-west-1.amazonaws.com
在前端Yes, it's possible and I've done this.
First, let's see how AWS SDK does it. In JavaScript AWS SDK, we call
getSignedUrlPromise
to get a signed url.Starting from getSignedUrlPromise, to getSignedUrl, request.presign, AWS.Signers.Presign().sign and we can see
The signing happens in signedUrlSigner for V3
The
Signature
is fromheaders['Authorization']
, but where is theAuthorization
set?It's set in AWS.Signers.S3.addAuthorization
sign
function is using sha1 with base64 digestAnd
stringToSign
is a little bit confusing but in my experiment the result isWith the above information, we can easily write a postgres function
The result is
and adding your s3 host
https://my_bucket.s3.us-west-1.amazonaws.com
in frontend to be我们可以通过参数(AWS签名版本4)
依赖项
创建扩展名(如果不存在)pgcrypto;
We can prepare SignedURL through Authenticating Requests: Using Query Parameters (AWS Signature Version 4)
Dependencies
CREATE EXTENSION IF NOT EXISTS pgcrypto;
数据库不是执行此类操作的地方。
您应该考虑已经将签名的URL放入数据库中,或者如果不应该重新搜索您的应用程序。
Database is not the place to perform such operation.
You should consider either putting a signed URL into the database already or to rethink your application if it shouldn't be rearchitected.