Skip to content

Commit 362cad2

Browse files
authored
Merge pull request #1212 from oracle/develop_OWLS-76349
Fix secure protocol in AdminURL
2 parents 268277c + f806a92 commit 362cad2

File tree

5 files changed

+82
-11
lines changed

5 files changed

+82
-11
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,31 @@ Integer getAsPort() {
142142
.getLocalAdminProtocolChannelPort();
143143
}
144144

145+
/**
146+
* Check if the server is listening on a secure port. NOTE: If the targetted server is a managed
147+
* server, this method is overridden to check if the managed server has a secure listen port rather
148+
* than the admin server. See PodHelper.ManagedPodStepContext
149+
*
150+
* @return true if server is listening on a secure port
151+
*/
145152
boolean isLocalAdminProtocolChannelSecure() {
153+
return domainTopology
154+
.getServerConfig(getServerName())
155+
.isLocalAdminProtocolChannelSecure();
156+
}
157+
158+
/**
159+
* Check if the admin server is listening on a secure port.
160+
*
161+
* @return true if admin server is listening on a secure port
162+
*/
163+
private boolean isAdminServerProtocolChannelSecure() {
146164
return domainTopology
147165
.getServerConfig(domainTopology.getAdminServerName())
148166
.isLocalAdminProtocolChannelSecure();
149167
}
150168

169+
151170
Integer getLocalAdminProtocolChannelPort() {
152171
return domainTopology
153172
.getServerConfig(domainTopology.getAdminServerName())
@@ -587,8 +606,16 @@ void addStartupEnvVars(List<V1EnvVar> vars) {
587606
addEnvVar(vars, ServerEnvVars.ADMIN_NAME, getAsName());
588607
addEnvVar(vars, ServerEnvVars.ADMIN_PORT, getAsPort().toString());
589608
if (isLocalAdminProtocolChannelSecure()) {
609+
// This env variable indicates whether the administration port in the WLS server on the local pod is secure
590610
addEnvVar(vars, ServerEnvVars.ADMIN_PORT_SECURE, "true");
591611
}
612+
if (isAdminServerProtocolChannelSecure()) {
613+
// The following env variable determines whether to set a secure protocol(https/t3s) in the "AdminURL" property
614+
// in NM startup.properties.
615+
// WebLogic Node Manager then sets the ADMIN_URL env variable(based on the "AdminURL") before starting
616+
// the managed server
617+
addEnvVar(vars, "ADMIN_SERVER_PORT_SECURE", "true");
618+
}
592619
addEnvVar(vars, ServerEnvVars.SERVER_NAME, getServerName());
593620
addEnvVar(vars, ServerEnvVars.DOMAIN_UID, getDomainUid());
594621
addEnvVar(vars, ServerEnvVars.NODEMGR_HOME, NODEMGR_HOME);

operator/src/main/java/oracle/kubernetes/operator/wlsconfig/WlsDomainConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ public String getName() {
245245
}
246246

247247
/**
248-
* Return the name of the WLS domain.
248+
* Return the name of the admin server.
249249
*
250-
* @return Name of the WLS domain
250+
* @return Name of the admin server
251251
*/
252252
public String getAdminServerName() {
253253
return this.adminServerName;

operator/src/main/resources/scripts/startNodeManager.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,8 @@ EOF
260260
[ ! $? -eq 0 ] && trace SEVERE "Failed to create '${wl_props_file}'." && exit 1
261261

262262
if [ ! "${ADMIN_NAME}" = "${SERVER_NAME}" ]; then
263-
admin_protocol="http"
264-
if [ "${ADMIN_PORT_SECURE}" = "true" ]; then
265-
admin_protocol="https"
266-
fi
267-
if [ "${ISTIO_ENABLED}" == "true" ]; then
268-
echo "AdminURL=t3\\://${AS_SERVICE_NAME}\\:${ADMIN_PORT}" >> ${wl_props_file}
269-
else
270-
echo "AdminURL=$admin_protocol\\://${AS_SERVICE_NAME}\\:${ADMIN_PORT}" >> ${wl_props_file}
271-
fi
263+
ADMIN_URL=$(getAdminServerUrl)
264+
echo "AdminURL=$ADMIN_URL" >> ${wl_props_file}
272265
fi
273266
fi
274267

operator/src/main/resources/scripts/utils.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,26 @@ checkWebLogicVersion()
395395
fi
396396
return 0
397397
}
398+
399+
400+
#
401+
# getAdminUrl
402+
# purpose: Get the admin URL used to connect to the admin server internally, e.g. when starting a managed server
403+
# sample:
404+
# ADMIN_URL=$(getAdminServerUrl)
405+
#
406+
function getAdminServerUrl() {
407+
local admin_protocol="http"
408+
if [ "${ISTIO_ENABLED}" = "true" ]; then
409+
admin_protocol="t3"
410+
fi
411+
412+
if [ "${ADMIN_SERVER_PORT_SECURE}" = "true" ]; then
413+
if [ "${ISTIO_ENABLED}" = "true" ]; then
414+
admin_protocol="t3s"
415+
else
416+
admin_protocol="https"
417+
fi
418+
fi
419+
echo ${admin_protocol}://${AS_SERVICE_NAME}:${ADMIN_PORT}
420+
}

operator/src/test/java/oracle/kubernetes/operator/helpers/AdminPodHelperTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,34 @@ public void whenAdminPodCreated_hasOperatorCertEnvVariable() {
218218
hasEnvVar(INTERNAL_OPERATOR_CERT_ENV_NAME, InMemoryCertificates.INTERNAL_CERT_DATA));
219219
}
220220

221+
@Test
222+
public void whenAdminPodCreatedWithAdminPortEnabled_adminServerPortSecureEnvVarIsTrue() {
223+
final Integer adminPort = 9002;
224+
getServerTopology().setAdminPort(adminPort);
225+
assertThat(getCreatedPodSpecContainer().getEnv(), hasEnvVar("ADMIN_SERVER_PORT_SECURE", "true"));
226+
}
227+
228+
@Test
229+
public void whenAdminPodCreatedWithNullAdminPort_adminServerPortSecureEnvVarIsNotSet() {
230+
final Integer adminPort = null;
231+
getServerTopology().setAdminPort(adminPort);
232+
assertThat(getCreatedPodSpecContainer().getEnv(), not(hasEnvVar("ADMIN_SERVER_PORT_SECURE", "true")));
233+
}
234+
235+
@Test
236+
public void whenAdminPodCreatedWithAdminServerHasSSLPortEnabled_adminServerPortSecureEnvVarIsTrue() {
237+
final Integer adminServerSSLPort = 9999;
238+
getServerTopology().setSslListenPort(adminServerSSLPort);
239+
assertThat(getCreatedPodSpecContainer().getEnv(), hasEnvVar("ADMIN_SERVER_PORT_SECURE", "true"));
240+
}
241+
242+
@Test
243+
public void whenAdminPodCreatedWithAdminServerHasNullSSLPort_adminServerPortSecureEnvVarIsNotSet() {
244+
final Integer adminServerSSLPort = null;
245+
getServerTopology().setSslListenPort(adminServerSSLPort);
246+
assertThat(getCreatedPodSpecContainer().getEnv(), not(hasEnvVar("ADMIN_SERVER_PORT_SECURE", "true")));
247+
}
248+
221249
@Test
222250
public void whenDomainPresenceHasNoEnvironmentItems_createAdminPodStartupWithDefaultItems() {
223251
assertThat(getCreatedPodSpecContainer().getEnv(), not(empty()));

0 commit comments

Comments
 (0)