From 4ab0dc19b1d4b89ea271410bd233971ec7ceedb9 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Tue, 18 Jul 2017 09:40:56 +0100 Subject: [PATCH] winssh communicator: retain the authorized_keys file acl permissions --- plugins/guests/windows/cap/public_key.rb | 2 ++ test/unit/plugins/guests/windows/cap/insert_public_key_test.rb | 2 ++ test/unit/plugins/guests/windows/cap/remove_public_key_test.rb | 2 ++ 3 files changed, 6 insertions(+) diff --git a/plugins/guests/windows/cap/public_key.rb b/plugins/guests/windows/cap/public_key.rb index 77a0466da..18e52d1fb 100644 --- a/plugins/guests/windows/cap/public_key.rb +++ b/plugins/guests/windows/cap/public_key.rb @@ -50,6 +50,7 @@ module VagrantPlugins end comm.upload(keys_file.path, remote_upload_path) keys_file.delete + comm.execute("Set-Acl \"#{remote_upload_path}\" (Get-Acl \"#{remote_authkeys_path}\")", shell: "powershell") comm.execute("move /y \"#{remote_upload_path}\" \"#{remote_authkeys_path}\"", shell: "cmd") end @@ -75,6 +76,7 @@ module VagrantPlugins File.write(keys_file.path, current_content.join("\r\n") + "\r\n") comm.upload(keys_file.path, remote_upload_path) keys_file.delete + comm.execute("Set-Acl \"#{remote_upload_path}\" (Get-Acl \"#{remote_authkeys_path}\")", shell: "powershell") comm.execute("move /y \"#{remote_upload_path}\" \"#{remote_authkeys_path}\"", shell: "cmd") end end diff --git a/test/unit/plugins/guests/windows/cap/insert_public_key_test.rb b/test/unit/plugins/guests/windows/cap/insert_public_key_test.rb index 37d5a64f8..a12373ac8 100644 --- a/test/unit/plugins/guests/windows/cap/insert_public_key_test.rb +++ b/test/unit/plugins/guests/windows/cap/insert_public_key_test.rb @@ -41,6 +41,7 @@ describe "VagrantPlugins::GuestWindows::Cap::InsertPublicKey" do it "inserts the public key" do expect(comm).to receive(:download) expect(comm).to receive(:upload) + expect(comm).to receive(:execute).with(/Set-Acl .*/, shell: "powershell") expect(comm).to receive(:execute).with(/move .*/, shell: "cmd") cap.insert_public_key(machine, "ssh-rsa ...") expect(File.read(@tempfile.path)).to include("ssh-rsa ...") @@ -56,6 +57,7 @@ describe "VagrantPlugins::GuestWindows::Cap::InsertPublicKey" do it "inserts the public key" do expect(comm).to_not receive(:download) expect(comm).to receive(:upload) + expect(comm).to receive(:execute).with(/Set-Acl .*/, shell: "powershell") expect(comm).to receive(:execute).with(/move .*/, shell: "cmd") cap.insert_public_key(machine, "ssh-rsa ...") expect(File.read(@tempfile.path)).to include("ssh-rsa ...") diff --git a/test/unit/plugins/guests/windows/cap/remove_public_key_test.rb b/test/unit/plugins/guests/windows/cap/remove_public_key_test.rb index 9fb2903dd..e82d26810 100644 --- a/test/unit/plugins/guests/windows/cap/remove_public_key_test.rb +++ b/test/unit/plugins/guests/windows/cap/remove_public_key_test.rb @@ -47,6 +47,7 @@ describe "VagrantPlugins::GuestWindows::Cap::RemovePublicKey" do it "removes the public key" do expect(comm).to receive(:download) expect(comm).to receive(:upload) + expect(comm).to receive(:execute).with(/Set-Acl .*/, shell: "powershell") expect(comm).to receive(:execute).with(/move .*/, shell: "cmd") cap.remove_public_key(machine, public_key_insecure) expect(File.read(@tempfile.path)).to include(public_key_other) @@ -58,6 +59,7 @@ describe "VagrantPlugins::GuestWindows::Cap::RemovePublicKey" do it "does nothing" do expect(comm).to_not receive(:download) expect(comm).to_not receive(:upload) + expect(comm).to_not receive(:execute).with(/Set-Acl .*/, shell: "powershell") expect(comm).to_not receive(:execute).with(/move .*/, shell: "cmd") cap.remove_public_key(machine, public_key_insecure) end