Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(host): devolutions-session bootstrap #997

Merged
merged 10 commits into from
Sep 9, 2024
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,14 @@ jobs:

$DAgentPedmShellExtMsix = Join-Path $TargetOutputPath "DevolutionsPedmShellExt.msix"
echo "dagent-pedm-shell-ext-msix=$DAgentPedmShellExtMsix" >> $Env:GITHUB_OUTPUT

$DAgentPedmHook = Join-Path $TargetOutputPath "devolutions_pedm_hook.dll"
echo "dagent-pedm-hook=$DAgentPedmHook" >> $Env:GITHUB_OUTPUT

$DAgentDevolutionsHostExecutable = Join-Path $TargetOutputPath "DevolutionsHost.exe"
echo "dagent-devolutions-host-executable=$DAgentDevolutionsHostExecutable" >> $Env:GITHUB_OUTPUT


Copy link
Member

Choose a reason for hiding this comment

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

nit: You may have added unintentional blank lines

}

$DAgentExecutable = Join-Path $TargetOutputPath $ExecutableFileName
Expand Down Expand Up @@ -603,8 +608,9 @@ jobs:
$Env:DAGENT_PEDM_HOOK = "${{ steps.load-variables.outputs.dagent-pedm-hook }}"
$Env:DAGENT_PEDM_SHELL_EXT_DLL = "${{ steps.load-variables.outputs.dagent-pedm-shell-ext-dll }}"
$Env:DAGENT_PEDM_SHELL_EXT_MSIX = "${{ steps.load-variables.outputs.dagent-pedm-shell-ext-msix }}"
$Env:DAGENT_DEVOLUTIONS_HOST_EXECUTABLE = "${{ steps.load-variables.outputs.dagent-devolutions-host-executable }}"
}

./ci/tlk.ps1 build -Product agent -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }} -CargoProfile ${{ needs.preflight.outputs.rust-profile }}

- name: Package
Expand All @@ -620,6 +626,7 @@ jobs:
$Env:DAGENT_PEDM_HOOK = "${{ steps.load-variables.outputs.dagent-pedm-hook }}"
$Env:DAGENT_PEDM_SHELL_EXT_DLL = "${{ steps.load-variables.outputs.dagent-pedm-shell-ext-dll }}"
$Env:DAGENT_PEDM_SHELL_EXT_MSIX = "${{ steps.load-variables.outputs.dagent-pedm-shell-ext-msix }}"
$Env:DAGENT_DEVOLUTIONS_HOST_EXECUTABLE = "${{ steps.load-variables.outputs.dagent-devolutions-host-executable }}"
}

./ci/tlk.ps1 package -Product agent -Platform ${{ matrix.os }} -Architecture ${{ matrix.arch }} -CargoProfile ${{ needs.preflight.outputs.rust-profile }}
Expand Down Expand Up @@ -827,4 +834,3 @@ jobs:
destination_path: /Gateway/${{ steps.prepare.outputs.version }}-${{ steps.timestamp.outputs.timestamp }}-${{ steps.prepare.outputs.short-ref }}
remote: prereleases
source_path: ${{ steps.prepare.outputs.files-to-upload }}

5 changes: 3 additions & 2 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ jobs:
$appx.Save($xmlTextWriter)
$xmlTextWriter.Close()
& 'MakeAppx.exe' pack /d $UnpackedMsix /p $PackedMsix /nv

Remove-Item $UnpackedMsix -Recurse -Force | Out-Null
}

Expand Down Expand Up @@ -326,6 +326,7 @@ jobs:
$Env:DAGENT_PEDM_SHELL_EXT_DLL = Get-ChildItem -Path $PackageRoot -Recurse -Include 'DevolutionsPedmShellExt.dll' | Select -First 1
$Env:DAGENT_PEDM_SHELL_EXT_MSIX = Get-ChildItem -Path $PackageRoot -Recurse -Include 'DevolutionsPedmShellExt.msix' | Select -First 1
$Env:DAGENT_PEDM_HOOK = Get-ChildItem -Path $PackageRoot -Recurse -Include 'devolutions_pedm_hook.dll' | Select -First 1
$Env:DAGENT_DEVOLUTIONS_HOST_EXECUTABLE = Get-ChildItem -Path $PackageRoot -Recurse -Include 'DevolutionsHost.dll' | Select -First 1

./ci/tlk.ps1 package -Product agent -PackageOption generate

Expand Down Expand Up @@ -431,7 +432,7 @@ jobs:
shell: pwsh
run: |
$PackageRoot = Join-Path ${{ runner.temp }} ${{ matrix.project}}

Get-ChildItem -Path $PackageRoot -Recurse

Compress-Archive "$PackageRoot\windows\x86_64\*.pdb" "$PackageRoot\windows\x86_64\DevolutionsAgent-x86_64-${{ needs.preflight.outputs.version }}.symbols.zip" -CompressionLevel Optimal
Expand Down
8 changes: 8 additions & 0 deletions ci/tlk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ class TlkRecipe
$Env:DAGENT_PEDM_HOOK
} elseif ($CargoPackage.Name -Eq "devolutions-pedm-shell-ext" -And (Test-Path Env:DAGENT_PEDM_SHELL_EXT_DLL)) {
$Env:DAGENT_PEDM_SHELL_EXT_DLL
} elseif ($CargoPackage.Name -Eq "devolutions-host" -And (Test-Path Env:DAGENT_DEVOLUTIONS_HOST_EXECUTABLE)) {
$Env:DAGENT_DEVOLUTIONS_HOST_EXECUTABLE
} else {
$null
}
Expand Down Expand Up @@ -500,6 +502,12 @@ class TlkRecipe
Copy-Item -Path $builtDesktopPdb -Destination $(Get-DestinationSymbolFile $Env:DAGENT_PEDM_DESKTOP_EXECUTABLE $this.Target)

}

if (Test-Path Env:DAGENT_DEVOLUTIONS_HOST_EXECUTABLE) {
$hostExe = Get-ChildItem -Recurse -Include 'devolutions-host.exe' | Select-Object -First 1

Copy-Item -Path $hostExe -Destination $Env:DAGENT_DEVOLUTIONS_HOST_EXECUTABLE
}
}

Pop-Location
Expand Down
16 changes: 15 additions & 1 deletion package/AgentWindowsManaged/Actions/AgentActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ internal static class AgentActions
Impersonate = false,
UsesProperties = UseProperties(new [] { AgentProperties.installId })
};

private static readonly ElevatedManagedAction cleanAgentConfigIfNeededRollback = new(
new Id($"CA.{nameof(cleanAgentConfigIfNeededRollback)}"),
CustomActions.CleanAgentConfigRollback,
Expand Down Expand Up @@ -252,6 +252,19 @@ internal static class AgentActions
Condition = Includes.PEDM_FEATURE.BeingUninstall(),
};

private static readonly ElevatedManagedAction installHost = new(
CustomActions.InstallHost
)
{
Id = new Id("installHost"),
Feature = Includes.PEDM_FEATURE,
Sequence = Sequence.InstallExecuteSequence,
Return = Return.check,
Step = Step.InstallFiles,
When = When.After,
Condition = Includes.PEDM_FEATURE.BeingInstall(),
};

private static string UseProperties(IEnumerable<IWixProperty> properties)
{
if (!properties?.Any() ?? false)
Expand Down Expand Up @@ -285,6 +298,7 @@ private static string UseProperties(IEnumerable<IWixProperty> properties)
cleanupPedmShellExt,
uninstallPedmShellExt,
installPedmShellExt,
installHost,

cleanAgentConfigIfNeeded,
cleanAgentConfigIfNeededRollback,
Expand Down
19 changes: 15 additions & 4 deletions package/AgentWindowsManaged/Actions/CustomActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ public static ActionResult GetInstalledNetFx45Version(Session session)
return ActionResult.Success;
}

[CustomAction]
public static ActionResult InstallPedm(Session session)
static ActionResult EnableAgentFeature(Session session, string feature)
{
string path = Path.Combine(ProgramDataDirectory, "agent.json");

Expand All @@ -215,7 +214,7 @@ public static ActionResult InstallPedm(Session session)
// ignored. Previous config is either invalid or non existent.
}

config["Pedm"] = new Dictionary<string, bool> { { "Enabled", true } };
config[feature] = new Dictionary<string, bool> { { "Enabled", true } };

using var writer = new StreamWriter(path);
writer.Write(JsonConvert.SerializeObject(config));
Expand All @@ -224,11 +223,23 @@ public static ActionResult InstallPedm(Session session)
}
catch (Exception e)
{
session.Log($"failed to install pedm: {e}");
session.Log($"failed to install {feature}: {e}");
return ActionResult.Failure;
}
}

[CustomAction]
public static ActionResult InstallPedm(Session session)
{
return EnableAgentFeature(session, "Pedm");
}

[CustomAction]
public static ActionResult InstallHost(Session session)
{
return EnableAgentFeature(session, "SessionHost");
}

[CustomAction]
public static ActionResult RestartAgent(Session session)
{
Expand Down
5 changes: 4 additions & 1 deletion package/AgentWindowsManaged/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ private static string ResolveArtifact(string varName, string error)

private static string DevolutionsPedmShellExtMsix => ResolveArtifact("DAGENT_PEDM_SHELL_EXT_MSIX", "The PEDM shell extension MSIX was not found");

private static string DevolutionsHost => ResolveArtifact("DAGENT_DEVOLUTIONS_HOST_EXECUTABLE", "The Devolutions Host executable was not found");

private static Version DevolutionsAgentVersion
{
get
Expand Down Expand Up @@ -281,7 +283,8 @@ static void Main()
},
new (Includes.PEDM_FEATURE, DevolutionsPedmHook),
new (Includes.PEDM_FEATURE, DevolutionsPedmShellExtDll),
new (Includes.PEDM_FEATURE, DevolutionsPedmShellExtMsix)
new (Includes.PEDM_FEATURE, DevolutionsPedmShellExtMsix),
new (Includes.HOST_FEATURE, DevolutionsHost)
},
Dirs = new[]
{
Expand Down
2 changes: 2 additions & 0 deletions package/AgentWindowsManaged/Resources/Includes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal static class Includes

internal static Feature PEDM_FEATURE = new Feature("Devolutions PEDM", "Installs Devolutions PEDM", false);

internal static Feature HOST_FEATURE = new Feature("Devolutions Host", "Installs Devolutions Host", false);

/// <summary>
/// SDDL string representing desired %programdata%\devolutions\agent ACL
/// Easiest way to generate an SDDL is to configure the required access, and then query the path with PowerShell: `Get-Acl | Format-List`
Expand Down