Copyparty with authentik and traefik - how to #1236
SKProCH
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have successfully configured Copyparty to work with Traefik and Authentik. This setup allows some volumes to be accessible without authentication (anonymous) while others require a login.
Prerequisites
auth.example.com.1. Authentik Setup (Optional)
Create an "Always Allow" Policy
This is useful if you want to allow all users to access the Copyparty UI but manage specific volume permissions within the Copyparty configuration file itself.
return True2. Create the Authentik App and Provider
cpp.example.com(or your chosen domain).always-allowpolicy (or a specific group policy).3. Docker Compose Configuration
For this deployment, I used the following Docker Compose setup. Note the specific labels used to handle the dual-router logic.
How the "Magic" Works:
Currently there is no straightforward way to allow unauthenticated access via traefik & authentik only (or i've doesn't know it).
If you setup the auth middleware, traefik always will redirect users to auth, and there is no way to allow unauthorized access. You can specify the
Unanthorized pathsin a proxy provider, but this is also disables auth headers for this paths (e.g. if you specify main page here, copyparty doesn't get auth headers on main page, and you, probably will miss some volumes that will require auth).To bypass this, we create two routers:
fs-guest: The default router with low priority. It allows anonymous access.fs-auth: A high-priority router that only activates if the user already has an Authentik session cookie or explicitly navigates to the Copyparty user info page (/?h).This allows anonymous users to browse public files. When they click "Login" in Copyparty, they are sent to
/?h, which triggers thefs-authrouter, prompting Authentik to log them in.4. copyparty.conf
Configure Copyparty to trust the headers provided by Authentik.
Note: Ensure the
slugin the logout URL matches the slug configured in Authentik.More volume access control examples here.
5. Fixing the Logout Loop
By default, logging out through the proxy will result in a loop where the cookie remains in the browser but is invalid, causing constant redirects. To fix this, we use Traefik to manually wipe the cookie and redirect to the global Authentik session end-point.
Add these labels to your Authentik Outpost (or Traefik dynamic config):
Here is some "dark magic."
I discovered that if we navigate to cpp.example.com/outpost.goauthentik.io/log_out, the proxy resets the cookie's validity but doesn't clear the cookie itself. This results in a loop: we click logout, the proxy redirects us to Authentik, Authentik invalidates the cookie and redirects us back to cpp, Traefik sees the cookie and sends it to the proxy outpost for validation, the outpost rejects it and redirects us back to Authentik, and so on.
To fix this, we need to create another router for /outpost.goauthentik.io/proxy_logout. This will tell Traefik to use the logout-cookie middleware to clear the cookie from the browser. After that, it should redirect us to the main Authentik URL (NOT the proxy one), and Authentik will handle the rest.
Why can’t we redirect to the proxy? Because the proxy will set a new cookie before redirecting us to auth.example.com.
WARNING: Make sure to change the cookie name, as yours will likely be different (e.g., authentik_proxy_XXXXX).
With this configuration, anonymous users have read access to
/.Once they authenticate via Authentik, they gain access to specific volumes based on their permissions (e.g.,
Infrastructuremembers receive admin access to/).Hopefully, I haven't overlooked anything.
Beta Was this translation helpful? Give feedback.
All reactions