Bug 1821999

Summary: [RHEL7.9] Do not log IMDSv2 token values into cloud-init.log
Product: Red Hat Enterprise Linux 7 Reporter: Frank Liang <xiliang>
Component: cloud-initAssignee: Eduardo Otubo <eterrell>
Status: CLOSED ERRATA QA Contact: Frank Liang <xiliang>
Severity: low Docs Contact:
Priority: low    
Version: 7.9CC: eterrell, huzhao, jgreguske, leiwang, linl, mrezanin, mtessun, ribarry, vkuznets, xiachen, yacao, ymao, yuxisun
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: cloud-init-19.4-7.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1822343 (view as bug list) Environment:
Last Closed: 2020-09-29 19:48:41 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1822343, 1850456    

Description Frank Liang 2020-04-08 03:29:42 UTC
After cloud-init added AWS IMDSv2 support, it saves token values in cloud-init.log. I am suggesting to backport the below patch to change this behavior.
commit 87cd040ed8fe7195cbb357ed3bbf53cd2a81436c
Author: Ryan Harper <ryan.harper>
Date:   Wed Feb 19 15:01:09 2020 -0600

    ec2: Do not log IMDSv2 token values, instead use REDACTED (#219)
   
    Instead of logging the token values used log the headers and replace the actual
    values with the string 'REDACTED'.  This allows users to examine cloud-init.log
    and see that the IMDSv2 token header is being used but avoids leaving the value
    used in the log file itself.

The current log is like this:
2020-04-07 09:49:34,693 - DataSourceEc2.py[DEBUG]: Fetching Ec2 IMDSv2 API Token
2020-04-07 09:49:34,693 - url_helper.py[DEBUG]: [0/1] open 'http://169.254.169.254/latest/api/token' with {'url': 'http://169.254.169.254/latest/api/token', 'headers': {'X-aws-ec2-metadata-token-ttl-seconds': '21600', 'User-Agent': 'Cloud-Init/19.4'}, 'allow_redirects': True, 'method': 'PUT', 'timeout': 1.0} configuration
2020-04-07 09:49:34,705 - url_helper.py[DEBUG]: Read from http://169.254.169.254/latest/api/token (200, 56b) after 1 attempts
2020-04-07 09:49:34,705 - DataSourceEc2.py[DEBUG]: Using metadata source: 'http://169.254.169.254'
2020-04-07 09:49:34,705 - url_helper.py[DEBUG]: [0/1] open 'http://169.254.169.254/2016-09-02/meta-data/instance-id' with {'url': 'http://169.254.169.254/2016-09-02/meta-data/instance-id', 'headers': {'X-aws-ec2-metadata-token': 'AQAEAKFXG-CkNfREz8EV84ZfvXwKeUOxK01GzrC5DgBd7Z7MzGrNLQ==', 'User-Agent': 'Cloud-Init/19.4'}, 'allow_redirects': True, 'method': 'GET'} configuration
2020-04-07 09:49:34,707 - url_helper.py[DEBUG]: Read from http://169.254.169.254/2016-09-02/meta-data/instance-id (200, 19b) after 1 attempts

Version-Release number of selected components (if applicable):

RHEL Version:
RHEL-7.9(cloud-init-19.4-3.el7.x86_64)

How reproducible:
100%

Steps to Reproduce:
1. Start a RHEL-7.9  AMI on aws.
2. Check /var/log/cloud-init.log.

Actual results:
token value is saved
Expected results:
No token value saved

Additional info:
- N/A

Comment 19 errata-xmlrpc 2020-09-29 19:48:41 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: cloud-init security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:3898