jenkinsci / jenkins-charm

Juju charm to deploy and scale Jenkins
Other
17 stars 36 forks source link

_make_client exhausts retries until urllib.error.HTTPError: HTTP Error 401: Invalid password/token for user: ubuntu #37

Closed ryan-beisner closed 5 years ago

ryan-beisner commented 7 years ago

_make_client exhausts retries until urllib.error.HTTPError: HTTP Error 401: Invalid password/token for user: ubuntu

This occurs with cs:xenial/jenkins-4 and cs:xenial/jenkins-2.

ubuntu@temp1-bastion:~/deploy2⟫ juju config osci-master | egrep "username:|password:" -A5
  password:
    description: Admin user password - used to manage slave nodes so please don't
      change in Jenkins.
    type: string
    value: ubuntu
  plugins:
--
  username:
    description: Admin user username - used to manage slave nodes so please don't
      change in Jenkins.
    type: string
    value: ubuntu
ubuntu@juju-3ee1f0-temp1-0:/var/lib/jenkins$ ls -alht
total 80K
drwxr-xr-x 11 jenkins jenkins 4.0K Apr 12 17:33 .
-rw-------  1 root    root       6 Apr 12 17:33 .admin_password
drwxr-xr-x  4 jenkins jenkins 4.0K Apr 12 17:33 users
-rw-------  1 root    root      32 Apr 12 17:33 .admin_token
-r--r--r--  1 jenkins nogroup  156 Apr 12 17:33 jenkins.model.JenkinsLocationConfiguration.xml
-r--r--r--  1 jenkins nogroup  475 Apr 12 17:33 config.xml
drwx------  4 jenkins jenkins 4.0K Apr 12 17:33 secrets
-rw-r--r--  1 jenkins jenkins    5 Apr 12 17:33 jenkins.install.UpgradeWizard.state
drwxr-xr-x  3 jenkins jenkins 4.0K Apr 12 17:33 logs
-rw-r--r--  1 jenkins jenkins  907 Apr 12 17:33 nodeMonitors.xml
drwxr-xr-x  2 jenkins jenkins 4.0K Apr 12 17:33 userContent
-rw-------  1 jenkins jenkins 1.7K Apr 12 17:33 identity.key.enc
-rw-r--r--  1 jenkins jenkins  159 Apr 12 17:32 hudson.model.UpdateCenter.xml
drwxr-xr-x  2 jenkins jenkins 4.0K Apr 12 17:32 nodes
drwxr-xr-x  2 jenkins jenkins 4.0K Apr 12 17:32 jobs
drwxr-xr-x  2 jenkins jenkins 4.0K Apr 12 17:32 plugins
-rw-r--r--  1 jenkins jenkins    0 Apr 12 17:32 secret.key.not-so-secret
-rw-r--r--  1 jenkins jenkins   64 Apr 12 17:32 secret.key
drwxr-xr-x  3 jenkins jenkins 4.0K Apr 12 17:32 .java
drwxr-xr-x  3 jenkins jenkins 4.0K Apr 12 17:32 .cache
drwxr-xr-x 44 root    root    4.0K Apr 12 17:32 ..
ubuntu@juju-3ee1f0-temp1-0:/var/lib/jenkins$ sudo head .admin_*
==> .admin_password <==
ubuntu
==> .admin_token <==
2017-04-12 17:33:12 INFO juju-log Configuring user for jenkins
2017-04-12 17:33:12 INFO juju-log Retrying '_make_client' 7 more times (delay=5)
2017-04-12 17:33:18 INFO juju-log Retrying '_make_client' 6 more times (delay=10)
2017-04-12 17:33:28 INFO juju-log Writing file /var/lib/jenkins/.admin_token root:root 600
2017-04-12 17:33:28 INFO juju-log Writing file /var/lib/jenkins/.admin_password root:root 600
2017-04-12 17:33:29 INFO juju-log Retrying '_make_client' 7 more times (delay=5)
2017-04-12 17:33:34 INFO juju-log Retrying '_make_client' 6 more times (delay=10)
2017-04-12 17:33:44 INFO juju-log Retrying '_make_client' 5 more times (delay=15)
2017-04-12 17:33:59 INFO juju-log Retrying '_make_client' 4 more times (delay=20)
2017-04-12 17:34:19 INFO juju-log Retrying '_make_client' 3 more times (delay=25)
2017-04-12 17:34:45 INFO juju-log Retrying '_make_client' 2 more times (delay=30)
2017-04-12 17:35:15 INFO juju-log Retrying '_make_client' 1 more times (delay=35)
2017-04-12 17:35:50 INFO install Traceback (most recent call last):
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 431, in jenkins_open
2017-04-12 17:35:50 INFO install     response = urlopen(req, timeout=self.timeout).read()
2017-04-12 17:35:50 INFO install   File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
2017-04-12 17:35:50 INFO install     return opener.open(url, data, timeout)
2017-04-12 17:35:50 INFO install   File "/usr/lib/python3.5/urllib/request.py", line 472, in open
2017-04-12 17:35:50 INFO install     response = meth(req, response)
2017-04-12 17:35:50 INFO install   File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
2017-04-12 17:35:50 INFO install     'http', request, response, code, msg, hdrs)
2017-04-12 17:35:50 INFO install   File "/usr/lib/python3.5/urllib/request.py", line 510, in error
2017-04-12 17:35:50 INFO install     return self._call_chain(*args)
2017-04-12 17:35:50 INFO install   File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
2017-04-12 17:35:50 INFO install     result = func(*args)
2017-04-12 17:35:50 INFO install   File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
2017-04-12 17:35:50 INFO install     raise HTTPError(req.full_url, code, msg, hdrs, fp)
2017-04-12 17:35:50 INFO install urllib.error.HTTPError: HTTP Error 401: Invalid password/token for user: ubuntu
2017-04-12 17:35:50 INFO install 
2017-04-12 17:35:50 INFO install During handling of the above exception, another exception occurred:
2017-04-12 17:35:50 INFO install 
2017-04-12 17:35:50 INFO install Traceback (most recent call last):
2017-04-12 17:35:50 INFO install   File "/var/lib/juju/agents/unit-osci-master-0/charm/hooks/install", line 19, in <module>
2017-04-12 17:35:50 INFO install     main()
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/charms/reactive/__init__.py", line 78, in main
2017-04-12 17:35:50 INFO install     bus.dispatch()
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 434, in dispatch
2017-04-12 17:35:50 INFO install     _invoke(other_handlers)
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 417, in _invoke
2017-04-12 17:35:50 INFO install     handler.invoke()
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 291, in invoke
2017-04-12 17:35:50 INFO install     self._action(*args)
2017-04-12 17:35:50 INFO install   File "/var/lib/juju/agents/unit-osci-master-0/charm/reactive/jenkins.py", line 115, in configure_admin
2017-04-12 17:35:50 INFO install     users.configure_admin()
2017-04-12 17:35:50 INFO install   File "lib/charms/layer/jenkins/users.py", line 34, in configure_admin
2017-04-12 17:35:50 INFO install     paths.LAST_EXEC, "{}\n".format(api.version()).encode("utf-8"),
2017-04-12 17:35:50 INFO install   File "lib/charms/layer/jenkins/api.py", line 47, in version
2017-04-12 17:35:50 INFO install     self.wait()
2017-04-12 17:35:50 INFO install   File "lib/charms/layer/jenkins/api.py", line 43, in wait
2017-04-12 17:35:50 INFO install     self._make_client()
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/charmhelpers/core/decorators.py", line 40, in _retry_on_exception_inner_2
2017-04-12 17:35:50 INFO install     return f(*args, **kwargs)
2017-04-12 17:35:50 INFO install   File "lib/charms/layer/jenkins/api.py", line 132, in _make_client
2017-04-12 17:35:50 INFO install     client.get_whoami()
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 575, in get_whoami
2017-04-12 17:35:50 INFO install     response = self.jenkins_open(Request(self._build_url(WHOAMI_URL)))
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 430, in jenkins_open
2017-04-12 17:35:50 INFO install     self.maybe_add_crumb(req)
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 303, in maybe_add_crumb
2017-04-12 17:35:50 INFO install     self._build_url(CRUMB_URL)), add_crumb=False)
2017-04-12 17:35:50 INFO install   File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 448, in jenkins_open
2017-04-12 17:35:50 INFO install     e.code, e.msg)
2017-04-12 17:35:50 INFO install jenkins.JenkinsException: Error in request. Possibly authentication failed [401]: Invalid password/token for user: ubuntu
2017-04-12 17:35:50 ERROR juju.worker.uniter.operation runhook.go:107 hook "install" failed: exit status 1
ryan-beisner commented 7 years ago

It looks like the .admin_token file needs to be owned by jenkins. Once I set that, the above errors went away and I could log into the Jenkins web UI with the configured user/pass. I've not proposed or modified the charm. That was just an exercise to confirm that is the issue.

-rw------- 1 jenkins jenkins 32 Apr 12 18:27 .admin_token

jamesbeedy commented 5 years ago

@ryan-beisner its this https://jenkins.io/blog/2018/07/02/new-api-token-system/

jamesbeedy commented 5 years ago

this is https://github.com/jenkinsci/jenkins-charm/issues/47

mthaddon commented 5 years ago

Closing this out, as #47 is now resolved.