Skip to content

Commit f576e9a

Browse files
authored
JIRA WDT-498 - Add a list of secrets to domain resource for WKO and VZ targets; exclude admin secrets (#765)
1 parent 8cf8ec9 commit f576e9a

File tree

6 files changed

+64
-9
lines changed

6 files changed

+64
-9
lines changed

core/src/main/python/discover.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ def main(args):
512512

513513
if model_context.is_targetted_config():
514514
# do this before variables have been inserted into model
515-
target_configuration_helper.create_additional_output(model, model_context, aliases, ExceptionType.DISCOVER)
515+
target_configuration_helper.create_additional_output(model, model_context, aliases, credential_injector,
516+
ExceptionType.DISCOVER)
516517

517518
model = __check_and_customize_model(model, model_context, aliases, credential_injector)
518519

core/src/main/python/prepare_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ def walk(self):
295295

296296
# create any additional outputs from full model dictionary
297297
target_configuration_helper.create_additional_output(Model(full_model_dictionary), self.model_context,
298-
self._aliases, ExceptionType.VALIDATE)
298+
self._aliases, self.credential_injector,
299+
ExceptionType.VALIDATE)
299300

300301
except ValidateException, te:
301302
self._logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(),

core/src/main/python/wlsdeploy/tool/util/targets/additional_output_helper.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
__logger = PlatformLogger('wlsdeploy.tool.util')
2626

2727
# substitution keys used in the templates
28+
ADDITIONAL_SECRET_NAME = 'additionalSecretName'
29+
ADDITIONAL_SECRETS = 'additionalSecrets'
2830
CLUSTER_NAME = 'clusterName'
2931
CLUSTERS = 'clusters'
3032
DATABASE_CREDENTIALS = 'databaseCredentials'
@@ -36,26 +38,28 @@
3638
DOMAIN_TYPE = 'domainType'
3739
DOMAIN_UID = 'domainUid'
3840
DS_URL = 'url'
41+
HAS_ADDITIONAL_SECRETS = 'hasAdditionalSecrets'
3942
HAS_CLUSTERS = 'hasClusters'
4043
HAS_DATABASES = 'hasDatabases'
4144
REPLICAS = 'replicas'
4245
WEBLOGIC_CREDENTIALS_SECRET = 'webLogicCredentialsSecret'
4346

4447

45-
def create_additional_output(model, model_context, aliases, exception_type):
48+
def create_additional_output(model, model_context, aliases, credential_injector, exception_type):
4649
"""
4750
Create and write additional output for the configured target type.
4851
:param model: Model object, used to derive some values in the output
4952
:param model_context: used to determine location and content for the output
5053
:param aliases: used to derive secret names
54+
:param credential_injector: used to identify secrets
5155
:param exception_type: the type of exception to throw if needed
5256
"""
5357

5458
# -output_dir argument was previously verified
5559
output_dir = model_context.get_output_dir()
5660

5761
# all current output types use this hash, and process a set of template files
58-
template_hash = _build_template_hash(model, model_context, aliases)
62+
template_hash = _build_template_hash(model, model_context, aliases, credential_injector)
5963

6064
file_names = model_context.get_target_configuration().get_additional_output_types()
6165
for file_name in file_names:
@@ -84,12 +88,13 @@ def _create_file(template_name, template_hash, model_context, output_dir, except
8488
file_template_helper.create_file_from_file(template_path, template_hash, output_file, exception_type)
8589

8690

87-
def _build_template_hash(model, model_context, aliases):
91+
def _build_template_hash(model, model_context, aliases, credential_injector):
8892
"""
8993
Create a dictionary of substitution values to apply to the templates.
9094
:param model: Model object used to derive values
9195
:param model_context: used to determine domain type
9296
:param aliases: used to derive folder names
97+
:param credential_injector: used to identify secrets
9398
:return: the hash dictionary
9499
"""
95100
template_hash = dict()
@@ -107,9 +112,13 @@ def _build_template_hash(model, model_context, aliases):
107112
template_hash[DOMAIN_NAME] = domain_uid
108113
template_hash[DOMAIN_PREFIX] = domain_uid
109114

115+
# secrets that should not be included in secrets section
116+
declared_secrets = []
117+
110118
# admin credential
111119

112120
admin_secret = domain_uid + target_configuration_helper.WEBLOGIC_CREDENTIALS_SECRET_SUFFIX
121+
declared_secrets.append(admin_secret)
113122
template_hash[WEBLOGIC_CREDENTIALS_SECRET] = admin_secret
114123

115124
# configuration / model
@@ -165,4 +174,26 @@ def _build_template_hash(model, model_context, aliases):
165174
template_hash[DATABASES] = databases
166175
template_hash[HAS_DATABASES] = len(databases) != 0
167176

177+
# additional secrets - exclude admin
178+
179+
additional_secrets = []
180+
181+
# combine user/password properties to get a single list
182+
secrets = []
183+
for property_name in credential_injector.get_variable_cache():
184+
halves = property_name.split(':', 1)
185+
name = halves[0]
186+
if name not in secrets:
187+
secrets.append(name)
188+
189+
for secret in secrets:
190+
secrets_hash = dict()
191+
qualified_name = domain_uid + "-" + secret
192+
if qualified_name not in declared_secrets:
193+
secrets_hash[ADDITIONAL_SECRET_NAME] = qualified_name
194+
additional_secrets.append(secrets_hash)
195+
196+
template_hash[ADDITIONAL_SECRETS] = additional_secrets
197+
template_hash[HAS_ADDITIONAL_SECRETS] = len(additional_secrets) != 0
198+
168199
return template_hash

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,19 @@ def get_secret_name_for_location(location, domain_uid, aliases):
229229
return domain_uid + '-' + secret_name
230230

231231

232-
def create_additional_output(model, model_context, aliases, exception_type):
232+
def create_additional_output(model, model_context, aliases, credential_injector, exception_type):
233233
"""
234234
Create any additional output specified in the target configuration.
235235
:param model: used to create additional content
236236
:param model_context: provides access to the target configuration
237237
:param aliases: used for template fields
238+
:param credential_injector: used to identify secrets
238239
:param exception_type: type of exception to throw
239240
"""
240241
_method_name = 'create_additional_output'
241242

242-
additional_output_helper.create_additional_output(model, model_context, aliases, exception_type)
243+
additional_output_helper.create_additional_output(model, model_context, aliases, credential_injector,
244+
exception_type)
243245

244246

245247
def create_secret_name(variable_name, suffix=None):

core/src/main/targetconfigs/vz/model.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ spec:
4747
configuration:
4848
model:
4949
domainType: {{{domainType}}}
50+
{{#hasAdditionalSecrets}}
51+
52+
# Secrets that are referenced by model yaml macros
53+
# (the model yaml in the optional configMap or in the image)
54+
secrets:
55+
{{/hasAdditionalSecrets}}
56+
{{#additionalSecrets}}
57+
- {{{additionalSecretName}}}
58+
{{/additionalSecrets}}
5059
connections:
5160
- ingress:
5261
- name: {{{domainPrefix}}}-ingress

core/src/main/targetconfigs/wko/model.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ spec:
3232
- name: USER_MEM_ARGS
3333
value: "-Djava.security.egd=file:/dev/./urandom -Xms64m -Xmx256m "
3434

35-
# clusters is used to configure the desired behavior for starting member servers of a cluster.
36-
# If you use this entry, then the rules will be applied to ALL servers that are members of the named clusters.
3735
{{#hasClusters}}
36+
# clusters is used to configure the desired behavior for starting member servers of a cluster.
37+
# If you use this entry, then the rules will be applied to ALL servers that are members of the named clusters.
3838
clusters:
3939
{{/hasClusters}}
4040
{{#clusters}}
@@ -58,3 +58,14 @@ spec:
5858
# The number of cluster member Managed Server instances to start for this WebLogic cluster
5959
replicas: {{{replicas}}}
6060
{{/clusters}}
61+
62+
configuration:
63+
{{#hasAdditionalSecrets}}
64+
65+
# Secrets that are referenced by model yaml macros
66+
# (the model yaml in the optional configMap or in the image)
67+
secrets:
68+
{{/hasAdditionalSecrets}}
69+
{{#additionalSecrets}}
70+
- {{{additionalSecretName}}}
71+
{{/additionalSecrets}}

0 commit comments

Comments
 (0)