diff --git a/CHANGELOG.md b/CHANGELOG.md index bf71dd86f..48f778f31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Fix regression with remote paths from chef-solo. [GH-431] - Fix issue where Vagrant crashes if `.vagrant` file becomes invalid. [GH-496] + - Issue a warning instead of an error for attempting to forward a port + <= 1024. [GH-487] ## 0.8.6 (August 28, 2011) diff --git a/lib/vagrant/action/vm/forward_ports.rb b/lib/vagrant/action/vm/forward_ports.rb index 26d0d5c22..ef0e8e2e9 100644 --- a/lib/vagrant/action/vm/forward_ports.rb +++ b/lib/vagrant/action/vm/forward_ports.rb @@ -10,7 +10,7 @@ module Vagrant @app = app @env = env - threshold_check unless ENV["USER"] == "root" + threshold_check external_collision_check end @@ -23,7 +23,10 @@ module Vagrant # 1024, which causes the forwarded ports to fail. def threshold_check @env.env.config.vm.forwarded_ports.each do |name, options| - raise Errors::ForwardPortBelowThreshold if options[:hostport] <= 1024 + if options[:hostport] <= 1024 + @env.ui.warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports") + return + end end end diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index b48d39e8d..7b4f0e7cc 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -168,11 +168,6 @@ module Vagrant error_key(:auto_empty, "vagrant.actions.vm.forward_ports") end - class ForwardPortBelowThreshold < VagrantError - status_code(25) - error_key(:below_threshold_error, "vagrant.actions.vm.forward_ports") - end - class ForwardPortCollision < VagrantError status_code(26) error_key(:collision_error, "vagrant.actions.vm.forward_ports") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index e2fecc7da..a0b96c6c0 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -314,11 +314,6 @@ en: VM: %{vm_name} Forwarded port: %{name} (%{guest_port} => %{host_port}) - below_threshold_error: |- - The host port of all forwarded ports must be above 1024. VirtualBox - does not allow host ports to be below 1024. (Guest ports below 1024 - are fine. For example: SSH on port 22 on the guest can be forwarded - to port 2222, but not 222). collision_error: |- Vagrant cannot forward the specified ports on this VM, since they would collide with another VirtualBox virtual machine's forwarded @@ -336,6 +331,12 @@ en: non_nat: |- VirtualBox adapter #%{adapter} not configured as "NAT" Skipping port forwarding '%{name}'. + privileged_ports: |- + You are trying to forward to privileged ports (ports <= 1024). Most + operating systems restrict this to only privileged process (typically + processes running as an administrative user). This is a warning in case + the port forwarding doesn't work. If any problems occur, please try a + port higher than 1024. halt: force: Forcing shutdown of VM... host_name: diff --git a/test/unit/vagrant/action/vm/forward_ports_test.rb b/test/unit/vagrant/action/vm/forward_ports_test.rb index 4eebb605d..175673e3b 100644 --- a/test/unit/vagrant/action/vm/forward_ports_test.rb +++ b/test/unit/vagrant/action/vm/forward_ports_test.rb @@ -9,7 +9,6 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase @vm.stubs(:name).returns("foo") @env["vm"] = @vm @env["vm.modify"] = mock("proc") - ENV["USER"] = "not-root" end context "initializing" do @@ -26,34 +25,19 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase @env.env.config.vm.forwarded_ports.clear end - context "for non-root users" do - - should "error if has a port below threshold" do - @env.env.config.vm.forward_port("foo", 22, 222) - assert_raises(Vagrant::Errors::ForwardPortBelowThreshold) { @klass.new(@app, @env) } - end - - should "not error if ports are fine" do - @env.env.config.vm.forward_port("foo", 22, 2222) - assert_nothing_raised { @klass.new(@app, @env) } - end - - end - context "for a root user" do - setup do - ENV["USER"] = "root" - end - - should "not error for any port" do - @env.env.config.vm.forward_port("foo", 22, 222) - assert_nothing_raised { @klass.new(@app, @env) } - - @env.env.config.vm.forward_port("foo", 22, 2222) - assert_nothing_raised { @klass.new(@app, @env) } - end + should "issue a warning for ports less than 1024" do + @env.env.config.vm.forward_port("foo", 22, 222) + @env.ui.expects(:warn).once + @klass.new(@app, @env) end + should "not issue a warning for ports greater than 1024" do + @env.env.config.vm.forward_port("foo", 22, 2222) + + @env.ui.expects(:warn).never + @klass.new(@app, @env) + end end context "checking for colliding external ports" do