installation.mdx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ---
  2. title: Setting up Anubis
  3. ---
  4. import RandomKey from "@site/src/components/RandomKey";
  5. import Tabs from "@theme/Tabs";
  6. import TabItem from "@theme/TabItem";
  7. Anubis is meant to sit between your reverse proxy (such as Nginx or Caddy) and your target service. One instance of Anubis must be used per service you are protecting.
  8. <center>
  9. ```mermaid
  10. ---
  11. title: With Anubis installed
  12. ---
  13. flowchart LR
  14. LB(Load balancer /
  15. TLS terminator)
  16. Anubis(Anubis)
  17. App(App)
  18. LB --> Anubis --> App
  19. ```
  20. </center>
  21. ## Docker image conventions
  22. Anubis is shipped in the Docker repo [`ghcr.io/techarohq/anubis`](https://github.com/TecharoHQ/anubis/pkgs/container/anubis). The following tags exist for your convenience:
  23. | Tag | Meaning |
  24. | :------------------ | :--------------------------------------------------------------------------------------------------------------------------------- |
  25. | `latest` | The latest [tagged release](https://github.com/TecharoHQ/anubis/releases), if you are in doubt, start here. |
  26. | `v<version number>` | The Anubis image for [any given tagged release](https://github.com/TecharoHQ/anubis/tags) |
  27. | `main` | The current build on the `main` branch. Only use this if you need the latest and greatest features as they are merged into `main`. |
  28. The Docker image runs Anubis as user ID 1000 and group ID 1000. If you are mounting external volumes into Anubis' container, please be sure they are owned by or writable to this user/group.
  29. Anubis has very minimal system requirements. I suspect that 128Mi of ram may be sufficient for a large number of concurrent clients. Anubis may be a poor fit for apps that use WebSockets and maintain open connections, but I don't have enough real-world experience to know one way or another.
  30. ## Native packages
  31. For more detailed information on installing Anubis with native packages, please read [the native install directions](./native-install.mdx).
  32. ## Environment variables
  33. Anubis uses these environment variables for configuration:
  34. | Environment Variable | Default value | Explanation |
  35. | :----------------------------- | :---------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  36. | `BASE_PREFIX` | unset | If set, adds a global prefix to all Anubis endpoints. For example, setting this to `/myapp` would make Anubis accessible at `/myapp/` instead of `/`. This is useful when running Anubis behind a reverse proxy that routes based on path prefixes. |
  37. | `BIND` | `:8923` | The network address that Anubis listens on. For `unix`, set this to a path: `/run/anubis/instance.sock` |
  38. | `BIND_NETWORK` | `tcp` | The address family that Anubis listens on. Accepts `tcp`, `unix` and anything Go's [`net.Listen`](https://pkg.go.dev/net#Listen) supports. |
  39. | `COOKIE_DOMAIN` | unset | The domain the Anubis challenge pass cookie should be set to. This should be set to the domain you bought from your registrar (EG: `techaro.lol` if your webapp is running on `anubis.techaro.lol`). See [here](https://stackoverflow.com/a/1063760) for more information. |
  40. | `COOKIE_PARTITIONED` | `false` | If set to `true`, enables the [partitioned (CHIPS) flag](https://developers.google.com/privacy-sandbox/cookies/chips), meaning that Anubis inside an iframe has a different set of cookies than the domain hosting the iframe. |
  41. | `DIFFICULTY` | `4` | The difficulty of the challenge, or the number of leading zeroes that must be in successful responses. |
  42. | `ED25519_PRIVATE_KEY_HEX` | unset | The hex-encoded ed25519 private key used to sign Anubis responses. If this is not set, Anubis will generate one for you. This should be exactly 64 characters long. See below for details. |
  43. | `ED25519_PRIVATE_KEY_HEX_FILE` | unset | Path to a file containing the hex-encoded ed25519 private key. Only one of this or its sister option may be set. |
  44. | `METRICS_BIND` | `:9090` | The network address that Anubis serves Prometheus metrics on. See `BIND` for more information. |
  45. | `METRICS_BIND_NETWORK` | `tcp` | The address family that the Anubis metrics server listens on. See `BIND_NETWORK` for more information. |
  46. | `OG_EXPIRY_TIME` | `24h` | The expiration time for the Open Graph tag cache. |
  47. | `OG_PASSTHROUGH` | `false` | If set to `true`, Anubis will enable Open Graph tag passthrough. |
  48. | `POLICY_FNAME` | unset | The file containing [bot policy configuration](./policies.mdx). See the bot policy documentation for more details. If unset, the default bot policy configuration is used. |
  49. | `REDIRECT_DOMAINS` | unset | If set, restrict the domains that Anubis can redirect to when passing a challenge.<br/><br/>If this is unset, Anubis may redirect to any domain which could cause security issues in the unlikely case that an attacker passes a challenge for your browser and then tricks you into clicking a link to your domain. |
  50. | `SERVE_ROBOTS_TXT` | `false` | If set `true`, Anubis will serve a default `robots.txt` file that disallows all known AI scrapers by name and then additionally disallows every scraper. This is useful if facts and circumstances make it difficult to change the underlying service to serve such a `robots.txt` file. |
  51. | `SOCKET_MODE` | `0770` | _Only used when at least one of the `*_BIND_NETWORK` variables are set to `unix`._ The socket mode (permissions) for Unix domain sockets. |
  52. | `TARGET` | `http://localhost:3923` | The URL of the service that Anubis should forward valid requests to. Supports Unix domain sockets, set this to a URI like so: `unix:///path/to/socket.sock`. |
  53. | `USE_REMOTE_ADDRESS` | unset | If set to `true`, Anubis will take the client's IP from the network socket. For production deployments, it is expected that a reverse proxy is used in front of Anubis, which pass the IP using headers, instead. |
  54. | `WEBMASTER_EMAIL` | unset | If set, shows a contact email address when rendering error pages. This email address will be how users can get in contact with administrators. |
  55. For more detailed information on configuring Open Graph tags, please refer to the [Open Graph Configuration](./configuration/open-graph.mdx) page.
  56. ### Using Base Prefix
  57. The `BASE_PREFIX` environment variable allows you to run Anubis behind a path prefix. This is useful when:
  58. - You want to host multiple services on the same domain
  59. - You're using a reverse proxy that routes based on path prefixes
  60. - You need to integrate Anubis with an existing application structure
  61. For example, if you set `BASE_PREFIX=/myapp`, Anubis will:
  62. - Serve its challenge page at `/myapp/` instead of `/`
  63. - Serve its API endpoints at `/myapp/.within.website/x/cmd/anubis/api/` instead of `/.within.website/x/cmd/anubis/api/`
  64. - Serve its static assets at `/myapp/.within.website/x/cmd/anubis/` instead of `/.within.website/x/cmd/anubis/`
  65. When using this feature with a reverse proxy:
  66. 1. Configure your reverse proxy to route requests for the specified path prefix to Anubis
  67. 2. Set the `BASE_PREFIX` environment variable to match the path prefix in your reverse proxy configuration
  68. 3. Ensure that your reverse proxy preserves the path when forwarding requests to Anubis
  69. Example with Nginx:
  70. ```nginx
  71. location /myapp/ {
  72. proxy_pass http://anubis:8923/myapp;
  73. proxy_set_header Host $host;
  74. proxy_set_header X-Real-IP $remote_addr;
  75. }
  76. ```
  77. With corresponding Anubis configuration:
  78. ```
  79. BASE_PREFIX=/myapp
  80. ```
  81. ### Key generation
  82. To generate an ed25519 private key, you can use this command:
  83. ```text
  84. openssl rand -hex 32
  85. ```
  86. Alternatively here is a key generated by your browser:
  87. <RandomKey />
  88. ## Next steps
  89. To get Anubis filtering your traffic, you need to make sure it's added to your HTTP load balancer or platform configuration. See the [environments category](/docs/category/environments) for detailed information on individual environments.
  90. - [Apache](./environments/apache.mdx)
  91. - [Docker compose](./environments/docker-compose.mdx)
  92. - [Kubernetes](./environments/kubernetes.mdx)
  93. - [Nginx](./environments/nginx.mdx)
  94. - [Traefik](./environments/traefik.mdx)
  95. :::note
  96. Anubis loads its assets from `/.within.website/x/xess/` and `/.within.website/x/cmd/anubis`. If you do not reverse proxy these in your server config, Anubis won't work.
  97. :::