From 864c05fadeb3340523aba3125e93b3a8fdcfb1ca Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Wed, 6 Mar 2019 16:04:24 +0000 Subject: [PATCH] mgr/dashboard: Support iSCSI password with '/' Signed-off-by: Ricardo Marques --- src/pybind/mgr/dashboard/controllers/iscsi.py | 30 +++++---------- ...scsi-target-discovery-modal.component.html | 4 +- .../iscsi-target-discovery-modal.component.ts | 2 +- .../iscsi-target-form.component.html | 4 +- .../iscsi-target-form.component.ts | 2 +- .../frontend/src/locale/messages.xlf | 16 ++++---- .../mgr/dashboard/services/iscsi_client.py | 25 ++++++------ src/pybind/mgr/dashboard/tests/test_iscsi.py | 38 ++++++++++--------- 8 files changed, 56 insertions(+), 65 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/iscsi.py b/src/pybind/mgr/dashboard/controllers/iscsi.py index 993b979110a..07f7abe846a 100644 --- a/src/pybind/mgr/dashboard/controllers/iscsi.py +++ b/src/pybind/mgr/dashboard/controllers/iscsi.py @@ -73,16 +73,10 @@ class Iscsi(BaseController): def _get_discoveryauth(self): config = IscsiClient.instance().get_config() - user = '' - password = '' - chap = config['discovery_auth']['chap'] - if chap: - user, password = chap.split('/') - mutual_user = '' - mutual_password = '' - chap_mutual = config['discovery_auth']['chap_mutual'] - if chap_mutual: - mutual_user, mutual_password = chap_mutual.split('/') + user = config['discovery_auth']['username'] + password = config['discovery_auth']['password'] + mutual_user = config['discovery_auth']['mutual_username'] + mutual_password = config['discovery_auth']['mutual_password'] return { 'user': user, 'password': password, @@ -425,12 +419,10 @@ class IscsiTarget(RESTController): target_iqn, client_iqn, image_id) user = client['auth']['user'] password = client['auth']['password'] - chap = '{}/{}'.format(user, password) if user and password else '' m_user = client['auth']['mutual_user'] m_password = client['auth']['mutual_password'] - m_chap = '{}/{}'.format(m_user, m_password) if m_user and m_password else '' IscsiClient.instance(gateway_name=gateway_name).create_client_auth( - target_iqn, client_iqn, chap, m_chap) + target_iqn, client_iqn, user, password, m_user, m_password) TaskManager.current_task().inc_progress(task_progress_inc) for group in groups: group_id = group['group_id'] @@ -490,14 +482,10 @@ class IscsiTarget(RESTController): 'image': image } luns.append(lun) - user = None - password = None - if '/' in client_config['auth']['chap']: - user, password = client_config['auth']['chap'].split('/', 1) - mutual_user = None - mutual_password = None - if '/' in client_config['auth']['chap_mutual']: - mutual_user, mutual_password = client_config['auth']['chap_mutual'].split('/', 1) + user = client_config['auth']['username'] + password = client_config['auth']['password'] + mutual_user = client_config['auth']['mutual_username'] + mutual_password = client_config['auth']['mutual_password'] client = { 'client_iqn': client_iqn, 'luns': luns, diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.html index ae888b72ea2..a5253fb88a6 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.html @@ -62,7 +62,7 @@ Passwords must have a length of 12 to 16 characters - and can only contain letters, '@', '-' or '_'. + and can only contain letters, '@', '-', '_' or '/'. @@ -121,7 +121,7 @@ Passwords must have a length of 12 to 16 characters and - can only contain letters, '@', '-' or '_'. + can only contain letters, '@', '-', '_' or '/'. diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts index 50fddfdd521..4b8c1809ab1 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts @@ -19,7 +19,7 @@ export class IscsiTargetDiscoveryModalComponent implements OnInit { discoveryForm: CdFormGroup; USER_REGEX = /[\w\.:@_-]{8,64}/; - PASSWORD_REGEX = /[\w@\-_]{12,16}/; + PASSWORD_REGEX = /[\w@\-_\/]{12,16}/; constructor( public bsModalRef: BsModalRef, diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.html index 8bb94a17c28..e5010ebc925 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.html @@ -290,7 +290,7 @@ Passwords must have a length of 12 to 16 characters - and can only contain letters, '@', '-' or '_'. + and can only contain letters, '@', '-', '_' or '/'. @@ -350,7 +350,7 @@ Passwords must have a length of 12 to 16 characters and - can only contain letters, '@', '-' or '_'. + can only contain letters, '@', '-', '_' or '/'. diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts index e16dddac8cd..99127652b7c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts @@ -73,7 +73,7 @@ export class IscsiTargetFormComponent implements OnInit { IQN_REGEX = /^iqn\.(19|20)\d\d-(0[1-9]|1[0-2])\.\D{2,3}(\.[A-Za-z0-9-]+)+(:[A-Za-z0-9-\.]+)*$/; USER_REGEX = /[\w\.:@_-]{8,64}/; - PASSWORD_REGEX = /[\w@\-_]{12,16}/; + PASSWORD_REGEX = /[\w@\-_\/]{12,16}/; constructor( private iscsiService: IscsiService, diff --git a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf index e60bb9e43fd..f3d4e306223 100644 --- a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf +++ b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf @@ -798,9 +798,9 @@ app/core/auth/user-form/user-form.component.html 42 - + Passwords must have a length of 12 to 16 characters - and can only contain letters, '@', '-' or '_'. + and can only contain letters, '@', '-', '_' or '/'. app/ceph/block/iscsi-target-form/iscsi-target-form.component.html 292 @@ -825,9 +825,9 @@ app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.html 98 - + Passwords must have a length of 12 to 16 characters and - can only contain letters, '@', '-' or '_'. + can only contain letters, '@', '-', '_' or '/'. app/ceph/block/iscsi-target-form/iscsi-target-form.component.html 352 @@ -981,16 +981,16 @@ app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.html 88 - + Passwords must have a length of 12 to 16 characters - and can only contain letters, '@', '-' or '_'. + and can only contain letters, '@', '-', '_' or '/'. app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.html 64 - + Passwords must have a length of 12 to 16 characters and - can only contain letters, '@', '-' or '_'. + can only contain letters, '@', '-', '_' or '/'. app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.html 123 diff --git a/src/pybind/mgr/dashboard/services/iscsi_client.py b/src/pybind/mgr/dashboard/services/iscsi_client.py index fed4a1542cd..1d616a2a57d 100644 --- a/src/pybind/mgr/dashboard/services/iscsi_client.py +++ b/src/pybind/mgr/dashboard/services/iscsi_client.py @@ -149,12 +149,15 @@ class IscsiClient(RestClient): }) @RestClient.api_put('/api/clientauth/{target_iqn}/{client_iqn}') - def create_client_auth(self, target_iqn, client_iqn, chap, chap_mutual, request=None): - logger.debug("iSCSI: Creating client auth: %s/%s/%s/%s", - target_iqn, client_iqn, chap, chap_mutual) + def create_client_auth(self, target_iqn, client_iqn, username, password, mutual_username, + mutual_password, request=None): + logger.debug("iSCSI: Creating client auth: %s/%s/%s/%s/%s/%s", + target_iqn, client_iqn, username, password, mutual_username, mutual_password) return request({ - 'chap': chap, - 'chap_mutual': chap_mutual + 'username': username, + 'password': password, + 'mutual_username': mutual_username, + 'mutual_password': mutual_password }) @RestClient.api_put('/api/hostgroup/{target_iqn}/{group_name}') @@ -174,15 +177,11 @@ class IscsiClient(RestClient): def update_discoveryauth(self, user, password, mutual_user, mutual_password, request=None): logger.debug("iSCSI: Updating discoveryauth: %s/%s/%s/%s", user, password, mutual_user, mutual_password) - chap = '' - if user and password: - chap = '{}/{}'.format(user, password) - chap_mutual = '' - if mutual_user and mutual_password: - chap_mutual = '{}/{}'.format(mutual_user, mutual_password) return request({ - 'chap': chap, - 'chap_mutual': chap_mutual + 'username': user, + 'password': password, + 'mutual_username': mutual_user, + 'mutual_password': mutual_password }) @RestClient.api_put('/api/targetauth/{target_iqn}') diff --git a/src/pybind/mgr/dashboard/tests/test_iscsi.py b/src/pybind/mgr/dashboard/tests/test_iscsi.py index 1d62e59e6fc..f86ac2a9e10 100644 --- a/src/pybind/mgr/dashboard/tests/test_iscsi.py +++ b/src/pybind/mgr/dashboard/tests/test_iscsi.py @@ -443,8 +443,12 @@ class IscsiClientMock(object): self.config = { "created": "2019/01/17 08:57:16", "discovery_auth": { - "chap": "", - "chap_mutual": "" + "username": "", + "password": "", + "password_encryption_enabled": False, + "mutual_username": "", + "mutual_password": "", + "mutual_password_encryption_enabled": False }, "disks": {}, "epoch": 0, @@ -542,8 +546,12 @@ class IscsiClientMock(object): target_config = self.config['targets'][target_iqn] target_config['clients'][client_iqn] = { "auth": { - "chap": "", - "chap_mutual": "" + "username": "", + "password": "", + "password_encryption_enabled": False, + "mutual_username": "", + "mutual_password": "", + "mutual_password_encryption_enabled": False }, "group_name": "", "luns": {} @@ -553,10 +561,12 @@ class IscsiClientMock(object): target_config = self.config['targets'][target_iqn] target_config['clients'][client_iqn]['luns'][image_id] = {} - def create_client_auth(self, target_iqn, client_iqn, chap, chap_mutual): + def create_client_auth(self, target_iqn, client_iqn, user, password, m_user, m_password): target_config = self.config['targets'][target_iqn] - target_config['clients'][client_iqn]['auth']['chap'] = chap - target_config['clients'][client_iqn]['auth']['chap_mutual'] = chap_mutual + target_config['clients'][client_iqn]['auth']['username'] = user + target_config['clients'][client_iqn]['auth']['password'] = password + target_config['clients'][client_iqn]['auth']['mutual_username'] = m_user + target_config['clients'][client_iqn]['auth']['mutual_password'] = m_password def create_group(self, target_iqn, group_name, members, image_ids): target_config = self.config['targets'][target_iqn] @@ -597,16 +607,10 @@ class IscsiClientMock(object): return {'data': ips[self.gateway_name]} def update_discoveryauth(self, user, password, mutual_user, mutual_password): - chap = '' - if user and password: - chap = '{}/{}'.format(user, password) - chap_mutual = '' - if mutual_user and mutual_password: - chap_mutual = '{}/{}'.format(mutual_user, mutual_password) - self.config['discovery_auth'] = { - 'chap': chap, - 'chap_mutual': chap_mutual - } + self.config['discovery_auth']['username'] = user + self.config['discovery_auth']['password'] = password + self.config['discovery_auth']['mutual_username'] = mutual_user + self.config['discovery_auth']['mutual_password'] = mutual_password def update_targetauth(self, target_iqn, action): self.config['targets'][target_iqn]['acl_enabled'] = (action == 'enable_acl') -- 2.39.5