签名已过期:现在早于错误:InvalidSignatureException

j10*_*j10 27 amazon-web-services amazon-iam postman aws-api-gateway

我正在尝试使用AWS API Gateway和IAM授权的一个小例子.AWS API Gateway生成以下端点:

https://xyz1234.execute-api.us-east-2.amazonaws.com/Users/users
Run Code Online (Sandbox Code Playgroud)

使用POST操作,没有参数.

最初我关闭了这个POST方法的IAM,我使用Postman验证了结果.然后我创建了一个新的IAM用户并将AmazonAPIGatewayInvokeFullAccess策略附加到用户,从而授予调用任何API的权限.为POST方法启用了IAM.

然后我去了Postman - 并使用AccessKey,Secret Key,AWS Region as us-east-2和Service Name 添加了Authorization,execute-api并尝试执行请求,但我得到InvalidSignatureException错误,403为返回码.

正文包含以下信息:

Signature expired: 20170517T062414Z is now earlier than 20170517T062840Z (20170517T063340Z - 5 min.)" 
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

Yes*_*rni 28

您需要将本地时钟与NTP同步.

例如.在ubuntu机器上:

sudo ntpdate pool.ntp.org
Run Code Online (Sandbox Code Playgroud)

系统时间经常不同步.您需要定期保持同步.

您可以运行每日CRON作业以使您的系统时间保持同步,如此链接所述:在Linux中定期同步时间

创建一个bash脚本来同步称为ntpdate的时间并将下面的内容放入其中

#!/bin/sh
# sync server time
/usr/sbin/ntpdate pool.ntp.org >> /tmp/ntpdate.log
Run Code Online (Sandbox Code Playgroud)

您可以将此脚本放在任何您喜欢的位置,然后设置一个cron我将它放入每日cron目录中,以便它每天运行一次因此我的ntpdate脚本现在位于/etc/cron.daily/ntpdate中它将运行每天

使此脚本可执行

chmod +x /etc/cron.daily/ntpdate
Run Code Online (Sandbox Code Playgroud)

通过运行脚本一次测试它,并在/tmp/ntpdate.log中查找一些输出

/etc/cron.daily/ntpdate
Run Code Online (Sandbox Code Playgroud)

在您的日志文件中,您应该看到类似的内容

26 Aug 12:19:06 ntpdate[2191]: adjust time server 206.108.0.131 offset 0.272120 sec
Run Code Online (Sandbox Code Playgroud)


Mik*_*AWS 24

使用AWS sigV4签署的请求包括创建签名的时间戳.签名仅在创建后的短时间内有效.(这限制了可以尝试重放攻击的时间.)

验证签名后,将时间戳与当前时间进行比较.如果这表明最近未创建签名,则签名验证将失败,并显示您提到的错误消息.

造成这种情况的主要原因是生成签名的主机上的本地时钟关闭了几分钟.


All*_*onC 15

对我来说,这个问题是在使用 WSL 时发生的。WSL 中的日期不同步。解决方案是运行命令 wsl --shutdown并重新启动 docker。


Coh*_*ius 13

在 Windows 上遇到这个问题。停电后当前时间不同步。解决方法:Setting-> date and time-> Sync now

日期和时间


小智 7

确保您的电脑时钟设置正确。我遇到了同样的问题,然后意识到由于某种原因我的时钟没有显示正确的时间。我一校正时间,它就又开始正常工作了!希望这有帮助。


Ali*_*Ali 6

This one command did the trick

sudo ntpdate pool.ntp.org
Run Code Online (Sandbox Code Playgroud)


小智 6

如果您在 AWS Ec2 Ubuntu 服务器中并且不知何故无法使用 NTP 来修复时间。

sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
Run Code Online (Sandbox Code Playgroud)

来源: https: //askubuntu.com/a/655528


Ash*_*Jha 5

我也面临这个问题,补充道

correctClockSkew: true

并为我解决了问题

const nodemailer = require('nodemailer');
const ses = require('nodemailer-ses-transport');



let transporter = nodemailer.createTransport(ses({
        correctClockSkew: true,
        accessKeyId: **,
        secretAccessKey: **,
        region: **
    }));
Run Code Online (Sandbox Code Playgroud)


Abh*_*ain 5

当我使用timedatectl命令更改基础计算机的日期时间时,遇到了类似的问题。MikeD和其他人给出的解释确实可以解决此问题。

sudo apt install ntp
sudo apt install ntpdate
sudo ntpdate ntp.ubuntu.com
Run Code Online (Sandbox Code Playgroud)

将时间与正确的当前日期时间同步后,此问题将得到解决