TechBuzzPro

Detect Unauthorized Admin Access & API Key Theft in LiteLLM Logs

· 5 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to spot unauthorized admin access and API key theft by analyzing LiteLLM logs. You'll learn what to look for, how to search effectively, and what actions to take when you find suspicious activity. Before starting, ensure you have access to your LiteLLM deployment's logs (e.g., via a log aggregation tool like Grafana, Kibana, or directly from the server) and basic familiarity with log queries.

What You'll Need

  • Access to LiteLLM logs (e.g., stdout, stderr, or a log file configured in your deployment).
  • Ability to run queries or search through logs (e.g., using grep, jq, or a log management platform).
  • Basic knowledge of your expected admin users and API key patterns.

Step-by-Step

  1. Identify log locations – LiteLLM logs are typically output to the console (stdout) and can be redirected to a file. Check your deployment configuration (e.g., Docker logs, systemd journal, or a file path like /var/log/litellm.log) to know where to look.
  2. Understand log structure – LiteLLM logs include timestamps, request details, user identifiers (if using authentication), API key hashes (or prefixes), and endpoint paths. Look for entries with "user", "api_key", "admin", or "role" fields.
  3. Search for admin actions – Query logs for requests to admin-specific endpoints like /admin, /user, /key/generate, /key/delete, or /config. Any request to these from an unexpected IP or user should raise a red flag.
  4. Look for unusual admin login patterns – If LiteLLM uses a UI, check for successful login events. Look for multiple failed logins followed by a success, logins from unfamiliar IPs, or logins at odd hours (e.g., 3 AM).
  5. Monitor API key creation and deletion – Unauthorized admin access often results in new API keys being generated. Search for "key/generate" or "key/create" events. Note the timestamp and the user who performed the action. Compare with expected activity.
  6. Detect API key theft through usage anomalies – Check for API keys that are used from multiple IPs simultaneously, or from IPs in different geographic regions within a short time. Also look for sudden spikes in request volume from a specific key.
  7. Inspect key metadata changes – Look for logs showing updates to key permissions, budgets, or expiration dates. Unauthorized admins might extend key validity or increase limits.
  8. Check for access to sensitive data – Search for requests to endpoints that return model lists, user lists, or configuration details. If these are accessed by non-admin keys, it may indicate privilege escalation.
  9. Set up alerts – If possible, configure alerts for failed admin logins, new key generation, or key usage from new IPs. This helps catch incidents in real-time.

Common Mistakes

  • Ignoring log verbosity – LiteLLM may log at different levels. If your logs are set to ERROR only, you might miss important access logs. Ensure you have INFO level logging enabled.
  • Not correlating timestamps – A single suspicious log entry might be a false positive. Always look at surrounding logs to understand the context (e.g., did the user just reset their password?).
  • Assuming API key hashes are enough – LiteLLM stores hashed keys, but the log may show a prefix. An attacker with access to the database could still match hashes. Use additional signals like IP and user-agent.
  • Forgetting to check the UI logs – If LiteLLM Proxy UI is used, admin actions might be logged separately. Check both backend and UI logs.

Tips

  • Use structured logging – If you control the deployment, enable JSON logging for easier parsing with tools like jq.
  • Maintain a baseline – Know your normal traffic patterns: which IPs, which times, which keys. This makes anomalies stand out.
  • Rotate keys regularly – Even if you don't detect theft, periodic rotation reduces the window of opportunity.
  • Enable audit logging – LiteLLM supports audit logs for admin actions. Turn this on to have a clear trail of who did what.
  • Use a SIEM – For large deployments, integrate logs with a Security Information and Event Management system to automate detection.

Troubleshooting

  • No logs found – Check if LiteLLM is running with --log-level=debug to increase verbosity. Also verify that the log file path is writable and the service has permission.
  • Logs are too verbose – Use grep to filter for specific patterns like grep "admin" or grep "key/generate" to narrow down.
  • Cannot correlate user identities – If you use virtual keys, the log may show the virtual key alias instead of the user. Map aliases to users beforehand.
  • False positives from legitimate activity – A developer might generate a key from a new IP. Cross-check with ticket systems or communication before acting.
  • Logs are being overwritten – Ensure log rotation is configured properly. If you suspect tampering, check file integrity or use a remote logging service.

Frequently Asked Questions

What exactly should I search for in the logs to detect key theft?

Look for API key usage from unexpected IPs, especially if the same key is used from multiple IPs within a short time. Also monitor for key generation events that you didn't initiate.

How can I tell if an admin account was compromised?

Check for successful admin logins from new IPs, especially after failed attempts. Also look for changes to admin user permissions or creation of new admin users.

Does LiteLLM log the full API key?

No, LiteLLM logs only a hash or a prefix of the key for security. You can still use the prefix to identify which key was used.

Can I set up real-time alerts for suspicious activity?

Yes, if you use a log monitoring tool like Grafana or a SIEM, you can create alerts on patterns like multiple failed logins or key generation outside business hours.

What should I do if I find unauthorized access?

Immediately revoke the affected API keys, reset admin passwords, and review recent changes. Also consider rotating all keys as a precaution.

How often should I review logs?

Ideally, you should have automated alerts and review logs at least weekly. For high-security environments, daily review is recommended.