curl命令无法正确阅读shell脚本中的输入

wbrvyc0a  于 2023-08-06  发布在  Shell
关注(0)|答案(1)|浏览(130)

我正在尝试在Linux VM中使用curl从Azure Key Vault获取密钥。我的命令是:

ACCESS_TOKEN=$(curl 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fvault.azure.net' -H Metadata:true | jq -r .access_token)

CONFIG_SECRET=$(curl 'https://sFlowDeploymentKeys.vault.azure.net/secrets/config?api-version=2016-10-01' -H "Authorization: Bearer $ACCESS_TOKEN" --http1.1)

字符串
400错误Bad Request访问令牌被正确检索,但第二个curl命令没有正确返回。从回显命令本身来看,似乎访问令牌的一部分被断开并附加到http1.1之后的命令末尾。

s5a0g9ez

s5a0g9ez1#

当从这边尝试时,我得到了一个HTTP/1.1 401 Unauthorized(这是预期的):
我添加了-v以使curl变得冗长,并将ACCESS_TOKEN更改为“TEST-TEST”

D:\TEMP>curl -v "https://sFlowDeploymentKeys.vault.azure.net/secrets/config?api-version=2016-10-01" -H "Authorization: Bearer TEST-TEST" --http1.1
*   Trying 20.192.44.113:443...
* Connected to sFlowDeploymentKeys.vault.azure.net (20.192.44.113) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
> GET /secrets/config?api-version=2016-10-01 HTTP/1.1
> Host: sFlowDeploymentKeys.vault.azure.net
> User-Agent: curl/7.83.1
> Accept: */*
> Authorization: Bearer TEST-TEST
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Length: 111
< Content-Type: application/json; charset=utf-8
< Expires: -1
< WWW-Authenticate: Bearer authorization="https://login.windows.net/cdc5aeea-15c5-4db6-b079-fcadd2505dc2", resource="https://vault.azure.net"
< x-ms-keyvault-region: centralindia
< x-ms-request-id: 4bde9db9-64d6-4509-995a-db04bf09a8c8
< x-ms-keyvault-service-version: 1.9.736.1
< x-ms-keyvault-network-info: conn_type=Ipv4;addr=195.240.162.281;act_addr_fam=InterNetwork;
< X-Content-Type-Options: nosniff
< Strict-Transport-Security: max-age=31536000;includeSubDomains
< Date: Tue, 14 Mar 2023 17:53:39 GMT
<
{"error":{"code":"Unauthorized","message":"[BearerReadAccessTokenFailed] Error validating token: 'S2S12005'."}}* Connection #0 to host sFlowDeploymentKeys.vault.azure.net left intact

字符串

相关问题