Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure role configuration management

I don't see how Windows Azure lets you vary the configuration of an application when you have no choice but to hold configuration settings in web.config (or app.config).

For example...

Quite often projects will make use of a 3rd party library that makes heavy use of web.config. The use of web.config may involve connection strings, app settings or custom configuration sections. A good example of this is ELMAH. A web.config file for ELMAH might look like the following:

<configuration>

  <configSections>
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
    </sectionGroup>
  </configSections>

  <connectionStrings>
    <add
      name="MyElmahDatabase"
      providerName="System.Data.SqlClient"
      connectionString="Server=tcp:myServer.database.windows.net,1433;Database=myDB;User ID=user@myServer;Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30" />
  </connectionStrings>

  <elmah>
    <security allowRemoteAccess="1" />
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="MyElmahDatabase" />
  </elmah>

</configuration>

There are a couple of problems here:

  • There is no way for me to update or vary whether remote access is enabled between Service Configurations.

  • There is no way for me to update or vary the ELMAH connection string between Service Configurations.

This is because the web.config is packaged as is into the .cspkg file and ELMAH will not look at the Service Configuration settings (which are the only way I can vary configuration settings between Service Configurations).

I can think of many other examples where this is a problem...

  • Any data access frameworks that look directly at the connection strings section.
  • Any custom configuration settings I need to create.

...to name just two.

Am I missing something or is this a significant gap in the configuration management offered by Windows Azure?

EDIT

From the answer and comments below, it looks like this is something that is not well supported. I think that managing multiple solution build configurations to support different configuration profiles is a very weak solution. I should not have to rebuild the solution for each configuration profile I need (there will likely be quite a few). Compilation is not equal to configuration.

I was wondering if there was a way to modify the .cspkg file as it is just a zip file. According to this documentation you can on Linux.

I've looked at the manifest in the .cspkg file and it looks like this:

<PackageManifest version="2">
  <Encryption keytype="1" />
  <Contents hashtype="1">
    <Item name="MyApp.Web.UI_<GUID>.cssx" hash="AED69299C5F89E060876BC16BD3D6DE5130F6E62FFD2B752BAF293435339B7E2" uri="/MyApp.Web.UI_<GUID>.cssx" />
    <Item name="MyApp.Web.Services_<GUID>.cssx" hash="7AC81AFF642E4345173C8470C32A41118A4E3CFD4185B82D0ADA44B71057192D" uri="/MyApp.Web.Services_<GUID>.cssx" />
    <Item name="SMPackage_<GUID>.csmx" hash="B5E6B83B62AF64C7C11CAC1A394ABBF15D7DB7667A773C5284CE5BE95C5834E9" uri="/SMPackage_<GUID>.csmx" />
    <Item name="SDPackage_<GUID>.csdx" hash="F34B7C02A551D82BAD96881E2DA9447D0014D49B47CCB3840475BDC575234A7D" uri="/SDPackage_<GUID>.csdx" />
    <Item name="NamedStreamPackage_<GUID>.csnsx" hash="FA2B5829FF5D9B2D69DCDDB0E5BDEE6B8B0BC09FFBF37DAEEE41CF3F3F4D0132" uri="/NamedStreamPackage_<GUID>.csnsx" />
  </Contents>
  <NamedStreams>
    <Stream name="RequiredFeatures/MyApp.Web.Services/1.0" />
    <Stream name="RequiredFeatures/MyApp.Web.UI/1.0" />
    <Stream name="SupportData/MyApp.Web.Services/1.0" />
    <Stream name="SupportData/MyApp.Web.UI/1.0" />
  </NamedStreams>
</PackageManifest>

Unfortunately, if I re-compute the hash of the unchanged "MyApp.Web.UI_.cssx" file, my hash is different from the one in the manifest.

Hash from manifest: AED69299C5F89E060876BC16BD3D6DE5130F6E62FFD2B752BAF293435339B7E2

My calculated hash: E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855

Note that I have not yet changed the file, so the hash should be the same.

This suggests I'm calculating it wrong. My method was as follows:

class Program
{
    static void Main(string[] args)
    {
        using (FileStream fs = new FileStream(args[0], FileMode.Open))
        {
            ComputeHash(new SHA256Managed(), fs);
        }
    }

    private static void ComputeHash(HashAlgorithm hashAlgorithm, Stream stream)
    {
        byte[] hash = hashAlgorithm.ComputeHash(stream);
        string hashString = BitConverter.ToString(hash);
        Console.WriteLine(hashString.Replace("-", string.Empty));
        Console.WriteLine();
    }
}

The documentation link above, suggests it is straightforward to re-calculate the hash (on Linux anyway).

Does anyone know how to re-compute the hashes?

like image 618
Callum Hibbert Avatar asked Nov 03 '22 20:11

Callum Hibbert


1 Answers

Passing a Stream to ComputeHash() ends up with a different hash as compared to using the byte[] overload. I don't know why.

Try something like:

private static void ComputeHash(HashAlgorithm hashAlgorithm, Stream stream)
{
    BinaryReader reader = new BinaryReader(stream)
    byte[] hash = hashAlgorithm.ComputeHash( reader.ReadBytes( (int)stream.Length ) );
    string hashString = BitConverter.ToString(hash);
    Console.WriteLine(hashString.Replace("-", string.Empty));
    Console.WriteLine();
}

This will give you the hash you're after.

As you've probably already discovered, on linux you can get the digest with

openssl dgst -sha256 /path/to/file
like image 146
user2216245 Avatar answered Nov 09 '22 05:11

user2216245