259 Commits

Author SHA1 Message Date
Chris Roberts
96f2039bcd Use ssh key type defined by configuration
If key type is defined as :auto, detect best key type to use. If no
acceptable key type is detected as supported by the server, raise an
error. If unable to determine supported key types from the server,
fallback to original behavior of rsa type key.

If key type is defined as custom value, use that type if the server
supports it, or if the supported types cannot be read. Otherwise, raise
an error informing the user that the key type is not supported.
2024-01-10 11:52:46 -08:00
hashicorp-copywrite[bot]
36a312ee26
add missing license headers and update copyright file headers to BUS-1.1 2023-08-10 21:53:25 +01:00
Chris Roberts
cebfb7a63b Use key type supported by server if possible
Check the key types supported by the server. If the data is not
available, default to the previous behavior which is using the rsa key
type.

Update insecure key check to match against any key files located within
the keys directory. For now, this effectively allows matching either rsa
or ed25519 insecure private keys.
2023-06-26 15:07:58 -07:00
Chris Roberts
41342dceb3 Remove keyboard-interactive authentication method
The keyboard-interactive authentication method was added due to a
mis-reading of a reported issue where the box was not properly
configured for Vagrant. This removes the keyboard-interactive
authentication method which resolves a password prompting issue caused
by its addition.
2023-06-01 17:49:15 -07:00
sophia
5f2ea0486e Update connection settings when using a password to connect ssh
When connecting over ssh using net-ssh use the non_interactive
argument must be set when authenticating with a password.

Add the keyboard-interactive default auth method
ref: 8a176a6ea0/lib/net/ssh/config.rb (L52)
2023-02-14 13:56:38 -08:00
sophia
b4925261fa Use netssh builtin keep alive functionality 2023-01-23 16:48:57 -08:00
sophia
9b48684226 Ensure last line from extracting the SSH_AUTH_SOCK is not nil 2022-09-21 15:25:44 -04:00
sophia
649f69747f Check for nil return from forwarded ports cap
Nil may be returned if the forwarded ports cap is called while the
machine is not in a running state.
2020-08-19 17:13:33 -05:00
Chris Roberts
5003bb6e15 Updates to address all Ruby deprecations and warnings
This includes updates for resolving all warnings provided by Ruby
for deprecations and/or removed methods. It also enables support
for Ruby 2.7 in the specification constraint as all 2.7 related
warnings are resolved with this changeset.
2020-08-10 13:05:41 -07:00
Sophia Castellarin
bedd141381
Merge pull request #11721 from jbonhag/f/ssh-nil-exit-status
Raise an error on nil exit status
2020-08-07 10:55:58 -05:00
sophia
187d8e9cfd Allow file provisioner to copy empty folders 2020-08-05 15:56:04 -05:00
Jeff Bonhag
9af48e5764
Raise an error on nil exit status
This commit changes the SSH communicator to raise an error if Vagrant
doesn't receive an exit status from an SSH command, for example if the
command is terminated by the OOM-killer.
2020-06-26 13:25:59 -04:00
Sophia Castellarin
56bc93e154
Merge pull request #11540 from soapy1/winrm-config-docs
Update winrm config docs
2020-04-29 09:57:23 -04:00
sophia
b4e13bf1ce Update winrm config docs 2020-04-23 09:47:16 -04:00
Chris Roberts
4546d804b1 Add support for configuring SSH connect timeout
Retains the original default value of 15 seconds for SSH connect
timeout. Allows users to modify this timeout via SSH communicator
option. Enforces integer values for timeout and validates custom
values are greater than 0.
2020-04-20 14:23:21 -07:00
Chris Roberts
852c549886 Force powershell on connection for consistent behavior
This patches the connection instances generated for the winssh
communicator so when a command is executed it is always run
with powershell. This prevents inconsistencies with argument
handling based on what the default shell is set to on the remote
side.

Since powershell is the default, environment variable template
only needs to be set for powershell style. If the shell setting
is updated to `cmd`, the command will be properly prefixed.

Default shell has been updated to powershell, to prevent extraneous
wrapping where it's not required. The `#ready?` check has also been
updated to use a constant value, which is overridden within winssh
as a blank command is invalid.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
9a26c123b9 Use SFTP for Windows file transfer
SFTP is more reliable than SCP when dealing with unknown sshd
configurations on the server side. It also provides a convenient
facility for creating remote directories, so we can remove the
Windows-specific `#create_remote_directory` method.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
b6e8262bf2 Perform scp commands with powershell.exe
This commit includes a monkey patch for Net::SCP#start_command so that
PowerShell commands are escaped correctly.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
85f0fce57a Allow #provision_winrm to modify upload_path
We need to ensure that Windows files have an extension when provisioning
via WinRM.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
4b7d55afaa Fixup paths to work with server-side Bash
This commit normalizes our Windows paths to use `/` instead of `\`.
These paths are compatible with both cmd and PowerShell, and are
required if the server-side shell is set to Bash.

The OpenSSH server executes all commands inside a default login shell
which cannot be controlled by the Vagrant configuration. So what ends up
getting executed on the server side looks something like this:

    "c:\\program files\\git\\bin\\bash.exe" -c "C:\\Windows\\Temp\\vagrant-ssh20200130-41670-1w5nsjy.bat"

By flipping the direction of the directory slashes, we end up with:

    "c:\\program files\\git\\bin\\bash.exe" -c "C:/Windows/Temp/vagrant-ssh20200130-43415-f1d5n2.bat"

This works whether the server-side shell is set to cmd, powershell, or
bash.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
fcd07e3a37 Switch to PowerShell for create_remote_directory 2020-03-04 15:08:03 -08:00
Jeff Bonhag
8affdd24b6 Wire up inline command for popular Windows shells
* Remove connection between shell provisioner directory config and WinSSH
directory config because these should remain separate.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
ee486203d1 Introduce force_raw option 2020-03-04 15:08:03 -08:00
Jeff Bonhag
df7c11a3a7 Fix issues with Windows SSH provisioner
Windows commands that run over SSH are wrapped in a script that writes a
special marker to the two output streams (stdout and stderr).  This
allows Vagrant to consume the output streams.

Unfortunately, this leads to a sort of chicken-and-egg problem where no
commands can be run before a wrapper script exists. For example, you
can't make a destination directory to upload the wrapper script without
first creating a wrapper script to make the directory. :)

This commit changes the behavior of the WinSSH communicator to assume
that the destination directory already exists for provisioning scripts.

It also moves the default `upload_path` from the shell provisioner
config so we can have OS-specific defaults.

Finally, it introduces a Windows-specific #upload method which will
properly use a Windows path separator on a non-Windows host.
2020-03-04 15:08:03 -08:00
Chris Roberts
e430809cdd Update exit code value used for retry check - ArgumentException 2020-02-12 16:42:21 -08:00
Chris Roberts
3ca8089920 Remove require of net/sftp library
Fixes #10733
2019-03-20 13:02:08 -07:00
Chris Roberts
e2b6a6645c Always ensure remote destination directory exists 2019-02-26 08:54:49 -08:00
Chris Roberts
6b105d704d Update communicator upload behavior to handle /. path directives
This update was prompted by updates in openssh to the scp behavior
making source directory paths suffixed with `.` no longer valid
resulting in errors on upload. The upload implementation within
the ssh communicator has been updated to retain the existing
behavior.

Included in this update is modifications to the winrm communicator
so the upload functionality matches that of the ssh communicator
respecting the trailing `.` behavior on source paths. With the
communicators updated to properly handle the paths, the file
provisioner was also updated to simply apply previously defined
path update rules only.

Fixes #10675
2019-02-26 08:02:09 -08:00
Chris Roberts
d87c645bd0 Fix garbage detection within SSH communicator
Fixes #10552
2019-01-07 16:20:56 -08:00
Chris Roberts
480bb47e1d
Merge pull request #10496 from chrisroberts/e-ssh-config-file
Add support for config and remote_user to SSH options
2018-12-13 09:16:49 -08:00
Gavin Williams
122ef7307c Flesh out :config support.
Also noticed whilst testing that if the `ProxyCommand` uses `%r`, then
it fails with `unable to find remote user`, so added support for
`config.ssh.remote_user` aswell
2018-12-11 07:51:47 -08:00
Gavin Williams
87e38a0bed Remove 'config' from ssh.defaults, and instead setup in '.connect' 2018-12-11 07:51:47 -08:00
Gavin Williams
87437317dc Add support for passing ssh config file in via config 2018-12-11 07:51:47 -08:00
Chris Roberts
24cd988d39 Only modify elevated username under specific conditions
Elevated commands can fail via winrm under certain conditions like
the machine name being changed. Detect this by checking for a known
exit code combined with known output included within stderr. If found,
attempt to re-execute the command using a machine prefixed username
if possible.
2018-12-07 12:11:17 -08:00
Chris Roberts
afc138478d Add reset! method to winrm communicator 2018-11-12 15:36:21 -08:00
Chris Roberts
747dd9301b Add reset! to ssh communicator. Reduce number of ssh info prints. 2018-11-12 15:36:21 -08:00
Chris Roberts
c8f431cf44 Prepend computer name to user when created scheduled tasks
When running a shell provisioner elevated with winrm a scheduled
task is created to bypass permissions issues. If the name of the
computer has changed this may no longer work. To prevent errors
this PR updates the implementation to fetch the computer name
and prepends it to the username before creating the task.
2018-11-08 14:21:20 -08:00
Brian Cain
54c8ebc31a
Fixes #10229: Add timeout for changing hostname on windows
Prior to this commit, if Windows was slow to reboot, Vagrant would fail
to find the right IP address to upload the wait_for_reboot script to.
This commit fixes this race condition by adding a timeout to ensure that
Vagrant can retry. It also properly catches an exception in the winrm
ready? method for checking if a guest is properly ready for
communications.
2018-11-02 09:23:00 -07:00
Chris Roberts
8562daf85e Prevent overly verbose output from SSH communicator
If the type of error changes on retry the messages will effectively
spam the user display with alternating messages. Log each message
sent and only re-display each message once within 10 seconds.
2018-10-19 15:18:03 -07:00
Chris Roberts
dcfb84893d Only reset the _init on testing cleanup 2018-07-30 14:44:36 -07:00
Chris Roberts
cd7215ab13 Add warning when vagrant-winrm is found 2018-07-30 13:27:20 -07:00
Chris Roberts
2628d93370 Rename method name when checking capability 2018-06-12 14:13:10 -07:00
Chris Roberts
5ba91de4d8 Use host capability to update key file permissions if available 2018-06-12 10:46:53 -07:00
Chris Roberts
f0e232d739 Log error and proceed when private key permissions fail
Fixes #9765
2018-05-03 11:48:57 -07:00
Brian Cain
93356d4635
Update rm filters to test for path
This commit updates the rm filter for winrm to operate like how rm works
in bash. If a folder doesn't exist, the command returns 0 rather than 1.
2018-05-01 13:35:45 -07:00
Joe Pleso
c882d888a7
Add docker cap to windows to detect daemon and fix whitespace 2018-04-27 09:45:24 -07:00
Chris Roberts
5d7506afe3
Merge pull request #9676 from chrisroberts/e-win-file-perms
Update generated ssh private key file permissions on create
2018-04-10 14:56:28 -07:00
Chris Roberts
9731720773 Update generated ssh private key file permissions on create
This updates the permissions on the automatically generated private
key file to only be readable by the user. Includes support for file
permission modification on Windows platform.
2018-04-10 14:15:14 -07:00
Chris Roberts
ddfd86f3d1 Split with shellwords and quote paths in command filter
This uses shellwords to split the command in the command filter
inside the winrm communicator. Using shellwords properly handles
things like quoted paths. Path arguments are also quoted to
prevent issues with paths that include spaces.

Fixes #9390
2018-04-09 17:00:30 -07:00
Josh Soref
1a5ddea9f4 Spelling fixes
* account
* addresses
* administrator
* afterwards
* because
* bridgeable
* capabilities
* capability
* checksum
* configuration
* configuration for
* configure
* criteria
* delimited
* delivered
* derivatives
* description
* detect
* directory
* display
* downloading
* during
* electric
* enabling
* encountered
* equivalent
* executable
* executed
* hashicorp
* hypervisor
* hyphens
* implementation
* incorporate
* inheritance
* initialize
* instance
* instead
* interactions
* invocable
* machine
* maximum
* message
* mounting
* overridden
* overwrite
* paramiko
* preparing
* provides
* provisioning
* recursively
* requested
* resetting
* retryable
* running
* satisfied
* searching
* sometimes
* specified
* successfully
* synced folders
* unauthorized
* underlying
* userprofile
* vagrant
* vagrantfile
* variable
* various
* version
* virtual
* windows
2018-03-14 14:41:04 +00:00