Class SshAuthHelper

java.lang.Object
io.jenkins.plugins.kubevirt.SshAuthHelper

public final class SshAuthHelper extends Object
Shared utility for detecting and retrying SSH authentication failures.

Cloud-init may still be injecting authorized_keys even though sshd is already running. The Jenkins SSH launcher treats auth failure as permanent, so this helper adds a retry layer on top.

The detection works by scanning the agent's log output for messages produced by the SSH launcher (e.g. "Server rejected the N private key(s)…").

  • Method Details

    • getSshAuthError

      public static String getSshAuthError(Computer computer, long sincePosition)
      Reads a computer's log (from the given byte position) to detect SSH authentication errors.
      Parameters:
      computer - the computer whose log to inspect
      sincePosition - byte offset to start reading from (0 for the entire log)
      Returns:
      a description of the error if found, or null if no auth error was detected
    • launchWithAuthRetry

      public static void launchWithAuthRetry(SlaveComputer computer, TaskListener listener, SshAuthHelper.SshLaunchAction launchAction, String nodeName) throws IOException, InterruptedException
      Launches SSH with automatic retry on authentication failures.

      The first attempt counts as attempt 1. If it fails with an auth error, up to KubeVirtConfiguration.SSH_AUTH_MAX_RETRIES additional attempts are made, sleeping KubeVirtConfiguration.SSH_AUTH_RETRY_INTERVAL_SECONDS seconds between each.

      Retries stop immediately when:

      • The computer comes online (success)
      • The failure is not an authentication error (different problem)
      • The maximum number of attempts is reached
      Parameters:
      computer - the agent computer
      listener - task listener for user-facing log messages
      launchAction - callback invoked for each SSH launch attempt
      nodeName - node name used in log messages
      Throws:
      IOException
      InterruptedException