Klucze API i rejestrowanie audytowe
Zabezpieczą Państwo programistyczny dostęp za pomocą ograniczonych zakresami kluczy API zamiast haseł oraz potwierdzą, kto wykonał daną czynność, włączając i odczytując dziennik audytowy Elasticsearch.
Klucze API i rejestrowanie audytowe to bezpłatna lekcja Elasticsearch & Full Text Search Systems na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Elasticsearch & Full Text Search Systems, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Elasticsearch & Full Text Search Systems zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
Beyond Passwords
Applications should not authenticate with a human's username and password. Elasticsearch provides API keys: scoped, revocable credentials ideal for services. Pair them with audit logging to track every security-relevant action.
What Is an API Key
An API key is a credential tied to a set of permissions, with an optional expiration. It can be limited to a subset of the creating user's privileges, following the principle of least privilege.
Creating a Key
Use the create API key endpoint. The response includes an id and api_key value shown only once, so store it securely.
POST /_security/api_key
{
"name": "logging-app",
"expiration": "30d"
}Restricting a Key
Attach role_descriptors to limit what the key can do, even if the creating user has more power. Here the key may only read one index.
POST /_security/api_key
{
"name": "reader",
"role_descriptors": {
"ro": {
"indices": [{ "names": ["logs-*"], "privileges": ["read"] }]
}
}
}Using a Key
Send the base64-encoded id:api_key pair in the Authorization header with the ApiKey scheme.
GET /logs-2024/_search
Authorization: ApiKey VnVhQ2ZHY0JDZGJrU...Revoking Keys
Compromised or retired keys are invalidated immediately, without changing any user's password. You can revoke by id, by name, or all keys owned by a user.
DELETE /_security/api_key
{
"name": "logging-app"
}Why Audit Logging
Audit logs answer the compliance question: who did what, when, and from where. They record authentication attempts, access grants and denials, and configuration changes.
Enabling the Audit Log
Audit logging is turned on in elasticsearch.yml. It is disabled by default because it generates significant volume.
xpack.security.audit.enabled: trueFiltering Events
Tune which events are captured with include/exclude lists to avoid drowning in noise. Common choices keep access_denied and authentication_failed while dropping routine reads.
xpack.security.audit.logfile.events.exclude: [ access_granted ]Reading Audit Output
Audit events are written as structured JSON to a dedicated log file. Each line includes the event type, user, client IP, request path, and outcome, making it easy to ship into Kibana for analysis.
Best Practices
Rotate API keys regularly, scope them tightly, store the audit log on durable storage separate from the cluster, and alert on repeated authentication_failed events that may signal an attack.
Quick Check
Test your understanding of API keys.
Recap
You learned to secure access and accountability:
- API keys are scoped, expiring, revocable credentials for applications.
- Use
role_descriptorsto enforce least privilege. - Audit logging records who did what, when, and from where.
- Filter audit events to manage volume and alert on failed authentications.
Często zadawane pytania
Czy lekcja „Klucze API i rejestrowanie audytowe” jest bezpłatna?
Tak — pełny tekst „Klucze API i rejestrowanie audytowe” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Elasticsearch & Full Text Search Systems, przejdź na CoddyKit PRO. Kurs Elasticsearch & Full Text Search Systems zawiera 4 lekcji w sumie.
Co nauczysz się w „Klucze API i rejestrowanie audytowe”?
Zabezpieczą Państwo programistyczny dostęp za pomocą ograniczonych zakresami kluczy API zamiast haseł oraz potwierdzą, kto wykonał daną czynność, włączając i odczytując dziennik audytowy Elasticsearc… Ćwiczysz Elasticsearch & Full Text Search Systems z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Elasticsearch & Full Text Search Systems?
Nie wymagamy żadnego doświadczenia. Elasticsearch & Full Text Search Systems w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Klucze API i rejestrowanie audytowe”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Elasticsearch & Full Text Search Systems?
Tak. Każda lekcja Elasticsearch & Full Text Search Systems zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Uwierzytelnianie użytkowników i role
- Bezpieczeństwo na poziomie pól i dokumentów
- TLS/SSL i bezpieczeństwo sieci
- Klucze API i rejestrowanie audytowe