Skip to content

Commit

Permalink
Adding basic [CallerShouldAudit] support and initial support for Stor…
Browse files Browse the repository at this point in the history
…age and Tables (Azure#39345)

Adding basic [CallerShouldAudit] support and initial annotations of Storage and Tables.
  • Loading branch information
tg-msft authored and matthohn-msft committed Oct 27, 2023
1 parent 0435b10 commit 85f952e
Show file tree
Hide file tree
Showing 30 changed files with 127 additions and 11 deletions.
27 changes: 27 additions & 0 deletions sdk/core/Azure.Core/src/Shared/CallerShouldAuditAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

#nullable enable

namespace Azure.Core
{
/// <summary>
/// Decorates an operation whose invocation should potentially be audited
/// by Azure service implementations. Auditing could be recommended
/// because the operation changes critical service state, creates delegated
/// access to a resource, affects data retention, etc. It's a best guess
/// from the service team that the operation should be audited to mitigate
/// any potential future issues.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
internal class CallerShouldAuditAttribute : Attribute
{
/// <summary>
/// Gets or sets a description or link to the rationale for potentially
/// auditing this operation.
/// </summary>
public string? Reason { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
<Compile Include="$(AzureCoreSharedSources)AuthorizationChallengeParser.cs" LinkBase="Shared\Core" />
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)AzureSasCredentialSynchronousPolicy.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)RetriableStream.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)CallerShouldAuditAttribute.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)CancellationHelper.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)ArrayBufferWriter.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)ForwardsClientCallsAttribute.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)HashCodeBuilder.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)NoBodyResponseOfT.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)RetriableStream.cs" LinkBase="SharedCore" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(AzureStorageSharedSources)ClientsideEncryption\*.cs" LinkBase="Shared" />
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
Expand Down Expand Up @@ -6556,6 +6555,7 @@ private async Task<Response<BlobLegalHoldResult>> SetLegalHoldInternal(
/// <remarks>
/// A <see cref="Exception"/> will be thrown if a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual Uri GenerateSasUri(BlobSasPermissions permissions, DateTimeOffset expiresOn) =>
GenerateSasUri(new BlobSasBuilder(permissions, expiresOn)
{
Expand Down Expand Up @@ -6589,6 +6589,7 @@ public virtual Uri GenerateSasUri(BlobSasPermissions permissions, DateTimeOffset
/// A <see cref="Exception"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual Uri GenerateSasUri(BlobSasBuilder builder)
{
if (builder == null)
Expand Down
6 changes: 4 additions & 2 deletions sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
Expand All @@ -15,7 +14,6 @@
using Azure.Storage.Blobs.Specialized;
using Azure.Storage.Cryptography;
using Azure.Storage.Sas;
using Azure.Storage.Shared;
using Metadata = System.Collections.Generic.IDictionary<string, string>;

#pragma warning disable SA1402 // File may only contain a single type
Expand Down Expand Up @@ -2204,6 +2202,7 @@ private async Task<Response<BlobContainerAccessPolicy>> GetAccessPolicyInternal(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual Response<BlobContainerInfo> SetAccessPolicy(
PublicAccessType accessType = PublicAccessType.None,
IEnumerable<BlobSignedIdentifier> permissions = default,
Expand Down Expand Up @@ -2259,6 +2258,7 @@ public virtual Response<BlobContainerInfo> SetAccessPolicy(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual async Task<Response<BlobContainerInfo>> SetAccessPolicyAsync(
PublicAccessType accessType = PublicAccessType.None,
IEnumerable<BlobSignedIdentifier> permissions = default,
Expand Down Expand Up @@ -3574,6 +3574,7 @@ internal async Task<Response<FilterBlobSegment>> FindBlobsByTagsInternal(
/// <remarks>
/// A <see cref="Exception"/> will be thrown if a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual Uri GenerateSasUri(BlobContainerSasPermissions permissions, DateTimeOffset expiresOn) =>
GenerateSasUri(new BlobSasBuilder(permissions, expiresOn) { BlobContainerName = Name });

Expand All @@ -3599,6 +3600,7 @@ public virtual Uri GenerateSasUri(BlobContainerSasPermissions permissions, DateT
/// <remarks>
/// A <see cref="Exception"/> will be thrown if a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual Uri GenerateSasUri(BlobSasBuilder builder)
{
builder = builder ?? throw Errors.ArgumentNull(nameof(builder));
Expand Down
6 changes: 6 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ private async Task<Response<BlobServiceProperties>> GetPropertiesInternal(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual Response SetProperties(
BlobServiceProperties properties,
CancellationToken cancellationToken = default) =>
Expand Down Expand Up @@ -1213,6 +1214,7 @@ public virtual Response SetProperties(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual async Task<Response> SetPropertiesAsync(
BlobServiceProperties properties,
CancellationToken cancellationToken = default) =>
Expand Down Expand Up @@ -1460,6 +1462,7 @@ private async Task<Response<BlobServiceStatistics>> GetStatisticsInternal(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual Response<UserDelegationKey> GetUserDelegationKey(
DateTimeOffset? startsOn,
DateTimeOffset expiresOn,
Expand Down Expand Up @@ -1496,6 +1499,7 @@ public virtual Response<UserDelegationKey> GetUserDelegationKey(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public virtual async Task<Response<UserDelegationKey>> GetUserDelegationKeyAsync(
DateTimeOffset? startsOn,
DateTimeOffset expiresOn,
Expand Down Expand Up @@ -2362,6 +2366,7 @@ internal async Task<Response<FilterBlobSegment>> FindBlobsByTagsInternal(
/// <remarks>
/// A <see cref="Exception"/> will be thrown if a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public Uri GenerateAccountSasUri(
AccountSasPermissions permissions,
DateTimeOffset expiresOn,
Expand Down Expand Up @@ -2394,6 +2399,7 @@ public Uri GenerateAccountSasUri(
/// <remarks>
/// A <see cref="Exception"/> will be thrown if a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public Uri GenerateAccountSasUri(AccountSasBuilder builder)
{
builder = builder ?? throw Errors.ArgumentNull(nameof(builder));
Expand Down
3 changes: 3 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/Sas/BlobSasBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel;
using System.Security.Cryptography;
using System.Text;
using Azure.Core;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;

Expand Down Expand Up @@ -337,6 +338,7 @@ public void SetPermissions(string rawPermissions)
/// The <see cref="BlobSasQueryParameters"/> used for authenticating
/// requests.
/// </returns>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public BlobSasQueryParameters ToSasQueryParameters(StorageSharedKeyCredential sharedKeyCredential)
{
sharedKeyCredential = sharedKeyCredential ?? throw Errors.ArgumentNull(nameof(sharedKeyCredential));
Expand Down Expand Up @@ -401,6 +403,7 @@ public BlobSasQueryParameters ToSasQueryParameters(StorageSharedKeyCredential sh
/// <returns>
/// The <see cref="BlobSasQueryParameters"/> used for authenticating requests.
/// </returns>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-blobs")]
public BlobSasQueryParameters ToSasQueryParameters(UserDelegationKey userDelegationKey, string accountName)
{
userDelegationKey = userDelegationKey ?? throw Errors.ArgumentNull(nameof(userDelegationKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)AuthorizationChallengeParser.cs" LinkBase="Shared\Core" />
<Compile Include="$(AzureCoreSharedSources)CallerShouldAuditAttribute.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)NoBodyResponseOfT.cs" LinkBase="Shared\Core" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions sdk/storage/Azure.Storage.Common/src/Sas/AccountSasBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Azure.Core;

namespace Azure.Storage.Sas
{
Expand Down Expand Up @@ -190,6 +191,7 @@ public void SetPermissions(string rawPermissions)
/// The <see cref="SasQueryParameters"/> used for authenticating
/// requests.
/// </returns>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-common")]
public SasQueryParameters ToSasQueryParameters(StorageSharedKeyCredential sharedKeyCredential)
{
// https://docs.microsoft.com/en-us/rest/api/storageservices/Constructing-an-Account-SAS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Compile Include="$(AzureCoreSharedSources)AuthorizationChallengeParser.cs" LinkBase="Shared\Core" />
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)AzureSasCredentialSynchronousPolicy.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)CallerShouldAuditAttribute.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)ForwardsClientCallsAttribute.cs" LinkBase="SharedCore" />
<Compile Include="$(AzureCoreSharedSources)NoBodyResponseOfT.cs" LinkBase="SharedCore" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ public override async Task<Response<PathAccessControl>> GetAccessControlAsync(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override Response<PathInfo> SetAccessControlList(
IList<PathAccessControlItem> accessControlList,
string owner = default,
Expand Down Expand Up @@ -1506,6 +1507,7 @@ public override Response<PathInfo> SetAccessControlList(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override async Task<Response<PathInfo>> SetAccessControlListAsync(
IList<PathAccessControlItem> accessControlList,
string owner = default,
Expand Down Expand Up @@ -1573,6 +1575,7 @@ public override async Task<Response<PathInfo>> SetAccessControlListAsync(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override Response<PathInfo> SetPermissions(
PathPermissions permissions = default,
string owner = default,
Expand Down Expand Up @@ -1637,6 +1640,7 @@ public override Response<PathInfo> SetPermissions(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override async Task<Response<PathInfo>> SetPermissionsAsync(
PathPermissions permissions = default,
string owner = default,
Expand Down Expand Up @@ -2948,6 +2952,7 @@ public virtual AsyncPageable<PathItem> GetPathsAsync(
/// <remarks>
/// A <see cref="Exception"/> will be thrown if a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override Uri GenerateSasUri(DataLakeSasPermissions permissions, DateTimeOffset expiresOn) =>
GenerateSasUri(new DataLakeSasBuilder(permissions, expiresOn)
{
Expand Down Expand Up @@ -2979,6 +2984,7 @@ public override Uri GenerateSasUri(DataLakeSasPermissions permissions, DateTimeO
/// <remarks>
/// A <see cref="Exception"/> will be thrown if a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override Uri GenerateSasUri(DataLakeSasBuilder builder)
{
builder = builder ?? throw Errors.ArgumentNull(nameof(builder));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,7 @@ public override async Task<Response<PathAccessControl>> GetAccessControlAsync(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override Response<PathInfo> SetAccessControlList(
IList<PathAccessControlItem> accessControlList,
string owner = default,
Expand Down Expand Up @@ -1495,6 +1496,7 @@ public override Response<PathInfo> SetAccessControlList(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override async Task<Response<PathInfo>> SetAccessControlListAsync(
IList<PathAccessControlItem> accessControlList,
string owner = default,
Expand Down Expand Up @@ -1562,6 +1564,7 @@ public override async Task<Response<PathInfo>> SetAccessControlListAsync(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override Response<PathInfo> SetPermissions(
PathPermissions permissions,
string owner = default,
Expand Down Expand Up @@ -1626,6 +1629,7 @@ public override Response<PathInfo> SetPermissions(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public override async Task<Response<PathInfo>> SetPermissionsAsync(
PathPermissions permissions,
string owner = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,7 @@ public virtual async Task<Response<FileSystemAccessPolicy>> GetAccessPolicyAsync
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public virtual Response<FileSystemInfo> SetAccessPolicy(
Models.PublicAccessType accessType = Models.PublicAccessType.None,
IEnumerable<DataLakeSignedIdentifier> permissions = default,
Expand Down Expand Up @@ -2985,6 +2986,7 @@ public virtual Response<FileSystemInfo> SetAccessPolicy(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public virtual async Task<Response<FileSystemInfo>> SetAccessPolicyAsync(
Models.PublicAccessType accessType = Models.PublicAccessType.None,
IEnumerable<DataLakeSignedIdentifier> permissions = default,
Expand Down Expand Up @@ -3179,6 +3181,7 @@ public virtual async Task<Response<FileSystemInfo>> SetAccessPolicyAsync(
/// <remarks>
/// A <see cref="Exception"/> will be thrown if a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public virtual Uri GenerateSasUri(DataLakeFileSystemSasPermissions permissions, DateTimeOffset expiresOn) =>
GenerateSasUri(new DataLakeSasBuilder(permissions, expiresOn) { FileSystemName = Name });

Expand All @@ -3205,6 +3208,7 @@ public virtual Uri GenerateSasUri(DataLakeFileSystemSasPermissions permissions,
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[CallerShouldAudit(Reason = "https://aka.ms/azsdk/callershouldaudit/storage-files-datalake")]
public virtual Uri GenerateSasUri(
DataLakeSasBuilder builder)
{
Expand Down
Loading

0 comments on commit 85f952e

Please sign in to comment.