Logging, Monitoring and Common Mistakes

Video + 11 min read · includes a lab

Cloud user
Cloud account
Audit log
Security team
Create access key
Who, what, when
Reviewed
Logging and Monitoring
0:00 / 5:48 · Logging and Monitoring
Chapters and transcript

Logging and Monitoring You cannot protect what you cannot see. Every time someone changes something in a cloud account, the provider can write it to a log. But logs only help if they are switched on, kept safe, and actually watched. In this lesson, you will learn about logging, alerts, the most common cloud mistakes, and what to do first when something goes wrong.

Audit logs An audit log records actions taken in your cloud account. It shows who did it, what they did and to which resource, when it happened, and from which IP address.

Audit logs Each provider has its own service. AWS CloudTrail records API calls and console actions. Azure Activity Log records actions on resources, such as creating or deleting them. Sign-ins are in the Entra ID sign-in logs. And Google Cloud Audit Logs record admin actions, and data access if you enable it.

Audit logs Here is a simplified audit log entry. Read it like a story. At two forty-one in the morning, the identity called backup script created a new access key, from an IP address you may not recognise. A backup script should not be making keys at night. That is worth a closer look.

Audit logs Three good practices. Make sure logging covers all regions and all accounts, not just the main one. Send logs to a separate, locked-down account, so an attacker cannot easily delete them. And keep logs long enough to investigate. Many attacks are found weeks after they start.

Monitoring and alerts Nobody can read every log line, so you set up alerts. Watch. The root account logs in. The event goes to the logs, and many companies send logs to a central system called a SIEM. A rule matches, and an alert reaches the security team.

Monitoring and alerts Which events deserve an alert? The root or owner account logs in. Logging is turned off. MFA is removed from a user. A new administrator or access key is created. A firewall rule opens a port to everyone. A storage bucket is made public. And activity from a region you do not use.

Monitoring and alerts Providers also offer threat detection services that look for suspicious patterns automatically. Examples are Amazon GuardDuty, Microsoft Defender for Cloud, and Google Security Command Center. They are not perfect, but they catch many common attacks. Their findings belong on these screens, next to your own alerts.

Cost alerts Attackers who steal cloud keys often start powerful servers to mine cryptocurrency. You pay the bill. Watch. With a stolen key, the attacker starts large GPU servers overnight, in a region your company never uses. Spending jumps, and a budget alert emails the owner. AWS Budgets, Azure Cost Management and Google Cloud Billing all offer these alerts.

Leaked keys in code One of the most common ways in is a secret written into code. A developer puts an access key in a file and pushes the code to a public repository. Automated tools scan public code for keys all the time. A bot copies the key and uses it on the cloud account.

Leaked keys in code Can the developer just delete the file? Look at the history. The newest commit removed the key. But git keeps every old commit, and the earlier one still contains it. GitHub secret scanning can detect many key formats, but you must assume a public key will be found and used. The only safe response is to disable and replace the key.

Leaked keys in code To prevent leaks, store secrets in a secrets manager, such as AWS Secrets Manager, Azure Key Vault or Google Secret Manager, or in environment variables. Add files like dot env to dot gitignore, so they are never committed. Scan code for secrets before it is pushed, with tools like gitleaks or TruffleHog. And prefer roles and temporary credentials, so there is no long-lived key to leak.

Common mistakes Most cloud incidents come from mistakes you have already met in this path. Admin accounts without MFA. Far more permissions than needed. Access keys in code, or old keys never removed. Public storage with private data. SSH, RDP or database ports open to the internet. Logging off, or logs nobody watches. And no budget alerts, or forgotten test servers nobody maintains.

When something goes wrong When you suspect an incident, stay calm and follow a plan. Do not delete everything. Preserve the audit logs first. Contain the access: disable the leaked key or suspicious user, and reset passwords. Investigate with the logs: new users, keys, servers, rules or downloads. Remove what the attacker created. Inform your manager or security team, and the provider if needed. And fix the root cause.

Quick check Quick check. An alert shows that a backup script identity created a new access key at night, from an IP address nobody recognises. You confirm nobody on the team did it. What should you do first? Choose your answer.

Key takeaways Let us put it together. Turn on audit logs in every region, and store them safely. Set alerts for risky events. Set a budget alert, because cost spikes can mean a break-in. Keep secrets out of code, and treat any leaked key as stolen. And in an incident, keep the logs, contain, investigate, and fix the cause. Now read the lesson below, and try the audit log lab.

You cannot protect what you cannot see. Cloud providers record almost every action in an account, but those records only help if they are switched on, kept safe, and actually watched. This lesson covers logging, alerts, the most common cloud mistakes, and what to do first when something goes wrong.

Audit logs

An audit log records actions taken in your cloud account: who did what, to which resource, when, and from which IP address. Each provider has its own service:

  • AWS CloudTrail records API calls and console actions in an AWS account.
  • Azure Activity Log records control-plane actions on Azure resources, such as creating or deleting them. Sign-ins are recorded separately in the Microsoft Entra ID sign-in logs.
  • Google Cloud Audit Logs record administrative actions and, if you enable them, data access.

A simplified audit log entry might look like this:

{
  "eventTime": "2025-03-14T02:41:09Z",
  "eventName": "CreateAccessKey",
  "userName": "backup-script",
  "sourceIPAddress": "198.51.100.23",
  "region": "us-east-1"
}

Read it like a story. At 2:41 in the morning, the identity backup-script created a new access key, from an IP address you may not recognise. That is worth a closer look.

Good practices for audit logs:

  • Make sure logging covers all regions and all accounts, not just the main one.
  • Send logs to a separate, locked-down account or storage location, so an attacker cannot easily delete them.
  • Keep logs for long enough to investigate. Many attacks are found weeks after they start.

Monitoring and alerts

Logs are only useful if someone reads them. Since nobody can read every line, you set up alerts for important events. Each provider has tools for this, and many companies also send logs to a central system called a SIEM.

Events that deserve an alert:

  • The root or owner account logs in
  • Logging is turned off or a log storage location is deleted
  • MFA is removed from a user
  • A new administrator or a new access key is created
  • A firewall rule opens a port to 0.0.0.0/0
  • A storage bucket is made public
  • Activity from a region you do not use

The providers also offer threat detection services that look for suspicious patterns automatically, such as Amazon GuardDuty, Microsoft Defender for Cloud and Google Security Command Center. They are not perfect, but they catch many common attacks.

Cost alerts as an attack signal

A common goal of attackers who steal cloud keys is to start powerful servers and use them to mine cryptocurrency. You pay the bill.

This makes cost alerts a useful security tool. Every major provider lets you set a budget and receive an email when spending goes above it: AWS Budgets, Azure Cost Management budgets, and Google Cloud Billing budgets.

Warning signs in billing:

  • Spending jumps suddenly, especially overnight or at weekends
  • Large or GPU servers appear that nobody ordered
  • Resources appear in a region your company never uses

Set a budget alert even on small or personal accounts. Students and freelancers testing the cloud are often surprised by bills after a key leaks.

Leaked keys in code

One of the most common ways cloud accounts are broken into is a secret written into code. A developer puts an access key in a file to make testing easier, then pushes the code to GitHub or another public site.

# Do NOT do this
AWS_ACCESS_KEY_ID = "AKIAEXAMPLEKEYID"
AWS_SECRET_ACCESS_KEY = "wJalrEXAMPLESECRETKEY"

Automated tools scan public repositories for keys constantly. GitHub also runs secret scanning, which can detect many known key formats and notify the provider or the repository owner. Even so, you must assume a public key will be found and used.

Deleting the file in a new commit does not remove the key. Git keeps the full history, so the old commit still contains it. The only safe response is to disable and replace the key.

To prevent leaks:

  • Store secrets in a secrets manager, such as AWS Secrets Manager, Azure Key Vault or Google Secret Manager, or in environment variables.
  • Add files like .env to .gitignore so they are never committed.
  • Scan code for secrets before it is pushed, using tools such as gitleaks or TruffleHog, and turn on GitHub push protection where available.
  • Prefer roles and temporary credentials, so there is no long-lived key to leak.

Common misconfigurations

Most cloud incidents come from a small set of mistakes you have already met in this path:

  • Root or admin accounts without MFA
  • Users and services with far more permissions than they need
  • Long-lived access keys in code, or old keys that were never removed
  • Public storage containing private data
  • SSH, RDP or database ports open to the internet
  • Logging turned off, or logs that nobody watches
  • No budget alerts
  • Forgotten test servers and accounts that nobody maintains

How to defend

When you suspect a cloud incident, stay calm and follow a plan. These are the first steps:

  1. Do not delete everything. You may destroy the evidence you need. Preserve the audit logs first.
  2. Contain the access. Disable the leaked access key or suspicious user, and reset passwords for affected accounts. Keep MFA on.
  3. Investigate with the logs. Find out what the attacker did: new users, new keys, new servers, changed rules, data downloads.
  4. Remove what the attacker created. Delete their users, keys and resources, and close any ports they opened.
  5. Inform the right people. Tell your manager or security team, and contact the provider's support if you need help.
  6. Learn from it. Fix the root cause so it cannot happen again.

Prevention is simpler than recovery. Turn on audit logs in every region, store them safely, set alerts for risky events, set a budget alert, and keep secrets out of code.

HANDS-ON LAB

Follow the Cloud Trail

A huge cloud bill arrived overnight. Use the audit log to find the stolen access key.

Start the lab →

Check your understanding

Answer every question correctly to complete this lesson. If you miss one, try the quiz again.

1. What does an audit log such as AWS CloudTrail or the Azure Activity Log record?

2. A developer pushed an access key to a public GitHub repository, then deleted the file in the next commit. Is the key safe now?

3. Your cloud bill jumps sharply overnight and you see many large servers in a region you never use. What is a likely cause?

Locked: answer every quiz question above correctly to complete this lesson.

Spotted a mistake or something unclear? Report a mistake