Skip to content

Commit d8f9e47

Browse files
ShashikanthRaoTGitHub Enterprise
authored andcommitted
Srt 2872 fix crashloopback error when using default developer configuration on a readonly root filesystem enabled (#556)
* Fix default devimage with rorfs issue * Added new docker test
1 parent 14be193 commit d8f9e47

File tree

4 files changed

+80
-12
lines changed

4 files changed

+80
-12
lines changed

Dockerfile-server

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ LABEL summary="IBM MQ Advanced for Developers Server" \
181181
base-image-release=$BASE_TAG
182182
USER 0
183183
COPY --from=cbuilder /opt/app-root/src/authservice/mqhtpass/build/mqhtpass.so /opt/mqm/lib64/
184-
COPY etc/mqm/qm-service-component.ini /run
184+
COPY etc/mqm/qm-service-component.ini.default /etc/mqm/
185185
COPY incubating/mqadvanced-server-dev/install-extra-packages.sh /usr/local/bin/
186186
RUN chmod u+x /usr/local/bin/install-extra-packages.sh \
187187
&& sleep 1 \
@@ -196,8 +196,6 @@ RUN ln -s /run/10-dev.mqsc /etc/mqm/10-dev.mqsc \
196196
RUN chown -R 1001:root /etc/mqm/* \
197197
&& chmod -R g+w /etc/mqm/web \
198198
&& chmod +x /usr/local/bin/runmq* \
199-
# Allow contents of qm-service-component.ini to be cleaned if MQ_CONNAUTH_USE_HTP is not set to true
200-
&& chmod 0660 /run/qm-service-component.ini \
201199
&& ln -s /run/qm-service-component.ini /etc/mqm/qm-service-component.ini
202200

203201
ENV MQ_DEV=true \

cmd/runmqdevserver/main.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222
"syscall"
2323

24+
"github.com/ibm-messaging/mq-container/internal/copy"
2425
"github.com/ibm-messaging/mq-container/internal/htpasswd"
2526
"github.com/ibm-messaging/mq-container/pkg/containerruntimelogger"
2627
"github.com/ibm-messaging/mq-container/pkg/logger"
@@ -127,6 +128,14 @@ func doMain() error {
127128
return err
128129
}
129130

131+
// Initialise /run/qm-service-component.ini file on ephemeral volume
132+
// #nosec G306 - its a read by owner/s group, and pose no harm.
133+
err = os.WriteFile("/run/qm-service-component.ini", []byte(""), 0660)
134+
if err != nil {
135+
logTermination(err)
136+
return err
137+
}
138+
130139
// Enable mq htpasswd if MQ_CONNAUTH_USE_HTP is set true
131140
// and either or both of MQ_APP_PASSWORD and MQ_ADMIN_PASSWORD
132141
// environment variables specified.
@@ -135,6 +144,11 @@ func doMain() error {
135144
appPassword, appPwdset := os.LookupEnv("MQ_APP_PASSWORD")
136145
if set && strings.EqualFold(enableHtPwd, "true") &&
137146
(adminPwdset && len(strings.TrimSpace(adminPassword)) > 0 || appPwdset && len(strings.TrimSpace(appPassword)) > 0) {
147+
err = copy.CopyFile("/etc/mqm/qm-service-component.ini.default", "/run/qm-service-component.ini")
148+
if err != nil {
149+
logTermination(err)
150+
return err
151+
}
138152
// Create an empty mq.htpasswd file on ephemeral volume
139153
// #nosec G306 - its a write by owner/s group, and pose no harm.
140154
err = os.WriteFile("/run/mq.htpasswd", []byte(""), 0660)
@@ -158,15 +172,6 @@ func doMain() error {
158172
return err
159173
}
160174
}
161-
} else {
162-
// Clean contents of qm-service-component.ini if MQ_CONNAUTH_USE_HTP is not set to true
163-
// so that mq.htpasswd exit is not loaded by queue manager
164-
// #nosec G306 - its a write by owner/s group, and pose no harm.
165-
err = os.WriteFile("/run/qm-service-component.ini", []byte(""), 0660)
166-
if err != nil {
167-
logTermination(err)
168-
return err
169-
}
170175
}
171176

172177
err = updateMQSC(set)
File renamed without changes.

test/container/devconfig_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,3 +847,68 @@ func testDevNoDefaultCredsUtil(t *testing.T, mqhtpassEnvs []string, htpwdInLog b
847847
}
848848
}
849849
}
850+
851+
// Test REST messaging with default developer configuration
852+
// MQ_CONNAUTH_USE_HTP is set to true in the dev image with
853+
// read only root filesystem enabled. The test
854+
// specifies password for admin userId via MQ_ADMIN_PASSWORD
855+
// environment variable but then attempts to do REST messaging
856+
// usig 'app' userId. HTTP 401 is expected.
857+
func TestRORFSDevNoAppPassword(t *testing.T) {
858+
t.Parallel()
859+
cli := ce.NewContainerClient()
860+
qm := "QM1"
861+
containerConfig := ce.ContainerConfig{
862+
Env: []string{
863+
"LICENSE=accept",
864+
"MQ_QMGR_NAME=" + qm,
865+
"DEBUG=true",
866+
"MQ_CONNAUTH_USE_HTP=true",
867+
"MQ_ADMIN_PASSWORD=" + defaultAdminPassword,
868+
},
869+
Image: imageName(),
870+
}
871+
872+
// Create volumes for mounting into container
873+
ephData := createVolume(t, cli, "ephData"+t.Name())
874+
defer removeVolume(t, cli, ephData)
875+
ephRun := createVolume(t, cli, "ephRun"+t.Name())
876+
defer removeVolume(t, cli, ephRun)
877+
ephTmp := createVolume(t, cli, "ephTmp"+t.Name())
878+
defer removeVolume(t, cli, ephTmp)
879+
880+
hostConfig := ce.ContainerHostConfig{
881+
Binds: []string{
882+
coverageBind(t),
883+
ephRun + ":/run",
884+
ephTmp + ":/tmp",
885+
ephData + ":/mnt/mqm",
886+
},
887+
ReadOnlyRootfs: true, //Enable read only root filesystem
888+
}
889+
// Assign a random port for the web server on the host
890+
var binding ce.PortBinding
891+
ports := []int{9443}
892+
for _, p := range ports {
893+
port := fmt.Sprintf("%v/tcp", p)
894+
binding = ce.PortBinding{
895+
ContainerPort: port,
896+
HostIP: "0.0.0.0",
897+
}
898+
hostConfig.PortBindings = append(hostConfig.PortBindings, binding)
899+
}
900+
networkingConfig := ce.ContainerNetworkSettings{}
901+
id, err := cli.ContainerCreate(&containerConfig, &hostConfig, &networkingConfig, t.Name())
902+
if err != nil {
903+
t.Fatal(err)
904+
}
905+
defer cleanContainer(t, cli, id)
906+
startContainer(t, cli, id)
907+
908+
waitForReady(t, cli, id)
909+
waitForWebReady(t, cli, id, insecureTLSConfig)
910+
// Expect a 401 Unauthorized HTTP Response
911+
testRESTMessaging(t, cli, id, insecureTLSConfig, qm, "app", defaultAppPasswordWeb, "401 Unauthorized")
912+
// Stop the container cleanly
913+
stopContainer(t, cli, id)
914+
}

0 commit comments

Comments
 (0)