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

initial upload #1

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6c1d270
initial upload
FriedrichWeinmann Apr 7, 2021
9251232
initial guest framework
FriedrichWeinmann Apr 7, 2021
0ce1842
done v1
FriedrichWeinmann Apr 8, 2021
17943d2
creating deployment script for inclusion in Guest OS image
FriedrichWeinmann Apr 8, 2021
7bcfe50
updates
FriedrichWeinmann Oct 22, 2021
c6d1348
Update vmdeploy.ps1
FriedrichWeinmann Oct 22, 2021
86637ac
actions, lots of actions
FriedrichWeinmann Dec 10, 2021
154945e
added persistent configuration for success
FriedrichWeinmann Apr 27, 2022
89ea68e
update
FriedrichWeinmann May 3, 2022
83c517f
update
FriedrichWeinmann May 3, 2022
96177c8
Update strings.psd1
FriedrichWeinmann May 4, 2022
1a8c3c7
Updated actions
FriedrichWeinmann May 24, 2022
5cf5d94
firewall processing update
FriedrichWeinmann May 24, 2022
fdf7dfd
Update firewall.action.ps1
FriedrichWeinmann May 24, 2022
29af43d
new action
FriedrichWeinmann May 24, 2022
016dda5
updates
FriedrichWeinmann May 25, 2022
38a0542
Create firewall_exemptions.action.ps1
FriedrichWeinmann May 25, 2022
01d1393
adding store parameter on get
FriedrichWeinmann May 26, 2022
4693af8
Update disk.action.ps1
FriedrichWeinmann Jun 1, 2022
261d546
Update disk.action.ps1
FriedrichWeinmann Jul 18, 2022
b32c22c
Adding CertDeploy action
FriedrichWeinmann Oct 10, 2023
3692ec9
adding PFX support
FriedrichWeinmann Feb 15, 2024
c44b19d
updates
FriedrichWeinmann Feb 15, 2024
37d1ced
updates
FriedrichWeinmann Feb 19, 2024
9c55f6d
updates
FriedrichWeinmann Mar 20, 2024
8aab49b
Update changelog.md
FriedrichWeinmann Mar 20, 2024
09848dc
updates
FriedrichWeinmann Mar 21, 2024
2ae6af0
Update network.action.ps1
FriedrichWeinmann Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github:
FriedrichWeinmann
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on:
push:
branches:
- main

jobs:
build:

runs-on: windows-2019

steps:
- uses: actions/checkout@v1
- name: Install Prerequisites
run: .\build\vsts-prerequisites.ps1
shell: powershell
- name: Validate
run: .\build\vsts-validate.ps1
shell: powershell
- name: Build
run: .\build\vsts-build.ps1 -ApiKey $env:APIKEY
shell: powershell
env:
APIKEY: ${{ secrets.ApiKey }}
15 changes: 15 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
on: [pull_request]

jobs:
validate:

runs-on: windows-2019

steps:
- uses: actions/checkout@v1
- name: Install Prerequisites
run: .\build\vsts-prerequisites.ps1
shell: powershell
- name: Validate
run: .\build\vsts-validate.ps1
shell: powershell
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# ignore the settings folder and files for VSCode and PSS
.vscode/*
*.psproj
*TempPoint*

# Ignore staging info from Visual Studio
library/VMDeploy.Guest/.vs/*
library/VMDeploy.Guest/VMDeploy.Guest/bin/*
library/VMDeploy.Guest/VMDeploy.Guest/obj/*

# ignore PowerShell Studio MetaData
VMDeploy.Guest/VMDeploy.Guest.psproj
VMDeploy.Guest/VMDeploy.Guest.psproj.bak
VMDeploy.Guest/VMDeploy.Guest.psprojs
VMDeploy.Guest/VMDeploy.Guest.psproj

# ignore the TestResults
TestResults/*

# ignore the publishing Directory
publish/*
63 changes: 63 additions & 0 deletions Actions/application.action.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
$executionCode = {
param (
$Configuration
)

$param = @{
Path = $Configuration.Path
Wait = $true
PassThru = $true
}
if ($Configuration.Arguments) { $param.ArgumentList = $Configuration.Arguments }

$result = Start-Process @param
if ($result.ExitCode -eq 0) {
$trackingFile = Join-Path -Path 'VMDeploy:\Runtime' -ChildPath $Configuration.Name
"Success" | Set-Content -Path $trackingFile
return
}

Write-PSFMessage -Level Warning -Message "Application '{0}' failed with exit code {1}" -StringValues $Configuration.Path, $result.ExitCode -ModuleName 'VMDeploy.Guest' -Data @{
Path = $Configuration.Path
Arguments = $Configuration.Arguments -join " "
ExitCode = $result.ExitCode
}
}

$validationCode = {
param (
$Configuration
)

if (-not (Test-Path 'VMDeploy:\Runtime')) {
$null = New-Item -Path 'VMDeploy:\Runtime' -ItemType Directory -Force
}

$trackingFile = Join-Path -Path 'VMDeploy:\Runtime' -ChildPath $Configuration.Name
Test-Path $trackingFile
}

$PreDeploymentCode = {
param (
$Configuration,

$WorkingDirectory
)
}

$param = @{
Name = 'application'
ScriptBlock = $executionCode
Validate = $validationCode
Description = 'Execute an application'
PreDeploymentCode = $PreDeploymentCode
ParameterMandatory = @(
'Name'
'Path'
)
ParameterOptional = @(
'Arguments'
)
Tag = 'application','generic'
}
Register-VMGuestAction @param
160 changes: 160 additions & 0 deletions Actions/certdeploy.action.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
$executionCode = {
param (
$Configuration
)

$driveLetter = (Get-Item -Path VMDeploy:\).FullName -replace ':.+'
Get-Volume -DriveLetter $driveLetter | Get-Partition | Get-Disk | Set-Disk -IsReadOnly $false

$filePath = Join-Path -Path 'VMDeploy:\Resources' -ChildPath $Configuration.FileName
if (-not (Test-Path -Path $filePath)) {
Write-PSFMessage -Level Warning -Message "Certificate file not found in the VMDeploy package! Ensure the $($Configuration.FileName) certificate is deployed as a resource!"
return
}
$fullFilePath = (Get-Item -Path $filePath).FullName
$fullPWFilePath = "$($fullFilePath)_password"
$password = ''
if (Test-Path -LiteralPath $fullPWFilePath) { $password = Get-Content -LiteralPath $fullPWFilePath }
try {
if (-not $password) {
$certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($fullFilePath)
}
else {
$certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new()
$certificate.Import($fullFilePath, $password, 'MachineKeySet')
}
}
catch {
Write-PSFMessage -Level Warning -Message "Error opening certificate $($Configuration.FileName)" -ErrorRecord $_
return
}

try {
$store = [System.Security.Cryptography.X509Certificates.X509Store]::new(
$Configuration.Store,
[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine
)
$store.Open('ReadWrite')
}
catch {
Write-PSFMessage -Level Warning -Message "Error accessing certificate store $($Configuration.Store)" -ErrorRecord $_
return
}

try {
if ($password) {
$store.Close()
$param = @{
FilePath = $fullFilePath
CertStoreLocation = "Cert:\LocalMachine\$($Configuration.Store)"
Password = $password | ConvertTo-SecureString -AsPlainText -Force
}
Import-PfxCertificate @param -ErrorAction Stop
}
else {
$store.Add($certificate)
$store.Close()
}
}
catch {
Write-PSFMessage -Level Warning -Message "Error writing certificate $($Configuration.FileName) to certificate store $($Configuration.Store)" -ErrorRecord $_
return
}
}

$validationCode = {
param (
$Configuration
)

$filePath = Join-Path -Path 'VMDeploy:\Resources' -ChildPath $Configuration.FileName
if (-not (Test-Path -Path $filePath)) {
Write-PSFMessage -Level Warning -Message "Certificate file not found in the VMDeploy package! Ensure the $($Configuration.FileName) certificate is deployed as a resource!"
return $false
}
$fullFilePath = (Get-Item -Path $filePath).FullName
$fullPWFilePath = "$($fullFilePath)_password"
$fullThumbprintPath = "$($fullFilePath)_thumbprint"
$password = ''
if (Test-Path -LiteralPath $fullThumbprintPath) {
$certificate = @{ Thumbprint = Get-Content -LiteralPath $fullThumbprintPath | Select-Object -First 1 }
}
else {
if (Test-Path -LiteralPath $fullPWFilePath) { $password = Get-Content -LiteralPath $fullPWFilePath }
try {
if (-not $password) {
$certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($fullFilePath)
}
else {
$certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new()
$certificate.Import($fullFilePath, $password, 'MachineKeySet')
}
}
catch {
Write-PSFMessage -Level Warning -Message "Error opening certificate $($Configuration.FileName)" -ErrorRecord $_
return $false
}
}

try {
$store = [System.Security.Cryptography.X509Certificates.X509Store]::new(
$Configuration.Store,
[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine
)
$store.Open('ReadOnly')
}
catch {
Write-PSFMessage -Level Warning -Message "Error accessing certificate store $($Configuration.Store)" -ErrorRecord $_
return $false
}

$result = $store.Certificates.ThumbPrint -contains $certificate.ThumbPrint
if ($result -and (Test-Path -LiteralPath $fullPWFilePath)) {
Remove-Item -LiteralPath $fullPWFilePath
$certificate.ThumbPrint | Set-Content -Path $fullThumbprintPath
}
$result
}

$PreDeploymentCode = {
param (
$Configuration,

$WorkingDirectory
)

$certPath = "$WorkingDirectory\Resources\$($Configuration.FileName)"
if (-not (Test-Path -Path $certPath)) {
throw "Certificate not found! $($Configuration.FileName)"
}

if ($Configuration.FileName -notmatch '\.pfx$') { return }

$securePassword = Read-Host "Specify password for certificate $($Configuration.FileName)" -AsSecureString
$password = [PSCredential]::new("Whatever", $securePassword).GetNetworkCredential().Password

$certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new()
try { $certificate.Import($certPath, $password, 'EphemeralKeySet') }
catch {
throw "Password does not match Certificate: $_"
}

$certPasswordPath = "$($certPath)_password"
$password | Set-Content -Path $certPasswordPath
}

$param = @{
Name = 'CertDeploy'
ScriptBlock = $executionCode
Validate = $validationCode
Description = 'Deploys a certificate to the specified certificate store'
PreDeploymentCode = $PreDeploymentCode
ParameterMandatory = @(
'FileName'
'Store'
)
ParameterOptional = @(
)
Tag = 'certificate', 'pki'
}
Register-VMGuestAction @param
Loading