FROM freeradius/freeradius-server:3.2.2

USER root
RUN apt-get update \
 && apt-get install -y --no-install-recommends freeradius-postgresql \
 && rm -rf /var/lib/apt/lists/*

## Copy configuration overrides (surgical, preserve defaults)
COPY --chown=root:freerad clients.conf /etc/freeradius/clients.conf
COPY --chown=root:freerad mods-available/rest /etc/freeradius/mods-available/rest
COPY --chown=root:freerad mods-available/sql /etc/freeradius/mods-available/sql
COPY --chown=root:freerad mods-enabled/eap /etc/freeradius/mods-enabled/eap
COPY --chown=root:freerad sites-enabled/default /etc/freeradius/sites-enabled/default
COPY --chown=root:freerad sites-enabled/inner-tunnel /etc/freeradius/sites-enabled/inner-tunnel

# Enable required modules
RUN ln -sf /etc/freeradius/mods-available/rest /etc/freeradius/mods-enabled/rest \
 && ln -sf /etc/freeradius/mods-available/sql /etc/freeradius/mods-enabled/sql \
 && chmod -R a+r /etc/freeradius

# Default command preserved by base image
