Ben*_*enH 6 amazon-s3 amazon-web-services python-2.7 boto3
有没有办法验证一组给定的S3凭证是否可以访问特定的存储桶而无需进行某种显式的PUT或GET?
实例化s3.Client,s3.Resource或s3.Bucket对象似乎根本不验证凭据,更不用说桶访问了.
boto3 1.4.7.python 2.7.13.
我们有自动化和编排,可以自动创建存储桶,我希望包含一个验证用户访问密钥和密钥的部分.我知道自从我创建它以来,存在这个存储桶.水桶是空的.
我想验证用户是否具有访问PUT操作的权限.
谢谢你的帮助.
*更新*
我最终使用s3.Client对象执行此操作:
objects = client.list_objects(Bucket=cfg['bucket'])
Run Code Online (Sandbox Code Playgroud)
由于铲斗是空的,因此这是一种轻型操作,并且大部分都是单行程.(包裹在try块中)
是的,您可以使用IAM策略模拟.这是一个例子:
import boto3
iam = boto3.client('iam')
sts = boto3.client('sts')
# Get the arn represented by the currently configured credentials
arn = sts.get_caller_identity()['Arn']
# Create an arn representing the objects in a bucket
bucket_objects_arn = 'arn:aws:s3:::%s/*' % 'my-test-bucket'
# Run the policy simulation for the basic s3 operations
results = iam.simulate_principal_policy(
PolicySourceArn=arn,
ResourceArns=[bucket_objects_arn],
ActionNames=['s3:PutObject', 's3:GetObject', 's3:DeleteObject']
)
for result in results['EvaluationResults']:
print("%s - %s" % (result['EvalActionName'], result['EvalDecision']))
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到所有s3操作.
有一点需要注意的是,IAM最终是一致的,所以如果您正在动态创建用户,您可能还需要等待一些更改才能传播.
| 归档时间: |
|
| 查看次数: |
1775 次 |
| 最近记录: |