Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Bindings is not respected for SSH port #932

Open
eric-lapierre opened this issue Jan 3, 2023 · 1 comment
Open

Port Bindings is not respected for SSH port #932

eric-lapierre opened this issue Jan 3, 2023 · 1 comment
Labels
bug An issue reporting a bug or a PR fixing one.

Comments

@eric-lapierre
Copy link

Jenkins and plugins versions report

Environment
Jenkins: 2.375.1
OS: Linux - 5.4.0-135-generic
---
DotCi:2.40.00
DotCi-DockerPublish:1.0.3
JiraTestResultReporter:2.0.15
PrioritySorter:4.1.0
ace-editor:1.1
active-directory:2.25.1
all-changes:1.5
analysis-collector:1.52
analysis-core:1.93
ant:1.13
antexec:1.11
antisamy-markup-formatter:2.7
apache-httpcomponents-client-4-api:4.5.13-1.0
async-http-client:1.9.40.0
authentication-tokens:1.4
badge:1.9.1
blame-upstream-commiters:1.2
bootstrap4-api:4.6.0-3
bootstrap5-api:5.1.3-6
bouncycastle-api:2.26
branch-api:2.7.0
build-environment:1.7
build-pipeline-plugin:1.5.8
build-symlink:1.1
build-timeout:1.20
build-view-column:0.3
build-with-parameters:1.6
buildgraph-view:1.8
built-on-column:1.1
bulk-builder:1.5
caffeine-api:2.9.2-29.v717aac953ff3
categorized-view:1.12
changelog-history:1.7
changes-since-last-success:0.6
checks-api:1.7.4
claim:2.18.2
clone-workspace-scm:0.6
cloud-stats:0.27
cloudbees-folder:6.17
cobertura:1.17
code-coverage-api:2.0.4
command-launcher:1.6
conditional-buildstep:1.4.1
convert-to-pipeline:1.0
copy-data-to-workspace-plugin:1.0
copy-project-link:1.5
copyartifact:1.46.2
cppcheck:1.25
credentials:1214.v1de940103927
credentials-binding:1.27.1
cvs:2.19
cvs-tag:1.7
dashboard-view:2.18
data-tables-api:1.11.3-6
description-setter:1.10
discard-old-build:1.05
disk-usage:0.28
display-upstream-changes:0.3.2
display-url-api:2.3.6
docker-build-publish:1.3.3
docker-commons:1.19
docker-custom-build-environment:1.7.3
docker-java-api:3.2.13-37.vf3411c9828b9
docker-plugin:1.2.10
docker-slaves:1.0.7
docker-traceability:1.2
docker-workflow:1.28
dockerhub-notification:2.6.0
downstream-buildview:1.9
dtkit-api:3.0.0
durable-task:503.v57154d18d478
dynamic-axis:1.0.3
echarts-api:5.3.2-1
email-ext:2.87
email-ext-recipients-column:1.0
emotional-jenkins-plugin:1.2
envinject:2.4.0
envinject-api:1.8
extended-choice-parameter:0.82
extended-read-permission:3.2
extensible-choice-parameter:1.8.0
external-monitor-job:191.v363d0d1efdf8
favorite-view:1.0
files-found-trigger:1.5
flow:1.3
font-awesome-api:6.0.0-1
forensics-api:1.7.0
fstrigger:0.42
ftppublisher:1.2
gerrit:0.7
gerrit-trigger:2.35.2
git:4.10.3
git-client:3.11.0
git-server:1.10
github:1.34.1
github-api:1.301-378.v9807bd746da5
github-branch-source:2.11.4
global-pre-script:20.02
golang:1.4
gradle:1.38
greenballs:1.15.1
groovy:2.4
groovy-label-assignment:1.2.0
groovy-postbuild:2.5
handlebars:3.0.8
hidden-parameter:0.0.5
htmlpublisher:1.29
http_request:1.14
hudson-pview-plugin:1.8
icon-shim:3.0.0
instance-identity:116.vf8f487400980
jackson2-api:2.13.2.20220328-273.v11d70a_b_a_1a_52
javadoc:1.6
javax-activation-api:1.2.0-2
javax-mail-api:1.6.2-5
jaxb:2.3.0.1
jdk-tool:1.5
jenkins-jira-issue-updater:1.18
jenkins-multijob-plugin:1.36
jira:3.6
jira-ext:0.9
jira-trigger:1.0.1
jjwt-api:0.11.2-9.c8b45b8bb173
jnr-posix-api:3.1.7-1
job-parameter-summary:0.5
job-poll-action-plugin:1.0
jobConfigHistory:2.31-rc1107.2354f08725a_8
jquery:1.12.4-1
jquery-detached:1.2.1
jquery3-api:3.6.0-2
jsch:0.1.55.2
junit:1119.1121.vc43d0fc45561
lastfailureversioncolumn:1.1
ldap:2.7
ldapemail:0.8
libvirt-slave:1.9.2
lockable-resources:2.13
log-parser:2.2
mailer:408.vd726a_1130320
mapdb-api:1.0.9.0
matrix-auth:3.0.1
matrix-project:1.20
maven-plugin:3.16
momentjs:1.1.1
multiple-scms:0.8
next-build-number:1.7
okhttp-api:4.9.3-105.vb96869f8ac3a
pam-auth:1.7
parameterized-scheduler:1.0
parameterized-trigger:2.43
pipeline-build-step:2.15
pipeline-github-lib:36.v4c01db_ca_ed16
pipeline-graph-analysis:188.v3a01e7973f2c
pipeline-input-step:446.vf27b_0b_83500e
pipeline-milestone-step:1.3.2
pipeline-model-api:1.9.3
pipeline-model-definition:1.9.3
pipeline-model-extensions:1.9.3
pipeline-rest-api:2.21
pipeline-stage-step:291.vf0a8a7aeeb50
pipeline-stage-tags-metadata:1.9.3
pipeline-stage-view:2.21
plain-credentials:1.8
plot:2.1.10
plugin-util-api:2.16.0
popper-api:1.16.1-2
popper2-api:2.11.2-1
postbuild-task:1.9
postbuildscript:3.1.0-348.vaf5cd5c632ce
preSCMbuildstep:0.3
prereq-buildstep:1.1
project-health-report:1.2
promoted-builds:3.11
promoted-builds-simple:1.9
radiatorviewplugin:1.29
rebuild:1.33
regression-report-plugin:1.5
release:2.13
resource-disposer:0.17
run-condition:1.5
scm-api:608.vfa_f971c5a_a_e9
scp:1.8
script-security:1189.vb_a_b_7c8fd5fde
scriptler:3.4
sectioned-view:1.25
shared-workspace:1.0.2
show-build-parameters:1.0
sidebar-link:1.12.1
signal-killer:1.1
simple-parameterized-builds-report:1.5
slave-prerequisites:1.0
slave-setup:1.10
slave-status:1.6
slave-utilization-plugin:1.8
sloccount:1.25
snakeyaml-api:1.29.1
sonar:2.14
ssh:2.6.1
ssh-agent:1.24.1
ssh-credentials:305.v8f4381501156
ssh-slaves:2.854.v7fd446b_337c9
sshd:3.236.ved5e1b_cb_50b_2
startup-trigger-plugin:2.9.3
status-view:1.0
statusmonitor:1.3
structs:324.va_f5d6774f3a_d
subversion:2.15.2
text-finder:1.18
timestamper:1.17
token-macro:321.vd7cc1f2a_52c8
toolenv:1.2
translation:1.16
trilead-api:2.84.v72119de229b_7
uno-choice:2.5.7
valgrind:0.28
view-job-filters:2.3
warnings:4.63
windows-slaves:1.8.1
workflow-aggregator:2.6
workflow-api:1164.v760c223ddb_32
workflow-basic-steps:2.24
workflow-cps:2648.va9433432b33c
workflow-cps-global-lib:552.vd9cc05b8a2e1
workflow-durable-task-step:1121.va_65b_d2701486
workflow-job:1145.v7f2433caa07f
workflow-multibranch:706.vd43c65dec013
workflow-scm-step:2.13
workflow-step-api:625.vd896b_f445a_f8
workflow-support:813.vb_d7c3d2984a_0
ws-cleanup:0.40
xunit:3.0.5
yet-another-docker-plugin:0.2.0

What Operating System are you using (both controller, and any agents involved in the problem)?

Ubuntu 20.4

Reproduction steps

  1. Dashboard > Manage Jenkins > Configure Clouds
  2. Add a new Cloud
  3. Connect method SSH
  4. Container settings
  5. Port Bindings
  6.      0.0.0.0:20000-20100:22
    

Expected Results

All docker-proxy process should use a port between 20000 and 20100

Actual Results

root 9197 6764 0 16:05 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 32770 -container-ip 172.17.0.2 -container-port 22
root 9203 6764 0 16:05 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 32770 -container-ip 172.17.0.2 -container-port 22
root 9214 6764 0 16:05 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 20002 -container-ip 172.17.0.2 -container-port 22

Anything else?

port 22 is handled as a special case in docker plugin

The following patch seems to address the issue
diff --git a/src/main/java/io/jenkins/docker/connector/DockerComputerSSHConnector.java b/src/main/java/io/jenkins/docker/connector/DockerComputerSSHConnector.java
index 21d339b..2aa2f42 100644
--- a/src/main/java/io/jenkins/docker/connector/DockerComputerSSHConnector.java
+++ b/src/main/java/io/jenkins/docker/connector/DockerComputerSSHConnector.java
@@ -253,8 +253,10 @@ public class DockerComputerSSHConnector extends DockerComputerConnector {
}
final Ports portBindings = hostConfig.getPortBindings();
if(portBindings != null) {

  •        portBindings.add(sshPortBinding);
    
  •        hostConfig.withPortBindings(portBindings);
    
  •           if(portBindings.getBindings().get(sshPortBinding.getExposedPort()).length == 0) {
    
  •                   portBindings.add(sshPortBinding);
    
  •                   hostConfig.withPortBindings(portBindings);
    
  •           }
       } else {
              hostConfig.withPortBindings(sshPortBinding);
       }
    
@eric-lapierre eric-lapierre added the bug An issue reporting a bug or a PR fixing one. label Jan 3, 2023
@basil
Copy link
Member

basil commented May 26, 2023

Would be great to have a pull request for this along with an explanation of how this change has been tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue reporting a bug or a PR fixing one.
Projects
None yet
Development

No branches or pull requests

2 participants