Skip to content

Commit 4623240

Browse files
committed
Merge branch 'prepare-model-fix' into 'main'
fixing password validation so that it does not run with Prepare Model See merge request weblogic-cloud/weblogic-deploy-tooling!1542
2 parents 6d629c6 + 8ddd148 commit 4623240

File tree

6 files changed

+55
-9
lines changed

6 files changed

+55
-9
lines changed

core/src/main/python/create.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def _precheck_rcu_connectivity(model_context, creator, rcu_db_info):
346346
e.getLocalizedMessage(), error=e)
347347
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
348348
raise ex
349-
except ee:
349+
except ee: # FIXME - WLSDPLY-12506 only has one placeholder so ee gets dropped on the floor.
350350
ex = exception_helper.create_create_exception('WLSDPLY-12506', domain_typename, ee)
351351
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
352352
raise ex
@@ -372,6 +372,7 @@ def main(model_context):
372372
# check for any content problems in the merged, substituted model
373373
content_validator = ContentValidator(model_context, aliases)
374374
content_validator.validate_model(model_dictionary)
375+
content_validator.validate_user_passwords(model_dictionary)
375376

376377
archive_helper = None
377378
archive_file_name = model_context.get_archive_file_name()

core/src/main/python/wlsdeploy/tool/validate/content_validator.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def validate_model(self, model_dict):
5454
"""
5555
_method_name = 'validate_model'
5656
self._logger.entering(class_name=self._class_name, method_name=_method_name)
57-
self.validate_user_passwords(model_dict)
57+
#
58+
# This code is called by both Create Domain and Prepare Model. Since passwords may still
59+
# be tokenized in Prepare Model, do not call validate_user_passwords() from here.
60+
#
5861
self.validate_dynamic_clusters(model_dict)
5962
self._logger.exiting(class_name=self._class_name, method_name=_method_name)
6063

@@ -108,8 +111,12 @@ def validate_user_passwords(self, model_dict):
108111

109112
found_errors = False
110113
try:
111-
if not password_validator.validate(admin_username, admin_password):
112-
found_errors = True
114+
if not self._model_context.password_is_tokenized(admin_password):
115+
if not password_validator.validate(admin_username, admin_password):
116+
found_errors = True
117+
else:
118+
self._logger.notification('WLSDPLY-05208', admin_username,
119+
class_name=self._class_name, method_name=_method_name)
113120
except ValidateException, ex:
114121
self._logger.severe('WLSDPLY-05203', ex.getLocalizedMessage(),
115122
error=ex, class_name=self._class_name, method_name=_method_name)
@@ -122,8 +129,12 @@ def validate_user_passwords(self, model_dict):
122129
password = dictionary_utils.get_element(user_dict, PASSWORD)
123130
password = self._aliases.decrypt_password(password)
124131
try:
125-
if not password_validator.validate(user_name, password):
126-
found_errors = True
132+
if not self._model_context.password_is_tokenized(password):
133+
if not password_validator.validate(user_name, password):
134+
found_errors = True
135+
else:
136+
self._logger.notification('WLSDPLY-05208', user_name,
137+
class_name=self._class_name, method_name=_method_name)
127138
except ValidateException, ex:
128139
self._logger.severe('WLSDPLY-05204', user_name, ex.getLocalizedMessage(),
129140
error=ex, class_name=self._class_name, method_name=_method_name)

core/src/main/python/wlsdeploy/util/model_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
DISABLE_RCU_DROP_SCHEMA_PROP='disable.rcu.drop.schema'
5151
DISABLE_RCU_DROP_SCHEMA_DEFAULT='false'
5252
ENABLE_CREATE_DOMAIN_PASSWORD_VALIDATION_PROP = 'enable.create.domain.password.validation'
53-
ENABLE_CREATE_DOMAIN_PASSWORD_VALIDATION_DEFAULT = 'false'
53+
ENABLE_CREATE_DOMAIN_PASSWORD_VALIDATION_DEFAULT = 'true'
5454

5555
# System Property overrides for WLST timeout properties
5656
SYS_PROP_PREFIX = 'wdt.config.'

core/src/main/python/wlsdeploy/util/model_context.py

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class ModelContext(object):
3333
"""
3434
_class_name = "ModelContext"
3535

36+
SECRET_REGEX = re.compile('@@SECRET:[a-zA-Z0-9_-]+:[a-zA-Z0-9_-]+@@')
37+
ENV_REGEX = re.compile('@@ENV:[a-zA-Z0-9_-]+@@')
3638
ORACLE_HOME_TOKEN = '@@ORACLE_HOME@@'
3739
WL_HOME_TOKEN = '@@WL_HOME@@'
3840
DOMAIN_HOME_TOKEN = '@@DOMAIN_HOME@@'
@@ -957,6 +959,18 @@ def tokenize_classpath(self, classpath):
957959

958960
return MODEL_LIST_DELIMITER.join(cp_elements)
959961

962+
def password_is_tokenized(self, password):
963+
"""
964+
Does the password contain a secret or environment variable token?
965+
:param password: the password to test
966+
:return: True if a secret or environment variable token is found; False otherwise
967+
"""
968+
result = False
969+
if password is not None:
970+
result = self.SECRET_REGEX.search(password) is not None or self.ENV_REGEX.search(password) is not None
971+
return result
972+
973+
960974
def copy(self, arg_map):
961975
model_context_copy = copy.copy(self)
962976
model_context_copy.__copy_from_args(arg_map)

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

+1
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ WLSDPLY-05204=Password validation failed for the {0} credentials: {1}
565565
WLSDPLY-05205=Password validation encountered validation errors
566566
WLSDPLY-05206=Found model attribute {0} of type {1} with value {2}
567567
WLSDPLY-05207=Found alias attribute {0} of type {1} with default value {2}
568+
WLSDPLY-05208=Skipping password validation for user {0} because the password appears to be tokenized
568569

569570
# wlsdeploy/tools/validate/validation_utils.py
570571
WLSDPLY-05300=NOT USED

core/src/test/python/wlsdeploy/util/model_context_test.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2020, Oracle and/or its affiliates.
2+
Copyright (c) 2020, 2023, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
44
"""
55
import unittest
@@ -10,7 +10,7 @@
1010

1111
class ClaHelperTest(unittest.TestCase):
1212

13-
def testCopyModelContext(self):
13+
def test_copy_model_context(self):
1414
__program_name = 'model_context_test'
1515
__oracle_home = '/my/oracle/home'
1616
__model_file = 'my_model_file.yaml'
@@ -28,3 +28,22 @@ def testCopyModelContext(self):
2828
self.assertEquals(model_context_copy.get_program_name(), __program_name)
2929
self.assertEquals(model_context_copy.get_oracle_home(), __oracle_home)
3030
self.assertEquals(model_context_copy.get_model_file(), __model_file)
31+
32+
def test_password_is_tokenized(self):
33+
__program_name = 'model_context_test'
34+
35+
__no_token_value = 'Welcome1'
36+
__complex_no_token_value = 'Abc@@def@@ghi'
37+
__secret_value = '@@SECRET:foo:username@@'
38+
__env_value = '@@ENV:FOO@@'
39+
__complex_token_value = '@@SECRET:foo:@@ENV:BAR@@@@'
40+
41+
model_context = ModelContext(__program_name)
42+
self.assertEquals(model_context.password_is_tokenized(None), False)
43+
self.assertEquals(model_context.password_is_tokenized(__no_token_value), False)
44+
self.assertEquals(model_context.password_is_tokenized(__complex_no_token_value), False)
45+
46+
self.assertEquals(model_context.password_is_tokenized(__secret_value), True)
47+
self.assertEquals(model_context.password_is_tokenized(__env_value), True)
48+
self.assertEquals(model_context.password_is_tokenized(__secret_value), True)
49+
self.assertEquals(model_context.password_is_tokenized(__complex_token_value), True)

0 commit comments

Comments
 (0)