Skip to content

Jenkins http CLI broken in latest Jenkins LTS releases with anonymous user, can't create ssh users or install pluginsΒ #789

@ChrisPetr0

Description

@ChrisPetr0

πŸ—£οΈ Foreword

Thank for taking the time to fill this bug report fully. Without it we may not be able to fix the bug, and the issue may be closed without resolution.

πŸ‘» Brief Description

Building Jenkins AMI / Image with packer and Ubuntu 20.04. Pattern has been rock solid for years. Truncated Runlist looks like this:

- jenkins_configuration_myorg::install_base_packages
- jenkins_configuration_myorg::install_open_jdk
- jenkins::master
- jenkins_configuration_myorg::jenkins_sudoers
- jenkins_configuration_myorg::install_plugins

No problems until install_plugins recipe. Using the install_plugin resource from Jenkins cookbook which leverages internal Jenkins CLI calls. Using http executor, plugin list is an array walked through for each plugin.

Jenkins LTS 2.319.3 (2022-02-09) works as expected and installs plugins successfully. It seems some security changes were made on later versions of Jenkins that breaks the ability to install plugins with http executor via Jenkins CLI and and anonymous user. Latest Jenkins LTS 2.332.3 and 2.332.2 have this issue (I believe it started in 2.332.1, as significant changes in change log start there).

Error executing action `install` on resource 'jenkins_plugin[ace-editor]'
    amazon-ebs:     ================================================================================
    amazon-ebs:
    amazon-ebs:     Mixlib::ShellOut::ShellCommandFailed
    amazon-ebs:     ------------------------------------
    amazon-ebs:     Expected process to exit with [0], but received '6'
    amazon-ebs:     ---- Begin output of "java" -jar "/tmp/packer-chef-solo/local-mode-cache/cache/jenkins-cli.jar" -s http://localhost:8080 -http install-plugin https://updates.jenkins.io/download/plugins/ace-editor/1.1/ace-editor.hpi  ----
    amazon-ebs:     STDOUT:
    amazon-ebs:     STDERR: ERROR: anonymous is missing the Overall/Read permission

I'm perfectly fine with using ssh executor and creating a user with public key and setting node.run_state[:jenkins_private_key] = private_key. In fact, I tried this. However, the same CLI problem exists. If I have a base install of Jenkins via this cookbook, want to configure a user via this cookbook via jenkins_user resource, that also needs to use the CLI. I can't create a Jenkins user with ssh configured via this cookbook / resource to use the CLI with ssh executor because it has the same problem when calling the jenkins_user resource (ERROR: anonymous is missing the Overall/Read permission.

In testing, I also tried to modify

<denyAnonymousReadAccess>false</denyAnonymousReadAccess> 

and run CLI calls with http executor via anonymous user and the error changes to ERROR: anonymous is missing the Overall/Administer permission

I'm thinking I may have to resort to trying to run CLI calls with -auth flag and use the admin user with $JENKINS_HOME/secrets/initialAdminPassword which I did try unsuccessfully but need to test more. EDIT: This works, going to try to figure out if I can use this pattern for initial configuration.

I would really like to get on latest LTS version, but it seems there is a chicken and egg problem here with CLI unable to be used at all until an ssh user is created, but this cookbook can't create an ssh user because the CLI no longer works with anonymous user.

πŸ₯ž Cookbook version

'9.5.2'

πŸ‘©β€πŸ³ Chef-Infra Version

17.9.26

🎩 Platform details

Ubuntu 20.04

Steps To Reproduce

Steps to reproduce the behavior:

  • Set Jenkins Version to 2.332.3
  • Instantiate Jenkins node configuration from scratch with default cookbook settings (after installing java) using Jenkins[master] recipe (http executor)
  • Leverage install_plugin resource and attempt to install a valid plugin
  • Notice failure with STDERR: ERROR: anonymous is missing the Overall/Read permission
  • Can also reproduce with jenkins_user, groovy_script, and jenkins_command, basically anything that uses internal CLI to configure Jenkins using http executor with no auth

EDIT: Upon reading cookbook documentation further, I am going to try the jenkins_credentials but unfamiliar with using that. I'm not sure if this will help get around this issue, but will post back.

EDIT_UPDATE: Looks like:

jenkins_password_credentials 'cliuser' do
  id          'cliuser'
  description 'cliuser'
  password    'clipass123'
end

also fails and uses the CLI to run a groovy script

amazon-ebs:     ================================================================================
    amazon-ebs:     Error executing action `create` on resource 'jenkins_password_credentials[cliuser]'
    amazon-ebs:     ================================================================================
    amazon-ebs:
    amazon-ebs:     Mixlib::ShellOut::ShellCommandFailed
    amazon-ebs:     ------------------------------------
    amazon-ebs:     Expected process to exit with [0], but received '6'
    amazon-ebs:     ---- Begin output of "java" -jar "/tmp/packer-chef-solo/local-mode-cache/cache/jenkins-cli.jar" -s http://localhost:8080 -http groovy = ----
    amazon-ebs:     STDOUT:
    amazon-ebs:     STDERR: ERROR: anonymous is missing the Overall/Read permission
  • Set Jenkins Version to 2.319.3
  • Perform exact same test as above and watch it install plugins with no issues

πŸš“ Expected behavior

Jenkins CLI calls leveraged in install_plugin or jenkins_user resources should work or a method to create Jenkins ssh user using an alternative method than Jenkins CLI should exist.

βž• Additional context

I'm not really sure what to do here. It seems like I am deadlocked from using the functionality of this cookbook natively without introducing additional yet to be determined code to create an ssh enabled user or use jenkins admin user auth flag with http executor to create ssh enabled users, which will require custom code.

Any help, suggestions, or workarounds would be greatly appreciated. I'm looking to keep up with LTS releases from a security perspective. If anything else is needed from me, I will be happy to provide.

Thank you !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions