Bug #1716
closedStrip whitespace on hostname save, invalidate input on embedded whitespace
Description
hostname input should probably strip/trim whitespace and possibly invalidate input with whitespace in it (which it may already do, didn't check yet)
Recently we had a case where an engineer copy/pasted a hostname string from some other source, pasted it in the host create window and there was a trailing whitespace (I believe a tab in this case).
This may be overly explicit but I'll paste some log snippets anyway:
Processing HostsController#create (for 10.0.9.9 at 2012-06-27 19:24:11) [POST] Parameters: {"commit"=>"Submit", "action"=>"create", "name"=>"Un-provisioned-777777 "}} Add DNS PTR record for Un-provisioned-777777 .prod.example.net Add DNS A record for Un-provisioned-777777 .prod.example.net/10.61.9.52 Create DHCP reservation for Un-provisioned-777777 .prod.example.net-00:11:22:33:44:55/10.61.9.52 Add the TFTP configuration for Un-provisioned-777777 .prod.example.net Fetching required TFTP boot files for Un-provisioned-777777 .prod.example.net Redirected to https://foreman.prod.example.net/hosts/Un-provisioned-777777%20.prod.example.net
Processing UnattendedController#provision (for 10.61.9.52 at 2012-06-27 19:29:55) [GET] Found Un-provisioned-777777 .prod.example.net Remove puppet certificate for Un-provisioned-777777 .prod.example.net Failed to remove Un-provisioned-777777 .prod.example.net's puppet certificate: bad URI(is not URI?): http://admin-lv-1.prod.example.net:8443/puppet/ca/Un-provisioned-777777 .prod.example.net Filter chain halted as [:handle_ca] rendered_or_redirected. Completed in 8ms (View: 0, DB: 2) | 200 OK [http://foreman.prod.example.net/unattended/provision]
Processing HostsController#update (for 10.0.9.9 at 2012-06-27 21:13:50) [PUT] Parameters: {"commit"=>"Submit", "action"=>"update", "_method"=>"put", "authenticity_token"=>"R5YHORYKEC10DkTXd7tcK+G0ZvDiqbTUqCRo6MBX2wU=", "id"=>"Un-provisioned-777777 .prod.example.net", "controller"=>"hosts", "host"=>{"comment"=>"", "architecture_id"=>"1", "subnet_id"=>"12", "managed"=>"1", "puppetproxy_id"=>"2", "name"=>"Un-provisioned-777777", "sp_mac"=>"", "puppetmaster_name"=>"admin-lv-1.prod.example.net", "sp_name"=>"", "mac"=>"00:21:9b:a7:7e:a1", "domain_id"=>"2", "enabled"=>"1", "root_pass"=>"[FILTERED]", "medium_id"=>"6", "hostgroup_id"=>"26", "is_owned_by"=>"2-Users", "ptable_id"=>"14", "sp_subnet_id"=>"", "ip"=>"10.61.9.52", "environment_id"=>"23", "model_id"=>"", "disk"=>"", "sp_ip"=>"", "puppetclass_ids"=>[""], "operatingsystem_id"=>"19"}} Delete the DNS PTR record for Un-provisioned-777777 .prod.example.net/10.61.9.52 Delete the DNS A record for Un-provisioned-777777 .prod.example.net/10.61.9.52 Remove DNS record for Un-provisioned-777777 .prod.example.net task failed with the following error: bad URI(is not URI?): http://admin-lv-1.prod.example.net:8443/dns/Un-provisioned-777777 .prod.example.net Rolling back due to a problem: Remove DNS record for Un-provisioned-777777 .prod.example.net 1 failed Un-provisioned-777777 .prod.example.netdel_dns_a_record Add DNS PTR record for Un-provisioned-777777 .prod.example.net/10.61.9.52 Failed to save: Remove DNS record for Un-provisioned-777777 .prod.example.net task failed with the following error: bad URI(is not URI?): http://admin-lv-1.prod.example.net:8443/dns/Un-provisioned-777777 .prod.example.net Rendering template within layouts/application Rendering hosts/edit Completed in 1342ms (View: 1058, DB: 16) | 200 OK [https://foreman.prod.example.net/hosts/Un-provisioned-777777%20.prod.example.net]
Processing HostsController#toggle_manage (for 10.0.9.9 at 2012-06-27 21:14:02) [PUT] Parameters: {"action"=>"toggle_manage", "_method"=>"put", "authenticity_token"=>"R5YHORYKEC10DkTXd7tcK+G0ZvDiqbTUqCRo6MBX2wU=", "id"=>"Un-provisioned-777777.prod.example.net", "controller"=>"hosts"} Rendering template within layouts/application Rendering common/404 (404) Filter chain halted as [:find_by_name] rendered_or_redirected. Completed in 28ms (View: 23, DB: 2) | 404 Not Found [https://foreman.prod.example.net/hosts/Un-provisioned-777777.prod.example.net/toggle_manage]
Eventually had to edit the dhcp leases file by hand.
Updated by Ohad Levy over 12 years ago
- Assignee changed from Ohad Levy to Mikael Fridh
i would add self.gsub!(/\s/,'') to the normalize hostname method.
also, its important to come with sane test cases as well for this pathch
Updated by Mikael Fridh over 12 years ago
Ohad Levy wrote:
i would add self.gsub!(/\s/,'') to the normalize hostname method.
Yes, you're right. Adding the simple gsub for now. Had a version that did strip (for leading and trailing whitespace) followed by rfc952/rfc1123-like hostname validation but scrapping it for now.
Updated by Mikael Fridh over 12 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100
Applied in changeset d860ed4ecc4e0bc6c0daeb62f807d9dd1418de1c.