Refresh local registry auth info each time when access local registry

(cherry picked from commit d6cff0496d)
(cherry picked from commit 1b50022d55)

Local registry uses admin account password as authentication info.
And this password may be changed by openstack client at any time.
When try to download images from local registry, auth info cannot
be cached, otherwise it may lead to authentication failure in keystone,
and account be locked at the end.
For this specific case, there is host-swact first, then function
"_upgrade_downgrade_kube_networking" in sysinv conductor is called.
And upgrade-k8s-networking.yml is executed which will try to download
kube network images from local registry. During this period, admin
account password is changed. And lead to account be locked due to
authentication failure in keystone.
With this update, there is still possibility that password be changed
just after get operation. And due to the images download are run in
parallel with multi threads, so account lock may still hit. This
change could minimize the issue rate, but cannot fix all.

Closes-Bug: 1853017

Change-Id: I686616937031a3f7ac6d65e5b118511dc549ab85
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
This commit is contained in:
Shuicheng Lin 2020-03-12 14:34:09 +08:00
parent 790186065e
commit 75b5edfa6c
2 changed files with 14 additions and 14 deletions

View File

@ -7,6 +7,7 @@
from eventlet import greenpool
import docker
import keyring
import sys
import time
import os
@ -26,6 +27,13 @@ DEFAULT_REGISTRIES = {
registries = json.loads(os.environ['REGISTRIES'])
def get_local_registry_auth():
password = keyring.get_password("CGCS", "admin")
if not password:
raise Exception("Local registry password not found.")
return dict(username="admin", password=str(password))
def download_an_image(img):
# This function is to pull image from public/private
# registry and push to local registry.
@ -59,7 +67,10 @@ def download_an_image(img):
client = docker.APIClient()
client.pull(target_img)
client.tag(target_img, local_img)
client.push(local_img)
# admin password may be changed by openstack client in parallel.
# So we cannot cache auth info, need refresh it each time.
auth = get_local_registry_auth()
client.push(local_img, auth_config=auth)
print("Image download succeeded: %s" % target_img)
print("Image push succeeded: %s" % local_img)
return target_img, True

View File

@ -121,10 +121,10 @@
vars:
script_content: |
import keyring
password = str(keyring.get_password("CGCS", "admin"))
password = keyring.get_password("CGCS", "admin")
if not password:
raise Exception("Local registry password not found.")
print dict(username='admin', password=password)
print dict(username='admin', password=str(password))
shell: "{{ script_content }}"
args:
executable: /usr/bin/python
@ -133,12 +133,6 @@
- set_fact:
local_registry_credentials: "{{ local_registry_credentials_output.stdout }}"
- name: Log in to local registry
docker_login:
registry: "{{ local_registry }}"
username: "{{ local_registry_credentials['username'] }}"
password: "{{ local_registry_credentials['password'] }}"
- name: Download images and push to local registry
script: download_images.py {{ download_images }}
register: download_images_output
@ -160,8 +154,3 @@
- "{{ docker_registry }}"
when: item.username is defined
no_log: true
- name: Log out of local registry
docker_login:
registry: "{{ local_registry }}"
state: absent