SKY-D407 · Deployment and infrastructure
Terraform lets EC2 servers use metadata without tokens (IMDSv1)
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 towardmax_highandmax_security; the rule never reports CRITICAL. - Finding type
- review
- Catalog name
- Terraform AWS instance metadata tokens optional
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
resource "aws_instance" "web" { ami = "ami-0abcdef1234567890" instance_type = "t3.small" metadata_options { http_endpoint = "enabled" http_tokens = "optional" }}What Skylos leaves alone
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
- Runs with
--danger(or-a). Reads.tfand.tf.jsonfiles, skipping.terraform,.git,node_modules,vendor,build,distand virtual-environment folders, and parses them as HCL without running Terraform or contacting AWS. - Resolves only literal values and
localvalues 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. - Skips a resource with
count = 0or an emptyfor_each, and needs the official AWS provider (hashicorp/aws, which anaws_resource uses unless another provider is configured). - Checks the single
metadata_optionsblock ofaws_instanceandaws_launch_template. - Reports
http_tokens = "optional"whilehttp_endpointisenabledor not set. An endpoint set todisabledpasses. - A missing
metadata_optionsblock, adynamicblock or an unknown value is not judged. - Reports HIGH on the
resourceline.
How to fix it
Require tokens. Most current SDKs and agents support IMDSv2; test old software first.
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_optionsblock 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_cidrsis not reported even when its default is0.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.