Skip to content

Commit 5825a4f

Browse files
committed
Merge branch 'jira-wdt-889-encrypt-args' into 'main'
Include one-way hashed LDAP passwords in target script and JSON output See merge request weblogic-cloud/weblogic-deploy-tooling!1697
2 parents 3f95478 + 1199fdd commit 5825a4f

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

core/src/main/python/wlsdeploy/tool/encrypt/encryption_utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,14 @@ def encrypt_one_password(passphrase, text):
217217
:raises EncryptionException if an error occurs
218218
"""
219219
return EncryptionUtils.encryptString(text, String(passphrase).toCharArray())
220+
221+
222+
def decrypt_one_password(passphrase, text):
223+
"""
224+
Decrypt the text provided using the specified passphrase.
225+
:param passphrase: the password to use for encryption
226+
:param text: the text to decrypt
227+
:return: the decrypted text
228+
:raises EncryptionException if an error occurs
229+
"""
230+
return str(String(EncryptionUtils.decryptString(text, String(passphrase).toCharArray())))

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import re
88

99
from java.io import File
10+
from oracle.weblogic.deploy.encrypt import EncryptionUtils
1011
from oracle.weblogic.deploy.json import JsonException
1112
from oracle.weblogic.deploy.util import FileUtils
1213
from oracle.weblogic.deploy.util import PyOrderedDict
@@ -23,6 +24,7 @@
2324
from wlsdeploy.exception import exception_helper
2425
from wlsdeploy.json.json_translator import PythonToJson
2526
from wlsdeploy.logging.platform_logger import PlatformLogger
27+
from wlsdeploy.tool.encrypt import encryption_utils
2628
from wlsdeploy.tool.util import k8s_helper
2729
from wlsdeploy.tool.util import variable_injector_functions
2830
from wlsdeploy.tool.util.targets import additional_output_helper
@@ -78,6 +80,8 @@
7880
K8S_SCRIPT_RESOURCE_PATH = 'oracle/weblogic/deploy/k8s/' + K8S_SCRIPT_NAME + file_template_helper.MUSTACHE_SUFFIX
7981
RESULTS_FILE_NAME = 'results.json'
8082

83+
PASSWORD_HASH_MARKER = "{ssha256}"
84+
8185

8286
def process_target_arguments(argument_map):
8387
"""
@@ -149,10 +153,7 @@ def _prepare_k8s_secrets(model_context, token_dictionary, model_dictionary):
149153
if secret_name not in secret_map:
150154
secret_map[secret_name] = {}
151155
secret_keys = secret_map[secret_name]
152-
if secret_key in PASSWORD_SECRET_KEY_NAMES:
153-
secret_keys[secret_key] = None
154-
else:
155-
secret_keys[secret_key] = value
156+
secret_keys[secret_key] = _get_output_value(secret_key, value, model_context)
156157

157158
# update the secrets hash
158159

@@ -267,10 +268,7 @@ def _build_json_secrets_result(model_context, token_dictionary):
267268
secrets_map[secret_name] = {'keys': {}}
268269

269270
secret_keys = secrets_map[secret_name]['keys']
270-
if secret_key in PASSWORD_SECRET_KEY_NAMES:
271-
secret_keys[secret_key] = ''
272-
else:
273-
secret_keys[secret_key] = value
271+
secret_keys[secret_key] = _get_output_value(secret_key, value, model_context)
274272

275273
# runtime encryption key is not included in token_dictionary
276274
target_config = model_context.get_target_configuration()
@@ -478,3 +476,24 @@ def _build_secret_hash(secret_name, secret_key_map):
478476
message = exception_helper.get_message("WLSDPLY-01683", secret_name, ', '.join(update_keys))
479477

480478
return {'secretName': secret_name, 'secretPairs': secret_pairs_text, 'comments': [{'comment': message}]}
479+
480+
481+
def _get_output_value(secret_key, value, model_context):
482+
"""
483+
Determine the secret value to be provided to the secrets script or results output JSON.
484+
Exclude password values unless they are one-way hashed values, such as those in LDIF files.
485+
:param secret_key: the key into the credentials map
486+
:param value: the value to be examined
487+
:param model_context: used to decrypt value
488+
:return: the value to be provided
489+
"""
490+
if secret_key in PASSWORD_SECRET_KEY_NAMES and value:
491+
if EncryptionUtils.isEncryptedString(value):
492+
value = encryption_utils.decrypt_one_password(model_context.get_encryption_passphrase(), value)
493+
494+
if value.startswith(PASSWORD_HASH_MARKER):
495+
return value
496+
else:
497+
return None
498+
else:
499+
return value

0 commit comments

Comments
 (0)