Project Phoenyx – Part 8: The Fortress Gate (Authentik & Proxy Protection)

Category: Core Stack / Identity | Read Time: approx. 20 minutes

Why "just" a login isn't enough

We have built our infrastructure (Network, Traefik, Crowdsec) in the last parts. Now one crucial component is missing: Identity Management.

Many tutorials show you how to install Authentik to log in to Grafana or Portainer (called SSO or OAuth). That's great, but often overkill for the start. What we need more urgently is protection for applications that don't have good security of their own.

Imagine you run a WordPress blog. The blog should be readable by everyone. But the admin area (/wp-admin) is often a target for attacks. Wouldn't it be brilliant if Traefik could completely hide this area until you have identified yourself with Authentik? That's exactly what we are building today.

Goal of this Article
  1. We install Authentik (Server, Worker & Database).
  2. We understand and install the Outpost (this is the actual bouncer).
  3. We configure a Forward-Auth Middleware in Traefik.
  4. We use it to selectively protect paths (like /admin) without locking down the whole site.

Step 1: Understanding the Architecture

Authentik is not a single ".exe" file. It is a distributed system. Let's look at the authentik-docker-compose.yml we prepared.

The Components

The "Outpost" (The Misunderstanding)

This is where most beginners get lost. Authentik separates the decision (Server) from the enforcement (Outpost).

The Authentik Server sits securely in its container. It doesn't see your website traffic at all. That's what the Outpost is for. It is a small, fast proxy container (based on Nginx/Go) standing right next to Traefik.

The flow of a request:

  1. Visitor accesses my-blog.com/wp-admin.
  2. Traefik intercepts the request.
  3. Traefik asks the Outpost: "Hey, someone wants to go to /wp-admin. Are they logged in?"
  4. The Outpost checks the session cookie.
    • No: Outpost tells Traefik: "Redirect user to login page."
    • Yes: Outpost tells Traefik: "Alright, let them through."

Step 2: Installation (Docker Compose)

We start our stack. In the file /opt/containers/authentik/authentik-docker-compose.yml, we have prepared everything. Especially important is the section for the Outpost:

  # === Authentik Outpost ===
  authentik-outpost-traefik:
    image: ghcr.io/goauthentik/proxy:2025.10
    container_name: authentik-outpost-traefik
    # ...
    labels:
      # Here we define the "magic" for Traefik
      - "traefik.http.middlewares.auth-traefik.forwardauth.address=http://authentik-outpost-traefik:9000/outpost.goauthentik.io/auth/traefik"
      - "traefik.http.middlewares.auth-traefik.forwardauth.trustForwardHeader=true"
      - "traefik.http.middlewares.auth-traefik.forwardauth.authResponseHeaders=X-Authentik-Username,X-Authentik-Email"

What is happening here?
We define a Traefik middleware named auth-traefik. Every time we assign this middleware to another container later, traffic is first sent to the address http://authentik-outpost-traefik:9000....

Start the stack now (if not already done) in the main directory:

cd /opt/containers
docker compose up -d

Step 3: Initial Setup (First Login)

Once the containers are running, access your Authentik URL (e.g., https://auth.your-domain.com/if/flow/initial-setup/). Set the password for the user akadmin there.

After that, you land in the dashboard. It might look empty and complicated at first. Don't be intimidated.

Attention: The Outpost container we started via Docker must be connected to the Authentik Server. It needs a token.
  1. Go to Applications -> Outposts in the Authentik Admin Interface.
  2. You will likely see an entry there or create a new one (Type: Proxy).
  3. Click on the Outpost and copy the Token.
  4. Paste this token into your .env file: AUTHENTIK_OUTPOST_TOKEN=your-long-token.
  5. Restart the Outpost container: docker compose up -d --force-recreate authentik-outpost-traefik.

Now a green checkmark ("Healthy") should appear next to the Outpost in the Authentik Dashboard. The connection is established!


Step 4: Creating a "Proxy Provider"

For Authentik to know what to protect, we need to create a "Provider". In Authentik terms, a provider is the piece of logic that decides "How is it protected?".

  1. Go to Applications -> Providers.
  2. Create a new provider of type Proxy Provider.
  3. Name: Wordpress-Protection
  4. Authorization flow: default-provider-authorization-implicit-consent (This means: If login correct, redirect immediately without "Are you sure?" question).
  5. Forward Auth (Single Application): Enter the domain of your app here, e.g., https://blog.your-domain.com.

Step 5: Creating the Application

A provider alone does nothing. It must be assigned to an "Application".

  1. Go to Applications -> Applications.
  2. Create a new Application.
  3. Name: My Blog Admin.
  4. Provider: Select the created Wordpress-Protection provider.

The Last Click: Go back to Applications -> Outposts. Edit your Outpost and make sure that your new app "My Blog Admin" is selected on the right under "Selected Applications". Only then does the Outpost's Docker container know it is responsible for this app.


Step 6: Activating Protection (Traefik Labels)

Now comes the moment of truth. We have prepared everything. Now we just have to tell our WordPress container: "Use the bouncer!"

Open the docker-compose.yml of your WordPress (or Whoami, or whatever you want to test) and add labels.

Scenario A: Protect Everything

If the whole site should be behind the login:

labels:
  - "traefik.http.routers.wordpress.middlewares=auth-traefik"

Scenario B: Protect only /wp-admin (Pro Version)

Here we define TWO routers for the same container. One public and one protected.

labels:
  # Router 1: Public (Everything except /wp-admin)
  - "traefik.http.routers.wp-public.rule=Host(`blog.com`)"
  - "traefik.http.routers.wp-public.entrypoints=websecure"
  
  # Router 2: Protected (Only /wp-admin)
  # Important: The rule is more specific ("longer"), so it wins for this path
  - "traefik.http.routers.wp-admin.rule=Host(`blog.com`) && PathPrefix(`/wp-admin`)"
  - "traefik.http.routers.wp-admin.entrypoints=websecure"
  - "traefik.http.routers.wp-admin.middlewares=auth-traefik"  <-- HERE is the protection!

If you deploy this, the following happens:


Conclusion

We now have an extremely powerful tool. We can protect any path of any application, even if the application itself has no user management. We have successfully placed Authentik as a "Forward Auth" proxy in front of our services.

In the next and final part, we will look at data storage: MariaDB and how to manage it easily.