Skip to content
Visual explainer 3h to learn 4 steps

Cloud misconfigurations & logging

Find public storage, open security groups and missing audit logs in a cloud account.

By Invicly Tech, , in Cyber Security Fundamentals. About 11 minutes to read.

Topic 43 of 49

In short

Most cloud breaches come from misconfiguration, not provider flaws: public storage buckets, wide-open security groups and disabled audit logs. Enabling audit logging and running posture checks finds these before an attacker does.

Explained simply

A misconfiguration is an unsafe setting: a storage bucket anyone on the internet can read, a database port open to the whole world, or audit logging switched off. The cloud lets you create things in seconds, which also makes it easy to create them wrongly.

Attackers scan the internet all day for these mistakes. A server with SSH open to everyone starts getting password guesses within minutes. A public bucket with a guessable name can be downloaded without any hacking at all.

The defence has three parts. Turn on audit logs, so every action in the account is recorded. Run a posture checker, a tool that compares your settings with best practice and lists what is wrong. And alert on risky changes, so tomorrow's mistake is caught in minutes, not months.

Prevention is even better. Use secure defaults, set account-wide guardrails that block the worst settings, and scan infrastructure-as-code templates, such as Terraform files, before anything is deployed.

Press Play on a diagram to walk through it one step at a time.

FlowFinding misconfigurations
  1. Step 1
    Enable logging

    Turn on the audit trail.

  2. Step 2
    Scan posture

    Run a configuration checker.

  3. Step 3
    Prioritise

    Public and privileged first.

  4. Step 4
    Alert on drift

    Catch risky changes.

MapCommon cloud misconfigurations
Misconfigurations
  • Storage
    • Public bucket policy
    • Anonymous blob access
    • Share links that never expire
  • Network
    • SSH or RDP open to 0.0.0.0/0
    • Database ports public
    • IMDSv1 still allowed
  • Identity
    • Admin policy on many users
    • Old unused access keys
    • No MFA
  • Logging
    • No trail or single region only
    • Log bucket writable by many
    • No alerts on changes
  • Data
    • Snapshots shared publicly
    • Encryption turned off

In depth

Public storage: how buckets end up open

An S3 bucket becomes public when its bucket policy grants access to Principal "*" (everyone) or when an access control list (ACL) grants the AllUsers or AuthenticatedUsers groups. The safety net is S3 Block Public Access, which can be set for the whole account and for each bucket and overrides public grants. Since April 2023, new buckets have Block Public Access turned on and ACLs disabled by default, but older buckets and accounts may not.

Other clouds have the same risk. In Azure, a storage account setting controls whether anonymous blob access is allowed at all. In Google Cloud, granting a role to allUsers or allAuthenticatedUsers makes data public, and the public access prevention setting blocks that. If content really must be public, such as website images, serve it through a CDN like CloudFront with origin access control, and keep the bucket itself private.

  • aws s3control get-public-access-block --account-id ID
  • aws s3api get-public-access-block --bucket NAME
  • aws s3api get-bucket-policy-status --bucket NAME (IsPublic)

Open security groups and exposed services

A security group is a stateful virtual firewall around a cloud resource. Rules that allow 0.0.0.0/0 (or ::/0 for IPv6) mean the whole internet. That is normal for ports 80 and 443 on a public load balancer, and dangerous almost everywhere else: SSH (22), RDP (3389), and database or cache ports such as MySQL (3306), PostgreSQL (5432), MongoDB (27017), Redis (6379) and Elasticsearch (9200).

For admin access, use AWS Systems Manager Session Manager, a bastion host or a VPN, or at least limit the source to your office range. Also check which instances have public IP addresses, and look at network ACLs, Azure network security groups and Google Cloud firewall rules. On EC2, require IMDSv2 for the instance metadata service. The 2019 Capital One breach combined an SSRF flaw with an over-privileged role whose credentials were read from metadata; IMDSv2 makes that kind of theft much harder.

Audit logging: CloudTrail and its cousins

AWS CloudTrail records API calls. Without any setup, event history shows the last 90 days of management events, which are actions that create, change or delete resources. For anything longer, create a multi-region trail, ideally an organisation trail, that writes to an S3 bucket in a separate log archive account. Turn on log file validation so tampering is detectable, and protect the bucket, for example with S3 Object Lock. Data events, such as S3 object reads or Lambda invocations, are off by default and cost extra, so enable them for sensitive buckets.

Azure keeps its Activity Log for 90 days; export it with a diagnostic setting to Log Analytics or storage. Entra ID sign-in and audit logs are separate and also need exporting. In Google Cloud, Admin Activity audit logs are always on, while Data Access logs are off by default for most services. Add network logs too, such as VPC Flow Logs.

FlowFrom one API call to an alert
  1. 1
    API call

    Someone runs PutBucketPolicy

  2. 2
    CloudTrail

    Records who, what, when, from where

  3. 3
    Trail to S3

    Kept long term in a log account

  4. 4
    EventBridge rule

    Matches risky event names

  5. 5
    Alert

    SNS, SIEM or chat in minutes

Posture management and infrastructure-as-code scanning

Cloud security posture management (CSPM) tools continuously compare your settings with best practices such as the CIS AWS Foundations Benchmark. Built-in options include AWS Security Hub with AWS Config rules, Microsoft Defender for Cloud and Google Security Command Center. Free open-source checkers include Prowler and ScoutSuite, which run read-only checks and produce a report.

It is cheaper to catch mistakes before deployment. Scanners such as Checkov and Trivy read Terraform, CloudFormation and Kubernetes files in your CI pipeline and fail the build if, for example, a bucket is public or a security group allows SSH from anywhere.

Prioritise wisely. A report with 400 findings is overwhelming. Fix first what combines public exposure, sensitive data and powerful identities, such as a public instance with an admin role. Do not chase a perfect score; chase the paths an attacker would actually use.

Alerting on risky configuration changes

Some API calls deserve an alert almost every time they happen. Logging changes: StopLogging, DeleteTrail, UpdateTrail. Data exposure: PutBucketPolicy, PutBucketAcl and DeletePublicAccessBlock. Network exposure: AuthorizeSecurityGroupIngress with a source of 0.0.0.0/0. Identity changes: CreateUser, CreateAccessKey, AttachUserPolicy with an admin policy, and any root sign-in.

In AWS, an EventBridge rule can match these events from CloudTrail and send them to SNS, a Lambda function or your SIEM. Amazon GuardDuty adds threat detection on top, such as credentials used from unusual places. Guardrails stop some changes outright: an SCP can deny cloudtrail:StopLogging for everyone except a security role, and AWS Config can automatically fix certain settings. Alerts tell you something happened; guardrails stop it happening.

  • Alert: someone disabled or changed logging
  • Alert: a bucket policy or ACL changed
  • Alert: a port opened to 0.0.0.0/0
  • Alert: root signed in or a new access key was created

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    Find public buckets and open ports~45m
  2. 2
    Enable audit logging like CloudTrail~45m
  3. 3
    Use a posture management checker~45m
  4. 4
    Alert on risky configuration changes~45m

Key points

  • Misconfiguration causes most cloud incidents.
  • Public buckets and open security groups are common.
  • Audit logging such as CloudTrail is foundational.
  • Posture tools and drift alerts catch regressions.

Key terms

Tap a card to flip it. 0/4 known

Examples

A quick public exposure check with the AWS CLI

Step 1: check whether Block Public Access is on for the whole account. Step 2: for every bucket, ask S3 whether its policy makes it public (buckets without a policy print no-policy). Step 3: find security groups with a rule open to 0.0.0.0/0 on port 22. The EC2 filters match a group if any of its rules match each filter, so confirm each result by looking at its actual rules. Anything public that should not be goes straight into a ticket with an owner.

bash
aws s3control get-public-access-block --account-id 111122223333

for b in $(aws s3api list-buckets --query 'Buckets[].Name' --output text); do
  s=$(aws s3api get-bucket-policy-status --bucket "$b" \
      --query PolicyStatus.IsPublic --output text 2>/dev/null || echo no-policy)
  echo "$b: $s"
done

aws ec2 describe-security-groups \
  --filters Name=ip-permission.cidr,Values=0.0.0.0/0 Name=ip-permission.from-port,Values=22 \
  --query 'SecurityGroups[].[GroupId,GroupName]' --output text

Alerting when someone turns off CloudTrail

An attacker who gets admin rights often disables logging first. Step 1: make sure a trail is logging, because EventBridge receives these API events through CloudTrail. Step 2: create an EventBridge rule with this event pattern in each region you use. Step 3: set its target to an SNS topic that emails or pages the security team, or to your SIEM. Step 4: test it in a lab account by stopping a test trail and confirming the alert arrives. Step 5: add an SCP that denies these actions except for a security admin role.

json
{
  "source": ["aws.cloudtrail"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["cloudtrail.amazonaws.com"],
    "eventName": ["StopLogging", "DeleteTrail", "UpdateTrail", "PutEventSelectors"]
  }
}

Quick reference

  • Turn on S3 Block Public Access for the whole account unless there is a reviewed exception
  • aws s3api get-bucket-policy-status --bucket NAME shows whether the bucket policy is public
  • Never allow 0.0.0.0/0 or ::/0 to SSH (22), RDP (3389) or database ports
  • CloudTrail event history keeps 90 days; a multi-region trail to S3 keeps logs as long as you want
  • CloudTrail data events, such as S3 object reads, are off by default and cost extra
  • Google Cloud Admin Activity logs are always on; most Data Access logs are off by default
  • Prowler and ScoutSuite check posture; Checkov and Trivy scan IaC before deploy
  • Require IMDSv2 on EC2 to make metadata credential theft through SSRF much harder

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which security group rule is the most dangerous?

Question 2

2Without creating a trail, how far back does CloudTrail event history show management events?

Question 3

3What does a CSPM tool do?

Question 4

4Why alert on the StopLogging API call?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    List all S3 buckets in a lab account and show the Block Public Access settings for each.

  2. Exercise 2medium

    Run Prowler against a lab AWS account, then pick the three findings you would fix first and explain why.

  3. Exercise 3hard

    Write a service control policy that denies stopping or deleting CloudTrail trails and changing the account's S3 public access block, except for a role named SecurityAdmin.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Why are so many cloud breaches caused by misconfiguration?
Cloud resources are created quickly by many people, often through code, and one wrong setting can expose them to the whole internet. Without logging and posture checks, nobody notices until an attacker or researcher does.
Is a public S3 bucket always a problem?
Not always; some buckets hold public website files on purpose. It is a problem when it is unintended or holds anything private, and serving public files through a CDN with a private bucket is safer anyway.
Does turning on CloudTrail cost money?
The first copy of management events delivered by a trail is free; you pay for the S3 storage. Data events, extra copies and features like CloudTrail Lake are charged.
What is the difference between CSPM and a vulnerability scanner?
A vulnerability scanner looks for known software flaws inside machines and images. CSPM looks at how your cloud account and services are configured, such as public buckets, open ports and missing logs.

Go deeper

ShareXLinkedInWhatsApp