Commit graph

268 commits

Author SHA1 Message Date
oss-core-libraries-dashboard[bot]
206f8102c9
[COMPLIANCE] Update Copyright and License Headers (Batch 2 of 7) (#13761)
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2025-12-22 16:46:17 +05:30
oss-core-libraries-dashboard[bot]
ea57f40b89
[COMPLIANCE] Update Copyright and License Headers (#13752)
Some checks failed
/ sync-acceptance (push) Has been cancelled
Vagrant Ruby Tests / Vagrant unit tests on Ruby 3.1 (push) Has been cancelled
Vagrant Ruby Tests / Vagrant unit tests on Ruby 3.2 (push) Has been cancelled
Vagrant Ruby Tests / Vagrant unit tests on Ruby 3.3 (push) Has been cancelled
Vagrant Ruby Tests / Vagrant unit tests on Ruby 3.4 (push) Has been cancelled
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2025-12-04 17:07:40 +05:30
Chris Roberts
eee6fefd67
Add a :none communicator
Adds a communicator which does not provide communication to the
guest machine. All methods for the communicator are simply stubbed
with a successful result. This allows a guest to be configured
with the `:none` communicator and Vagrant to properly `up` it.

This currently lacks any user notification or guards within
configuration to verify guest configuration does not rely on
the communicator. It is wrapped as experimental to allow early
access to the basic functionality without making it generally
available.
2025-04-22 15:50:36 -07:00
Chris Roberts
ea25996b21
Update Vagrant behavior outside of installers
Remove customized require behaviors and modify the bin executable
to check for missing tools that Vagrant expects to exist when
running outside of an installer.
2025-04-02 11:40:17 -07:00
Chris Roberts
4f79fe59c6
Provide configurable retries for connect on SSH communicator
Adds two new options to the SSH connect configuration: `connect_retries`
and `connect_retry_delay`. Provides user configurable values used when
establishing the SSH connection. Previous behavior would retry generally
by the default value without a pause between attempts. Updated behavior
will retry the number of times set within the config (unless value is
provided directly to connect call) and each retry will pause based on
the delay value set in the config (unless value is provided directly
to the connect call).
2025-03-20 17:44:47 -07:00
Allison Larson
b6c7a15581 Catch IO::Timeout when waiting for communicator
Ruby 3.2 introduced a new error, `IO:TimeoutError`, for blocking
operations. Formerly, this case would return `Errno::ETIMEDOUT`. Catch
the new error while waiting for the communicator so that the retries can
be correctly attempted.

https://bugs.ruby-lang.org/issues/18630
2025-03-12 16:21:06 -07:00
Chris Roberts
8b06640fcf
Use helper for require calls 2024-11-06 17:33:00 -08:00
Chris Roberts
5a7fd6b302 Inspect guest for supported key types
Updates the SSH communicator to inspect the guest sshd configuration for
supported key types when creating a new key to replace the default
insecure public key. If the guest cannot be inspected, the connection
will be inspected. If the connection cannot be inspected, it will simply
fall back to the original behavior of using an rsa type key.
2024-01-18 11:53:00 -08:00
Chris Roberts
0a8f99df52 Open private key file in binary mode when writing
Prevent newlines from being converted to CRLF when writing private key
to file.
2024-01-12 16:01:23 -08:00
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