Chaves de API e registro de auditoria
Proteja o acesso programático com chaves de API limitadas por escopo em vez de senhas e comprove quem fez o quê ativando e lendo o registro de auditoria do Elasticsearch.
Chaves de API e registro de auditoria é uma aula grátis de Elasticsearch & Full Text Search Systems no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Elasticsearch & Full Text Search Systems, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Elasticsearch & Full Text Search Systems inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
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.
Perguntas Frequentes
A aula “Chaves de API e registro de auditoria” é grátis?
Sim — o texto completo de “Chaves de API e registro de auditoria” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Elasticsearch & Full Text Search Systems, atualize para CoddyKit PRO. O curso de Elasticsearch & Full Text Search Systems inclui 4 aulas no total.
O que vou aprender em “Chaves de API e registro de auditoria”?
Proteja o acesso programático com chaves de API limitadas por escopo em vez de senhas e comprove quem fez o quê ativando e lendo o registro de auditoria do Elasticsearch. Você pratica Elasticsearch & Full Text Search Systems com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Elasticsearch & Full Text Search Systems?
Nenhuma experiência prévia é necessária. Elasticsearch & Full Text Search Systems no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Chaves de API e registro de auditoria”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Elasticsearch & Full Text Search Systems?
Sim. Cada aula de Elasticsearch & Full Text Search Systems inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Autenticação e funções de usuários
- Segurança em nível de campo e documento
- TLS/SSL e segurança de rede
- Chaves de API e registro de auditoria