Skip to content

Commit 85f952e

Browse files
tg-msftmatthohn-msft
authored andcommitted
Adding basic [CallerShouldAudit] support and initial support for Storage and Tables (Azure#39345)
Adding basic [CallerShouldAudit] support and initial annotations of Storage and Tables.
1 parent 0435b10 commit 85f952e

30 files changed

+127
-11
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
6+
#nullable enable
7+
8+
namespace Azure.Core
9+
{
10+
/// <summary>
11+
/// Decorates an operation whose invocation should potentially be audited
12+
/// by Azure service implementations. Auditing could be recommended
13+
/// because the operation changes critical service state, creates delegated
14+
/// access to a resource, affects data retention, etc. It's a best guess
15+
/// from the service team that the operation should be audited to mitigate
16+
/// any potential future issues.
17+
/// </summary>
18+
[AttributeUsage(AttributeTargets.Method)]
19+
internal class CallerShouldAuditAttribute : Attribute
20+
{
21+
/// <summary>
22+
/// Gets or sets a description or link to the rationale for potentially
23+
/// auditing this operation.
24+
/// </summary>
25+
public string? Reason { get; set; }
26+
}
27+
}

sdk/storage/Azure.Storage.Blobs/src/Azure.Storage.Blobs.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
<Compile Include="$(AzureCoreSharedSources)AuthorizationChallengeParser.cs" LinkBase="Shared\Core" />
3636
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" LinkBase="SharedCore" />
3737
<Compile Include="$(AzureCoreSharedSources)AzureSasCredentialSynchronousPolicy.cs" LinkBase="SharedCore" />
38-
<Compile Include="$(AzureCoreSharedSources)RetriableStream.cs" LinkBase="SharedCore" />
38+
<Compile Include="$(AzureCoreSharedSources)CallerShouldAuditAttribute.cs" LinkBase="SharedCore" />
3939
<Compile Include="$(AzureCoreSharedSources)CancellationHelper.cs" LinkBase="SharedCore" />
4040
<Compile Include="$(AzureCoreSharedSources)ArrayBufferWriter.cs" LinkBase="SharedCore" />
4141
<Compile Include="$(AzureCoreSharedSources)ForwardsClientCallsAttribute.cs" LinkBase="SharedCore" />
4242
<Compile Include="$(AzureCoreSharedSources)HashCodeBuilder.cs" LinkBase="SharedCore" />
4343
<Compile Include="$(AzureCoreSharedSources)NoBodyResponseOfT.cs" LinkBase="SharedCore" />
44+
<Compile Include="$(AzureCoreSharedSources)RetriableStream.cs" LinkBase="SharedCore" />
4445
</ItemGroup>
4546
<ItemGroup>
4647
<Compile Include="$(AzureStorageSharedSources)ClientsideEncryption\*.cs" LinkBase="Shared" />

sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.ComponentModel;
66
using System.IO;
7-
using System.Runtime.CompilerServices;
87
using System.Threading;
98
using System.Threading.Tasks;
109
using Azure.Core;
@@ -6556,6 +6555,7 @@ private async Task<Response<BlobLegalHoldResult>> SetLegalHoldInternal(
65566555
/// <remarks>
65576556
/// A <see cref="Exception"/> will be thrown if a failure occurs.
65586557
/// </remarks>
6558+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
65596559
public virtual Uri GenerateSasUri(BlobSasPermissions permissions, DateTimeOffset expiresOn) =>
65606560
GenerateSasUri(new BlobSasBuilder(permissions, expiresOn)
65616561
{
@@ -6589,6 +6589,7 @@ public virtual Uri GenerateSasUri(BlobSasPermissions permissions, DateTimeOffset
65896589
/// A <see cref="Exception"/> will be thrown if
65906590
/// a failure occurs.
65916591
/// </remarks>
6592+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
65926593
public virtual Uri GenerateSasUri(BlobSasBuilder builder)
65936594
{
65946595
if (builder == null)

sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.ComponentModel;
77
using System.IO;
88
using System.Linq;
9-
using System.Net;
109
using System.Threading;
1110
using System.Threading.Tasks;
1211
using Azure.Core;
@@ -15,7 +14,6 @@
1514
using Azure.Storage.Blobs.Specialized;
1615
using Azure.Storage.Cryptography;
1716
using Azure.Storage.Sas;
18-
using Azure.Storage.Shared;
1917
using Metadata = System.Collections.Generic.IDictionary<string, string>;
2018

2119
#pragma warning disable SA1402 // File may only contain a single type
@@ -2204,6 +2202,7 @@ private async Task<Response<BlobContainerAccessPolicy>> GetAccessPolicyInternal(
22042202
/// A <see cref="RequestFailedException"/> will be thrown if
22052203
/// a failure occurs.
22062204
/// </remarks>
2205+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
22072206
public virtual Response<BlobContainerInfo> SetAccessPolicy(
22082207
PublicAccessType accessType = PublicAccessType.None,
22092208
IEnumerable<BlobSignedIdentifier> permissions = default,
@@ -2259,6 +2258,7 @@ public virtual Response<BlobContainerInfo> SetAccessPolicy(
22592258
/// A <see cref="RequestFailedException"/> will be thrown if
22602259
/// a failure occurs.
22612260
/// </remarks>
2261+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
22622262
public virtual async Task<Response<BlobContainerInfo>> SetAccessPolicyAsync(
22632263
PublicAccessType accessType = PublicAccessType.None,
22642264
IEnumerable<BlobSignedIdentifier> permissions = default,
@@ -3574,6 +3574,7 @@ internal async Task<Response<FilterBlobSegment>> FindBlobsByTagsInternal(
35743574
/// <remarks>
35753575
/// A <see cref="Exception"/> will be thrown if a failure occurs.
35763576
/// </remarks>
3577+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
35773578
public virtual Uri GenerateSasUri(BlobContainerSasPermissions permissions, DateTimeOffset expiresOn) =>
35783579
GenerateSasUri(new BlobSasBuilder(permissions, expiresOn) { BlobContainerName = Name });
35793580

@@ -3599,6 +3600,7 @@ public virtual Uri GenerateSasUri(BlobContainerSasPermissions permissions, DateT
35993600
/// <remarks>
36003601
/// A <see cref="Exception"/> will be thrown if a failure occurs.
36013602
/// </remarks>
3603+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
36023604
public virtual Uri GenerateSasUri(BlobSasBuilder builder)
36033605
{
36043606
builder = builder ?? throw Errors.ArgumentNull(nameof(builder));

sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ private async Task<Response<BlobServiceProperties>> GetPropertiesInternal(
11791179
/// A <see cref="RequestFailedException"/> will be thrown if
11801180
/// a failure occurs.
11811181
/// </remarks>
1182+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
11821183
public virtual Response SetProperties(
11831184
BlobServiceProperties properties,
11841185
CancellationToken cancellationToken = default) =>
@@ -1213,6 +1214,7 @@ public virtual Response SetProperties(
12131214
/// A <see cref="RequestFailedException"/> will be thrown if
12141215
/// a failure occurs.
12151216
/// </remarks>
1217+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
12161218
public virtual async Task<Response> SetPropertiesAsync(
12171219
BlobServiceProperties properties,
12181220
CancellationToken cancellationToken = default) =>
@@ -1460,6 +1462,7 @@ private async Task<Response<BlobServiceStatistics>> GetStatisticsInternal(
14601462
/// A <see cref="RequestFailedException"/> will be thrown if
14611463
/// a failure occurs.
14621464
/// </remarks>
1465+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
14631466
public virtual Response<UserDelegationKey> GetUserDelegationKey(
14641467
DateTimeOffset? startsOn,
14651468
DateTimeOffset expiresOn,
@@ -1496,6 +1499,7 @@ public virtual Response<UserDelegationKey> GetUserDelegationKey(
14961499
/// A <see cref="RequestFailedException"/> will be thrown if
14971500
/// a failure occurs.
14981501
/// </remarks>
1502+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
14991503
public virtual async Task<Response<UserDelegationKey>> GetUserDelegationKeyAsync(
15001504
DateTimeOffset? startsOn,
15011505
DateTimeOffset expiresOn,
@@ -2362,6 +2366,7 @@ internal async Task<Response<FilterBlobSegment>> FindBlobsByTagsInternal(
23622366
/// <remarks>
23632367
/// A <see cref="Exception"/> will be thrown if a failure occurs.
23642368
/// </remarks>
2369+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
23652370
public Uri GenerateAccountSasUri(
23662371
AccountSasPermissions permissions,
23672372
DateTimeOffset expiresOn,
@@ -2394,6 +2399,7 @@ public Uri GenerateAccountSasUri(
23942399
/// <remarks>
23952400
/// A <see cref="Exception"/> will be thrown if a failure occurs.
23962401
/// </remarks>
2402+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
23972403
public Uri GenerateAccountSasUri(AccountSasBuilder builder)
23982404
{
23992405
builder = builder ?? throw Errors.ArgumentNull(nameof(builder));

sdk/storage/Azure.Storage.Blobs/src/Sas/BlobSasBuilder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.ComponentModel;
77
using System.Security.Cryptography;
88
using System.Text;
9+
using Azure.Core;
910
using Azure.Storage.Blobs;
1011
using Azure.Storage.Blobs.Models;
1112

@@ -337,6 +338,7 @@ public void SetPermissions(string rawPermissions)
337338
/// The <see cref="BlobSasQueryParameters"/> used for authenticating
338339
/// requests.
339340
/// </returns>
341+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
340342
public BlobSasQueryParameters ToSasQueryParameters(StorageSharedKeyCredential sharedKeyCredential)
341343
{
342344
sharedKeyCredential = sharedKeyCredential ?? throw Errors.ArgumentNull(nameof(sharedKeyCredential));
@@ -401,6 +403,7 @@ public BlobSasQueryParameters ToSasQueryParameters(StorageSharedKeyCredential sh
401403
/// <returns>
402404
/// The <see cref="BlobSasQueryParameters"/> used for authenticating requests.
403405
/// </returns>
406+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
404407
public BlobSasQueryParameters ToSasQueryParameters(UserDelegationKey userDelegationKey, string accountName)
405408
{
406409
userDelegationKey = userDelegationKey ?? throw Errors.ArgumentNull(nameof(userDelegationKey));

sdk/storage/Azure.Storage.Common/src/Azure.Storage.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</ItemGroup>
2626
<ItemGroup>
2727
<Compile Include="$(AzureCoreSharedSources)AuthorizationChallengeParser.cs" LinkBase="Shared\Core" />
28+
<Compile Include="$(AzureCoreSharedSources)CallerShouldAuditAttribute.cs" LinkBase="SharedCore" />
2829
<Compile Include="$(AzureCoreSharedSources)NoBodyResponseOfT.cs" LinkBase="Shared\Core" />
2930
</ItemGroup>
3031
<ItemGroup>

sdk/storage/Azure.Storage.Common/src/Sas/AccountSasBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.ComponentModel;
77
using System.Text;
8+
using Azure.Core;
89

910
namespace Azure.Storage.Sas
1011
{
@@ -190,6 +191,7 @@ public void SetPermissions(string rawPermissions)
190191
/// The <see cref="SasQueryParameters"/> used for authenticating
191192
/// requests.
192193
/// </returns>
194+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-common")]
193195
public SasQueryParameters ToSasQueryParameters(StorageSharedKeyCredential sharedKeyCredential)
194196
{
195197
// https://docs.microsoft.com/en-us/rest/api/storageservices/Constructing-an-Account-SAS

sdk/storage/Azure.Storage.Files.DataLake/src/Azure.Storage.Files.DataLake.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<Compile Include="$(AzureCoreSharedSources)AuthorizationChallengeParser.cs" LinkBase="Shared\Core" />
3232
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" LinkBase="SharedCore" />
3333
<Compile Include="$(AzureCoreSharedSources)AzureSasCredentialSynchronousPolicy.cs" LinkBase="SharedCore" />
34+
<Compile Include="$(AzureCoreSharedSources)CallerShouldAuditAttribute.cs" LinkBase="SharedCore" />
3435
<Compile Include="$(AzureCoreSharedSources)ForwardsClientCallsAttribute.cs" LinkBase="SharedCore" />
3536
<Compile Include="$(AzureCoreSharedSources)NoBodyResponseOfT.cs" LinkBase="SharedCore" />
3637
</ItemGroup>

sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeDirectoryClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,7 @@ public override async Task<Response<PathAccessControl>> GetAccessControlAsync(
14421442
/// A <see cref="RequestFailedException"/> will be thrown if
14431443
/// a failure occurs.
14441444
/// </remarks>
1445+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
14451446
public override Response<PathInfo> SetAccessControlList(
14461447
IList<PathAccessControlItem> accessControlList,
14471448
string owner = default,
@@ -1506,6 +1507,7 @@ public override Response<PathInfo> SetAccessControlList(
15061507
/// A <see cref="RequestFailedException"/> will be thrown if
15071508
/// a failure occurs.
15081509
/// </remarks>
1510+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
15091511
public override async Task<Response<PathInfo>> SetAccessControlListAsync(
15101512
IList<PathAccessControlItem> accessControlList,
15111513
string owner = default,
@@ -1573,6 +1575,7 @@ public override async Task<Response<PathInfo>> SetAccessControlListAsync(
15731575
/// A <see cref="RequestFailedException"/> will be thrown if
15741576
/// a failure occurs.
15751577
/// </remarks>
1578+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
15761579
public override Response<PathInfo> SetPermissions(
15771580
PathPermissions permissions = default,
15781581
string owner = default,
@@ -1637,6 +1640,7 @@ public override Response<PathInfo> SetPermissions(
16371640
/// A <see cref="RequestFailedException"/> will be thrown if
16381641
/// a failure occurs.
16391642
/// </remarks>
1643+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
16401644
public override async Task<Response<PathInfo>> SetPermissionsAsync(
16411645
PathPermissions permissions = default,
16421646
string owner = default,
@@ -2948,6 +2952,7 @@ public virtual AsyncPageable<PathItem> GetPathsAsync(
29482952
/// <remarks>
29492953
/// A <see cref="Exception"/> will be thrown if a failure occurs.
29502954
/// </remarks>
2955+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
29512956
public override Uri GenerateSasUri(DataLakeSasPermissions permissions, DateTimeOffset expiresOn) =>
29522957
GenerateSasUri(new DataLakeSasBuilder(permissions, expiresOn)
29532958
{
@@ -2979,6 +2984,7 @@ public override Uri GenerateSasUri(DataLakeSasPermissions permissions, DateTimeO
29792984
/// <remarks>
29802985
/// A <see cref="Exception"/> will be thrown if a failure occurs.
29812986
/// </remarks>
2987+
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
29822988
public override Uri GenerateSasUri(DataLakeSasBuilder builder)
29832989
{
29842990
builder = builder ?? throw Errors.ArgumentNull(nameof(builder));

0 commit comments

Comments
 (0)