Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myunisoft/loki-reverse-proxy
Reverse proxy for Loki with proper Grafana API authentication
https://github.com/myunisoft/loki-reverse-proxy
api authenticated authentication grafana loki proxy reverse-proxy
Last synced: about 1 month ago
JSON representation
Reverse proxy for Loki with proper Grafana API authentication
- Host: GitHub
- URL: https://github.com/myunisoft/loki-reverse-proxy
- Owner: MyUnisoft
- License: mit
- Created: 2024-03-21T20:50:21.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-11-11T21:17:25.000Z (about 1 month ago)
- Last Synced: 2024-11-11T22:22:51.455Z (about 1 month ago)
- Topics: api, authenticated, authentication, grafana, loki, proxy, reverse-proxy
- Language: TypeScript
- Homepage:
- Size: 413 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# loki-reverse-proxy
Reverse proxy for Loki API with proper Grafana API token authentication.Under the hood it use Grafana `/api/auth/keys` API to validate the token and then dispatch the request to Loki.
> [!CAUTION]
> When succesfully authenticated, by default tokens are cached for 5 minutes## Getting started
```bash
$ git clone https://github.com/MyUnisoft/loki-reverse-proxy.git
$ cd loki-reverse-proxy
$ npm ci
$ npm run build
```### Environment Variables
To configure the project you have to register (set) environment variables on your system. These variables can be set in a .env file (that file must be created at the root of the project).
```ini
GRAFANA_URL=""
LOKI_URL=""SERVER_HOST=xxx.domain.com
SERVER_PORT=4000# SSL/TLS Configuration
SERVER_SSL_ENABLED=false
SERVER_SSL_CERT=/absolute/path/to/file.crt
SERVER_SSL_KEY=/absolute/path/to/file.key# Enable if behind a proxy like NGINX or Haproxy
TRUST_PROXY=false# Automatically forward pino (logger) logs to LOKI_URL
SELF_MONITORING=false
```### Let's go baby 🔥
```bash
$ npm start
```## Env
Here is the full Zod schema for envs:
```js
const envSchema = z.object({
GRAFANA_URL: z.string().url().trim(),
LOKI_URL: z.string().url().trim(),
TOKEN_CACHE_MS: z.coerce.number().optional().default(1_000 * 60 * 5),
SERVER_PORT: z.coerce.number().optional().default(0),
SERVER_HOST: z.string().optional(),
SERVER_SSL_ENABLED: zBoolean("false"),
SERVER_SSL_CERT: z.string().optional(),
SERVER_SSL_KEY: z.string().optional(),
SERVER_SSL_CA: z.string().optional(),
TRUST_PROXY: zBoolean("false"),
SELF_MONITORING: zBoolean("false")
});
```Where zBoolean is defined as
```ts
function zBoolean(defaultValue?: "false" | "true") {
const zEnum = z.enum(["true", "false"]).transform((value) => value === "true");return defaultValue ? zEnum.optional().default(defaultValue) : zEnum;
}
```## API
### /health
Return proxy uptime
```json
{
"uptime": 10
}
```## Roadmap
- Find a way to also proxy Grafana API (currently that's not possible with the same root prefix).
## Contributors ✨
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Thomas.G
💻 🐛 🛡️ 📖
PierreDemailly
👀
## License
MIT