Description
For a service delivered by CloudFront, match default_cache_behavior.target_origin_id to an ID in origins and set enabled: true.
Potential impact
A disabled distribution cannot serve the content. A directly reachable origin may accept requests without the authentication or filtering applied at CloudFront.
Remediation
Check that the service hostname points to the distribution, request a real file and verify log delivery. Apply the origin restrictions and authentication the service needs, and keep private responses out of shared caches.
Examples
Supply an HTTPS-capable origin and a logging bucket that CloudFront can write to.
Before
- name: Create a CloudFront distribution
community.aws.cloudfront_distribution:
state: present
caller_reference: unique test distribution ID
default_cache_behavior:
target_origin_id: "my test origin-000111"
forwarded_values:
query_string: true
cookies:
forward: all
headers:
- "*"
viewer_protocol_policy: allow-all
smooth_streaming: true
compress: true
allowed_methods:
items:
- GET
- HEAD
cached_methods:
- GET
- HEAD
enabled: false
logging:
enabled: true
include_cookies: false
bucket: mylogbucket.s3.amazonaws.com
prefix: myprefix/
The first task disables the distribution and omits the origin referenced by the cache behavior, so it cannot create a new distribution.
After
- name: Create a CloudFront distribution
community.aws.cloudfront_distribution:
state: present
caller_reference: unique test distribution ID
origins:
- id: "my test origin-000111"
domain_name: www.example.com
origin_path: /production
custom_origin_config:
http_port: 80
https_port: 443
origin_protocol_policy: https-only
origin_ssl_protocols:
- TLSv1.2
default_cache_behavior:
target_origin_id: "my test origin-000111"
forwarded_values:
query_string: true
cookies:
forward: all
headers:
- "*"
viewer_protocol_policy: allow-all
compress: true
allowed_methods:
items:
- GET
- HEAD
cached_methods:
- GET
- HEAD
logging:
enabled: true
include_cookies: false
bucket: mylogbucket.s3.amazonaws.com
prefix: myprefix/
enabled: true
The second uses HTTPS to the origin, but viewer_protocol_policy: allow-all also permits HTTP from viewers. Its legacy cache settings forward all request headers, which disables object caching for this behavior.