Skip to content

Commit bf6cc4a

Browse files
wrenixjessebot
andauthored
fix: improve handling of config files (#480)
* fix: improve handling of config file Signed-off-by: WrenIX <[email protected]> * change all the gotmpl file extensions to be tpl Signed-off-by: jessebot <[email protected]> --------- Signed-off-by: WrenIX <[email protected]> Signed-off-by: Jesse Hitch <[email protected]> Signed-off-by: jessebot <[email protected]> Co-authored-by: Jesse Hitch <[email protected]>
1 parent 34fc2df commit bf6cc4a

File tree

13 files changed

+248
-263
lines changed

13 files changed

+248
-263
lines changed

charts/nextcloud/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: nextcloud
3-
version: 5.3.1
3+
version: 5.3.2
44
appVersion: 29.0.4
55
description: A file sharing server that puts the control and security of your own data back into your hands.
66
keywords:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# line below if for Apache 2.4
2+
<ifModule mod_authz_core.c>
3+
Require all denied
4+
</ifModule>
5+
# line below if for Apache 2.2
6+
<ifModule !mod_authz_core.c>
7+
deny from all
8+
</ifModule>
9+
# section for Apache 2.2 and 2.4
10+
<ifModule mod_autoindex.c>
11+
IndexIgnore *
12+
</ifModule>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
$CONFIG = array (
3+
'htaccess.RewriteBase' => '/',
4+
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
$CONFIG = array (
3+
'memcache.local' => '\OC\Memcache\APCu',
4+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
$CONFIG = array (
3+
"apps_paths" => array (
4+
0 => array (
5+
"path" => OC::$SERVERROOT."/apps",
6+
"url" => "/apps",
7+
"writable" => false,
8+
),
9+
1 => array (
10+
"path" => OC::$SERVERROOT."/custom_apps",
11+
"url" => "/custom_apps",
12+
"writable" => true,
13+
),
14+
),
15+
);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
$autoconfig_enabled = false;
3+
if (getenv('SQLITE_DATABASE')) {
4+
$AUTOCONFIG["dbtype"] = "sqlite";
5+
$AUTOCONFIG["dbname"] = getenv('SQLITE_DATABASE');
6+
$autoconfig_enabled = true;
7+
} elseif (getenv('MYSQL_DATABASE') && getenv('MYSQL_USER') && getenv('MYSQL_PASSWORD') && getenv('MYSQL_HOST')) {
8+
$AUTOCONFIG["dbtype"] = "mysql";
9+
$AUTOCONFIG["dbname"] = getenv('MYSQL_DATABASE');
10+
$AUTOCONFIG["dbuser"] = getenv('MYSQL_USER');
11+
$AUTOCONFIG["dbpass"] = getenv('MYSQL_PASSWORD');
12+
$AUTOCONFIG["dbhost"] = getenv('MYSQL_HOST');
13+
$autoconfig_enabled = true;
14+
} elseif (getenv('POSTGRES_DB') && getenv('POSTGRES_USER') && getenv('POSTGRES_PASSWORD') && getenv('POSTGRES_HOST')) {
15+
$AUTOCONFIG["dbtype"] = "pgsql";
16+
$AUTOCONFIG["dbname"] = getenv('POSTGRES_DB');
17+
$AUTOCONFIG["dbuser"] = getenv('POSTGRES_USER');
18+
$AUTOCONFIG["dbpass"] = getenv('POSTGRES_PASSWORD');
19+
$AUTOCONFIG["dbhost"] = getenv('POSTGRES_HOST');
20+
$autoconfig_enabled = true;
21+
}
22+
if ($autoconfig_enabled) {
23+
$AUTOCONFIG["directory"] = getenv('NEXTCLOUD_DATA_DIR') ?: "/var/www/html/data";
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
if (getenv('REDIS_HOST')) {
3+
$CONFIG = array (
4+
'memcache.distributed' => '\OC\Memcache\Redis',
5+
'memcache.locking' => '\OC\Memcache\Redis',
6+
'redis' => array(
7+
'host' => getenv('REDIS_HOST'),
8+
'port' => getenv('REDIS_HOST_PORT') ?: 6379,
9+
{{- if .Values.redis.auth.enabled }}
10+
'password' => getenv('REDIS_HOST_PASSWORD'),
11+
{{- end }}
12+
),
13+
);
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) {
3+
$CONFIG = array (
4+
'mail_smtpmode' => 'smtp',
5+
'mail_smtphost' => getenv('SMTP_HOST'),
6+
'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25),
7+
'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '',
8+
'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'),
9+
'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN',
10+
'mail_smtpname' => getenv('SMTP_NAME') ?: '',
11+
'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '',
12+
'mail_from_address' => getenv('MAIL_FROM_ADDRESS'),
13+
'mail_domain' => getenv('MAIL_DOMAIN'),
14+
);
15+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
upstream php-handler {
2+
server 127.0.0.1:9000;
3+
}
4+
5+
server {
6+
listen {{ .Values.nginx.containerPort }};
7+
8+
# HSTS settings
9+
# WARNING: Only add the preload option once you read about
10+
# the consequences in https://hstspreload.org/. This option
11+
# will add the domain to a hardcoded list that is shipped
12+
# in all major browsers and getting removed from this list
13+
# could take several months.
14+
#add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
15+
16+
# set max upload size
17+
client_max_body_size 10G;
18+
fastcgi_buffers 64 4K;
19+
20+
# Enable gzip but do not remove ETag headers
21+
gzip on;
22+
gzip_vary on;
23+
gzip_comp_level 4;
24+
gzip_min_length 256;
25+
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
26+
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
27+
28+
# Pagespeed is not supported by Nextcloud, so if your server is built
29+
# with the `ngx_pagespeed` module, uncomment this line to disable it.
30+
#pagespeed off;
31+
32+
# HTTP response headers borrowed from Nextcloud `.htaccess`
33+
add_header Referrer-Policy "no-referrer" always;
34+
add_header X-Content-Type-Options "nosniff" always;
35+
add_header X-Download-Options "noopen" always;
36+
add_header X-Frame-Options "SAMEORIGIN" always;
37+
add_header X-Permitted-Cross-Domain-Policies "none" always;
38+
add_header X-Robots-Tag "noindex, nofollow" always;
39+
add_header X-XSS-Protection "1; mode=block" always;
40+
41+
# Remove X-Powered-By, which is an information leak
42+
fastcgi_hide_header X-Powered-By;
43+
44+
# Add .mjs as a file extension for javascript
45+
# Either include it in the default mime.types list
46+
# or include you can include that list explicitly and add the file extension
47+
# only for Nextcloud like below:
48+
include mime.types;
49+
types {
50+
text/javascript js mjs;
51+
}
52+
53+
# Path to the root of your installation
54+
root /var/www/html;
55+
56+
# Specify how to handle directories -- specifying `/index.php$request_uri`
57+
# here as the fallback means that Nginx always exhibits the desired behaviour
58+
# when a client requests a path that corresponds to a directory that exists
59+
# on the server. In particular, if that directory contains an index.php file,
60+
# that file is correctly served; if it doesn't, then the request is passed to
61+
# the front-end controller. This consistent behaviour means that we don't need
62+
# to specify custom rules for certain paths (e.g. images and other assets,
63+
# `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
64+
# `try_files $uri $uri/ /index.php$request_uri`
65+
# always provides the desired behaviour.
66+
index index.php index.html /index.php$request_uri;
67+
68+
# Rule borrowed from `.htaccess` to handle Microsoft DAV clients
69+
location = / {
70+
if ( $http_user_agent ~ ^DavClnt ) {
71+
return 302 /remote.php/webdav/$is_args$args;
72+
}
73+
}
74+
75+
location = /robots.txt {
76+
allow all;
77+
log_not_found off;
78+
access_log off;
79+
}
80+
81+
# Make a regex exception for `/.well-known` so that clients can still
82+
# access it despite the existence of the regex rule
83+
# `location ~ /(\.|autotest|...)` which would otherwise handle requests
84+
# for `/.well-known`.
85+
location ^~ /.well-known {
86+
# The following 6 rules are borrowed from `.htaccess`
87+
88+
location = /.well-known/carddav { return 301 /remote.php/dav/; }
89+
location = /.well-known/caldav { return 301 /remote.php/dav/; }
90+
# Anything else is dynamically handled by Nextcloud
91+
location ^~ /.well-known { return 301 /index.php$uri; }
92+
93+
try_files $uri $uri/ =404;
94+
}
95+
96+
# Rules borrowed from `.htaccess` to hide certain paths from clients
97+
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
98+
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
99+
100+
# Ensure this block, which passes PHP files to the PHP process, is above the blocks
101+
# which handle static assets (as seen below). If this block is not declared first,
102+
# then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
103+
# to the URI, resulting in a HTTP 500 error response.
104+
location ~ \.php(?:$|/) {
105+
# Required for legacy support
106+
rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode(_arm64)?\/proxy) /index.php$request_uri;
107+
108+
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
109+
set $path_info $fastcgi_path_info;
110+
111+
try_files $fastcgi_script_name =404;
112+
113+
include fastcgi_params;
114+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
115+
fastcgi_param PATH_INFO $path_info;
116+
#fastcgi_param HTTPS on;
117+
118+
fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
119+
fastcgi_param front_controller_active true; # Enable pretty urls
120+
fastcgi_pass php-handler;
121+
122+
fastcgi_intercept_errors on;
123+
fastcgi_request_buffering off;
124+
}
125+
126+
location ~ \.(?:css|js|svg|gif)$ {
127+
try_files $uri /index.php$request_uri;
128+
expires 6M; # Cache-Control policy borrowed from `.htaccess`
129+
access_log off; # Optional: Don't log access to assets
130+
}
131+
132+
location ~ \.woff2?$ {
133+
try_files $uri /index.php$request_uri;
134+
expires 7d; # Cache-Control policy borrowed from `.htaccess`
135+
access_log off; # Optional: Don't log access to assets
136+
}
137+
138+
location / {
139+
try_files $uri $uri/ /index.php$request_uri;
140+
}
141+
}

charts/nextcloud/templates/config.yaml

Lines changed: 8 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -9,119 +9,14 @@ metadata:
99
app.kubernetes.io/instance: {{ .Release.Name }}
1010
app.kubernetes.io/managed-by: {{ .Release.Service }}
1111
data:
12-
{{- range $key, $value := .Values.nextcloud.configs }}
13-
{{ $key }}: |-
14-
{{- $value | nindent 4 }}
12+
{{- range $filename, $content := .Values.nextcloud.configs }}
13+
{{ $filename }}: |-
14+
{{- $content | nindent 4 }}
1515
{{- end }}
16-
{{- if .Values.nextcloud.defaultConfigs }}
17-
{{- if index .Values.nextcloud.defaultConfigs ".htaccess" }}
18-
.htaccess: |-
19-
# line below if for Apache 2.4
20-
<ifModule mod_authz_core.c>
21-
Require all denied
22-
</ifModule>
23-
# line below if for Apache 2.2
24-
<ifModule !mod_authz_core.c>
25-
deny from all
26-
</ifModule>
27-
# section for Apache 2.2 and 2.4
28-
<ifModule mod_autoindex.c>
29-
IndexIgnore *
30-
</ifModule>
16+
{{- range $filename, $enabled := .Values.nextcloud.defaultConfigs }}
17+
{{- if $enabled }}
18+
{{ $filename }}: |-
19+
{{- tpl ($.Files.Get (printf "files/defaultConfigs/%s.tpl" $filename)) $ | nindent 4 }}
3120
{{- end }}
32-
{{- if index .Values.nextcloud.defaultConfigs "redis.config.php" }}
33-
redis.config.php: |-
34-
<?php
35-
if (getenv('REDIS_HOST')) {
36-
$CONFIG = array (
37-
'memcache.distributed' => '\OC\Memcache\Redis',
38-
'memcache.locking' => '\OC\Memcache\Redis',
39-
'redis' => array(
40-
'host' => getenv('REDIS_HOST'),
41-
'port' => getenv('REDIS_HOST_PORT') ?: 6379,
42-
{{- if .Values.redis.auth.enabled }}
43-
'password' => getenv('REDIS_HOST_PASSWORD'),
44-
{{- end }}
45-
),
46-
);
47-
}
4821
{{- end }}
49-
{{- if index .Values.nextcloud.defaultConfigs "apache-pretty-urls.config.php" }}
50-
apache-pretty-urls.config.php: |-
51-
<?php
52-
$CONFIG = array (
53-
'htaccess.RewriteBase' => '/',
54-
);
55-
{{- end }}
56-
{{- if index .Values.nextcloud.defaultConfigs "apcu.config.php" }}
57-
apcu.config.php: |-
58-
<?php
59-
$CONFIG = array (
60-
'memcache.local' => '\OC\Memcache\APCu',
61-
);
62-
{{- end }}
63-
{{- if index .Values.nextcloud.defaultConfigs "apps.config.php" }}
64-
apps.config.php: |-
65-
<?php
66-
$CONFIG = array (
67-
"apps_paths" => array (
68-
0 => array (
69-
"path" => OC::$SERVERROOT."/apps",
70-
"url" => "/apps",
71-
"writable" => false,
72-
),
73-
1 => array (
74-
"path" => OC::$SERVERROOT."/custom_apps",
75-
"url" => "/custom_apps",
76-
"writable" => true,
77-
),
78-
),
79-
);
80-
{{- end }}
81-
{{- if index .Values.nextcloud.defaultConfigs "autoconfig.php" }}
82-
autoconfig.php: |-
83-
<?php
84-
$autoconfig_enabled = false;
85-
if (getenv('SQLITE_DATABASE')) {
86-
$AUTOCONFIG["dbtype"] = "sqlite";
87-
$AUTOCONFIG["dbname"] = getenv('SQLITE_DATABASE');
88-
$autoconfig_enabled = true;
89-
} elseif (getenv('MYSQL_DATABASE') && getenv('MYSQL_USER') && getenv('MYSQL_PASSWORD') && getenv('MYSQL_HOST')) {
90-
$AUTOCONFIG["dbtype"] = "mysql";
91-
$AUTOCONFIG["dbname"] = getenv('MYSQL_DATABASE');
92-
$AUTOCONFIG["dbuser"] = getenv('MYSQL_USER');
93-
$AUTOCONFIG["dbpass"] = getenv('MYSQL_PASSWORD');
94-
$AUTOCONFIG["dbhost"] = getenv('MYSQL_HOST');
95-
$autoconfig_enabled = true;
96-
} elseif (getenv('POSTGRES_DB') && getenv('POSTGRES_USER') && getenv('POSTGRES_PASSWORD') && getenv('POSTGRES_HOST')) {
97-
$AUTOCONFIG["dbtype"] = "pgsql";
98-
$AUTOCONFIG["dbname"] = getenv('POSTGRES_DB');
99-
$AUTOCONFIG["dbuser"] = getenv('POSTGRES_USER');
100-
$AUTOCONFIG["dbpass"] = getenv('POSTGRES_PASSWORD');
101-
$AUTOCONFIG["dbhost"] = getenv('POSTGRES_HOST');
102-
$autoconfig_enabled = true;
103-
}
104-
if ($autoconfig_enabled) {
105-
$AUTOCONFIG["directory"] = getenv('NEXTCLOUD_DATA_DIR') ?: "/var/www/html/data";
106-
}
107-
{{- end }}
108-
{{- if index .Values.nextcloud.defaultConfigs "smtp.config.php" }}
109-
smtp.config.php: |-
110-
<?php
111-
if (getenv('SMTP_HOST') && getenv('MAIL_FROM_ADDRESS') && getenv('MAIL_DOMAIN')) {
112-
$CONFIG = array (
113-
'mail_smtpmode' => 'smtp',
114-
'mail_smtphost' => getenv('SMTP_HOST'),
115-
'mail_smtpport' => getenv('SMTP_PORT') ?: (getenv('SMTP_SECURE') ? 465 : 25),
116-
'mail_smtpsecure' => getenv('SMTP_SECURE') ?: '',
117-
'mail_smtpauth' => getenv('SMTP_NAME') && getenv('SMTP_PASSWORD'),
118-
'mail_smtpauthtype' => getenv('SMTP_AUTHTYPE') ?: 'LOGIN',
119-
'mail_smtpname' => getenv('SMTP_NAME') ?: '',
120-
'mail_smtppassword' => getenv('SMTP_PASSWORD') ?: '',
121-
'mail_from_address' => getenv('MAIL_FROM_ADDRESS'),
122-
'mail_domain' => getenv('MAIL_DOMAIN'),
123-
);
124-
}
125-
{{- end }}
126-
{{- end }}{{/* end-if defaultConfigs */}}
127-
{{- end }}{{/* end-if configs */}}
22+
{{- end }}{{/* end-if configs */}}

0 commit comments

Comments
 (0)