1111using Minio ;
1212using Minio . DataModel ;
1313using Monai . Deploy . Storage . Common ;
14+ using Monai . Deploy . Storage . Common . Extensions ;
1415using Monai . Deploy . Storage . Configuration ;
16+ using Newtonsoft . Json ;
1517
1618namespace Monai . Deploy . Storage . MinIo
1719{
@@ -39,6 +41,7 @@ public MinIoStorageService(IOptions<StorageServiceConfiguration> options, ILogge
3941 var accessKey = configuration . Settings [ ConfigurationKeys . AccessKey ] ;
4042 var accessToken = configuration . Settings [ ConfigurationKeys . AccessToken ] ;
4143 var securedConnection = configuration . Settings [ ConfigurationKeys . SecuredConnection ] ;
44+ var credentialServiceUrl = configuration . Settings [ ConfigurationKeys . CredentialServiceUrl ] ;
4245
4346 _client = new MinioClient ( endpoint , accessKey , accessToken ) ;
4447
@@ -49,8 +52,8 @@ public MinIoStorageService(IOptions<StorageServiceConfiguration> options, ILogge
4952
5053 var config = new AmazonSecurityTokenServiceConfig
5154 {
52- AuthenticationRegion = RegionEndpoint . EUWest2 . SystemName , // Should match the `MINIO_REGION` environment variable.
53- ServiceURL = "http://" + endpoint , // replace http://localhost:9000 with URL of your MinIO server
55+ AuthenticationRegion = RegionEndpoint . EUWest2 . SystemName ,
56+ ServiceURL = credentialServiceUrl
5457 } ;
5558
5659 _tokenServiceClient = new AmazonSecurityTokenServiceClient ( accessKey , accessToken , config ) ;
@@ -162,11 +165,14 @@ public async Task<Credentials> CreateTemporaryCredentials(string bucketName, str
162165 Guard . Against . NullOrWhiteSpace ( bucketName , nameof ( bucketName ) ) ;
163166 Guard . Against . NullOrEmpty ( folderName , nameof ( folderName ) ) ;
164167
168+ var policy = PolicyExtensions . ToPolicy ( bucketName , folderName ) ;
169+
170+ var policyString = JsonConvert . SerializeObject ( policy , Formatting . None , new JsonSerializerSettings { NullValueHandling = NullValueHandling . Ignore } ) ;
171+
165172 var assumeRoleRequest = new AssumeRoleRequest
166173 {
167174 DurationSeconds = durationSeconds ,
168- Policy = "{\" Version\" :\" 2012-10-17\" ,\" Statement\" :[{\" Sid\" :\" AllowUserToSeeBucketListInTheConsole\" ,\" Action\" :[\" s3:ListAllMyBuckets\" ,\" s3:GetBucketLocation\" ],\" Effect\" :\" Allow\" ,\" Resource\" :[\" arn:aws:s3:::*\" ]},{\" Sid\" :\" AllowRootAndHomeListingOfBucket\" ,\" Action\" :[\" s3:ListBucket\" ],\" Effect\" :\" Allow\" ,\" Resource\" :[\" arn:aws:s3:::" +
169- bucketName + "\" ],\" Condition\" :{\" StringEquals\" :{\" s3:prefix\" :[\" \" ,\" " + folderName + "\" ],\" s3:delimiter\" :[\" /\" ]}}},{\" Sid\" :\" AllowListingOfUserFolder\" ,\" Action\" :[\" s3:ListBucket\" ],\" Effect\" :\" Allow\" ,\" Resource\" :[\" arn:aws:s3:::" + bucketName + "\" ],\" Condition\" :{\" StringLike\" :{\" s3:prefix\" :[\" " + folderName + "/*\" ]}}},{\" Sid\" :\" AllowAllS3ActionsInUserFolder\" ,\" Effect\" :\" Allow\" ,\" Action\" :[\" s3:*\" ],\" Resource\" :[\" arn:aws:s3:::" + $ "{ bucketName } /{ folderName } " + "/*\" ]}]}"
175+ Policy = policyString
170176 } ;
171177
172178 var role = await _tokenServiceClient . AssumeRoleAsync ( assumeRoleRequest , cancellationToken : cancellationToken ) ;
0 commit comments