Skip to content

Commit a8ff0a5

Browse files
ShashikanthRaoTGitHub Enterprise
authored andcommitted
Disable default developer configuration (#541)
* Disable default developer configuration * Add new docker test * Avoid loading of mq.htpasswd exit when MQ_CONNAUTH_USE_HTP not set * Fix gosec error * Copy ini file with specific name * Load mqhtpasswd exit if admin and/or app password and MQ_CONNAUTH_USE_HTP=true * Update develiper configuration documentation * Fix typo and correct function description
1 parent 2c9d713 commit a8ff0a5

File tree

10 files changed

+216
-99
lines changed

10 files changed

+216
-99
lines changed

Dockerfile-server

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ USER 0
3232
WORKDIR $GO_WORKDIR/
3333
ADD $MQ_ARCHIVE /opt/mqm
3434
ENV CGO_CFLAGS="-I/opt/mqm/inc/" \
35-
CGO_LDFLAGS_ALLOW="-Wl,-rpath.*" \
36-
PATH="${PATH}:/opt/mqm/bin"
35+
CGO_LDFLAGS_ALLOW="-Wl,-rpath.*" \
36+
PATH="${PATH}:/opt/mqm/bin"
3737
COPY go.mod go.sum ./
3838
COPY cmd/ ./cmd
3939
COPY internal/ ./internal
@@ -62,27 +62,27 @@ ARG BASE_TAG
6262
ARG MQ_ARCHIVE
6363
WORKDIR /tmp/mq
6464
ENV genmqpkg_inc32=0 \
65-
genmqpkg_incadm=1 \
66-
genmqpkg_incamqp=0 \
67-
genmqpkg_incams=1 \
68-
genmqpkg_inccbl=0 \
69-
genmqpkg_inccics=0 \
70-
genmqpkg_inccpp=0 \
71-
genmqpkg_incdnet=0 \
72-
genmqpkg_incjava=1 \
73-
genmqpkg_incjre=1 \
74-
genmqpkg_incman=0 \
75-
genmqpkg_incmqbc=0 \
76-
genmqpkg_incmqft=0 \
77-
genmqpkg_incmqsf=0 \
78-
genmqpkg_incmqxr=0 \
79-
genmqpkg_incnls=1 \
80-
genmqpkg_incras=1 \
81-
genmqpkg_incsamp=1 \
82-
genmqpkg_incsdk=0 \
83-
genmqpkg_inctls=1 \
84-
genmqpkg_incunthrd=0 \
85-
genmqpkg_incweb=1
65+
genmqpkg_incadm=1 \
66+
genmqpkg_incamqp=0 \
67+
genmqpkg_incams=1 \
68+
genmqpkg_inccbl=0 \
69+
genmqpkg_inccics=0 \
70+
genmqpkg_inccpp=0 \
71+
genmqpkg_incdnet=0 \
72+
genmqpkg_incjava=1 \
73+
genmqpkg_incjre=1 \
74+
genmqpkg_incman=0 \
75+
genmqpkg_incmqbc=0 \
76+
genmqpkg_incmqft=0 \
77+
genmqpkg_incmqsf=0 \
78+
genmqpkg_incmqxr=0 \
79+
genmqpkg_incnls=1 \
80+
genmqpkg_incras=1 \
81+
genmqpkg_incsamp=1 \
82+
genmqpkg_incsdk=0 \
83+
genmqpkg_inctls=1 \
84+
genmqpkg_incunthrd=0 \
85+
genmqpkg_incweb=1
8686
ADD $MQ_ARCHIVE /opt/mqm-noinstall
8787
# Run genmqpkg to reduce the MQ packages included
8888
RUN /opt/mqm-noinstall/bin/genmqpkg.sh -b /opt/mqm-redux
@@ -96,17 +96,17 @@ ARG BASE_IMAGE
9696
ARG BASE_TAG
9797
ARG GO_WORKDIR
9898
LABEL summary="IBM MQ Advanced Server" \
99-
description="Simplify, accelerate and facilitate the reliable exchange of data with a security-rich messaging solution — trusted by the world’s most successful enterprises" \
100-
vendor="IBM" \
101-
maintainer="IBM" \
102-
distribution-scope="private" \
103-
authoritative-source-url="https://www.ibm.com/software/passportadvantage/" \
104-
url="https://www.ibm.com/products/mq/advanced" \
105-
io.openshift.tags="mq messaging" \
106-
io.k8s.display-name="IBM MQ Advanced Server" \
107-
io.k8s.description="Simplify, accelerate and facilitate the reliable exchange of data with a security-rich messaging solution — trusted by the world’s most successful enterprises" \
108-
base-image=$BASE_IMAGE \
109-
base-image-release=$BASE_TAG
99+
description="Simplify, accelerate and facilitate the reliable exchange of data with a security-rich messaging solution — trusted by the world’s most successful enterprises" \
100+
vendor="IBM" \
101+
maintainer="IBM" \
102+
distribution-scope="private" \
103+
authoritative-source-url="https://www.ibm.com/software/passportadvantage/" \
104+
url="https://www.ibm.com/products/mq/advanced" \
105+
io.openshift.tags="mq messaging" \
106+
io.k8s.display-name="IBM MQ Advanced Server" \
107+
io.k8s.description="Simplify, accelerate and facilitate the reliable exchange of data with a security-rich messaging solution — trusted by the world’s most successful enterprises" \
108+
base-image=$BASE_IMAGE \
109+
base-image-release=$BASE_TAG
110110
COPY --from=mq-redux /opt/mqm-redux/ /opt/mqm/
111111
COPY setup-image.sh /usr/local/bin/
112112
COPY install-mq-server-prereqs.sh /usr/local/bin/
@@ -169,19 +169,19 @@ ARG BASE_IMAGE
169169
ARG BASE_TAG
170170
ARG GO_WORKDIR
171171
LABEL summary="IBM MQ Advanced for Developers Server" \
172-
description="Simplify, accelerate and facilitate the reliable exchange of data with a security-rich messaging solution — trusted by the world’s most successful enterprises" \
173-
vendor="IBM" \
174-
distribution-scope="private" \
175-
authoritative-source-url="https://www.ibm.com/software/passportadvantage/" \
176-
url="https://www.ibm.com/products/mq/advanced" \
177-
io.openshift.tags="mq messaging" \
178-
io.k8s.display-name="IBM MQ Advanced for Developers Server" \
179-
io.k8s.description="Simplify, accelerate and facilitate the reliable exchange of data with a security-rich messaging solution — trusted by the world’s most successful enterprises" \
180-
base-image=$BASE_IMAGE \
181-
base-image-release=$BASE_TAG
172+
description="Simplify, accelerate and facilitate the reliable exchange of data with a security-rich messaging solution — trusted by the world’s most successful enterprises" \
173+
vendor="IBM" \
174+
distribution-scope="private" \
175+
authoritative-source-url="https://www.ibm.com/software/passportadvantage/" \
176+
url="https://www.ibm.com/products/mq/advanced" \
177+
io.openshift.tags="mq messaging" \
178+
io.k8s.display-name="IBM MQ Advanced for Developers Server" \
179+
io.k8s.description="Simplify, accelerate and facilitate the reliable exchange of data with a security-rich messaging solution — trusted by the world’s most successful enterprises" \
180+
base-image=$BASE_IMAGE \
181+
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/*.ini /etc/mqm/
184+
COPY etc/mqm/qm-service-component.ini /run
185185
COPY etc/mqm/mq.htpasswd.default /etc/mqm/
186186
COPY incubating/mqadvanced-server-dev/install-extra-packages.sh /usr/local/bin/
187187
RUN chmod u+x /usr/local/bin/install-extra-packages.sh \
@@ -197,13 +197,16 @@ RUN ln -s /run/10-dev.mqsc /etc/mqm/10-dev.mqsc \
197197
RUN chown -R 1001:root /etc/mqm/* \
198198
&& chmod -R g+w /etc/mqm/web \
199199
&& chmod +x /usr/local/bin/runmq* \
200-
&& chmod 0660 /etc/mqm/mq.htpasswd.default
201-
200+
&& chmod 0660 /etc/mqm/mq.htpasswd.default \
201+
# Allow contents of qm-service-component.ini to be cleaned if MQ_CONNAUTH_USE_HTP is not set to true
202+
&& chmod 0660 /run/qm-service-component.ini \
203+
&& ln -s /run/qm-service-component.ini /etc/mqm/qm-service-component.ini
204+
202205
ENV MQ_DEV=true \
203-
MQ_ENABLE_EMBEDDED_WEB_SERVER=1 \
204-
MQ_GENERATE_CERTIFICATE_HOSTNAME=localhost \
205-
LD_LIBRARY_PATH=/opt/mqm/lib64 \
206-
MQ_CONNAUTH_USE_HTP=true \
207-
MQS_PERMIT_UNKNOWN_ID=true
206+
MQ_ENABLE_EMBEDDED_WEB_SERVER=1 \
207+
MQ_GENERATE_CERTIFICATE_HOSTNAME=localhost \
208+
LD_LIBRARY_PATH=/opt/mqm/lib64 \
209+
MQ_CONNAUTH_USE_HTP=true \
210+
MQS_PERMIT_UNKNOWN_ID=true
208211
USER 1001
209212
ENTRYPOINT ["runmqdevserver"]

cmd/runmqdevserver/main.go

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,43 @@ func doMain() error {
128128
return err
129129
}
130130

131-
// Copy default mq.htpasswd file to ephemeral volume
132-
err = copy.CopyFile("/etc/mqm/mq.htpasswd.default", "/run/mq.htpasswd")
133-
if err != nil {
134-
logTermination(err)
135-
return err
136-
}
137-
138-
adminPassword, set := os.LookupEnv("MQ_ADMIN_PASSWORD")
139-
if !set {
140-
adminPassword = "passw0rd"
141-
err = os.Setenv("MQ_ADMIN_PASSWORD", adminPassword)
131+
// Enable mq htpasswd if MQ_CONNAUTH_USE_HTP is set true
132+
// and either or both of MQ_APP_PASSWORD and MQ_ADMIN_PASSWORD
133+
// environment variables specified.
134+
enableHtPwd, set := os.LookupEnv("MQ_CONNAUTH_USE_HTP")
135+
adminPassword, adminPwdset := os.LookupEnv("MQ_ADMIN_PASSWORD")
136+
appPassword, appPwdset := os.LookupEnv("MQ_APP_PASSWORD")
137+
if set && strings.EqualFold(enableHtPwd, "true") &&
138+
(adminPwdset && len(strings.TrimSpace(adminPassword)) > 0 || appPwdset && len(strings.TrimSpace(appPassword)) > 0) {
139+
// Copy default mq.htpasswd file to ephemeral volume
140+
err = copy.CopyFile("/etc/mqm/mq.htpasswd.default", "/run/mq.htpasswd")
142141
if err != nil {
143-
logTerminationf("Error setting admin password variable: %v", err)
142+
logTermination(err)
144143
return err
145144
}
146-
}
147-
err = htpasswd.SetPassword("admin", adminPassword, false)
148-
if err != nil {
149-
logTerminationf("Error setting admin password: %v", err)
150-
return err
151-
}
152145

153-
appPassword, set := os.LookupEnv("MQ_APP_PASSWORD")
154-
if set {
155-
err = htpasswd.SetPassword("app", appPassword, false)
146+
if adminPwdset {
147+
err = htpasswd.SetPassword("admin", adminPassword, false)
148+
if err != nil {
149+
logTerminationf("Error setting admin password: %v", err)
150+
return err
151+
}
152+
}
153+
154+
if appPwdset {
155+
err = htpasswd.SetPassword("app", appPassword, false)
156+
if err != nil {
157+
logTerminationf("Error setting app password: %v", err)
158+
return err
159+
}
160+
}
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)
156166
if err != nil {
157-
logTerminationf("Error setting app password: %v", err)
167+
logTermination(err)
158168
return err
159169
}
160170
}

cmd/runmqserver/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/ibm-messaging/mq-container/internal/copy"
2828
"github.com/ibm-messaging/mq-container/internal/fips"
2929
"github.com/ibm-messaging/mq-container/internal/ha"
30+
"github.com/ibm-messaging/mq-container/internal/htpasswd"
3031
"github.com/ibm-messaging/mq-container/internal/metrics"
3132
"github.com/ibm-messaging/mq-container/internal/ready"
3233
"github.com/ibm-messaging/mq-container/internal/tls"
@@ -329,7 +330,7 @@ func doMain() error {
329330
}
330331
}
331332

332-
if *devFlag {
333+
if *devFlag && htpasswd.IsEnabled() {
333334
_, err = mirrorHTPasswdLogs(ctx, &wg, name, newQM, mf)
334335
if err != nil {
335336
logTermination(err)
@@ -354,7 +355,7 @@ func doMain() error {
354355

355356
// This is a developer image only change
356357
// This workaround should be removed and handled via <crtmqm -ii>, when inimerge is ready to handle stanza ordering
357-
if *devFlag {
358+
if *devFlag && htpasswd.IsEnabled() {
358359
err = updateQMini(name)
359360
if err != nil {
360361
logTermination(err)

cmd/runmqserver/webserver.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,9 @@ func startWebServer(webKeystore, webkeystorePW, webTruststoreRef string) error {
3535
log.Println("Starting web server")
3636
// #nosec G204 - command is fixed, no injection vector
3737
cmd := exec.Command("strmqweb")
38-
// Set a default app password for the web server, if one isn't already set
39-
_, set := os.LookupEnv("MQ_APP_PASSWORD")
40-
if !set {
41-
// Take all current environment variables, and add the app password
42-
cmd.Env = append(os.Environ(), "MQ_APP_PASSWORD=passw0rd")
43-
} else {
44-
cmd.Env = os.Environ()
45-
}
38+
39+
// Pass all the environment to MQ Web Server JVM
40+
cmd.Env = os.Environ()
4641

4742
// TLS enabled
4843
if webKeystore != "" {

docs/developer-config.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ If you build this image with MQ Advanced for Developers, then an optional set of
77
The MQ Developer Defaults supports some customization options, these are all controlled using environment variables:
88

99
* **MQ_DEV** - Set this to `false` to stop the default objects being created.
10-
* **MQ_ADMIN_PASSWORD** - Changes the password of the `admin` user. Must be at least 8 characters long.
11-
* **MQ_APP_PASSWORD** - Changes the password of the app user. If set, this will cause the `DEV.APP.SVRCONN` channel to become secured and only allow connections that supply a valid userid and password. Must be at least 8 characters long.
10+
* **MQ_ADMIN_PASSWORD** - Specify the password of the `admin` user. Must be at least 8 characters long.
11+
* **MQ_APP_PASSWORD** - Specify the password of the `app` user. If set, this will cause the `DEV.APP.SVRCONN` channel to become secured and only allow connections that supply a valid userid and password. Must be at least 8 characters long.
1212

1313
## Details of the default configuration
1414

1515
The following users are created:
1616

17-
* User **admin** for administration. Default password is **passw0rd**.
18-
* User **app** for messaging (in a group called `mqclient`). No password by default.
17+
* User **admin** for administration. No password by default. Password must be set using **MQ_ADMIN_PASSWORD** environment variable.
18+
* User **app** for messaging (in a group called `mqclient`). No password by default. Password must be set using **MQ_APP_PASSWORD** environment variable.
1919

2020
Users in `mqclient` group have been given access connect to all queues and topics starting with `DEV.**` and have `put`, `get`, `pub`, `sub`, `browse` and `inq` permissions.
2121

@@ -41,8 +41,6 @@ When you navigate to this page you may be presented with a security exception wa
4141
If you choose to accept the security warning, you will be presented with the login menu for the IBM MQ Web Console. The default login for the console is:
4242

4343
* **User:** admin
44-
* **Password:** passw0rd
45-
46-
If you wish to change the password for the admin user, this can be done using the `MQ_ADMIN_PASSWORD` environment variable.
44+
* **Password:** No password by default. The password for the admin user must be specified using the `MQ_ADMIN_PASSWORD` environment variable.
4745

4846
If you do not wish the web console to run, you can disable it by setting the environment variable `MQ_ENABLE_EMBEDDED_WEB_SERVER` to `false`.

incubating/mqadvanced-server-dev/web/installations/Installation1/servers/mqweb/mqwebcontainer.xml.dev

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
</enterpriseApplication>
2424
<basicRegistry id="basic" realm="defaultRealm">
2525
<user name="admin" password="${env.MQ_ADMIN_PASSWORD}"/>
26-
<!-- The app user will always get a default password of "passw0rd",
27-
even if you don't set the environment variable.
28-
See `webserver.go` -->
2926
<user name="app" password="${env.MQ_APP_PASSWORD}"/>
3027
<group name="MQWebUI">
3128
<member name="admin"/>

internal/htpasswd/htpasswd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,15 @@ func (htpfile mapHtPasswd) updateHtPasswordFile(isTest bool) error {
111111
// #nosec G306 - its a read by owner/s group, and pose no harm.
112112
return os.WriteFile(file, htpfile.GetBytes(), 0660)
113113
}
114+
115+
func IsEnabled() bool {
116+
htpassEnabled := false
117+
enableHtPwd, set := os.LookupEnv("MQ_CONNAUTH_USE_HTP")
118+
adminPassword, adminPwdset := os.LookupEnv("MQ_ADMIN_PASSWORD")
119+
appPassword, appPwdset := os.LookupEnv("MQ_APP_PASSWORD")
120+
if set && strings.EqualFold(enableHtPwd, "true") &&
121+
(adminPwdset && len(strings.TrimSpace(adminPassword)) > 0 || appPwdset && len(strings.TrimSpace(appPassword)) > 0) {
122+
htpassEnabled = true
123+
}
124+
return htpassEnabled
125+
}

0 commit comments

Comments
 (0)