Skip to content

Commit 6e6f449

Browse files
committed
Fix secure protocol in AdminURL
1 parent 53cf6b6 commit 6e6f449

File tree

5 files changed

+81
-11
lines changed

5 files changed

+81
-11
lines changed

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

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

144+
/**
145+
* Check if the server is listening on a secure port. NOTE: If the targetted server is a managed
146+
* server, this method is overridden to check if the managed server has a secure listen port rather
147+
* than the admin server. See PodHelper.ManagedPodStepContext
148+
*
149+
* @return true if server is listening on a secure port
150+
*/
144151
boolean isLocalAdminProtocolChannelSecure() {
145152
return domainTopology
146153
.getServerConfig(domainTopology.getAdminServerName())
147154
.isLocalAdminProtocolChannelSecure();
148155
}
149156

157+
/**
158+
* Check if the admin server is listening on a secure port.
159+
*
160+
* @return true if admin server is listening on a secure port
161+
*/
162+
private boolean isAdminServerProtocolChannelSecure() {
163+
return domainTopology
164+
.getServerConfig(domainTopology.getAdminServerName())
165+
.isLocalAdminProtocolChannelSecure();
166+
}
167+
168+
150169
Integer getLocalAdminProtocolChannelPort() {
151170
return domainTopology
152171
.getServerConfig(domainTopology.getAdminServerName())
@@ -603,6 +622,13 @@ void overrideContainerWeblogicEnvVars(List<V1EnvVar> vars) {
603622
if (isLocalAdminProtocolChannelSecure()) {
604623
addEnvVar(vars, "ADMIN_PORT_SECURE", "true");
605624
}
625+
if (isAdminServerProtocolChannelSecure()) {
626+
// The following env variable determines whether to set a secure protocol(https/t3s) in the "AdminURL" property
627+
// in NM startup.properties.
628+
// WebLogic Node Manager then sets the ADMIN_URL env variable(based on the "AdminURL") before starting
629+
// the managed server
630+
addEnvVar(vars, "ADMIN_SERVER_PORT_SECURE", "true");
631+
}
606632
addEnvVar(vars, "SERVER_NAME", getServerName());
607633
addEnvVar(vars, "DOMAIN_UID", getDomainUid());
608634
addEnvVar(vars, "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=$(getAdminUrl)
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=$(getAdminUrl)
405+
#
406+
function getAdminUrl() {
407+
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)