Skip to content

Commit

Permalink
* Add admin owner group on upgrade * detailed logging (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Hsu committed Feb 26, 2019
1 parent 3a27196 commit 5285cf8
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 36 deletions.
11 changes: 4 additions & 7 deletions scripts/publish/publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ if (-not([string]::IsNullOrEmpty($SignType))) {
}
}
catch {
Write-Warning $_.Exception.Message
throw "Could not find msbuild"
throw "Could not find msbuild: $($_.Exception.Message)"
}

if ([string]::IsNullOrEmpty($SigningIdentity)) {
Expand All @@ -135,8 +134,7 @@ try {
}
}
catch {
Write-Warning $_.Exception.Message
throw "Could not find dotnet tools"
throw "Could not find dotnet tools: $($_.Exception.Message)"
}

DeletePreExistingFiles $OutputPath
Expand Down Expand Up @@ -171,8 +169,7 @@ try{
}
}
catch {
Write-Warning $_.Exception.Message
throw "Publish failed"
throw "Publish failed: $($_.Exception.Message)"
}

$outputConfigPath = Join-Path $applicationPath "config"
Expand Down Expand Up @@ -218,7 +215,7 @@ try {
}
}
catch {
throw "Could not build plugins for publishing"
throw "Could not build plugins for publishing: $($_.Exception.Message)"
}

# Copy setup
Expand Down
26 changes: 19 additions & 7 deletions scripts/setup/config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ function Remove($_path) {
}
}

## create "IIS Administration API Owners" group if it does not exist, and and the current user to the group if not already added
## Note that this method also includes a phase the indiciates the group is created by the installer so it can be removed if the application
## is uninistalled
function Ensure-IncludesIisAdminApiOwners($settings) {
$groupName = .\globals.ps1 'IIS_ADMIN_API_OWNERS'
$groupDescription = .\globals.ps1 'IIS_ADMIN_API_OWNERS_DESCRIPTION'
$currentAdUser = .\security.ps1 CurrentAdUser
.\security.ps1 EnsureLocalGroupMember -AdPath $currentAdUser -Name $groupName -Description $groupDescription
if (!$settings.security.users.administrators.Contains($groupName)) {
$settings.security.users.administrators += $groupName
}
if (!$settings.security.users.owners.Contains($groupName)) {
$settings.security.users.owners += $groupName
}
}

# Writes install time information into the appsettings.json file
# AppSettingsPath: The full path to the appsettings.json file
function Write-AppSettings($_appSettingsPath, $_port) {
Expand All @@ -126,13 +142,7 @@ function Write-AppSettings($_appSettingsPath, $_port) {
}

$settings = .\json.ps1 Get-JsonContent -Path $_appSettingsPath

$groupName = .\globals.ps1 'IIS_ADMIN_API_OWNERS'
$groupDescription = .\globals.ps1 'IIS_ADMIN_API_OWNERS_DESCRIPTION'
$currentAdUser = .\security.ps1 CurrentAdUser
.\security.ps1 EnsureLocalGroupMember -AdPath $currentAdUser -Name $groupName -Description $groupDescription
$settings.security.users.administrators += $groupName
$settings.security.users.owners += $groupName
Ensure-IncludesIisAdminApiOwners $settings

if ($IncludeDefaultCors) {
$settings.cors.rules += @{ "origin" = "https://manage.iis.net"; "allow" = $true }
Expand Down Expand Up @@ -161,6 +171,7 @@ function Migrate-AppSettings($_source, $_destination) {
if ($oldAppSettings.administrators -ne $null) {
.\json.ps1 Remove-Property -JsonObject $oldAppSettings -Name "administrators"
}
Ensure-IncludesIisAdminApiOwners $oldAppSettings

.\json.ps1 Set-JsonContent -Path $(Join-Path $Destination $userFiles["appsettings.json"]) -JsonObject $oldAppSettings
}
Expand Down Expand Up @@ -238,6 +249,7 @@ function Write-Config($obj, $_path) {
$port = [int]::parse($sPort)
}
catch {
Write-Warning $_.Exception.Message
throw "Misconfigured 'urls' in appsettings: $($appsettings.urls)."
}
}
Expand Down
20 changes: 10 additions & 10 deletions scripts/setup/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function rollback() {
Stop-Service $rollbackStore.createdService -ErrorAction SilentlyContinue
}
catch {
Write-Warning "Could not stop newly created service"
Write-Warning "Could not stop newly created service: $($_.Exception.Message)"
}

sc.exe delete "$($rollbackStore.createdService)" | Out-Null
Expand Down Expand Up @@ -172,7 +172,7 @@ function rollback() {
New-Service -BinaryPathName $binaryPath -StartupType $startType -DisplayName $name -Name $name -ErrorAction Stop | Out-Null
}
catch {
Write-Warning "Could not restore the $($name) service."
Write-Warning "Could not restore the $($name) service: $($_.Exception.Message)"
}
}

Expand All @@ -185,7 +185,7 @@ function rollback() {
.\net.ps1 DeleteSslBinding -Port $rollbackStore.newBoundCertPort
}
catch {
Write-Warning "Could not roll back SSL binding on port $($rollbackStore.newBoundCertPort)"
Write-Warning "Could not roll back SSL binding on port $($rollbackStore.newBoundCertPort): $($_.Exception.Message)"
}
}

Expand All @@ -199,7 +199,7 @@ function rollback() {
.\net.ps1 BindCert -Hash $($info.CertificateHash) -AppId $($info.AppId) -Port $($info.IpEndpoint.Port)
}
catch {
Write-Warning "Could not restore previous SSL binding"
Write-Warning "Could not restore previous SSL binding: $($_.Exception.Message)"
}
}

Expand All @@ -213,7 +213,7 @@ function rollback() {
.\config.ps1 Remove -Path $configPath
}
catch {
Write-Warning "Could not remove setup config"
Write-Warning "Could not remove setup config: $($_.Exception.Message)"
}
}

Expand All @@ -230,7 +230,7 @@ function rollback() {
}
}
catch {
write-warning "Could not delete certificate that was created during installation."
write-warning "Could not delete certificate that was created during installation: $($_.Exception.Message)"
}
}

Expand All @@ -243,7 +243,7 @@ function rollback() {
Start-Service $rollbackStore.stoppedOldService
}
catch {
write-warning "Could not restart service $($rollbackStore.stoppedOldService)."
write-warning "Could not restart service $($rollbackStore.stoppedOldService): $($_.Exception.Message)"
}
}

Expand All @@ -257,7 +257,7 @@ function rollback() {
.\files.ps1 Remove-ItemForced -Path $logsPath
}
catch {
write-warning "Could not delete logs folder $logsPath."
write-warning "Could not delete logs folder ${logsPath}: $($_.Exception.Message)"
}
}

Expand All @@ -271,7 +271,7 @@ function rollback() {
.\files.ps1 Remove-ItemForced -Path $adminRoot
}
catch {
write-warning "Could not delete installation folder $adminRoot."
write-warning "Could not delete installation folder ${adminRoot}: $($_.Exception.Message)"
}
}

Expand Down Expand Up @@ -458,7 +458,7 @@ function Install
Start-Service "$ServiceName" -ErrorAction Stop
}
catch {
throw "Could not start service"
throw "Could not start service: $($_.Exception.Message)"
}

$svc = Get-Service "$ServiceName" -ErrorAction SilentlyContinue
Expand Down
9 changes: 5 additions & 4 deletions scripts/setup/migrate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Rollback {
Stop-Service $migrateRollback.startedNewService -ErrorAction Stop
}
catch {
Write-Warning "Could not stop newly created service $($migrateRollback.startedNewService)"
Write-Warning "Could not stop newly created service $($migrateRollback.startedNewService): $($_.Exception.Message)"
}
}

Expand All @@ -37,7 +37,7 @@ function Rollback {
sc.exe delete "$($migrateRollback.createdNewService)" | Out-Null
}
catch {
Write-Warning "Could not remove newly created service '$($migrateRollback.createdNewService)'"
Write-Warning "Could not remove newly created service '$($migrateRollback.createdNewService)': $($_.Exception.Message)"
}
}

Expand All @@ -55,7 +55,7 @@ function Rollback {
New-Service -BinaryPathName $binaryPath -StartupType $startType -DisplayName $name -Name $name -ErrorAction Stop | Out-Null
}
catch {
Write-Warning "Could not restore the $($name) service."
Write-Warning "Could not restore the $($name) service: $($_.Exception.Message)"
}
}

Expand All @@ -68,7 +68,7 @@ function Rollback {
Start-Service $migrateRollback.stoppedSourceService -ErrorAction Stop
}
catch {
Write-Warning "Could not restart source service"
Write-Warning "Could not restart source service: $($_.Exception.Message)"
}
}
}
Expand Down Expand Up @@ -116,6 +116,7 @@ function Migrate {
.\sanitize-logs.ps1 -Source $source
}
catch {
Write-Warning "Error sanitizing logs: $($_.Exception.Message)"
# Never fail
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/setup/msi-setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Upgrade() {
$installed = $true
.\migrate.ps1 -Source $latest -Destination $(Join-Path $adminRoot $Version)
try {
.\uninstall.ps1 -Path $latest -KeepFiles
.\uninstall.ps1 -Path $latest -KeepFiles -KeepGroups
}
catch {
# Uninstall must not throw
Expand Down
1 change: 1 addition & 0 deletions scripts/setup/sanitize-logs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function Clear-CcsAuditPasswords($IisAdministrationPath) {
Clear-CcsAuditPasswordsFromFile -filePath $file.FullName
}
catch {
Write-Warning "Error clearing ccs audit password from $($file.FullName): $($_.Exception.Message)"
#If one file fails, do not block the remaining files
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/setup/security.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function GetLocalGroup($groupName) {
$group = $localAd.Children.Find($groupName, 'group')
}
catch {
Write-Warning $_.Exception.Message
#COM Exception if group doesn't exit
}
}
Expand Down Expand Up @@ -376,7 +377,7 @@ function _Set-AclForced($_path, $_acl, $_recurse) {
}
catch {
# Fail state: owner will be the Administrators group
Write-Warning "Could not restore owner for $($item.fullname)"
Write-Warning "Could not restore owner for $($item.fullname): $($_.Exception.Message)"
}

# Revert any token privileges adjusted
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Upgrade() {
throw $_
}

.\uninstall.ps1 -Path $latest
.\uninstall.ps1 -Path $latest -KeepGroups
}

function Uninstall() {
Expand Down
16 changes: 11 additions & 5 deletions scripts/setup/uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ Param(

[parameter()]
[switch]
$KeepFiles
$KeepFiles,

[parameter()]
[switch]
$KeepGroups
)

.\require.ps1 Is-Administrator
Expand Down Expand Up @@ -83,7 +87,7 @@ function Uninstall($_path)
.\security.ps1 Add-FullControl -Path $InstallationDirectory.FullName -Identity $system -Recurse
}
catch {
Write-Warning "Unable to obtain full control of installation directory"
Write-Warning "Unable to obtain full control of installation directory: $($_.Exception.Message)"
}
}

Expand Down Expand Up @@ -117,16 +121,18 @@ function Uninstall($_path)
.\files.ps1 Remove-ItemForced -Path $setupConfig -ErrorAction Stop
}
catch {
Write-Warning "Could not remove installation configuration file"
Write-Warning "Could not remove installation configuration file: $($_.Exception.Message)"
}
}
}

$groupName = .\globals.ps1 'IIS_ADMIN_API_OWNERS'
$group = .\security.ps1 GetLocalGroup -Name $groupName
$installerFlag = .\globals.ps1 'INSTALLER_FLAG'
if ($group -and $group.Description.Contains($installerFlag)) {
.\security.ps1 RemoveLocalGroup -Name $groupName
if (!$KeepGroups) {
if ($group -and $group.Description.Contains($installerFlag)) {
.\security.ps1 RemoveLocalGroup -Name $groupName
}
}

exit 0
Expand Down

0 comments on commit 5285cf8

Please sign in to comment.