Skip to content

Updating value of StorageKeyKind when storage account is under VNet. #11609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/Sql/Sql.Test/ScenarioTests/AuditTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ function Test-AuditOnDatabase
Assert-AreEqual 0 $policy.AuditAction.Length
Assert-Null $policy.PredicateExpression
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is disabled.
Expand Down Expand Up @@ -966,7 +966,7 @@ function Test-AuditOnDatabase
Assert-AreEqual 0 $policy.AuditAction.Length
Assert-AreEqual "" $policy.PredicateExpression
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is enabled.
Expand Down Expand Up @@ -995,7 +995,7 @@ function Test-AuditOnDatabase
# Verify storage auditing policy is disabled.
Assert-AreEqual "Disabled" $policy.BlobStorageTargetState
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is enabled.
Expand All @@ -1021,7 +1021,7 @@ function Test-AuditOnDatabase
# Verify storage auditing policy is disabled.
Assert-AreEqual "Disabled" $policy.BlobStorageTargetState
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify log analytics auditing policy is disabled.
Expand Down Expand Up @@ -1065,7 +1065,7 @@ function Test-RemoveAuditOnDatabase
Assert-AreEqual 0 $policy.AuditAction.Length
Assert-Null $policy.PredicateExpression
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is disabled.
Expand Down Expand Up @@ -1162,7 +1162,7 @@ function Test-RemoveAuditOnDatabase
Assert-AreEqual 0 $policy.AuditAction.Length
Assert-AreEqual "" $policy.PredicateExpression
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is disabled.
Expand Down Expand Up @@ -1309,7 +1309,7 @@ function Test-AuditOnServer
Assert-AreEqual 0 $policy.AuditActionGroup.Length
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "" $policy.PredicateExpression
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is disabled.
Expand Down Expand Up @@ -1402,7 +1402,7 @@ function Test-AuditOnServer
Assert-True {$policy.AuditActionGroup.Contains([Microsoft.Azure.Commands.Sql.Auditing.Model.AuditActionGroups]::FAILED_DATABASE_AUTHENTICATION_GROUP)}
Assert-AreEqual "" $policy.PredicateExpression
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is enabled.
Expand Down Expand Up @@ -1430,7 +1430,7 @@ function Test-AuditOnServer
# Verify storage auditing policy is disabled.
Assert-AreEqual "Disabled" $policy.BlobStorageTargetState
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is enabled.
Expand All @@ -1455,7 +1455,7 @@ function Test-AuditOnServer
# Verify storage auditing policy is disabled.
Assert-AreEqual "Disabled" $policy.BlobStorageTargetState
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify log analytics auditing policy is disabled.
Expand Down Expand Up @@ -1499,7 +1499,7 @@ function Test-RemoveAuditOnServer
Assert-AreEqual 0 $policy.AuditActionGroup.Length
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "" $policy.PredicateExpression
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is disabled.
Expand Down Expand Up @@ -1592,7 +1592,7 @@ function Test-RemoveAuditOnServer
Assert-True {$policy.AuditActionGroup.Contains([Microsoft.Azure.Commands.Sql.Auditing.Model.AuditActionGroups]::FAILED_DATABASE_AUTHENTICATION_GROUP)}
Assert-AreEqual "" $policy.PredicateExpression
Assert-Null $policy.StorageAccountResourceId
Assert-AreEqual "Primary" $policy.StorageKeyType
Assert-AreEqual "None" $policy.StorageKeyType
Assert-Null $policy.RetentionInDays

# Verify event hub auditing policy is disabled.
Expand Down
2 changes: 1 addition & 1 deletion src/Sql/Sql/Auditing/Model/ServerAuditModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum AuditActionGroups
USER_CHANGE_PASSWORD_GROUP
}

public enum StorageKeyKind { Primary, Secondary };
public enum StorageKeyKind { None, Primary, Secondary };

public class ServerAuditModel
{
Expand Down
3 changes: 2 additions & 1 deletion src/Sql/Sql/Auditing/Services/SqlAuditAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ private void PolicizeStorageInfo(ServerAuditModel model, dynamic policy)
else
{
policy.IsStorageSecondaryKeyInUse = model.StorageKeyType == StorageKeyKind.Secondary;
policy.StorageAccountAccessKey = AzureCommunicator.RetrieveStorageKeysAsync(model.StorageAccountResourceId).GetAwaiter().GetResult()[model.StorageKeyType];
policy.StorageAccountAccessKey = AzureCommunicator.RetrieveStorageKeysAsync(
model.StorageAccountResourceId).GetAwaiter().GetResult()[model.StorageKeyType == StorageKeyKind.Secondary ? StorageKeyKind.Secondary : StorageKeyKind.Primary];
}

if (model.RetentionInDays != null)
Expand Down
1 change: 1 addition & 0 deletions src/Sql/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## Upcoming Release
* Added cmdlets `Get-AzSqlInstanceOperation` and `Stop-AzSqlInstanceOperation`
* Supported auditing to a storage account in VNet.
* Assign 'None' value as StorageKeyKind when a storage account under VNet is a target for the audit records.

## Version 2.5.0
* Added readable secondary parameter to `Invoke-AzSqlDatabaseFailover`
Expand Down