Skip to content

Commit 37b0bd5

Browse files
committed
Merge branch 'JIRA-WDT-760-secrets-overlap' into 'main'
Fix overlapping secret names; allow secret key walletPassword for OPSSSecrets See merge request weblogic-cloud/weblogic-deploy-tooling!1482
2 parents 0f3f53b + 547437a commit 37b0bd5

20 files changed

+655
-311
lines changed

core/src/main/python/wlsdeploy/aliases/alias_constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
PREFERRED_MODEL_TYPE = 'preferred_model_type'
3030
PRODUCTION_DEFAULT = 'production_default'
3131
RESTART_REQUIRED = 'restart_required'
32+
SECRET_KEY = 'secret_key'
33+
SECRET_SUFFIX = 'secret_suffix'
3234
SECURE_DEFAULT = 'secure_default'
3335
SET_MBEAN_TYPE = 'set_mbean_type'
3436
SET_METHOD = 'set_method'
@@ -103,6 +105,10 @@
103105
STRING = 'string'
104106
MASKED = '<masked>'
105107

108+
# alias owns these, they are derived from secret_key, wlst_type
109+
SECRET_USERNAME_KEY = "username"
110+
SECRET_PASSWORD_KEY = "password"
111+
106112
ALIAS_DELIMITED_TYPES = [
107113
COMMA_DELIMITED_STRING,
108114
DELIMITED_STRING,

core/src/main/python/wlsdeploy/aliases/aliases.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from wlsdeploy.aliases.alias_constants import ALIAS_LIST_TYPES
1616
from wlsdeploy.aliases.alias_constants import ALIAS_MAP_TYPES
1717
from wlsdeploy.aliases.alias_constants import ATTRIBUTES
18+
from wlsdeploy.aliases.alias_constants import CREDENTIAL
1819
from wlsdeploy.aliases.alias_constants import ChildFoldersTypes
1920
from wlsdeploy.aliases.alias_constants import DEFAULT_VALUE
2021
from wlsdeploy.aliases.alias_constants import DERIVED_DEFAULT
@@ -36,6 +37,10 @@
3637
from wlsdeploy.aliases.alias_constants import PROPERTIES
3738
from wlsdeploy.aliases.alias_constants import RESTART_REQUIRED
3839
from wlsdeploy.aliases.alias_constants import RO
40+
from wlsdeploy.aliases.alias_constants import SECRET_KEY
41+
from wlsdeploy.aliases.alias_constants import SECRET_PASSWORD_KEY
42+
from wlsdeploy.aliases.alias_constants import SECRET_SUFFIX
43+
from wlsdeploy.aliases.alias_constants import SECRET_USERNAME_KEY
3944
from wlsdeploy.aliases.alias_constants import SECURE_DEFAULT
4045
from wlsdeploy.aliases.alias_constants import SET_MBEAN_TYPE
4146
from wlsdeploy.aliases.alias_constants import SET_METHOD
@@ -1414,6 +1419,57 @@ def is_derived_default(self, location, model_attribute):
14141419
self._logger.exiting(class_name=self._class_name, method_name=_method_name, result=result)
14151420
return result
14161421

1422+
def get_secret_suffix(self, location, model_attribute):
1423+
"""
1424+
Get the secret suffix for the specified location and attribute.
1425+
:param location: location of the attribute
1426+
:param model_attribute: model name of attribute to check
1427+
:return: the secret suffix, or None
1428+
"""
1429+
_method_name = "get_secret_suffix"
1430+
self._logger.entering(model_attribute, class_name=self._class_name, method_name=_method_name)
1431+
1432+
result = None
1433+
try:
1434+
attribute_info = self._alias_entries.get_alias_attribute_entry_by_model_name(location, model_attribute)
1435+
if attribute_info is not None:
1436+
result = dictionary_utils.get_element(attribute_info, SECRET_SUFFIX)
1437+
except AliasException, ae:
1438+
self._raise_exception(ae, _method_name, 'WLSDPLY-19049', model_attribute, location.get_folder_path(),
1439+
ae.getLocalizedMessage())
1440+
1441+
self._logger.exiting(class_name=self._class_name, method_name=_method_name, result=result)
1442+
return result
1443+
1444+
def get_secret_key(self, location, model_attribute):
1445+
"""
1446+
Get the secret key for the specified location and attribute.
1447+
Return the secret_key value, or derive the value from the WLST type.
1448+
:param location: location of the attribute
1449+
:param model_attribute: model name of attribute to check
1450+
:return: the secret key, or None
1451+
"""
1452+
_method_name = "get_secret_key"
1453+
self._logger.entering(model_attribute, class_name=self._class_name, method_name=_method_name)
1454+
1455+
result = None
1456+
try:
1457+
attribute_info = self._alias_entries.get_alias_attribute_entry_by_model_name(location, model_attribute)
1458+
if attribute_info is not None:
1459+
result = dictionary_utils.get_element(attribute_info, SECRET_KEY)
1460+
if not result:
1461+
attribute_type = self.get_model_attribute_type(location, model_attribute)
1462+
if attribute_type == PASSWORD:
1463+
result = SECRET_PASSWORD_KEY
1464+
elif attribute_type == CREDENTIAL:
1465+
result = SECRET_USERNAME_KEY
1466+
except AliasException, ae:
1467+
self._raise_exception(ae, _method_name, 'WLSDPLY-19050', model_attribute, location.get_folder_path(),
1468+
ae.getLocalizedMessage())
1469+
1470+
self._logger.exiting(class_name=self._class_name, method_name=_method_name, result=result)
1471+
return result
1472+
14171473
###########################################################################
14181474
# Convenience Methods #
14191475
###########################################################################

core/src/main/python/wlsdeploy/tool/util/credential_injector.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""
2-
Copyright (c) 2020, 2022, 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 https://oss.oracle.com/licenses/upl.
44
"""
55

66
import oracle.weblogic.deploy.util.PyOrderedDict as OrderedDict
77
from wlsdeploy.aliases.alias_constants import CREDENTIAL
88
from wlsdeploy.aliases.alias_constants import PASSWORD
9+
from wlsdeploy.aliases.alias_constants import SECRET_PASSWORD_KEY
10+
from wlsdeploy.aliases.alias_constants import SECRET_USERNAME_KEY
911
from wlsdeploy.aliases.location_context import LocationContext
1012
from wlsdeploy.aliases.model_constants import DOMAIN_INFO_ALIAS
1113
from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_PROPERTY_VALUE
@@ -27,8 +29,6 @@
2729
from wlsdeploy.util import variables
2830
from wlsdeploy.util.target_configuration import CONFIG_OVERRIDES_SECRETS_METHOD
2931
from wlsdeploy.util.target_configuration import SECRETS_METHOD
30-
from wlsdeploy.util.target_configuration_helper import SECRET_PASSWORD_KEY
31-
from wlsdeploy.util.target_configuration_helper import SECRET_USERNAME_KEY
3232
from wlsdeploy.util.target_configuration_helper import WEBLOGIC_CREDENTIALS_SECRET_NAME
3333

3434
_class_name = 'CredentialInjector'
@@ -168,28 +168,16 @@ def get_variable_name(self, attribute_location, attribute, suffix=None):
168168
aliases = self.get_aliases()
169169
target_config = self._model_context.get_target_configuration()
170170

171-
# domainInfo attributes have separate model and attribute locations
171+
# the attribute location passed may differ from the model location (rare).
172+
# for example, DomainInfo/... attribute location is a top-level model location.
172173
model_location = attribute_location
173174
if model_location.get_current_model_folder() == DOMAIN_INFO_ALIAS:
174175
model_location = LocationContext()
175176

176177
if target_config.uses_credential_secrets():
177-
# use the secret token name as variable name in the cache, such as jdbc-generic1.password .
178-
# secret name is the adjusted variable name, with the last element replaced with "username" or "password".
179-
180-
attribute_type = aliases.get_model_attribute_type(attribute_location, attribute)
181-
variable_name = VariableInjector.get_variable_name(self, model_location, attribute)
182-
secret_name = target_configuration_helper.create_secret_name(variable_name, suffix)
183-
184-
secret_key = SECRET_USERNAME_KEY
185-
if attribute_type == PASSWORD:
186-
secret_key = SECRET_PASSWORD_KEY
187-
188-
# suffix such as map3.password in MailSession properties
189-
if suffix and suffix.endswith(".password"):
190-
secret_key = SECRET_PASSWORD_KEY
191-
192-
return '%s:%s' % (secret_name, secret_key)
178+
# use the secret token name as variable name in the cache, such as jdbc-generic1:password
179+
return target_configuration_helper.get_secret_path(model_location, attribute_location,
180+
attribute, aliases, suffix)
193181

194182
return VariableInjector.get_variable_name(self, model_location, attribute, suffix=suffix)
195183

core/src/main/python/wlsdeploy/tool/util/variable_injector.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2018, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2018, 2023, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import copy
@@ -72,7 +72,6 @@
7272

7373
# global variables for functions in VariableInjector
7474
_find_special_names_pattern = re.compile('[\[\]]')
75-
_fake_name_marker = 'fakename'
7675
_split_around_special_names = re.compile('([\w]+\[[\w\.,]+\])|\.')
7776

7877
_class_name = 'variable_injector'
@@ -333,7 +332,7 @@ def inject_variables(self, injector_dictionary):
333332
if injector_dictionary:
334333
location = LocationContext()
335334
domain_token = self.__aliases.get_name_token(location)
336-
location.add_name_token(domain_token, _fake_name_marker)
335+
location.add_name_token(domain_token, variable_injector_functions.FAKE_NAME_MARKER)
337336
for injector, injector_values in injector_dictionary.iteritems():
338337
entries_dict = self.__inject_variable(location, injector, injector_values)
339338
if len(entries_dict) > 0:
@@ -639,7 +638,7 @@ def _process_pattern_dictionary(self, attribute_name, attribute_dict, location,
639638

640639
def _check_name_token(self, location, name_token):
641640
if self.__aliases.requires_unpredictable_single_name_handling(location):
642-
location.add_name_token(name_token, _fake_name_marker)
641+
location.add_name_token(name_token, variable_injector_functions.FAKE_NAME_MARKER)
643642

644643
def _replace_tokens(self, path_string):
645644
result = path_string

core/src/main/python/wlsdeploy/tool/util/variable_injector_functions.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
"""
2-
Copyright (c) 2018, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2018, 2023, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import re
66

7+
from oracle.weblogic.deploy.aliases import AliasException
8+
79
import wlsdeploy.aliases.model_constants as model_constants
810
import wlsdeploy.util.model as model_sections
9-
from oracle.weblogic.deploy.aliases import AliasException
11+
import wlsdeploy.util.unicode_helper as str_helper
1012
from wlsdeploy.aliases.location_context import LocationContext
1113
from wlsdeploy.logging.platform_logger import PlatformLogger
12-
import wlsdeploy.util.unicode_helper as str_helper
1314

1415
_class_name = 'variable_injector'
1516
_logger = PlatformLogger('wlsdeploy.tool.util')
1617

17-
_fake_name_marker = 'fakename'
18-
_fake_name_replacement = re.compile('.' + _fake_name_marker)
18+
FAKE_NAME_MARKER = 'fakename'
19+
_fake_name_replacement = re.compile('.' + FAKE_NAME_MARKER)
1920
_white_space_replacement = re.compile('\\s')
2021

2122
# bad characters for a property name - anything that isn't a good character
@@ -73,6 +74,25 @@ def format_variable_name(location, attribute, aliases):
7374
"""
7475
_method_name = 'format_variable_name'
7576

77+
short_name = get_short_name(location, attribute, aliases)
78+
79+
# remove or replace invalid characters in the variable name for use as a property name.
80+
short_name = short_name.replace('/', '.')
81+
short_name = _white_space_replacement.sub('-', short_name)
82+
short_name = _bad_chars_replacement.sub('-', short_name)
83+
return short_name
84+
85+
86+
def get_short_name(location, attribute, aliases):
87+
"""
88+
Return a dot-delimited string representation of the location and attribute.
89+
There are adjustments to use shorter element names and skip some redundant elements
90+
This is used to make variable property names and secret names.
91+
:param location: the location of the attribute
92+
:param attribute: the attribute to be evaluated
93+
:param aliases: for information about the location and attribute
94+
:return: the short name
95+
"""
7696
short_list = __traverse_location(LocationContext(location), attribute, list(), aliases)
7797

7898
short_name = ''
@@ -81,10 +101,6 @@ def format_variable_name(location, attribute, aliases):
81101
short_name += node + '.'
82102
short_name += attribute
83103

84-
# remove or replace invalid characters in the variable name for use as a property name.
85-
short_name = short_name.replace('/', '.')
86-
short_name = _white_space_replacement.sub('-', short_name)
87-
short_name = _bad_chars_replacement.sub('-', short_name)
88104
short_name = _fake_name_replacement.sub('', short_name)
89105
return short_name
90106

0 commit comments

Comments
 (0)