Skip to content

Commit 13041e0

Browse files
rakillenrobertpatrick
authored andcommitted
Include encrypted secrets from discover/prepare
1 parent 3addcca commit 13041e0

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
from wlsdeploy.aliases.model_constants import JDBC_SYSTEM_RESOURCE
1919
from wlsdeploy.aliases.model_constants import MAIL_SESSION
2020
from wlsdeploy.aliases.model_constants import PROPERTIES
21+
from wlsdeploy.aliases.model_constants import REMOTE_RESOURCE
22+
from wlsdeploy.aliases.model_constants import USER
23+
from wlsdeploy.aliases.model_constants import WLS_USER_PASSWORD_CREDENTIAL_MAPPINGS
2124
from wlsdeploy.logging.platform_logger import PlatformLogger
2225
from wlsdeploy.tool.util.variable_injector import REGEXP
2326
from wlsdeploy.tool.util.variable_injector import REGEXP_PATTERN
@@ -45,6 +48,7 @@ class CredentialInjector(VariableInjector):
4548

4649
# used for user token search
4750
JDBC_PROPERTIES_PATH = '%s.%s.%s.%s' % (JDBC_SYSTEM_RESOURCE, JDBC_RESOURCE, JDBC_DRIVER_PARAMS, PROPERTIES)
51+
REMOTE_CREDENTIAL_MAPPING_PATH = '%s.%s' % (WLS_USER_PASSWORD_CREDENTIAL_MAPPINGS, REMOTE_RESOURCE)
4852

4953
# regex for tokenizing MailSession.Properties passwords and retaining the value
5054
PASSWORD_COMMANDS = {
@@ -126,6 +130,15 @@ def check_and_tokenize(self, model_dict, attribute, location):
126130
injector_commands.update({VARIABLE_VALUE: model_value})
127131
self.custom_injection(model_dict, attribute, location, injector_commands)
128132

133+
elif folder_path.endswith(self.REMOTE_CREDENTIAL_MAPPING_PATH) and (attribute == USER):
134+
# this attribute is a list type, it needs to be tokenized as a comma-separated string
135+
value = model_dict[attribute]
136+
if isinstance(value, list):
137+
value = ','.join(value)
138+
variable_name = self.get_variable_name(location, attribute)
139+
model_dict[attribute] = self.get_variable_token(attribute, variable_name)
140+
self.add_to_cache(dictionary={variable_name: value})
141+
129142
elif folder_path.endswith(MAIL_SESSION) and (attribute == PROPERTIES):
130143
# users and passwords are property assignments
131144
value = model_dict[attribute]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ def _get_remote_resource_model_entry(self, credential_map_ldift_entry, resource_
348348
location.add_name_token(name_token, entry_name)
349349
self._credential_injector.check_and_tokenize(result, REMOTE_USER, location)
350350
self._credential_injector.check_and_tokenize(result, REMOTE_PASSWORD, location)
351+
self._credential_injector.check_and_tokenize(result, USER, location)
351352

352353
_logger.exiting(class_name=self.__class_name, method_name=_method_name, result=result)
353354
return result

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _prepare_k8s_secrets(model_context, token_dictionary, model_dictionary):
153153
if secret_name not in secret_map:
154154
secret_map[secret_name] = {}
155155
secret_keys = secret_map[secret_name]
156-
secret_keys[secret_key] = _get_output_value(secret_key, value, model_context)
156+
secret_keys[secret_key] = _get_output_value(secret_key, value, model_context, False)
157157

158158
# update the secrets hash
159159

@@ -268,7 +268,7 @@ def _build_json_secrets_result(model_context, token_dictionary):
268268
secrets_map[secret_name] = {'keys': {}}
269269

270270
secret_keys = secrets_map[secret_name]['keys']
271-
secret_keys[secret_key] = _get_output_value(secret_key, value, model_context)
271+
secret_keys[secret_key] = _get_output_value(secret_key, value, model_context, True)
272272

273273
# runtime encryption key is not included in token_dictionary
274274
target_config = model_context.get_target_configuration()
@@ -478,17 +478,20 @@ def _build_secret_hash(secret_name, secret_key_map):
478478
return {'secretName': secret_name, 'secretPairs': secret_pairs_text, 'comments': [{'comment': message}]}
479479

480480

481-
def _get_output_value(secret_key, value, model_context):
481+
def _get_output_value(secret_key, value, model_context, include_encrypted_passwords):
482482
"""
483483
Determine the secret value to be provided to the secrets script or results output JSON.
484484
Exclude password values unless they are one-way hashed values, such as those in LDIF files.
485485
:param secret_key: the key into the credentials map
486486
:param value: the value to be examined
487487
:param model_context: used to decrypt value
488+
:param include_encrypted_passwords: whether to return encrypted passwords
488489
:return: the value to be provided
489490
"""
490491
if secret_key in PASSWORD_SECRET_KEY_NAMES and value:
491492
if EncryptionUtils.isEncryptedString(value):
493+
if include_encrypted_passwords:
494+
return value
492495
value = encryption_utils.decrypt_one_password(model_context.get_encryption_passphrase(), value)
493496

494497
if value.startswith(PASSWORD_HASH_MARKER):

core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/WLSUserPasswordCredentialMappings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"RemotePassword": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "RemotePassword", "wlst_path": "WP001", "default_value": null, "wlst_type": "password" } ],
3333
"RemotePort": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "RemotePort", "wlst_path": "WP001", "default_value": null, "wlst_type": "integer" } ],
3434
"RemoteUser": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "RemoteUser", "wlst_path": "WP001", "default_value": null, "wlst_type": "credential" } ],
35-
"User": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "User", "wlst_path": "WP001", "default_value": null, "wlst_type": "list" } ]
35+
"User": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "User", "wlst_path": "WP001", "default_value": null, "wlst_type": "list", "secret_key": "localuser" } ]
3636
},
3737
"wlst_attributes_path": "WP001",
3838
"wlst_paths": {

0 commit comments

Comments
 (0)