> For the complete documentation index, see [llms.txt](https://docs.kangal.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kangal.dev/tr/sdklar/plugin-sdk.md).

# Custom plugin geliştirme

Kangal Plugin SDK, custom gateway policy geliştiren platform ekipleri içindir.

## Kurulum

```bash
python -m pip install kangal-plugin-sdk
```

Her sürüm doğrulanmış wheel ve kaynak arşivi olarak yayınlanır. Eşleşen GitHub release kaydı SHA-256 özetlerini ve anahtarsız Sigstore bundle dosyalarını içerir. Public runtime contract `kangal.plugin/v1` değeridir; canonical SDK şu anda Python 3.11 ve üzerini hedefler.

## Plugin implementasyonu

```python
from kangal_plugin_sdk import Plugin


class HeaderPolicy(Plugin):
    async def before_request(self, request, headers, tenant_id):
        updated = dict(headers)
        updated["X-Policy-Version"] = str(self.config.get("version", "1"))
        return updated
```

Yalnızca policy'nin ihtiyaç duyduğu hook'ları implement edin:

| Protocol       | Hook'lar                                                 |
| -------------- | -------------------------------------------------------- |
| HTTP           | `before_request`, `after_response`, `on_error`           |
| Streaming HTTP | `before_request`, `stream`, `after_response`, `on_error` |
| WebSocket      | `before_request`, `stream`, `on_error`                   |
| gRPC           | `before_request`, `stream`, `after_response`, `on_error` |
| TCP            | `tcp`, `on_error`                                        |

## Package ve imzalama

1. `sdk/examples/header_policy/manifest.template.json` ile başlayın.
2. Entrypoint, protocol stage, configuration schema ve runtime limitlerini tanımlayın.
3. Değiştirilemez artifact'i build edip SHA-256 digest değerini kaydedin.
4. Manifest'i Ed25519 publisher key ile imzalayın.
5. Public key'i trusted signer yapılandırmasına ekleyin.
6. Değiştirilemez version'ı onaylanmış private registry'ye yayınlayın.
7. Plugin'i Kangal üzerinden sync edin, kurun, yapılandırın ve etkinleştirin.

Package kurulumundan önce Kangal control-plane process'inde `PLUGIN_PACKAGE_TRUSTED_SIGNERS` değerini yapılandırın. Değer, manifest'teki her `signer` kimliğini Ed25519 public key ile eşleyen bir JSON nesnesi olmalıdır:

```bash
export PLUGIN_PACKAGE_TRUSTED_SIGNERS='{"platform-publisher":"BASE64_RAW_ED25519_PUBLIC_KEY"}'
```

Her eşleme değeri, `-----BEGIN PUBLIC KEY-----` ile başlayan bir PEM public key (satır sonları JSON içinde escape edilmelidir) veya ham 32 byte Ed25519 public key'in Base64 karşılığı olabilir. Package'ı sync edip kurmadan önce eşlemeyi yapılandırın ve process'i yeniden başlatın; kurulum yalnızca signer kimliği geçerli bir trusted key ile eşleşen package'ı kabul eder.

## Runtime kontrolleri

Plugin configuration; timeout, hook bazlı timeout, maximum concurrency, failure threshold, recovery timeout ve failure mode destekler. Authentication ve enforcement policy'leri belirsiz sonuçta her zaman fail closed çalışır.

Runtime, registry sync sırasında indirilen rastgele kodu çalıştırmaz. Executable plugin kodu onaylanmış gateway runtime image içine eklenmeli ve tam package version, digest ve entrypoint ile kaydedilmelidir.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.kangal.dev/tr/sdklar/plugin-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
