Azure SAS key substitution issue with .config files

Hi Team,

We are using Azure SAS token as a variable in our dotnet project config files.
If I add normal SAS token in Octopus variable deployment is failing with below error.

So I am adding encoded SAS token by replacing the & with & in Octpus variable then deployment is happening and application is working but after some time the config file is going to change, means & became & though there is no deployment happened.

I want to understand how can I add this SAS token in Octopus variable and work the application without any issue.

Exception while replacing configuration-variables in: C:\Octopus\Applications\Glss-Aqua\glss-report-web\373_2\app.config
System.Xml.XmlException: ‘=’ is an unexpected token. The expected token is ‘;’. Line 21, position 69.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos)
at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at Calamari.Integration.ConfigurationVariables.ConfigurationVariablesReplacer.ReadXmlDocument(String configurationFilePath)
at Calamari.Integration.ConfigurationVariables.ConfigurationVariablesReplacer.ModifyConfigurationFile(String configurationFilePath, VariableDictionary variables)
at Calamari.Deployment.Conventions.ConfigurationVariablesConvention.Install(RunningDeployment deployment)
at Calamari.Deployment.ConventionProcessor.RunInstallConventions()
at Calamari.Deployment.ConventionProcessor.RunConventions()
Running rollback conventions…
‘=’ is an unexpected token. The expected token is ‘;’. Line 21, position 69.
System.Xml.XmlException
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos)
at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at Calamari.Integration.ConfigurationVariables.ConfigurationVariablesReplacer.ReadXmlDocument(String configurationFilePath)
at Calamari.Integration.ConfigurationVariables.ConfigurationVariablesReplacer.ModifyConfigurationFile(String configurationFilePath, VariableDictionary variables)
at Calamari.Deployment.Conventions.ConfigurationVariablesConvention.Install(RunningDeployment deployment)
at Calamari.Deployment.ConventionProcessor.RunInstallConventions()
at Calamari.Deployment.ConventionProcessor.RunConventions()
at Calamari.Commands.DeployPackageCommand.Execute(String[] commandLineArguments)
at Calamari.Program.Execute(String[] args)
The remote script failed with exit code 100

Regards,
Satish

Hi Satish, thanks for reaching out.

Octopus provides a number of filters that can be used with variable replacements, which are documented at https://octopus.com/docs/deployment-process/variables/variable-substitutions#VariableSubstitutionSyntax-Providedfilters. In particular it sounds like you would use the XmlEscape filter to ensure special characters like & are output as amp;.

So in your config file you would have a replacement like #{AzureSASKey | XmlEscape}, and that would print the correctly escaped chars in the config file.

Regards
Matt C

Hi Matthew,

Thanks for your reply, I will check and confirm you.

Regards,
Satish

Hi Matthew,

Sorry for late reply, your solution working fine.

Thanks for your help.

Regards,
Satish

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.