google-compute-engine-plugin icon indicating copy to clipboard operation
google-compute-engine-plugin copied to clipboard

SSH connection to Jenkins slave is established twice

Open SchulteDev opened this issue 6 years ago • 4 comments

Is This plugin starts up a new instance in GCE. It connects to the new instances via SSH using an user, which is configured in the plugin settings in Jenkins (for example, the user "jenkins" is used for connecting via SSH). If this is successful, the plugin reconnects as root via SSH again to the instance. As root, the Jenkins slave is started. See https://github.com/jenkinsci/google-compute-engine-plugin/blob/master/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineLinuxLauncher.java#L110 and https://github.com/jenkinsci/google-compute-engine-plugin/blob/master/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineWindowsLauncher.java#L112

Question Why is the Jenkins slave started as root?

Downsides As far as I can see, the Jenkins slave could be started as the first SSH-user, too. This should decrease the time it takes to setup a new Jenkins slave. Furthermore, running the Jenkins slave as root should be avoided for security reasons.

SchulteDev avatar May 07 '19 07:05 SchulteDev

Thanks for pointing this out. I'll do a little digging to discover the motivation behind the current permissions strategy and follow up.

craigdbarber avatar May 07 '19 19:05 craigdbarber

Earlier I ran my a jenkins job with whoami. Just prints out my runAsUser. The log statement seems to be incorrect and we will remove it.

rachely3n avatar May 11 '19 00:05 rachely3n

Hmm, confusing. But the SSH connection is established twice, isn't it?

  1. https://github.com/jenkinsci/google-compute-engine-plugin/blob/master/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineLinuxLauncher.java#L108 -> https://github.com/jenkinsci/google-compute-engine-plugin/blob/master/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineLinuxLauncher.java#L204
  2. https://github.com/jenkinsci/google-compute-engine-plugin/blob/master/src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineLinuxLauncher.java#L112

SchulteDev avatar May 11 '19 09:05 SchulteDev

Yep, they both use the same way of authenticating. When I'm authenticating, I'm authenticating as the runAsUser.

rachely3n avatar May 13 '19 03:05 rachely3n