2014-12-05 117 views
0

我一直在学习如何使用开源的Eucalyptus来使用Amazon S3 API。到目前为止,我已经能够成功使用REST,但现在我也想使用SOAP。我似乎无法为我的请求生成正确的签名。该服务是给我一个403 Forbidden错误:Eucalyptus Walrus/Amazon S3 SOAP签名失败

Traceback (most recent call last): 
    File "soap.py", line 31, in <module> 
    r = w.download_file('mybucket', 'test.txt') 
    File "soap.py", line 27, in download_file 
    r = self.client.service.ListAllMyBuckets(self.access_key, timestamp, signature) 
    File "/usr/lib/python2.6/site-packages/suds/client.py", line 521, in __call__ 
    return client.invoke(args, kwargs) 
    File "/usr/lib/python2.6/site-packages/suds/client.py", line 581, in invoke 
    result = self.send(soapenv) 
    File "/usr/lib/python2.6/site-packages/suds/client.py", line 619, in send 
    description=tostr(e), original_soapenv=original_soapenv) 
    File "/usr/lib/python2.6/site-packages/suds/client.py", line 677, in process_reply 
    raise Exception((status, description)) 
Exception: (403, u'Forbidden') 

我的代码是在Python 2和使用无泡沫Jurko库发送SOAP请求:

from suds.client import Client 

class WalrusSoap: 
    wsdl_url = 'https://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl' 
    server_url = 'https://localhost:8773/services/Walrus' 

    def __init__(self, access_key, secret_key): 
     self.access_key = access_key 
     self.secret_key = secret_key 
     self.client = Client(self.wsdl_url) 
     self.client.wsdl.services[0].setlocation(self.server_url) 
     #print self.client 

    def create_signature(self, operation, timestamp): 
     import base64, hmac, hashlib 
     h = hashlib.sha1(self.secret_key) 
     h.update("AmazonS3" + operation + timestamp) 
     #h = hmac.new(key=self.secret_key, msg="AmazonS3" + operation + timestamp, digestmod=hashlib.sha1) 
     return base64.encodestring(h.digest()).strip() 

    def download_file(self, bucket, filename): 
     from time import gmtime, strftime 
     timestamp = strftime('%Y-%m-%dT%H:%M:%S.001Z', gmtime()) 
     print(timestamp) 
     signature = self.create_signature('ListAllMyBuckets', timestamp) 
     print(signature) 
     r = self.client.service.ListAllMyBuckets(self.access_key, timestamp, signature) 
     return r 

w = WalrusSoap(access_key='MOBSE7FNS6OC5NYC75PG8', secret_key='yxYZmSLCg5Xw6rQVgoIuVLMAx3hZRlxDc0VOJqox') 
r = w.download_file('mybucket', 'test.txt') 
print(r) 

我改变了服务器端点,否则WSDL指向亚马逊的常规S3服务器。我也有两种不同的方法在我的create_signature函数中创建签名。我只是简单地评论第二个,就是在彼此之间交换。两者似乎都不起作用。我的问题是我做错了什么?

SOAP验证:http://docs.aws.amazon.com/AmazonS3/latest/dev/SOAPAuthentication.html

SUDS-Jurko文档:https://bitbucket.org/jurko/suds/overview

编辑:我发现我忘了,包括的打印什么时间戳和签名用于调试目的的例子。

2014-12-05T00:27:41.001Z 
0h8vxE2+k10tetXZQJxXNnNUjjw= 

编辑2:另外,我知道download_file功能无法下载文件:)我仍然在测试/调试阶段

编辑3:我知道,REST是更好地使用,至少根据亚马逊的说法。 (我个人认为REST也更好。)我也已经意识到SOAP已被亚马逊弃用。然而,无论如何,我想顺着这条道路走下去,所以请帮我一个忙,不要浪费我的时间与链接到弃用。我向你保证,在编写这个SOAP代码时,我已经清楚了这个弃用。事实上,我发布的其中一个链接已在其页面顶部打印了弃用通知。但是,如果您有证据表明Walrus完全抛弃SOAP或他们停止了SOAP部分的工作,我希望看到类似的东西。但请不要告诉我亚马逊已弃用SOAP。

回答

1

的S3 SOAP API不支持 “新” 的特点,因此REST API应该尽可能使用:

http://docs.aws.amazon.com/AmazonS3/latest/dev/SOAPAPI3.html

https://forums.aws.amazon.com/message.jspa?messageID=77821

IIRC最近桉树的版本不支持SOAP与S3 。

也就是说,签名看起来不错,所以我会检查客户端/服务主机是否有正确的时间,如果有超过15分钟的差异,认证将会失败。

您还可以检查Walrus服务主机上的cloud-error.log,因为那里可能有更多关于失败的细节。

+0

我知道时间不能错,因为我正在运行的连接到Walrus的脚本是从托管Walrus的虚拟机运行的。您可能已经注意到server_url指向localhost。我确实试过'localtime()'而不是'gmtime()',只是为了确定,并没有用。不幸的是,在cloud-error.log中没有任何帮助。感谢您检查我的签名。 – 2014-12-05 13:23:29

+0

你也有证据证明Walrus不支持SOAP吗? – 2014-12-05 13:40:03

0

从Eucalyptus版本4.0.0开始,Eucalyptus不支持S3的SOAP。

如果您使用的是早期版本的Eucalyptus(4.0之前),那么SOAP应该可以工作。但请注意,由S3提供的wsdl对于他们自己的服务而言不一定是最新的或准确的。 S3在修改API时没有版本或wsdl颠簸,尤其是因为它们停止更新SOAP API。因此,Walrus可能会不符合已发布的WSDL,因为我们的XML基于我们从S3(通过REST)看到的响应以及SOAP和REST响应的分歧进行更新。但是,签名应该是兼容的,所以最糟糕的情况是,您会看到500或400个错误,而不是403个响应。

我的建议是,如果你真的想学习S3 SOAP API,你必须使用S3本身。 Eucalyptus中的S3 SOAP支持在4.0之前,但可能不符合S3 SOAP的当前状态 - 当AWS SDK停止使用SOAP以支持更好的REST支持时,我们直接停止对S3 SOAP API进行测试,因为那是API正在向前发展。

+0

从你说话的方式来看,我假设你已经参与了这个项目。如果是这样,谢谢你提供证据。在将来,我会在哪里寻找桉树的更新日志? – 2014-12-08 03:28:10

+0

@KevinTindall是的,我是桉树存储的主角。我应该说得更清楚。如果你有更多的问题,你也可以在#eucalyptus-devel – ZachH 2014-12-09 19:06:20

+0

@KevinTindall的freenode IRC上找到我们,关于更新日志,它是[here](https://www.eucalyptus.com/docs/eucalyptus/4.0。 2/index.html中#共享/ release_notes.html)。它看起来不包括S3 SOAP支持删除,这是一个问题,我会努力在文档中解决这个问题。 – ZachH 2014-12-09 19:50:44