Skip to main content

SKY-D407 · Deployment and infrastructure

Terraform lets EC2 servers use metadata without tokens (IMDSv1)

High

Every EC2 server can ask a local metadata service for its temporary AWS credentials. SKY-D407 reports a Terraform aws_instance or aws_launch_template with http_tokens = "optional", which keeps the old token-free version 1 (IMDSv1) turned on.

Languages
Terraform
Quality gate
counted toward the gate limits (full and diff scans). Reported under security (danger). It counts toward max_high and max_security; the rule never reports CRITICAL.
Finding type
review
Catalog name
Terraform AWS instance metadata tokens optional
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

With IMDSv1, a server-side request forgery bug (an app that fetches a URL an attacker chooses) is enough to read the server's AWS keys from http://169.254.169.254. IMDSv2's session token stops these one-request attacks; the 2019 Capital One breach used exactly this path.

What Skylos flags

main.tf · TerraformReported on line 1
resource "aws_instance" "web" {  ami           = "ami-0abcdef1234567890"  instance_type = "t3.small"   metadata_options {    http_endpoint = "enabled"    http_tokens   = "optional"  }}

What Skylos leaves alone

main.tf · Terraform
resource "aws_instance" "web" {  ami           = "ami-0abcdef1234567890"  instance_type = "t3.small"   metadata_options {    http_endpoint = "enabled"    http_tokens   = "required"  }}

Why Skylos leaves it alone

The same block with tokens required: only IMDSv2 is served.

How Skylos decides

  1. Runs with --danger (or -a). Reads .tf and .tf.json files, skipping .terraform, .git, node_modules, vendor, build, dist and virtual-environment folders, and parses them as HCL without running Terraform or contacting AWS.
  2. Resolves only literal values and local values of the same module. Input variables, data sources, attributes of other resources and module outputs stay unknown, and an unknown value never produces a finding.
  3. Skips a resource with count = 0 or an empty for_each, and needs the official AWS provider (hashicorp/aws, which an aws_ resource uses unless another provider is configured).
  4. Checks the single metadata_options block of aws_instance and aws_launch_template.
  5. Reports http_tokens = "optional" while http_endpoint is enabled or not set. An endpoint set to disabled passes.
  6. A missing metadata_options block, a dynamic block or an unknown value is not judged.
  7. Reports HIGH on the resource line.

How to fix it

Require tokens. Most current SDKs and agents support IMDSv2; test old software first.

main.tf · Terraform · the fix, against the flagged file
resource "aws_instance" "web" {  ami           = "ami-0abcdef1234567890"  instance_type = "t3.small"   metadata_options {    http_endpoint = "enabled"Removed:     http_tokens   = "optional"Added:     http_tokens   = "required"  }}

When it can be wrong

  • An instance with no metadata_options block is not reported, although many AMIs then still accept IMDSv1. Write the block.
  • Values that come from variables, modules or other resources are not checked, because Skylos does not run Terraform: cidr_blocks = var.admin_cidrs is not reported even when its default is 0.0.0.0/0.
  • It judges the declaration only. It does not know what is deployed, and other settings (account defaults, security groups, routing) can make the real exposure smaller or larger.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Terraform rules read no inline marker: # skylos: ignore[SKY-D407] on the resource line does not hide the finding.

  • [tool.skylos] ignore = ["SKY-D407"] turns the rule off for the project.

  • A baseline (skylos baseline ., then --baseline) accepts the declarations that exist today and reports new ones.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.