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

Add logging to download-ec2-pubkey script #1828

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion os-images/AWS/windows/scripts/InstallAndConfigureOpenSSH.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Get-ChildItem $DATA_DIR\ssh_host_*_key -ErrorAction SilentlyContinue | % {
$keyDownloadScript = @'
$INSTALL_DIR = [io.path]::combine($env:ProgramFiles, 'OpenSSH')
$OPENSSH_UTILS_MODULE = [io.path]::combine($INSTALL_DIR, 'OpenSSHUtils.psd1')
$VerbosePreference = 'Continue'

Import-Module $OPENSSH_UTILS_MODULE -Force
# Download the instance key pair and authorize Administrator logins using it
Expand All @@ -171,6 +172,7 @@ $token=Invoke-RestMethod -Method PUT -Uri "http://169.254.169.254/latest/api/tok

Write-Host "Downloading the current EC2 Instance Public Key from AWS"
Invoke-WebRequest "http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key" -Headers @{"X-aws-ec2-metadata-token" = $token} -Outfile $openSSHAuthorizedKeys
Get-Content $openSSHAuthorizedKeys
Write-Host "EC2 Instance Public Key Written To $openSSHAuthorizedKeys"

# Ensure access control on administrators_authorized_keys meets the requirements
Expand All @@ -188,7 +190,7 @@ $principal = New-ScheduledTaskPrincipal `
-LogonType ServiceAccount `
-RunLevel Highest
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' `
-Argument "-NoProfile -File ""$DOWNLOAD_KEYS_SCRIPT"""
-Argument "-NoProfile -File ""$DOWNLOAD_KEYS_SCRIPT"" -Verbose > c:\download-ec2-pubkey.log"
$trigger = New-ScheduledTaskTrigger -AtStartup
Register-ScheduledTask -Action $action `
-Trigger $trigger `
Expand Down