为什么 'terraform plan' 由于我的时区未设置为自动而失败?

why does 'terraform plan' fail due to my timezone not set to automatic?

我有问题

terraform plan
╷
│ Error: error configuring Terraform AWS Provider: error validating 
provider credentials: error calling sts:GetCallerIdentity: operation error STS: 
GetCallerIdentity, https response error 
StatusCode: 403, RequestID: 4772c754-fcc4-4933-85c7-f36407f51c74, 
api error SignatureDoesNotMatch: Signature expired: 20220214T143902Z is now earlier 
 than 20220214T152434Z (20220214T153934Z - 15 min.)
│
│   with provider["registry.terraform.io/hashicorp/aws"],
│   on main.tf line 2, in provider "aws":
│    2: provider "aws" {

我在这个 github issue 中找到了解决办法。为什么它甚至取决于系统时间日期?!我用win10.

当我将其设置为自动时它起作用了 - 想知道为什么吗?

hashicorp/aws 提供商必须向 AWS API 发送使用 AWS Signature Version 4 算法签名的请求。

AWS 签名方案的目标之一是最大限度地缩短 window 被破坏的签名可能被攻击者重复使用的时间。为实现这一点,签名方案包括创建签名时的时间戳,并且远程系统要求时间戳在远程系统理解的请求时间的 15 分钟内。

在我写这篇文章的时候,官方文档是这样描述的:

  • Protect against reuse of the signed portions of the request – The signed portions (using AWS Signatures) of requests are valid within 15 minutes of the timestamp in the request. An unauthorized party who has access to a signed request can modify the unsigned portions of the request without affecting the request's validity in the 15 minute window. Because of this, we recommend that you maximize protection by signing request headers and body, making HTTPS requests to Amazon S3, and by using the s3:x-amz-content-sha256 condition key (see Amazon S3 Signature Version 4 Authentication Specific Policy Keys) in AWS policies to require users to sign Amazon S3 request bodies.

如果您的本地系统的系统时间不正确,或者如果您的系统认为其本地时间与您实际工作的时区不同,那么 AWS SDK(构建 Terraform AWS 提供程序时使用的)将生成超出允许的 15 分钟 window 的时间戳,因此您的请求将失败。这适用于使用此标准签名方案向 AWS API 发送的任何请求,无论是由 Terraform 的 AWS 提供商还是任何其他 AWS-integrated 工具发出的。

为了使请求成功,您的系统必须能够生成正确的 UTC-referenced 时间戳。为了实现这一点,它必须具有正确的时间,并且 - 如果您使用的是像 Windows 这样的操作系统,其中系统时间存储在本地时间而不是 UTC - 您的系统时间的正确配置与 UTC 的偏移量,以便 SDK 可以根据 AWS API 的要求转换为 UTC 时间戳。