Skip to content
Back to skills

Cloud Security Defensive

ASecurity

Use when the user asks to harden an AWS account or Azure tenant, write SCP guardrails, CloudTrail or GuardDuty detections, enforce IMDSv2, apply least-privilege IAM, or improve cloud posture. Produces preventive guardrails, detections and policy code for AWS/Azure/GCP. Not for cloud attack-path analysis (use cloud-native-security-offensive) or secret storage (use vault).

  • 46 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 27, 2026
ai-agentssqlrailsawsgcpazureterraformgitdevopssecurity

Security analysis

A100/100

Scanned November 27, 2026

npx -y skills add j4flmao/agent-skills --skill cloud-security-defensive --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cloud Security Defensive?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cloud Security Defensive
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/j4flmao-cloud-security-defensive/badge)](https://www.skillsdirectory.com/skills/j4flmao-cloud-security-defensive)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cloud-native-security-defensive
description: >
  Use when the user asks to harden an AWS account or Azure tenant, write SCP guardrails, CloudTrail or GuardDuty detections, enforce IMDSv2, apply least-privilege IAM, or improve cloud posture. Produces preventive guardrails, detections and policy code for AWS/Azure/GCP. Not for cloud attack-path analysis (use cloud-native-security-offensive) or secret storage (use vault).
version: "2.0.0"
author: "j4flmao"
license: "MIT"
last_verified: "2026-11-17"
tags: [cloud-native, security, aws, azure, gcp, iam, scp, cloudtrail, detection]
---

# Cloud Security — Defensive Engineering

## Purpose
Turn a cloud estate into one where dangerous actions are prevented by organization-level guardrails, everything else is logged centrally and immutably, and anomalous identity activity is detected quickly. Identity is the perimeter in cloud, so most controls are IAM controls.

## Agent Protocol

### Trigger
"harden aws account", "detect cloud intrusion", "cloudtrail", "SCP", "guardrails", "secure azure tenant", "cloud posture", "guardduty", "IMDSv2", "least privilege".

### Input Context
- Cloud(s) and org structure (AWS Organizations OUs, Azure management groups, GCP folders).
- Existing logging destinations (SIEM, log archive account).
- Compliance targets (CIS Benchmarks, SOC 2, ISO 27001).

### Output Artifact
Policy-as-code (SCP/Azure Policy/Org Policy JSON or Terraform) and detection queries. No file unless requested.

### Response Format
```
Layer: {preventive|detective|responsive}
Control: {name}
Scope: {org/OU/account/subscription/project}
Code: {policy or query}
Break-glass impact: {who is exempt and how}
```

### Completion Criteria
- [ ] Preventive guardrails applied at org/OU level with a documented break-glass exemption.
- [ ] Org-wide audit logging to a separate, write-protected account/project.
- [ ] Detections mapped to concrete log events.

## Control Layers

| Layer | AWS | Azure | GCP |
|---|---|---|---|
| Org guardrails | Service Control Policies, Resource Control Policies, declarative policies | Azure Policy (deny), management-group RBAC | Organization Policy constraints |
| Audit log | CloudTrail organization trail (+ data events where needed) | Activity Log + Microsoft Entra sign-in/audit logs via diagnostic settings | Cloud Audit Logs (Admin Activity always on; Data Access opt-in) |
| Threat detection | GuardDuty, Security Hub | Microsoft Defender for Cloud, Sentinel | Security Command Center |
| Unused access | IAM Access Analyzer (unused access findings) | Entra access reviews | IAM Recommender |

## Preventive Guardrails (AWS SCP)
SCPs do not grant permissions; they cap what principals in member accounts can do. They never affect the management account.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ProtectAuditTrail",
      "Effect": "Deny",
      "Action": ["cloudtrail:StopLogging", "cloudtrail:DeleteTrail", "cloudtrail:UpdateTrail",
                 "guardduty:DeleteDetector", "guardduty:DisassociateFromMasterAccount",
                 "config:StopConfigurationRecorder", "config:DeleteConfigurationRecorder"],
      "Resource": "*",
      "Condition": { "ArnNotLike": { "aws:PrincipalArn": "arn:aws:iam::*:role/BreakGlassAdmin" } }
    },
    {
      "Sid": "RegionAllowList",
      "Effect": "Deny",
      "NotAction": ["iam:*", "organizations:*", "sts:*", "support:*", "cloudfront:*", "route53:*"],
      "Resource": "*",
      "Condition": { "StringNotEquals": { "aws:RequestedRegion": ["eu-west-1", "eu-central-1"] } }
    },
    {
      "Sid": "RequireIMDSv2",
      "Effect": "Deny",
      "Action": "ec2:RunInstances",
      "Resource": "arn:aws:ec2:*:*:instance/*",
      "Condition": { "StringNotEquals": { "ec2:MetadataHttpTokens": "required" } }
    }
  ]
}
```
Global services (IAM, Organizations, STS global endpoint, CloudFront, Route 53) must be excluded from region deny lists or they break.

Also enable at account level: S3 Block Public Access (account-wide), EBS encryption by default, and the EC2 account default `HttpTokens=required` for new instances.

## Detective Controls — High-Signal Events
| Signal | Log event | Why |
|---|---|---|
| Root user activity | CloudTrail `userIdentity.type = "Root"` | Root should be unused after setup |
| Console login without MFA | `ConsoleLogin` with `additionalEventData.MFAUsed = "No"` | Credential theft |
| Logging tampering | `StopLogging`, `DeleteTrail`, `PutEventSelectors` | Defense evasion |
| Persistence via IAM | `CreateAccessKey`, `CreateLoginProfile`, `AttachUserPolicy`, `PutRolePolicy`, `UpdateAssumeRolePolicy` | Backdoor creation |
| Enumeration burst | Many `List*`/`Describe*`/`Get*` from one principal in minutes, especially `AccessDenied` | Recon tooling (e.g. Pacu, ScoutSuite run by an attacker) |
| Credential exfil | GuardDuty `UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration.OutsideAWS` | Stolen instance role creds used elsewhere |

Example (CloudTrail Lake / Athena SQL):
```sql
SELECT eventTime, userIdentity.arn, sourceIPAddress, eventName
FROM cloudtrail_logs
WHERE eventName IN ('CreateAccessKey','CreateLoginProfile','AttachUserPolicy','PutUserPolicy')
  AND eventTime > now() - interval '1' day
ORDER BY eventTime DESC;
```

## Least Privilege Workflow
1. Start from AWS managed job-function policies only for humans; workloads get custom policies.
2. Generate a policy from CloudTrail activity (IAM Access Analyzer policy generation) after a soak period.
3. Remove unused roles, keys, and permissions using Access Analyzer unused-access findings.
4. Replace IAM users + access keys with SSO (IAM Identity Center) for humans and roles/OIDC federation for CI.
5. Add permission boundaries for delegated role creation.

## Anti-Patterns
- `"Action": "*"` / `"Resource": "*"` on workload roles.
- Logs stored in the same account an attacker can administer.
- Long-lived access keys in CI systems (use GitHub/GitLab OIDC → `AssumeRoleWithWebIdentity`).
- Alerting on everything from CSPM with no owner routing → alert fatigue, real findings ignored.
- SCP deny without a break-glass path → locked out during an incident.

## Checklist
- [ ] Org trail + log archive account with S3 Object Lock or bucket policy denying deletes.
- [ ] SCPs: protect logging/security services, region allow-list, IMDSv2, deny leaving org.
- [ ] GuardDuty/Defender/SCC enabled org-wide with delegated admin.
- [ ] Detections above routed to on-call with runbooks.
- [ ] CIS Benchmark scan scheduled; drift in IaC detected (`terraform plan` in CI).

## References
- Related skills: `skills/cloud-native/cloud-security-offensive/SKILL.md`, `skills/devops/vault/SKILL.md`, `skills/devops/policy-as-code/SKILL.md`.

### Shared References
Additional reference material for this skill, stored outside its own `references/` folder.

- `../../security/cspm/references/automated-remediation.md` — Automated Remediation for CSPM
- `../../security/cspm/references/ciem-permissions.md` — CIEM — Cloud Infrastructure Entitlement Management
- `../../security/cspm/references/compliance-frameworks.md` — Compliance Frameworks for CSPM
- `../../security/cspm/references/cspm-advanced.md` — CSPM Advanced Topics
- `../../security/cspm/references/cspm-drift-detection.md` — CSPM: Cloud Configuration Drift Detection & Remediation Engine
- `../../security/cspm/references/cspm-fundamentals.md` — CSPM Fundamentals
- `../../security/cspm/references/cspm-integration.md` — CSPM Integration
- `../../security/cspm/references/cspm-platforms.md` — CSPM Platforms
- `../../security/cspm/references/cspm-scanning-architecture.md` — CSPM: Scanning Architecture & Multi-Account Strategy

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.