Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 10 additions & 8 deletions src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</Reference>
<Reference Include="Microsoft.Azure.Management.Sql, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.3-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Monitoring, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -58,7 +58,7 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.7.1-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Utilities.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Reference Include="Microsoft.Azure.Utilities.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Hydra.HttpRecorder.1.0.5417.13285-prerelease\lib\net45\Microsoft.Azure.Utilities.HttpRecorder.dll</HintPath>
</Reference>
Expand All @@ -82,20 +82,22 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Common">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.3.1.0\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Testing, Version=1.0.5417.13285, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Reference Include="Microsoft.WindowsAzure.Testing, Version=1.0.5417.13285, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Hydra.SpecTestSupport.1.0.5417.13285-prerelease\lib\net45\Microsoft.WindowsAzure.Testing.dll</HintPath>
</Reference>
</Reference>
<Reference Include="Moq, Version=4.2.1402.2112, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>
Expand Down
6 changes: 3 additions & 3 deletions src/ResourceManager/Sql/Commands.Sql.Test/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<package id="Hydra.SpecTestSupport" version="1.0.5406.28672-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Gallery" version="2.2.1-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.7.1-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Sql" version="0.14.0-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Sql" version="0.14.3-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Monitoring" version="2.2.1-preview" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.11.10918.1222" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common" version="1.4.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common" version="1.4.1" targetFramework="net45" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating only one project out of the solution to a newer NuGet package may cause run-time issues. Please update all projects in the AzurePowerShell.sln solution with the latest package.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if I revert this change in my project, and keep only the update o the reference to the Sql auditing Nuget?

<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.Storage" version="3.1.0" targetFramework="net45" />
<package id="Moq" version="4.2.1402.2112" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
Expand Down
6 changes: 3 additions & 3 deletions src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<ItemGroup>
<Reference Include="Microsoft.Azure.Management.Sql, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.14.3-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -110,11 +110,11 @@
</Reference>
<Reference Include="Microsoft.WindowsAzure.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/ResourceManager/Sql/Commands.Sql/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,27 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="EnterPassword" xml:space="preserve">
<value>{your_password_here}</value>
</data>
<data name="EnterUserId" xml:space="preserve">
<value>{your_user_id_here}</value>
</data>
<data name="InvalidEventTypeSet" xml:space="preserve">
<value>Cannot use the '{0}' option with other event types.</value>
</data>
<data name="NoStorageAccountWhenConfiguringAuditingPolicy" xml:space="preserve">
<value>Cannot set auditing policy without a storage account name.</value>
</data>
<data name="PdoTitle" xml:space="preserve">
<value>PHP Data Objects(PDO) Sample Code:</value>
</data>
<data name="PhpConnectionError" xml:space="preserve">
<value>Error connecting to SQL Server</value>
</data>
<data name="sqlSampleTitle" xml:space="preserve">
<value>SQL Server Extension Sample Code:</value>
</data>
<data name="StorageAccountNotFound" xml:space="preserve">
<value>Cannot find a storage account with the name '{0}'. It either does not exist, associated with a different subscription or you do not have the appropriate credentials to access it.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Azure.Commands.Sql.Security.Services
{
Expand Down Expand Up @@ -65,6 +66,7 @@ public AuditingPolicy GetDatabaseAuditingPolicy(string resourceGroup, string ser
wrapper.ResourceGroupName = resourceGroup;
wrapper.ServerName = serverName;
wrapper.DatabaseName = databaseName;
AddConnectionStringsToWrapperFromPolicy(wrapper, policy.Properties);
return wrapper;
}

Expand All @@ -86,7 +88,6 @@ private AuditingPolicy WrapPolicy(DatabaseSecurityPolicy policy)
wrapper.DirectAccessEnabled = !properties.IsBlockDirectAccessEnabled;
addStorageInfoToWrapperFromPolicy(wrapper, properties);
AddEventTypesToWrapperFromPolicy(wrapper, properties);
AddConnectionStringsToWrapperFromPolicy(wrapper, properties);
this.FetchedProperties = properties;
return wrapper;
}
Expand All @@ -102,10 +103,69 @@ private void addStorageInfoToWrapperFromPolicy(AuditingPolicy wrapper, DatabaseS

private void AddConnectionStringsToWrapperFromPolicy(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties)
{
wrapper.ConnectionStrings.AdoNetConnectionString = properties.AdoNetConnectionString;
wrapper.ConnectionStrings.OdbcConnectionString = properties.OdbcConnectionString;
wrapper.ConnectionStrings.JdbcConnectionString = properties.JdbcConnectionString;
wrapper.ConnectionStrings.PhpConnectionString = properties.PhpConnectionString;
wrapper.ConnectionStrings.AdoNetConnectionString = ConstructAdoNetConnectionString(wrapper, properties);
wrapper.ConnectionStrings.OdbcConnectionString = ConstructOdbcConnectionString(wrapper, properties);
wrapper.ConnectionStrings.JdbcConnectionString = ConstructJdbcConnectionString(wrapper, properties);
wrapper.ConnectionStrings.PhpConnectionString = ConstructPhpConnectionString(wrapper, properties);
}

private string ConstructPhpConnectionString(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties)
{
string enterUser = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterUserId;
string enterPassword = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterPassword;
string pdoTitle = Microsoft.Azure.Commands.Sql.Properties.Resources.PdoTitle;
string sqlServerSampleTitle = Microsoft.Azure.Commands.Sql.Properties.Resources.sqlSampleTitle;
string connectionError = Microsoft.Azure.Commands.Sql.Properties.Resources.PhpConnectionError;
StringBuilder sb = new StringBuilder();
sb.Append(string.Format("Server: {0}, {1}", properties.ProxyDnsName, properties.ProxyPort)).Append(Environment.NewLine);
sb.Append(string.Format("SQL Database: {0}", wrapper.DatabaseName)).Append(Environment.NewLine);
sb.Append(string.Format("User Name: {0}", enterUser)).Append(Environment.NewLine).Append(Environment.NewLine);
sb.Append(pdoTitle).Append(Environment.NewLine);
sb.Append("try{").Append(Environment.NewLine);
sb.Append(string.Format("$conn = new PDO ( \"sqlsrv:server = tcp:{0},{1}; Database = \"{2}\", \"{3}\", \"{4}\");",
properties.ProxyDnsName, properties.ProxyPort, wrapper.DatabaseName, enterUser, enterPassword)).Append(Environment.NewLine);
sb.Append("$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );").Append(Environment.NewLine);
sb.Append("}").Append(Environment.NewLine);
sb.Append("catch ( PDOException $e ) {").Append(Environment.NewLine);
sb.Append(string.Format("print( \"{0}\" );", connectionError)).Append(Environment.NewLine);
sb.Append("die(print_r($e));").Append(Environment.NewLine);
sb.Append("}").Append(Environment.NewLine);
sb.Append(sqlServerSampleTitle).Append(Environment.NewLine).Append(Environment.NewLine);
sb.Append(string.Format("connectionInfo = array(\"UID\" => \"{0}@{1}\", \"pwd\" => \"{2}\", \"Database\" => \"{3}\", \"LoginTimeout\" => 30, \"Encrypt\" => 1);",
enterUser, wrapper.ServerName, enterPassword, wrapper.DatabaseName)).Append(Environment.NewLine);
sb.Append(string.Format("$serverName = \"tcp:{0},{1}\";", properties.ProxyDnsName, properties.ProxyPort)).Append(Environment.NewLine);
sb.Append("$conn = sqlsrv_connect($serverName, $connectionInfo);");
return sb.ToString();
}

private string ConstructOdbcConnectionString(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties)
{
string enterUser = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterUserId;
string enterPassword = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterPassword;
StringBuilder sb = new StringBuilder();
sb.Append("Driver={SQL Server Native Client 11.0};");
sb.Append(string.Format("Server=tcp:{0},{1};", properties.ProxyDnsName, properties.ProxyPort));
sb.Append(string.Format("Database={0};", wrapper.DatabaseName));
sb.Append(string.Format("Uid={0}@{1};", enterUser, wrapper.ServerName));
sb.Append(string.Format("Pwd={0};", enterPassword));
sb.Append("Encrypt=yes;Connection Timeout=30;");
return sb.ToString();
}

private string ConstructJdbcConnectionString(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties)
{
string enterUser = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterUserId;
string enterPassword = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterPassword;
return string.Format("jdbc:sqlserver://{0}:{1};database={2};user={3}@{4};password={5};encrypt=true;hostNameInCertificate=*.database.secure.windows.net;loginTimeout=30;",
properties.ProxyDnsName, properties.ProxyPort, wrapper.DatabaseName, enterUser, wrapper.ServerName, enterPassword);
}

private string ConstructAdoNetConnectionString(AuditingPolicy wrapper,DatabaseSecurityPolicyProperties properties)
{
string enterUser = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterUserId;
string enterPassword = Microsoft.Azure.Commands.Sql.Properties.Resources.EnterPassword;
return string.Format("Server=tcp:{0},{1};Database={2};User ID={3}@{4};Password={5};Trusted_Connection=False;Encrypt=True;Connection Timeout=30",
properties.ProxyDnsName, properties.ProxyPort, wrapper.DatabaseName, enterUser, wrapper.ServerName, enterPassword);
}

private void AddEventTypesToWrapperFromPolicy(AuditingPolicy wrapper, DatabaseSecurityPolicyProperties properties)
Expand Down
6 changes: 3 additions & 3 deletions src/ResourceManager/Sql/Commands.Sql/packages.config
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Azure.Management.Resources" version="2.7.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Sql" version="0.14.0-prerelease" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Sql" version="0.14.3-prerelease" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net45" />
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net45" />
<package id="Microsoft.Data.Services.Client" version="5.6.0" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common" version="1.4.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common" version="1.4.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="1.8.0.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.Storage" version="3.1.0" targetFramework="net45" />
Expand Down