diff options
-rw-r--r-- | changelogs/unreleased/53676-ip-address-of-gitlab-runner-is-wrong-in-the-runners-description.yml | 5 | ||||
-rw-r--r-- | lib/api/helpers/runner.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/runner_spec.rb | 6 |
3 files changed, 9 insertions, 4 deletions
diff --git a/changelogs/unreleased/53676-ip-address-of-gitlab-runner-is-wrong-in-the-runners-description.yml b/changelogs/unreleased/53676-ip-address-of-gitlab-runner-is-wrong-in-the-runners-description.yml new file mode 100644 index 00000000000..12a6509e6f7 --- /dev/null +++ b/changelogs/unreleased/53676-ip-address-of-gitlab-runner-is-wrong-in-the-runners-description.yml @@ -0,0 +1,5 @@ +--- +title: Get remote IP address of runner +merge_request: 24624 +author: +type: changed diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 45d0343bc89..16df8e830e1 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -26,7 +26,7 @@ module API end def get_runner_ip - { ip_address: request.ip } + { ip_address: request.env["HTTP_X_FORWARDED_FOR"] || request.ip } end def current_runner diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index ec48bf60426..ed0108c846a 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -210,8 +210,8 @@ describe API::Runner, :clean_gitlab_redis_shared_state do it "sets the runner's ip_address" do post api('/runners'), - params: { token: registration_token }, - headers: { 'REMOTE_ADDR' => '123.111.123.111' } + params: { token: registration_token }, + headers: { 'X-Forwarded-For' => '123.111.123.111' } expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.ip_address).to eq('123.111.123.111') @@ -520,7 +520,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do it "sets the runner's ip_address" do post api('/jobs/request'), params: { token: runner.token }, - headers: { 'User-Agent' => user_agent, 'REMOTE_ADDR' => '123.222.123.222' } + headers: { 'User-Agent' => user_agent, 'X-Forwarded-For' => '123.222.123.222' } expect(response).to have_gitlab_http_status 201 expect(runner.reload.ip_address).to eq('123.222.123.222') |