Encrypting Arbitrary Configuration Sections using MSDeploy
Web Deploy 3.5 added the EncryptWebConfig for encrypting connection strings in Web.config files. While great, the feature only works with connectionStrings and doesn’t support configSource.
To workaround this, we can use the runCommand
provider to invoke “aspnet_regiis.exe” directly:
This leaves us with a problem: non-administrator deploy users don’t have sufficient permission to encrypt configuration sections. And we’re all using non-administrator deploy users, right?
Configuring non-administrator deployments
Assuming non-administrator deployments are already configured, the following changes will allow the user to encrypt configuration sections:
- Grant the deplopy user access to the encryption key:
aspnet_regiis -pa YourKeyProvider your_webdeploy_user
- Create a delegation rule to allow the deploy user to invoke aspnet_regiis.exe
- In IIS Manager, go to “Management service Delegation”
- Create a new, blank rule with the following settings:
- Provider: runCommand
- User: CurrentUser
- RegularExpression: aspnet_regiis.exe
- Grant the deploy user read access to %windir%\system32\inetsrv\config (ignore the errors on the sub-folders)
- Add the deploy user to the “Replace a process level token” group policy (Group Policy :: Local Policies :: User Rights Assignment)