【问题标题】:Azure Mass Container security settings change to public (or private)Azure Mass Container 安全设置更改为公共(或私有)
【发布时间】:2015-03-10 16:54:46
【问题描述】:

我正在寻找一种方法来大规模更改我的 Azure 存储中多个容器的安全设置。我正在研究几个程序(celebrata / Azure Explorer 等),但到目前为止,我无法选择容器列表并将所有容器的设置更改为公共(反之亦然)。有没有可以做到这一点的工具?

或者我应该只使用 cloudcopy 并使用 -P 参数让它再次运行所有容器,这真的有效吗?由于 cloudcopy 不会替换文件,并且可能仅在添加新容器时才有效。

任何人有任何好的提示或以前有过这个,我有成千上万的容器,不能一个接一个地检查它们:-(谢谢你的帮助

【问题讨论】:

    标签: azure containers


    【解决方案1】:

    AFAIK,今天没有工具可以做到这一点。你必须自己做。该过程相当简单:您在存储帐户中列出容器,然后遍历容器列表并单独更改每个容器上的 ACL。请看下面的代码。

        private static void ChangeContainerACL()
        {
            var cloudStorageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
            var blobClient = cloudStorageAccount.CreateCloudBlobClient();
            BlobContinuationToken token = null;
            do
            {
                var listingResult = blobClient.ListContainersSegmented(token);
                token = listingResult.ContinuationToken;
                var containers = listingResult.Results;
                foreach (var container in containers)
                {
                    //Code below assumes that you have not defined any access policies on the blob container. 
                    //If that is not the case, then you would need to get permissions on the container by using container.GetPermissions()
                    container.SetPermissions(new BlobContainerPermissions()
                    {
                        PublicAccess = BlobContainerPublicAccessType.Off
                    });
                    Console.WriteLine("ACL for " + container.Name + " changed to Off (Private).");
                }
            }
            while (token != null);
            Console.WriteLine("All done...");
        }
    

    【讨论】:

    • 谢谢 Gaurav,今晚将进行测试。
    猜你喜欢
    • 2014-03-30
    • 2011-12-10
    • 2015-06-09
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多