- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 SAS token 从 React spa 将文件上传和下载到 Azure 存储。
在本地主机上运行时,一切正常,但是当部署到 Azure 上的 Kubernetes 时,我收到以下身份验证错误。
onError RestError: <?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:e6bfca97-c01e-0030-2e29-4e7d7c000000
Time:2020-06-29T15:26:39.7164613Z</Message><AuthenticationErrorDetail>Signature did not match. String to sign used was w
2020-06-29T20:26:39Z
/blob/datalake/container/Natural_Language_Processing.pdf
负责上传的 JavaScript 代码是
// upload to Azure
const blobName = file.name;
const accountSas = resp.data.SAS;
const account = resp.data.account;
const containerName = resp.data.container;
const anonymousCredential = new AnonymousCredential();
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net?${accountSas}`,
anonymousCredential
);
// Create a container
const containerClient = blobServiceClient.getContainerClient(
containerName
);
// Create a blob
const content = file;
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const uploadBlobResponse = await blockBlobClient.upload(
content,
Buffer.byteLength(content)
);
用于生成 SAS token 的后端 Python 代码如下
if content['up_down'] == 'download':
permission = BlobSasPermissions(read=True)
else:
permission = BlobSasPermissions(write=True)
account_name = os.getenv("STORAGE_ACCOUNT_NAME")
container_name = metadata.get_container_name()
blob_name = content['filePath']
expiry = datetime.utcnow() + timedelta(hours=5)
options = {
'account_name': account_name,
'container_name': container_name,
'blob_name': blob_name,
'account_key': os.getenv("STORAGE_ACCESS_KEY"),
'permission': permission,
'expiry': expiry
}
SAS = generate_blob_sas(**options)
哪里generate_blob_sas
从 azure-storage-blob(版本 12.3.1)导入。
知道如何解决这个问题吗?
最佳答案
绞尽脑汁寻找解决方案后,我终于找到了问题所在。
它与访问 blob 的 Python 库无关,而是与 Kubernetes pod 中的环境变量有关。
使用 yaml 文件将环境变量作为 secret 传递给 Kubernetes(如 link 中所述)。使用此方法, secret 需要进行 Base64 编码。为此,我使用了以下内容
echo 'secret' | base64
>> c2VjcmV0Cg==
但是,通过这种方式,echo
命令默认会在输出中附加一个换行符。我应该使用的是
echo -n 'secret' | base64
>> c2VjcmV0
这个错误特别难以发现,特别是因为在打印时,错误的解决方案似乎会导致正确的结果
echo 'secret' | base64 | base64 -d
>> secret
无论如何,我希望我的错误能帮助将来的人!
关于javascript - Azure 存储 SAS token 在本地主机上工作,但部署在 Azure Kubernetes 上时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62641907/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!