AdGuardDNS/doc/externalhttp.md

175 lines
7.3 KiB
Markdown
Raw Permalink Normal View History

2024-10-14 17:44:24 +03:00
# AdGuard DNS external HTTP API requirements
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
AdGuard DNS uses information from external HTTP APIs for filtering and other pieces of its functionality. Whenever it makes requests to these services, AdGuard DNS sets the `User-Agent` header. All services described in this document should set the `Server` header in their replies.
2022-08-26 14:18:35 +03:00
<!--
TODO(a.garipov): Reinspect uses of “should” and “must” throughout this
document.
-->
2024-10-14 17:44:24 +03:00
## Contents
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
- [Backend billing statistics](#backend-billstat)
2024-11-08 16:26:22 +03:00
- [Backend DNSCheck service](#backend-dnscheck)
2024-10-14 17:44:24 +03:00
- [Backend profiles service](#backend-profiles)
2024-11-08 16:26:22 +03:00
- [Backend ratelimit service](#backend-ratelimit)
2024-10-14 17:44:24 +03:00
- [Consul key-value storage](#consul)
- [Filtering](#filters)
- [Blocked services](#filters-blocked-services)
- [Filtering rule lists](#filters-lists)
- [Safe search](#filters-safe-search)
- [Proxied linked IP and dynamic DNS (DDNS) Endpoints](#backend-linkip)
- [Rule statistics service](#rulestat)
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
## <a href="#backend-billstat" id="backend-billstat" name="backend-billstat">Backend billing statistics</a>
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
This is the service to which the [`BILLSTAT_URL`][env-billstat_url] environment variable points. Supports gRPC(s) URLs. The service must correspond to `./internal/backendpb/dns.proto`.
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
This service is disabled when all server groups have property [`profiles_enabled`][conf-srvgrp-prof] set to `false`.
2023-08-08 18:31:48 +03:00
[env-billstat_url]: environment.md#BILLSTAT_URL
2024-10-14 17:44:24 +03:00
[conf-srvgrp-prof]: configuration.md#sg-*-profiles_enabled
2022-08-26 14:18:35 +03:00
2024-11-08 16:26:22 +03:00
## <a href="#backend-dnscheck" id="backend-dnscheck" name="backend-dnscheck">Backend DNSCheck service</a>
This is the service to which the [`DNSCHECK_REMOTEKV_URL`][env-dnscheck_remotekv_url] environment variable points. Supports gRPC(s) URLs. The service must correspond to `./internal/backendpb/dns.proto`.
This service is only enabled when the `check.kv` object has the [`type`][conf-check-kv-type] property set to `backend`.
[env-dnscheck_remotekv_url]: environment.md#DNSCHECK_REMOTEKV_URL
[conf-check-kv-type]: configuration.md#check-kv-type
2024-10-14 17:44:24 +03:00
## <a href="#backend-profiles" id="backend-profiles" name="backend-profiles">Backend profiles service</a>
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
This is the service to which the [`PROFILES_URL`][env-profiles_url] environment variable points. Supports gRPC(s) URLs. The service must correspond to `./internal/backendpb/dns.proto`.
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
This service is disabled when all server groups have property [`profiles_enabled`][conf-srvgrp-prof] set to `false`.
2022-08-26 14:18:35 +03:00
2023-08-08 18:31:48 +03:00
[env-profiles_url]: environment.md#PROFILES_URL
2022-08-26 14:18:35 +03:00
2024-11-08 16:26:22 +03:00
## <a href="#backend-ratelimit" id="backend-ratelimit" name="backend-ratelimit">Backend ratelimit_service</a>
This is the service to which the [`BACKEND_RATELIMIT_URL`][env-backend_ratelimit_url] environment variable points. Supports gRPC(s) URLs. The service must correspond to `./internal/backendpb/dns.proto`.
This service is only enabled when the `ratelimit` object has the [`type`][conf-ratelimit-type] property set to `backend`.
[conf-ratelimit-type]: configuration.md#ratelimit-type
[env-backend_ratelimit_url]: environment.md#BACKEND_RATELIMIT_URL
2024-10-14 17:44:24 +03:00
## <a href="#consul" id="consul" name="consul">Consul key-value storage</a>
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
A [Consul][consul-io] service can be used for the DNS server check and dynamic rate-limit allowlist features. Currently used endpoints can be seen in the documentation of the [`CONSUL_ALLOWLIST_URL`][env-consul-allowlist], [`CONSUL_DNSCHECK_KV_URL`][env-consul-dnscheck-kv], and [`CONSUL_DNSCHECK_SESSION_URL`][env-consul-dnscheck-session] environment variables.
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
The `CONSUL_ALLOWLIST_URL` endpoint must respond with a `200 OK` response code and a JSON document in the following format:
2022-12-29 15:36:26 +03:00
```json
[
{
"Address": "1.2.3.4"
}
]
```
**TODO(a.garipov):** Add examples of other responses.
2022-08-26 14:18:35 +03:00
[consul-io]: https://www.consul.io/
[env-consul-allowlist]: environment.md#CONSUL_ALLOWLIST_URL
[env-consul-dnscheck-kv]: environment.md#CONSUL_DNSCHECK_KV_URL
[env-consul-dnscheck-session]: environment.md#CONSUL_DNSCHECK_SESSION_URL
2024-10-14 17:44:24 +03:00
## <a href="#filters" id="filters" name="filters">Filtering</a>
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
### <a href="#filters-blocked-services" id="filters-blocked-services" name="filters-blocked-services">Blocked services</a>
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
This endpoint, defined by [`BLOCKED_SERVICE_INDEX_URL`][env-services], must respond with a `200 OK` response code and a JSON document in the following format:
2022-08-26 14:18:35 +03:00
```json
{
"blocked_services": [
{
"id": "my_filter",
"rules": [
"||example.com^",
2023-08-08 18:31:48 +03:00
"||example.net^"
2022-08-26 14:18:35 +03:00
]
}
]
}
```
2024-10-14 17:44:24 +03:00
All properties must be filled with valid IDs and rules. Additional fields in objects are ignored.
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
### <a href="#filters-lists" id="filters-lists" name="filters-lists">Filtering rule lists</a>
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
This endpoint, defined by [`FILTER_INDEX_URL`][env-filters], must respond with a `200 OK` response code and a JSON document in the following format:
2022-08-26 14:18:35 +03:00
```json
{
"filters": [
{
2024-07-10 19:49:07 +03:00
"filterKey": "my_filter",
"downloadUrl": "https://cdn.example.com/assets/my_filter.txt"
2022-08-26 14:18:35 +03:00
}
]
}
```
2024-10-14 17:44:24 +03:00
All properties must be filled with valid IDs and URLs. Additional fields in objects are ignored.
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
### <a href="#filters-safe-search" id="filters-safe-search" name="filters-safe-search">Safe search</a>
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
These endpoints, defined by [`GENERAL_SAFE_SEARCH_URL`][env-general] and [`YOUTUBE_SAFE_SEARCH_URL`][env-youtube], must respond with a `200 OK` response code and filtering rule lists with [`$dnsrewrite`][rules-dnsrewrite] rules for `A`, `AAAA`, or `CNAME` types. For example, for YouTube:
2022-08-26 14:18:35 +03:00
```none
|m.youtube.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com
|www.youtube-nocookie.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com
|www.youtube.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com
|youtube.googleapis.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com
|youtubei.googleapis.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com
```
[env-filters]: environment.md#FILTER_INDEX_URL
[env-general]: environment.md#GENERAL_SAFE_SEARCH_URL
[env-services]: environment.md#BLOCKED_SERVICE_INDEX_URL
[env-youtube]: environment.md#YOUTUBE_SAFE_SEARCH_URL
<!--
TODO(a.garipov): Replace with a link to the new KB when it is finished.
-->
2024-10-14 17:44:24 +03:00
[rules-dnsrewrite]: https://github.com/AdguardTeam/AdGuardHome/wiki/Hosts-Blocklists#dnsrewrite
2022-08-26 14:18:35 +03:00
2024-10-14 17:44:24 +03:00
## <a href="#backend-linkip" id="backend-linkip" name="backend-linkip">Proxied linked iP and dynamic DNS (DDNS) endpoints</a>
2023-08-08 18:31:48 +03:00
2024-10-14 17:44:24 +03:00
The service defined by the [`LINKED_IP_TARGET_URL`][env-linked_ip_target_url] environment variable should define the following endpoints:
2023-08-08 18:31:48 +03:00
2024-10-14 17:44:24 +03:00
- `GET /linkip/{device_id}/{encrypted}/status`
- `GET /linkip/{device_id}/{encrypted}`
- `POST /ddns/{device_id}/{encrypted}/{domain}`
- `POST /linkip/{device_id}/{encrypted}`
2023-08-08 18:31:48 +03:00
2024-10-14 17:44:24 +03:00
The AdGuard DNS proxy will add the `X-Connecting-Ip` header with the IP address of the original client as well as set the `User-Agent` header to its own value.
2023-08-08 18:31:48 +03:00
[env-linked_ip_target_url]: environment.md#LINKED_IP_TARGET_URL
2024-10-14 17:44:24 +03:00
## <a href="#rulestat" id="rulestat" name="rulestat">Rule statistics service</a>
2023-08-08 18:31:48 +03:00
2024-10-14 17:44:24 +03:00
This endpoint, defined by [`RULESTAT_URL`][env-rulestat], must respond with a `200 OK` response code and accept a JSON document in the following format:
2022-08-26 14:18:35 +03:00
```json
{
"filters": [
{
"15": {
"||example.com^": 1234,
2023-08-08 18:31:48 +03:00
"||example.net^": 5678
2022-08-26 14:18:35 +03:00
}
}
]
}
```
The objects may include new properties in the future.
[env-rulestat]: environment.md#RULESTAT_URL