Authelia: Access restrictions by working hours
Authelia provides fine-grained access control, and restricting internal service access to working hours is a common self-hosted infrastructure task. Using local accounts and Docker Compose, you can enforce time-based policies without external identity providers.
1. Preparation and compose
A typical Authelia deployment via Docker Compose includes the authserver/auth-server container, a PostgreSQL database for local users or LDAP, and volumes for configuration and data. A minimal docker-compose.yml may look like this:
After running docker-compose up -d, access to the Authelia web console opens at https://auth.example.com (replace with your domain with SSL configured). The first authentication uses the built-in account admin@authelia.local with the password set in configuration.yml, after which it is recommended to change the password and add real users.
Further policy edits are best performed via configuration.yml editing or the Access Control web interface section, so you can roll back in case of policy errors.
2. Local users and groups setup
Authelia stores users in a PostgreSQL database. Adding a user and group happens either via SQL commands or through the web interface under Identity Providers → Local Users.
Example adding the user devops-team and group engineers via PostgreSQL console (connecting to the authelia container):
Inside the psql console:
Exit psql (\q) and return to the container shell.
Next, create an application (application) to which the access restriction will apply. In the config configuration.yml or via the Applications interface, add an entry linking the engineers group to the internal service, e.g., sonarr or prowlarr, and specify the service address behind the Authelia proxy.
When using the local storage, users and groups are not lost on container restart, as data is preserved in the pg_data volume. Transitioning to LDAP/SAML will change the policy structure, but the time-restriction logic remains similar.
3. Creating time-based access policy
The core of the restriction setup is the access control policy. In Authelia, a policy defines who (subject), to which resource (resource), and what action (action) is allowed, along with conditions, among which is time.
Policy structure in configuration.yml looks approximately like this (syntax may slightly differ depending on version, always check current documentation):
In this example, access is allowed only from 08:00 to 18:00 considering the +03:00 time zone (set under your TZ). The not_before condition blocks entry before the specified time, not_after — after. If access needs to be limited to specific weekdays, this is configured via additional conditions or a combination of multiple policies.
Table of key access control policy fields:
| Field | Description | Example |
|---|---|---|
subject.user | User or group the policy applies to | group: engineers |
resource.ip | List of allowed IP addresses (optional) | 192.168.1.0/24 |
action.type | Action type (usually access) | access |
conditions.time.not_before | Early entry allow time | 08:00:00+03:00 |
conditions.time.not_after | Late entry allow time | 18:00:00+03:00 |
Applying the policy:
- Open the Access Control section in the Authelia web console or edit
configuration.yml. - Add a new policy as shown above (or adapted to your IPs, groups, and hours).
- Save the config and run
docker-compose up -dto apply changes.
| Time is specified in ISO 8601 format with time zone offset. If Authelia runs on a host with one TZ and users are in another, a mismatch will cause restrictions to trigger at the wrong hour. It is recommended to synchronize time on the host and inside the container via NTP. |
4. Verifying restrictions work
After restarting Authelia, check two situations: entry within the allowed time window and entry outside its limits.
Within hours (e.g., 10:00 local TZ): an attempt to access the service behind Authelia should succeed; the user is redirected to the login page, and after authentication — to the actual service.
Outside hours (e.g., 22:00): access should be blocked. Authelia returns a
403 Forbiddenpage or a message that access is unavailable at the current time.
For diagnostics, you can view Authelia logs:
Or via the API/status page https://auth.example.com/api/status. In logs, look for policy-blocking entries, e.g.:
It is also useful to check how Authelia calculates time by executing a request to the internal time service or ensuring the container has correct TZ environment data or host time binding via volumes: - /etc/localtime:/etc/localtime:ro.
5. Common errors and typical failures
Time zone mismatch. The most frequent cause — Authelia runs on a server with one TZ (e.g., UTC), while users expect another. Result: access is blocked or allowed at the wrong hour. Solution: set
TZ=Europe/Moscowin the Authelia container environment and ensure the host is also synchronized via NTP.Incorrect policy order. Authelia applies policies in the order they are listed in the config. If a policy with time restriction is followed by a global
allowwithout conditions, access remains open always. Ensure the policy withconditions.timeis placed higher in the list, or use more specific rules.Group not linked to application. A user may be added to a group, but if the group is not selected in the application (resource) settings, the policy will not take effect. Verify the connection
group: engineersandapplication: sonarrin the interface orconfiguration.yml.Time format errors. Using time without time zone offset (
08:00instead of08:00:00+03:00) may cause Authelia to apply system UTC time, shifting boundaries. Always write the full ISO string with+HH:MM.NTP not running on host. If the host machine does not synchronize time, Authelia will operate with drift. In production, always enable NTP or
systemd-timesyncd, and indocker-compose.ymladdrestart: unless-stoppedand control time viaenvironment: - TZ=Europe/Moscow.Policy covers too broad a range. Sometimes administrators set
not_before: "00:00:00+03:00"andnot_after: "23:59:59+03:00"for testing, which effectively disables the restriction. Use exact working hours and test at the boundaries.
If an unexpected block occurs, first check logs for time condition and ensure the time on the host and in the Authelia container matches within a second.