Skip to content

Commit 9c054e5

Browse files
authored
Make access log pattern configurable for Jira and Confluence when running as non root (#961)
Co-authored-by: Yevhen Ivantsov <[email protected]>
1 parent cff3e3c commit 9c054e5

File tree

13 files changed

+41
-8
lines changed

13 files changed

+41
-8
lines changed

docs/docs/containers/CONFLUENCE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ see <https://tomcat.apache.org/tomcat-7.0-doc/config/index.html>.
191191
You can set the maximum number of days for access logs to be retained before being deleted. The default value of -1 means never delete old files.
192192

193193
* `ATL_TOMCAT_ACCESS_LOGS_MAXDAYS` (default: -1)
194+
* `ATL_TOMCAT_ACCESS_LOG_PATTERN` (default: `%h %{X-AUSERNAME}o %t &quot;%r&quot; %s %b %D %U %I &quot;%{User-Agent}i&quot;`)
194195

195196
### JVM configuration
196197

docs/docs/containers/JIRA.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ see https://tomcat.apache.org/tomcat-7.0-doc/config/index.html.
183183
You can set the maximum number of days for access logs to be retained before being deleted. The default value of -1 means never delete old files.
184184

185185
* `ATL_TOMCAT_ACCESS_LOGS_MAXDAYS` (default: -1)
186+
* `ATL_TOMCAT_ACCESS_LOG_PATTERN` (default: `%a %{jira.request.id}r %{jira.request.username}r %t &quot;%m %U%q %H&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot; &quot;%{jira.request.assession.id}r&quot;`)
186187

187188
### JVM configuration
188189

src/main/charts/confluence/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Kubernetes: `>=1.21.x-0`
104104
| confluence.startupProbe.failureThreshold | int | `120` | The number of consecutive failures of the Confluence container startup probe before the pod fails startup checks. |
105105
| confluence.startupProbe.initialDelaySeconds | int | `60` | Time to wait before starting the first probe |
106106
| confluence.startupProbe.periodSeconds | int | `5` | How often (in seconds) the Confluence container startup probe will run |
107-
| confluence.tomcatConfig | object | `{"acceptCount":"100","accessLogMaxDays":"-1","connectionTimeout":"20000","customServerXml":"","debug":"0","enableLookups":"false","generateByHelm":false,"maxHttpHeaderSize":"8192","maxThreads":"100","mgmtPort":"8000","minSpareThreads":"10","port":"8090","protocol":"org.apache.coyote.http11.Http11NioProtocol","proxyInternalIps":null,"proxyName":null,"proxyPort":null,"redirectPort":"8443","requestAttributesEnabled":"false","scheme":null,"secure":null,"stuckThreadDetectionValveThreshold":"60","trustedProxies":null,"uriEncoding":"UTF-8"}` | By default Tomcat's server.xml is generated in the container entrypoint from a template shipped with an official Confluence image. However, server.xml generation may fail if container is not run as root, which is a common case if Confluence is deployed to OpenShift. |
107+
| confluence.tomcatConfig | object | `{"acceptCount":"100","accessLogMaxDays":"-1","accessLogPattern":"%h %{X-AUSERNAME}o %t &quot;%r&quot; %s %b %D %U %I &quot;%{User-Agent}i&quot;","connectionTimeout":"20000","customServerXml":"","debug":"0","enableLookups":"false","generateByHelm":false,"maxHttpHeaderSize":"8192","maxThreads":"100","mgmtPort":"8000","minSpareThreads":"10","port":"8090","protocol":"org.apache.coyote.http11.Http11NioProtocol","proxyInternalIps":null,"proxyName":null,"proxyPort":null,"redirectPort":"8443","requestAttributesEnabled":"false","scheme":null,"secure":null,"stuckThreadDetectionValveThreshold":"60","trustedProxies":null,"uriEncoding":"UTF-8"}` | By default Tomcat's server.xml is generated in the container entrypoint from a template shipped with an official Confluence image. However, server.xml generation may fail if container is not run as root, which is a common case if Confluence is deployed to OpenShift. |
108108
| confluence.tomcatConfig.customServerXml | string | `""` | Custom server.xml to be mounted into /opt/atlassian/confluence/conf |
109109
| confluence.tomcatConfig.generateByHelm | bool | `false` | Mount server.xml as a ConfigMap. Override configuration elements if necessary |
110110
| confluence.topologySpreadConstraints | list | `[]` | Defines topology spread constraints for Confluence pods. See details: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/ |

src/main/charts/confluence/templates/configmap-server-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ data:
7070
suffix=".log"
7171
rotatable="true"
7272
maxDays="{{ .Values.confluence.tomcatConfig.accessLogMaxDays | default "-1" }}"
73-
pattern="%h %{X-AUSERNAME}o %t &quot;%r&quot; %s %b %D %U %I &quot;%{User-Agent}i&quot;" />
73+
pattern="{{ .Values.confluence.tomcatConfig.accessLogPattern }}" />
7474
<Valve className="org.apache.catalina.valves.RemoteIpValve"
7575
proxiesHeader="x-forwarded-by"
7676
{{- if .Values.confluence.tomcatConfig.proxyInternalIps }}

src/main/charts/confluence/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ confluence:
961961
trustedProxies:
962962
stuckThreadDetectionValveThreshold: "60"
963963
accessLogMaxDays: "-1"
964+
accessLogPattern: "%h %{X-AUSERNAME}o %t &quot;%r&quot; %s %b %D %U %I &quot;%{User-Agent}i&quot;"
964965
requestAttributesEnabled: "false"
965966

966967
# -- Custom server.xml to be mounted into /opt/atlassian/confluence/conf

src/main/charts/jira/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Kubernetes: `>=1.21.x-0`
137137
| jira.startupProbe.failureThreshold | int | `120` | The number of consecutive failures of the Jira container startup probe before the pod fails startup checks. |
138138
| jira.startupProbe.initialDelaySeconds | int | `60` | Time to wait before starting the first probe |
139139
| jira.startupProbe.periodSeconds | int | `5` | How often (in seconds) the Jira container startup probe will run |
140-
| jira.tomcatConfig | object | `{"acceptCount":"100","accessLogMaxDays":"-1","connectionTimeout":"20000","customServerXml":"","enableLookups":"false","generateByHelm":false,"maxHttpHeaderSize":"8192","maxThreads":"100","mgmtPort":"8005","minSpareThreads":"10","port":"8080","protocol":"HTTP/1.1","proxyName":null,"proxyPort":null,"redirectPort":"8443","requestAttributesEnabled":"false","scheme":null,"secure":null,"stuckThreadDetectionValveThreshold":"120"}` | By default Tomcat's server.xml is generated in the container entrypoint from a template shipped with an official Jira image. However, server.xml generation may fail if container is not run as root, which is a common case if Jira is deployed to OpenShift. |
140+
| jira.tomcatConfig | object | `{"acceptCount":"100","accessLogMaxDays":"-1","accessLogPattern":"%a %{jira.request.id}r %{jira.request.username}r %t &quot;%m %U%q %H&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot; &quot;%{jira.request.assession.id}r&quot;","connectionTimeout":"20000","customServerXml":"","enableLookups":"false","generateByHelm":false,"maxHttpHeaderSize":"8192","maxThreads":"100","mgmtPort":"8005","minSpareThreads":"10","port":"8080","protocol":"HTTP/1.1","proxyName":null,"proxyPort":null,"redirectPort":"8443","requestAttributesEnabled":"false","scheme":null,"secure":null,"stuckThreadDetectionValveThreshold":"120"}` | By default Tomcat's server.xml is generated in the container entrypoint from a template shipped with an official Jira image. However, server.xml generation may fail if container is not run as root, which is a common case if Jira is deployed to OpenShift. |
141141
| jira.tomcatConfig.customServerXml | string | `""` | Custom server.xml to be mounted into /opt/atlassian/jira/conf |
142142
| jira.tomcatConfig.generateByHelm | bool | `false` | Mount server.xml as a ConfigMap. Override configuration elements if necessary |
143143
| jira.topologySpreadConstraints | list | `[]` | Defines topology spread constraints for Jira pods. See details: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/ |

src/main/charts/jira/templates/configmap-server-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ data:
8686
<Valve className="org.apache.catalina.valves.AccessLogValve"
8787
maxDays="{{ .Values.jira.tomcatConfig.accessLogMaxDays | default "-1" }}"
8888
requestAttributesEnabled="{{ .Values.jira.tomcatConfig.requestAttributesEnabled | default "false" }}"
89-
pattern="%a %{jira.request.id}r %{jira.request.username}r %t &quot;%m %U%q %H&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot; &quot;%{jira.request.assession.id}r&quot;"/>
89+
pattern="{{ .Values.jira.tomcatConfig.accessLogPattern }}"/>
9090
</Engine>
9191

9292
</Service>

src/main/charts/jira/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ jira:
825825
maxHttpHeaderSize: "8192"
826826
stuckThreadDetectionValveThreshold: "120"
827827
accessLogMaxDays: "-1"
828+
accessLogPattern: "%a %{jira.request.id}r %{jira.request.username}r %t &quot;%m %U%q %H&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot; &quot;%{jira.request.assession.id}r&quot;"
828829
requestAttributesEnabled: "false"
829830

830831
# -- Custom server.xml to be mounted into /opt/atlassian/jira/conf

src/test/java/test/ServerConfigTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,30 @@ void additional_connector_overrides(Product product) throws Exception {
263263
assertThat(serverConfigMap.getConfigMapData().path("server.xml")).hasTextContaining("secure=\"true\"");
264264
assertThat(serverConfigMap.getConfigMapData().path("server.xml")).hasTextContaining("URIEncoding=\"UTF-9\"");
265265
}
266+
267+
@ParameterizedTest
268+
@EnumSource(value = Product.class, names = {"confluence", "jira"}, mode = EnumSource.Mode.INCLUDE)
269+
void access_log_pattern_default(Product product) throws Exception {
270+
final var resources = helm.captureKubeResourcesFromHelmChart(product, Map.of(
271+
product.name() + ".tomcatConfig.generateByHelm", "true"
272+
));
273+
String expectedPattern;
274+
if (product == Product.confluence) {
275+
expectedPattern = "pattern=\"%h %{X-AUSERNAME}o %t &quot;%r&quot; %s %b %D %U %I &quot;%{User-Agent}i&quot;";
276+
} else expectedPattern = "pattern=\"%a %{jira.request.id}r %{jira.request.username}r %t &quot;%m %U%q %H&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot; &quot;%{jira.request.assession.id}r&quot;";
277+
278+
KubeResource serverConfigMap = resources.get(Kind.ConfigMap, product.getHelmReleaseName() + "-server-config");
279+
assertThat(serverConfigMap.getConfigMapData().path("server.xml")).hasTextContaining(expectedPattern);
280+
}
281+
282+
@ParameterizedTest
283+
@EnumSource(value = Product.class, names = {"confluence", "jira"}, mode = EnumSource.Mode.INCLUDE)
284+
void access_log_pattern_overrides(Product product) throws Exception {
285+
final var resources = helm.captureKubeResourcesFromHelmChart(product, Map.of(
286+
product.name() + ".tomcatConfig.generateByHelm", "true",
287+
product.name() + ".tomcatConfig.accessLogPattern", "%%"
288+
));
289+
KubeResource serverConfigMap = resources.get(Kind.ConfigMap, product.getHelmReleaseName() + "-server-config");
290+
assertThat(serverConfigMap.getConfigMapData().path("server.xml")).hasTextContaining("%%");
291+
}
266292
}

src/test/resources/expected_helm_output/bitbucket/output.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ data:
165165
image:
166166
pullPolicy: IfNotPresent
167167
repository: atlassian/bitbucket-mesh
168-
tag: 3.4.0
168+
tag: 3.4.1
169169
nodeAutoRegistration: false
170170
nodeSelector: {}
171171
podAnnotations: {}
@@ -601,7 +601,7 @@ spec:
601601
template:
602602
metadata:
603603
annotations:
604-
checksum/config-jvm: e4aa354a8937cd7fc2a42a8c3d76df9db3ce13533fc820b9aadf79123d502aea
604+
checksum/config-jvm: 43829441bdc498da898213f3137e92733710729b8d5c7203b3233a8b589f837d
605605
labels:
606606
app.kubernetes.io/name: bitbucket-mesh
607607
app.kubernetes.io/instance: unittest-bitbucket
@@ -722,7 +722,7 @@ spec:
722722
template:
723723
metadata:
724724
annotations:
725-
checksum/config-jvm: b6283cca4ebdaceb0aa7da41b3d406dea0129a95c99f25448b3a41e83df4d674
725+
checksum/config-jvm: 292bf7b1ecb603b29737433657afaad632a4f70a8127b8042add339194de8741
726726
labels:
727727
helm.sh/chart: bitbucket-1.22.4
728728
app.kubernetes.io/name: bitbucket

0 commit comments

Comments
 (0)