Skip to content

Commit 487107e

Browse files
authored
chore(e2e): Ensure permissions on key file are correct (#6062)
1 parent 6f945ec commit 487107e

File tree

3 files changed

+20
-2
lines changed
  • enos/modules

3 files changed

+20
-2
lines changed

enos/modules/aws_rdp_member_server/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,16 @@ resource "aws_instance" "member_server" {
133133
$AuthorizedKey = (Invoke-WebRequest -Uri 'http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key' -Headers $ImdsHeaders -UseBasicParsing).Content
134134
$AuthorizedKeysPath = 'C:\ProgramData\ssh\administrators_authorized_keys'
135135
New-Item -Path $AuthorizedKeysPath -ItemType File -Value $AuthorizedKey -Force
136+
# Set the correct permissions on the authorized_keys file
137+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r
138+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /grant "Administrators:F" /grant "SYSTEM:F"
139+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Users"
140+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Authenticated Users"
136141
137142
# Ensure the SSH agent pulls in the new key.
138143
Set-Service -Name ssh-agent -StartupType "Automatic"
139144
Restart-Service -Name ssh-agent
145+
Restart-Service -Name sshd
140146
141147
# Open the firewall for SSH connections
142148
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

enos/modules/aws_rdp_member_server_with_worker/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,16 @@ resource "aws_instance" "worker" {
158158
$AuthorizedKey = (Invoke-WebRequest -Uri 'http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key' -Headers $ImdsHeaders -UseBasicParsing).Content
159159
$AuthorizedKeysPath = 'C:\ProgramData\ssh\administrators_authorized_keys'
160160
New-Item -Path $AuthorizedKeysPath -ItemType File -Value $AuthorizedKey -Force
161+
# Set the correct permissions on the authorized_keys file
162+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r
163+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /grant "Administrators:F" /grant "SYSTEM:F"
164+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Users"
165+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Authenticated Users"
161166
162167
# Ensure the SSH agent pulls in the new key.
163168
Set-Service -Name ssh-agent -StartupType "Automatic"
164169
Restart-Service -Name ssh-agent
170+
Restart-Service -Name sshd
165171
166172
# Open the firewall for SSH
167173
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

enos/modules/aws_windows_client/main.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ resource "aws_instance" "client" {
160160
161161
# Set up SSH so we can remotely manage the instance
162162
## Install OpenSSH Server and Client
163-
# Loop to make sure that SSH installs correctly
164-
$elapsed = 0
163+
# Loop to make sure that SSH installs correctly
164+
$elapsed = 0
165165
do {
166166
try {
167167
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
@@ -215,10 +215,16 @@ resource "aws_instance" "client" {
215215
$AuthorizedKey = (Invoke-WebRequest -Uri 'http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key' -Headers $ImdsHeaders -UseBasicParsing).Content
216216
$AuthorizedKeysPath = 'C:\ProgramData\ssh\administrators_authorized_keys'
217217
New-Item -Path $AuthorizedKeysPath -ItemType File -Value $AuthorizedKey -Force
218+
# Set the correct permissions on the authorized_keys file
219+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r
220+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /grant "Administrators:F" /grant "SYSTEM:F"
221+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Users"
222+
icacls "C:\ProgramData\ssh\administrators_authorized_keys" /remove "Authenticated Users"
218223
219224
## Ensure the SSH agent pulls in the new key.
220225
Set-Service -Name ssh-agent -StartupType "Automatic"
221226
Restart-Service -Name ssh-agent
227+
Restart-Service -Name sshd
222228
223229
## Open the firewall for SSH connections
224230
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

0 commit comments

Comments
 (0)