Open hobyte opened 1 year ago
I'm currently also trying to change the user to 33 (www-data) and I encounter the same problem.
If I understand it correctly, the problem is that the docker-image per default uses Port 80 for Apache2 which seems not to be configurable via Kubernetes. According to https://github.com/nextcloud/helm/pull/98#issuecomment-844551455, it should be possible to use an FPM image in combination with nginx, but even if one could get the webserver listen to something different than port 80, I think the static targetPort
in the service template would cause problems.
Update: I've got nginx to run on port 8080 and the targetPort
didn't cause a problem. However, now I've got the nginx container that fails if not run as root, so that's not really an improvement. Also the data
directory has mode 775
and is owned by root
which prevents Nextcloud to start.
For the nginx-config, I basically just copied the default
value from the nginx-template and changed the listen
parameter:
Maybe some of my test results will help somebody to find a proper solution. But I assume the main objective of this issue (change port used by apache2) needs to be done in the docker-container.
I've just merged this PR, which might help: https://github.com/nextcloud/helm/commit/a215de8e0cafd940818b888e94806a387500abc4
Could you try again and see if the issue persists with helm chart version 3.5.12
?
Hi @jessebot , thanks for your work, unfortunately this does not fix the issue. The problem is that Apache is configured to listen on port 80 (which cannot be changed):
$ kubectl exec -it deploy/nextcloud -- cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
...
Same issue here. Running a rootless container for obvious security benefits but I need to mount a file like manual.conf
to /etc/apache2/
that contains
Listen 8080
ServerName <FQDN>
This is annoying and inconsistent with the web server configuration. ping @jessebot :)
Sorry, been busy at work! I don't actually use the apache flavor of the docker tag, but let me poke around https://github.com/nextcloud/docker and see if anything jumps out at me :)
I think to accommodate this, we'd need to have this be configurable in the apache docker container 🤔
@georglauterbach can you post an example of what you did? Is it just an extra mount? Where do you get the config file from? I guess it should be a configmap 🤔
@provokateurin interested in your thoughts as well.
I think to accommodate this, we'd need to have this be configurable in the apache docker container thinking
I knew about the fpm
version, but is there another image flavor next to the Apache and fpm
flavors?
@georglauterbach can you post an example of what you did? Is it just an extra mount? Where do you get the config file from? I guess it should be a configmap thinking
Indeed, it is a ConfigMap
I created manually. I mount it via
extraVolumes:
- name: extra-configuration-files
configMap:
name: extra-configuration-files
extraVolumeMounts:
- name: extra-configuration-files
subPath: ports.conf
mountPath: /etc/apache2/ports.conf
readOnly: true
in values.yaml
.
I knew about the fpm version, but is there another image flavor next to the Apache and fpm flavors?
There is the regular apache flavor and fpm
, but there's also a fpm-alpine
version as well :) You can see all the tags here: https://hub.docker.com/_/nextcloud/
For your solution, that seems ok doable 🤔 Do you want to submit a PR for that? If not, it'll probably be a few days before I have some time to write out a solution and test it quickly.
I knew about the fpm version, but is there another image flavor next to the Apache and fpm flavors?
There is the regular apache flavor and
fpm
, but there's also afpm-alpine
version as well :) You can see all the tags here: https://hub.docker.com/_/nextcloud/
I see, thanks! 👍🏼
For your solution, that seems ok doable 🤔 Do you want to submit a PR for that? If not, it'll probably be a few days before I have some time to write out a solution and test it quickly.
I have close to zero time at the moment, so I cannot provide a PR. I'd really appreciate if you could provide a PR:) When you do, please also try to provide the ServerName
part 🙈
I got it to work as rootless using this config:
image:
tag: 27.1.3-fpm # https://hub.docker.com/r/library/nextcloud/tags/
nextcloud:
host: "nextcloud.mydomain.tld"
configs:
custom.config.php: |
<?php
$CONFIG = array(
"check_data_directory_permissions"=> false, # fix data directory permissions error
"trusted_domains" => array (
$_ENV["NEXTCLOUD_TRUSTED_DOMAINS"], # fix probes 400 error
),
);
securityContext:
runAsUser: 1000
runAsGroup: 1000
runAsNonRoot: true
fsGroup: 1000
podSecurityContext:
runAsUser: 1000
runAsGroup: 1000
runAsNonRoot: true
fsGroup: 1000
containerPort: 8080
extraVolumes:
- name: nginx-cache
emptyDir: {}
extraVolumeMounts:
- name: nginx-cache
mountPath: "/var/cache/nginx" # fix permission denied error
nginx:
## You need to set an fpm version of the image for nextcloud if you want to use nginx!
enabled: true
image:
repository: nginxinc/nginx-unprivileged
tag: 1.25.3 # https://hub.docker.com/r/nginxinc/nginx-unprivileged/tags
containerPort: 8080
@devthejo that looks like you're using NGINX, not Apache. What am I missing here?
@devthejo that looks like you're using NGINX, not Apache. What am I missing here?
I misspoke, that doesn't solve changing apache port, but the challenge of running nextcloud rootless, I thought that was the underlying objective
Ah, I see. Thank you very much for posting this here!
As we are running instances in a relatively high restricted k8s environment, where low ports are absolutely no-go. We rebuild every image by adding these layers amongst other things:
ENV APACHE_LISTEN_PORT=8080
RUN sh -c 'find /etc/apache2 -type f | xargs sed -s -i -e "s/Listen 80/Listen ${APACHE_LISTEN_PORT}/"'
EXPOSE ${APACHE_LISTEN_PORT}
The really annoying thing is set -eu
and > /usr/local/etc/php/conf.d/redis-session.ini
in entrypoint.sh, as it prevents start-up with non-root user.
We handle this by
redis.config.php
in nextcloud.configs
nextcloud.defaultConfigs.redis.config.php
FYI just for @Wopf:
RUN sh -c 'find /etc/apache2 -type f | xargs sed -s -i -e "s/Listen 80/Listen ${APACHE_LISTEN_PORT}/"'
Piping
find
intoxargs
is usually done when people do not know aboutfind
's-exec
argument; why not writefind /etc/apache2 -type f -exec sed -i -E "s/(Listen) 80/\1 ${APACHE_LISTEN_PORT}/" {} \;
That is more concise and definitely faster (saving the fork-exec that the pipe has to do). As a rule of thumb: piping into
xargs
can in most cases be done in a better way :)
Works for sure - piping is a bad habit from the days, when Solaris 2.6 had no gnu-ish shells...
Describe your Issue
setting
nextcloud.containerPort
value doesn't change the Port apache httpd is listening to. it only changes the container Port in the deployment yaml, while the apache config still uses Port 80Logs and Errors
nextcloud pod logs:
Describe your Environment
Kubernetes distribution: talos v1.2.7, kubernetes 1.26.0
storage class: hetzner storagebox mounted with smb storage class.
Helm Version (or App that manages helm): helm version 3.11.2
Helm Chart Version: 3.5.3
values.yaml
:Additional context, if any
I use a hetzner storage box for my kubernetes storage. It's mounted with a smb storage class. This is my storageClass definition:
Due to permission issues, User and UserGroup are set to
1001
in nextcloud. I don't think the storage class itself is the issue, but the container port, that isn't configured completely