Auth0 and AWS Policy

Auth0 and AWS Policy

本文关键字:Policy AWS and Auth0      更新时间:2023-09-26

我的web应用程序正在使用Auth0和AWS(委派令牌)访问S3中的一些资源。

我在一个名为testinfo的bucket中有以下目录结构-目录1-子目录11-子目录11-目录2-子目录21-目录3

我有以下S3 Buckets的策略。{"版本":"2012-10-17","声明":[{"Sid":"Stmt1423804993000","效果":"允许","操作":["s3:"],"资源":["arn:aws:s3:::testinfo/Directory1","arn:aws:s3:::testinfo/Directory1/"]}]}

我有下面的javascript代码来显示bucket 的内容

var getTokenPromise = auth.getToken({api: 'aws', role: "xyz", principal: "xyz"});
getTokenPromise.then(function (value) {
    console.log('delegation: ' + value);
    bucket = new AWS.S3({params: {Bucket: 'testinfo'}});
    bucket.config.credentials =new AWS.Credentials('x','y','z');
    bucket.listObjects({}, function (err, data) {
        if (err)
            alert(err);
        var files = [];
        for (var i in data.Contents) {
            //show files
        }
    });
}, function (reason) {
    console.log('failed: ' + reason);

});

根据政策,只显示Directory1 show的内容。不幸的是,我遇到了访问被拒绝的异常。有人能帮忙解决这个问题吗?

干杯

你能试着在目录中添加一个通配符吗

"arn:aws:s3:::testinfo/Directory1/*"