Skip to content

Commit 5d88451

Browse files
rakillenddsharpe
authored andcommitted
Issue #484 - Use of model encryption with online update fails (#485)
* Issue #484 - Use of model encryption with online update fails * Issue #484 - Separated encrypted model unit test from password test
1 parent e53e7d7 commit 5d88451

File tree

4 files changed

+95
-16
lines changed

4 files changed

+95
-16
lines changed

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,7 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
397397
attribute_info = module_folder[ATTRIBUTES][model_attribute_name]
398398

399399
if attribute_info and not self.__is_model_attribute_read_only(location, attribute_info):
400-
password_attribute_name = \
401-
password_utils.get_wlst_attribute_name(attribute_info, model_attribute_value, self._wlst_mode)
402-
403-
if password_attribute_name is not None:
404-
wlst_attribute_name = password_attribute_name
405-
else:
406-
wlst_attribute_name = attribute_info[WLST_NAME]
400+
wlst_attribute_name = attribute_info[WLST_NAME]
407401

408402
if self._model_context and USES_PATH_TOKENS in attribute_info and \
409403
string_utils.to_boolean(attribute_info[USES_PATH_TOKENS]):
@@ -413,6 +407,14 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
413407
if data_type == 'password':
414408
try:
415409
wlst_attribute_value = self.decrypt_password(model_attribute_value)
410+
411+
# the attribute name may change for special cases, check against decrypted value
412+
password_attribute_name = \
413+
password_utils.get_wlst_attribute_name(attribute_info, wlst_attribute_value, self._wlst_mode)
414+
415+
if password_attribute_name is not None:
416+
wlst_attribute_name = password_attribute_name
417+
416418
except EncryptionException, ee:
417419
ex = exception_helper.create_alias_exception('WLSDPLY-08402', model_attribute_name,
418420
location.get_folder_path(),
@@ -1200,7 +1202,7 @@ def get_wlst_read_type(self, location, model_attribute_name):
12001202

12011203
def decrypt_password(self, text):
12021204
"""
1203-
Encrypt the specified password if encryption is used and the password is encrypted.
1205+
Decrypt the specified password if model encryption is used and the password is encrypted.
12041206
:param text: the text to check and decrypt, if needed
12051207
:return: the clear text
12061208
:raises EncryptionException: if an error occurs while decrypting the password
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
Copyright (c) 2019, Oracle Corporation and/or its affiliates. All rights reserved.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
"""
5+
import unittest
6+
7+
from wlsdeploy.aliases.aliases import Aliases
8+
from wlsdeploy.aliases.location_context import LocationContext
9+
from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS
10+
from wlsdeploy.aliases.model_constants import JDBC_RESOURCE
11+
from wlsdeploy.aliases.model_constants import JDBC_SYSTEM_RESOURCE
12+
from wlsdeploy.aliases.model_constants import PASSWORD_ENCRYPTED
13+
from wlsdeploy.aliases.wlst_modes import WlstModes
14+
from wlsdeploy.logging.platform_logger import PlatformLogger
15+
from wlsdeploy.util.cla_utils import CommandLineArgUtil
16+
from wlsdeploy.util.model_context import ModelContext
17+
18+
19+
class AliasEncryptedModelTestCase(unittest.TestCase):
20+
"""
21+
Test cases for a the -use_encryption feature.
22+
"""
23+
24+
_logger = PlatformLogger('wlsdeploy.aliases')
25+
_wls_version = '12.2.1.3'
26+
_wlst_password_name = "Password"
27+
_wlst_password_encrypted_name = "PasswordEncrypted"
28+
29+
_passphrase = 'RE a drop of golden sun'
30+
_password = 'welcome1'
31+
_encrypted_password = '{AES}UC9rZld3blZFUnMraW12cHkydmtmdmpSZmNNMWVHajA6VERPYlJoeWxXU09IaHVrQzpBeWsrd2ZacVkyVT0='
32+
33+
def setUp(self):
34+
# construct aliases as if the -use_encryption and -passphrase switches were used
35+
model_context = ModelContext("test", {CommandLineArgUtil.USE_ENCRYPTION_SWITCH: 'true',
36+
CommandLineArgUtil.PASSPHRASE_SWITCH: self._passphrase})
37+
self.aliases = Aliases(model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self._wls_version)
38+
self.online_aliases = Aliases(model_context, wlst_mode=WlstModes.ONLINE, wls_version=self._wls_version)
39+
40+
self.location = LocationContext()
41+
self.location.append_location(JDBC_SYSTEM_RESOURCE)
42+
self.location.add_name_token(self.aliases.get_name_token(self.location), "Mine")
43+
self.location.append_location(JDBC_RESOURCE)
44+
self.location.append_location(JDBC_DRIVER_PARAMS)
45+
46+
def testOfflineWlstNames(self):
47+
# Using offline WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST
48+
# attribute, regardless of whether the password is encrypted. The password value should be plain text.
49+
50+
# using encrypted password
51+
wlst_name, wlst_value = \
52+
self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._encrypted_password)
53+
self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
54+
self.assertEqual(wlst_value, self._password)
55+
56+
# using unencrypted password
57+
wlst_name, wlst_value = \
58+
self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
59+
self.assertEquals(wlst_name, self._wlst_password_encrypted_name)
60+
self.assertEqual(wlst_value, self._password)
61+
62+
def testOnlineWlstNames(self):
63+
# Using online WLST, the PasswordEncrypted model attribute should always translate to the Password WLST
64+
# attribute, and the value should translate to the unencrypted value.
65+
66+
# using encrypted password
67+
wlst_name, wlst_value = \
68+
self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED,
69+
self._encrypted_password)
70+
self.assertEqual(wlst_name, self._wlst_password_name)
71+
self.assertEqual(wlst_value, self._password)
72+
73+
# using unencrypted password
74+
wlst_name, wlst_value = \
75+
self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password)
76+
self.assertEquals(wlst_name, self._wlst_password_name)
77+
self.assertEqual(wlst_value, self._password)

core/src/test/python/alias_password_test.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Copyright (c) 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
5-
import jarray
65
import unittest
76

87
from wlsdeploy.aliases.aliases import Aliases
@@ -13,25 +12,24 @@
1312
from wlsdeploy.aliases.model_constants import PASSWORD_ENCRYPTED
1413
from wlsdeploy.aliases.wlst_modes import WlstModes
1514
from wlsdeploy.logging.platform_logger import PlatformLogger
16-
from wlsdeploy.util.cla_utils import CommandLineArgUtil
1715
from wlsdeploy.util.model_context import ModelContext
1816

1917

2018
class AliasPasswordTestCase(unittest.TestCase):
19+
"""
20+
Test domain-encrypted passwords in a model.
21+
"""
2122

2223
_logger = PlatformLogger('wlsdeploy.aliases')
2324
_wls_version = '12.2.1.3'
2425
_wlst_password_name = "Password"
2526
_wlst_password_encrypted_name = "PasswordEncrypted"
2627

27-
_passphrase = 'RE a drop of golden sun'
2828
_password = 'welcome1'
2929
_encrypted_password = '{AES}UC9rZld3blZFUnMraW12cHkydmtmdmpSZmNNMWVHajA6VERPYlJoeWxXU09IaHVrQzpBeWsrd2ZacVkyVT0='
30-
_encrypted_password_bytes = jarray.array(_encrypted_password, 'b')
3130

3231
def setUp(self):
33-
model_context = ModelContext("test", {CommandLineArgUtil.USE_ENCRYPTION_SWITCH: 'true',
34-
CommandLineArgUtil.PASSPHRASE_SWITCH: self._passphrase})
32+
model_context = ModelContext("test", {})
3533
self.aliases = Aliases(model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self._wls_version)
3634
self.online_aliases = Aliases(model_context, wlst_mode=WlstModes.ONLINE, wls_version=self._wls_version)
3735

@@ -73,7 +71,7 @@ def testOfflineWlstNames(self):
7371
wlst_name, wlst_value = \
7472
self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._encrypted_password)
7573
self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
76-
self.assertEqual(wlst_value, self._password)
74+
self.assertEqual(wlst_value, self._encrypted_password)
7775

7876
# using unencrypted password
7977
wlst_name, wlst_value = \
@@ -89,7 +87,7 @@ def testOnlineWlstNames(self):
8987
self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED,
9088
self._encrypted_password)
9189
self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
92-
self.assertEqual(wlst_value, self._password)
90+
self.assertEqual(wlst_value, self._encrypted_password)
9391

9492
# using unencrypted password
9593
wlst_name, wlst_value = \

site/encrypt.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
Models contain WebLogic Server domain configuration. Certain types of resources and other configurations require passwords; for example, a JDBC data source requires the password for the user establishing the database connection. When creating or configuring a resource that requires a password, that password must be specified either in the model directly or in the variable file. Clear-text passwords are not conducive to storing configurations as source, so the Encrypt Model Tool gives the model author the ability to encrypt the passwords in the model and variable file using passphrase-based, reversible encryption. When using a tool with a model containing encrypted passwords, the encryption passphrase must be provided, so that the tool can decrypt the password in memory to set the necessary WebLogic Server configuration (which supports its own encryption mechanism based on a domain-specific key). While there is no requirement to use the Oracle WebLogic Server Deploy Tooling encryption mechanism, it is highly recommended because storing clear text passwords on disk is never a good idea.
66

7+
**NOTE: WebLogic Server Deploy Tooling also supports the use of domain-encrypted passwords directly in the model. The Encrypt Model Tool should not be used in tandem with this method.**
8+
79
Start with the following example model:
810

911
```yaml

0 commit comments

Comments
 (0)