canonical / canonical/cloud-init
cc_phone_home.py would benefit from allowing headers for the request to be specified by the user
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 1.1k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 18
Description
This bug was originally filed in Launchpad as [LP: #1771174](https://bugs.launchpad.net/cloud-init/+bug/1771174)
Launchpad details
affected_projects = []
assignee = None
assignee_name = None
date_closed = None
date_created = 2018-05-14T18:00:44.254686+00:00
date_fix_committed = None
date_fix_released = None
id = 1771174
importance = wishlist
is_complete = False
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1771174
milestone = None
owner = dpneumo
owner_name = Mitch Kuppinger
private = False
status = triaged
submitter = dpneumo
submitter_name = Mitch Kuppinger
tags = []
duplicates = []
_Launchpad user **Mitch Kuppinger(dpneumo)** wrote on 2018-05-14T18:00:44.254686+00:00_
I user phone_home to programmatically set allowed_hosts on my management node when creating cloud based VMs. eg. on DigitalOcean. I use a Rails based tool to manage the VM creation. Without some workarounds that lower security I receive a "Can't verify CSRF token authenticity." error from Rails when phone_home attempts to connect. The ability to set a header would be very useful:
phone_home:
url: http://example.com/$INSTANCE_ID/
post:
- pub_key_rsa
- instance_id
- fqdn
tries: 10
headers: { X-CSRF-Token: 1234567890 } #<<<<<<<
Since util.read_file_or_url allows specifying headers
minor modifications to cc_phone_home.py would make this possible:
line 85:
url = ph_cfg['url']
post_list = ph_cfg.get('post', 'all')
header_dict = ph_cfg.get('headers', {}) #<<<<< Added
tries = ph_cfg.get('tries')
line 138:
try:
util.read_file_or_url(url, data=real_submit_keys,
retries=tries, sec_between=3,
ssl_details=util.fetch_ssl_details(cloud.paths),
headers=header_dict) #<<<<< Added
Contributor guide
Assessment
This issue has not been assessed yet.