Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement internal mode #4912

Merged
merged 5 commits into from
Jul 11, 2024
Merged

Implement internal mode #4912

merged 5 commits into from
Jul 11, 2024

Conversation

docjyJ
Copy link
Collaborator

@docjyJ docjyJ commented Jun 29, 2024

It allows you not to expose AIO servers when you use reverse proxy attach in the docker aio network.

It is useful for filtered all AIO services access (with Forward Auth and Community Container).
And it prevents the proxy from bypass.

Sample compose.yaml:

services:
  nextcloud-aio-mastercontainer:
    image: nextcloud/all-in-one:latest
    init: true
    restart: always
    container_name: nextcloud-aio-mastercontainer
    volumes:
      - nextcloud_aio_mastercontainer:/mnt/docker-aio-config
      - /var/run/docker.sock:/var/run/docker.sock:ro
    ports:
      - 127.0.0.1:8080:8080
    environment:
      - APACHE_IP_BINDING=@INTERNAL
      - APACHE_PORT=80
    networks:
      - nextcloud-aio

  caddy:
    image: caddy:alpine
    restart: always
    container_name: caddy
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
    ports:
      - 80:80
      - 433:433
    networks:
      - nextcloud-aio

volumes:
 nextcloud_aio_mastercontainer:
   name: nextcloud_aio_mastercontainer

networks:
  nextcloud-aio:
    name: nextcloud-aio

I do not think that services exposed on the host is a real issue, but in terms of security and isolation it is an appropriate improvement.

Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com>
@docjyJ docjyJ requested a review from szaimen June 29, 2024 17:46
@docjyJ docjyJ added 0. Needs triage Pending approval or rejection. This issue is pending approval. enhancement New feature or request labels Jun 29, 2024
@szaimen
Copy link
Collaborator

szaimen commented Jul 1, 2024

Hi, thanks for the PR!

    environment:
      - APACHE_IP_BINDING=@INTERNAL
      - APACHE_PORT=80

I fear this is only going to work if you skip the domain validation.

Also I think this is currently going to break here:

if [ -n "$APACHE_IP_BINDING" ]; then
if ! echo "$APACHE_IP_BINDING" | grep -q '^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$\|^[0-9a-f:]\+$'; then
print_red "You provided an ip-address for the apache container's ip-binding but it was not a valid ip-address.
It is set to '$APACHE_IP_BINDING'."
exit 1

@szaimen szaimen added 2. developing Work in progress and removed 0. Needs triage Pending approval or rejection. This issue is pending approval. labels Jul 1, 2024
@szaimen szaimen added this to the next milestone Jul 1, 2024
Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com>
@docjyJ
Copy link
Collaborator Author

docjyJ commented Jul 1, 2024

Also I think this is currently going to break here:

if [ -n "$APACHE_IP_BINDING" ]; then
if ! echo "$APACHE_IP_BINDING" | grep -q '^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$\|^[0-9a-f:]\+$\|^@INTERNAL$'; then
print_red "You provided an ip-address for the apache container's ip-binding but it was not a valid ip-address.
It is set to '$APACHE_IP_BINDING'."
exit 1

Fix

@docjyJ
Copy link
Collaborator Author

docjyJ commented Jul 1, 2024

According :

  • If you run into issues with your domain being accepted, see <a href="https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md#6-how-to-debug-things">these steps</a> for how to debug things. <br /><br/>
  • 1. Make sure that all ports to which your reverse proxy is pointing match the chosen `APACHE_PORT`.

If reverse proxy points correctly to http://nextcloud-aio-apache:$APACHE_PORT/ from https://exemple.com:443/, it should work.

But, Caddy Community Container is set up after validation, so it will not work. Reverse proxy must be configured before validation.

@szaimen
Copy link
Collaborator

szaimen commented Jul 1, 2024

If reverse proxy points correctly to http://nextcloud-aio-apache:$APACHE_PORT/ from https://exemple.com:443/, it should work.

No, it will not because it would need to point at http://nextcloud-aio-domaincheck:$APACHE_PORT/ during the domain validation. However this makes the domain validation useless because the container gets replaced after the validation by the apache container...

But, Caddy Community Container is set up after validation, so it will not work. Reverse proxy must be configured before validation.

Yes, the caddy community works differently...

@docjyJ
Copy link
Collaborator Author

docjyJ commented Jul 2, 2024

What is the purpose of the domaine validations ?

@matteoipri
Copy link

Hi all,
I'll add my experience to this thread.

On my Arch Linux server, I am running several docker compose stacks and one of them is NC AiO and another one is for HAProxy to serve as reverse proxy in front of all web services, including TLS termination.
Every stack has its own docker network and then I have an additional network created outside of docker compose to connect all frontends with HAProxy.
My HAProxy stack is also connected to the NC AiO docker network.

My HAProxy config has the following lines in the HTTPS frontend

  acl host_nc hdr_beg(host) -i nc
  use_backend nextcloud if host_nc

and the following backend

backend nextcloud
  server nextcloud-aio-apache nextcloud-aio-apache:11000 check init-addr none resolvers dockerdns
  server nextcloud-aio-domaincheck nextcloud-aio-domaincheck:11000 check init-addr none resolvers dockerdns

With this setup, I got AiO installed, including the domain verification, using HAProxy as a reverse proxy running on the same host in a different container.

I would say that things work, the only issue that I still encounter is the login rate limit, which I do not know if it is legitimate (I am under brute force attack) or if it is due to my setup.

Your remote address was identified as "fd12:3456:789a:2::a" and is brute-force throttled at the moment  
slowing down the performance of various requests. If the remote address is not your address this can be  
an indication that a proxy is not configured correctly. For more details see the documentation ↗.

Can my setup inspire a solution for this topic?
How can I fix the login throttling?

Thanks,
Matteo

@docjyJ
Copy link
Collaborator Author

docjyJ commented Jul 3, 2024

Can my setup inspire a solution for this topic?
How can I fix the login throttling?

I dont know how resolve this issue.

Disable https://apps.nextcloud.com/apps/bruteforcesettings fix the warning message.

I don't know if you've read it yet, but it might help:
https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/reverse_proxy_configuration.html

Static IP for docker containers : https://www.baeldung.com/ops/docker-assign-static-ip-container

@docjyJ
Copy link
Collaborator Author

docjyJ commented Jul 3, 2024

Sample (Not tested):

services:
  nextcloud-aio-mastercontainer:
    image: nextcloud/all-in-one:latest
    init: true
    restart: always
    container_name: nextcloud-aio-mastercontainer
    volumes:
      - nextcloud_aio_mastercontainer:/mnt/docker-aio-config
      - /var/run/docker.sock:/var/run/docker.sock:ro
    ports:
      - 127.0.0.1:8080:8080
    environment:
      - APACHE_IP_BINDING=@INTERNAL
      - APACHE_PORT=80
    networks:
      - nextcloud-aio

  caddy:
    image: caddy:alpine
    restart: always
    container_name: my-caddy
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
    ports:
      - 80:80
      - 433:433
    networks:
      nextcloud-aio:
        ipv4_address: 10.9.8.7

volumes:
 nextcloud_aio_mastercontainer:
   name: nextcloud_aio_mastercontainer

networks:
  nextcloud-aio:
    name: nextcloud-aio
    driver: bridge
    ipam:
      config:
        - subnet: 10.9.8.0/24
          gateway: 10.9.8.1
https://mycloud.com:443 {
  reverse_proxy {
    to http://nextcloud-aio-apache:80 http://nextcloud-aio-domaincheck:80
    lb_policy first
    health_uri /
    health_port 80
    health_interval 60s
  }
}
$CONFIG = array (
  'trusted_proxies'   => ['10.9.8.7'],
  'overwritehost'     => 'my-caddy',
  'overwriteprotocol' => 'http'
);

@ManOki
Copy link
Collaborator

ManOki commented Jul 8, 2024

@matteoipri I have a similar setup (swag instead of HAProxy) including an additional network just for frontends.

client -1-> swag -2-> caddy -3-> nextcloud

1 LAN/WAN
2 swag-network
3 nextcloud-aio-network

While caddy is automatically marked as a trusted proxy, this ain't the case for your HAProxy.
https://github.com/nextcloud/all-in-one/blob/main/Containers/nextcloud/entrypoint.sh#L563C73-L563C97
You have to setup ADDITIONAL_TRUSTED_PROXY environment variable for your nextcloud-aio-nextcloud container.

reverse-proxy.md Outdated Show resolved Hide resolved
add sample for @internal

Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com>
@szaimen
Copy link
Collaborator

szaimen commented Jul 11, 2024

So my problem with this in general is that the reverse proxy documentation is already very complicated because it offers many options. Adding yet another method will not make it easier to understand...

We can add this but lets not document this for now.

…emove legacy code

Signed-off-by: Simon L. <szaimen@e.mail.de>
Signed-off-by: Simon L. <szaimen@e.mail.de>
Copy link
Collaborator

@szaimen szaimen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks a lot @docjyJ!

@szaimen szaimen added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 11, 2024
@szaimen szaimen merged commit d304c79 into main Jul 11, 2024
10 checks passed
@szaimen szaimen deleted the no-listen branch July 11, 2024 12:58
@szaimen
Copy link
Collaborator

szaimen commented Jul 11, 2024

This is now released with v9.2.0 Beta. Testing and feedback is welcome! See https://github.com/nextcloud/all-in-one#how-to-switch-the-channel

@docjyJ
Copy link
Collaborator Author

docjyJ commented Jul 14, 2024

This is now released with v9.2.0 Beta. Testing and feedback is welcome! See https://github.com/nextcloud/all-in-one#how-to-switch-the-channel

Work without domain validation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants