RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1454491 - cloud-init with config drive does not populate dns information correctly
Summary: cloud-init with config drive does not populate dns information correctly
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: cloud-init
Version: 7.3
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: 7.5
Assignee: Ryan McCabe
QA Contact: Udi Shkalim
URL:
Whiteboard:
Depends On:
Blocks: 1537439
TreeView+ depends on / blocked
 
Reported: 2017-05-22 22:45 UTC by Graeme Gillies
Modified: 2023-02-22 23:02 UTC (History)
15 users (show)

Fixed In Version: cloud-init-0.7.9-16.el7
Doc Type: Bug Fix
Doc Text:
Prior to this update, the cloud-init service in some cases did not provide newly created virtual machines with appropriate DNS configuration. The underlying code has been fixed, which prevents this problem from occurring.
Clone Of:
: 1537439 (view as bug list)
Environment:
Last Closed: 2018-04-10 14:05:07 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Launchpad 1693251 0 None None None 2017-05-26 14:45:36 UTC
Launchpad 1693265 0 None None None 2017-05-26 14:46:00 UTC
Red Hat Product Errata RHEA-2018:0806 0 normal SHIPPED_LIVE cloud-init bug fix and enhancement update 2018-04-10 12:40:54 UTC

Description Graeme Gillies 2017-05-22 22:45:00 UTC
Description of problem:
when using cloud-init in an Openstack/other cloud environment where no dhcp server is available, cloud init draws on the "config drive" functionality to get the networking information to assign to interfaces on the system.

This works fine with the exception of dns server information.

If I read the code at cloud-init/cloudinit/net/sysconfig.py, it looks like it attempts to write the dns information directly into /etc/resolv.conf which is not the correct way to do this, as it will get clobbered by the network/NetworkManager services. It instead should be written directly into the ifcfg file as DNS1= and DNS2= entries

Version-Release number of selected component (if applicable):
cloud-init-0.7.9-5.el7.x86_64

How reproducible:
Very reproducable

Steps to Reproduce:
1. Deploy an Openstack installation with a provider network for a tenant, no dhcp
2. create an instance with something like
openstack server create gg-test --image rhel-guest-image-7.2-20160302.0.x86_64 --flavor m1.large --nic net-id=provider-network --config-drive True --key ggillies

Actual results:
Note once the instance boots that cloud-init populates the network configuration file /etc/sysconfig/network-scripts/ifcfg-eth0 correctly but without dns information


Expected results:
The file /etc/sysconfig/network-scripts/ifcfg-eth0 should be populated with the correct dns information (DNS1= and DNS2=)

Additional info:

Comment 2 Lars Kellogg-Stedman 2017-05-23 18:58:18 UTC
Can you attach the contents of openstack/latest/network_data.json from the config drive?

Comment 3 Graeme Gillies 2017-05-24 02:12:21 UTC
# cat openstack/latest/network_data.json
{"services": [{"type": "dns", "address": "10.11.142.1"}, {"type": "dns", "address": "10.11.142.2"}], "networks": [{"network_id": "3d065b27-8f5f-4fe0-abad-0a05a0fdba75", "type": "ipv4", "netmask": "255.255.252.0", "link": "tapf80c0351-5d", "routes": [{"netmask": "0.0.0.0", "network": "0.0.0.0", "gateway": "10.8.231.254"}], "ip_address": "10.8.229.8", "id": "network0"}], "links": [{"ethernet_mac_address": "fa:16:3e:2b:c5:5e", "mtu": 1500, "type": "ovs", "id": "tapf80c0351-5d", "vif_id": "f80c0351-5d4a-450b-9c4d-35800dadcecc"}]}

Comment 4 Lars Kellogg-Stedman 2017-05-24 13:22:23 UTC
I'm testing this using cloud-init-0.7.9-7, which includes some patches that impact network config generation.

Using your network_data.json, I see that as you reported, /etc/resolv.conf is configured correctly, although the DNS servers are not added to ifcfg-eth0.  The resolver configuration in /etc/resolv.conf appears to survive both an ifdown/ifup and a reboot.  That is, it does not get clobbered by NetworkManager.

NetworkManager will never update /etc/resolv.conf directly; it only updates /run/NetworkManager/resolv.conf, and if /etc/resolv.conf is simply a file rather than a symlink, that information will never be removed by NetworkManager.

I agree that the DNS server information *ought* to be added to ifcfg-eth0, but is the current behavior actively causing a problem?

Comment 5 Lars Kellogg-Stedman 2017-05-24 14:36:33 UTC
Actually, I lied about how NM treats /etc/resolv.conf, but the rest of the #4 stands; everything seems to persist as expected and I was not able to generate a problem.  For the record, I discussed this with the NetworkManager folks on #nm:

09:27 <larsks> Will NM update /etc/resolv.conf if it's a file? Or only if it is a symlink to e.g. /run/NetworkManager/resolv.conf?
09:30 <thaller> larsks, depends on rc-manager setting. But both for "file" and "symlink" it would
09:30 <thaller> described in `man NetworkManager.conf`
09:30 <larsks> I was just reading through that.  To make sure I've reading it correctly...when rc-manager is "file", it will just update /etc/resolv.conf in place if it's a file, right?
09:32 <thaller> with rc-manager=file:    yes, a file will be updated. And a symlink will be followed.   
09:32 <larsks> ..and if /etc/resolv.conf is pre-configured with nameserver entries, and ifcfg-eth* does not contain any DNSn=x.x.x.x entries, the pre-existing nameserver configuration should persist?
09:32 <larsks> (assuming static interface configs and not dhcP)
09:33 <thaller> no. NM would not pick up configuration from /etc/resolv.conf. It would update resolve.conf with the information it has (no name servers)...
09:34 <larsks> Huh. So now I am confused.
09:34 <larsks> THis question stems from how cloud-init is setting up resolv.conf.
09:34 <larsks> It is editing nameserver entries to /etc/resolv.conf, but does not include that information in the generate interface config files (ifcfg-eth*).
09:34 <larsks> Howerver, running 'ifdown eth0/ifup eth0' does not clobber /etc/resolv.conf.
09:35 <larsks> This is on a CentOS 7 image, running NetworkManager 1.8.0.
09:37 <thaller> larsks, I think we changed, that NM will not write out resolv.conf it has no nameservers... in that case, writing out an empty resolve.conf is deemed pointless, and it would leave the existing one in place (bengal ??).    
09:39 <bengal> thaller: correct
09:39 <larsks> bengal: thaller: awesome, thanks.
09:39 <thaller> (however, that does not mean that NM could merge DNS configuration from outside sources. Meaning: (a) you either manage all your DNS with NM exclusively; or (b) you tell NM to not manage it (rc-manager=unmanged, dns=none);     or (c) you have an external service that can manage nameserver information from multiple sources (sd-resolved, resolveconf, netconf, your own script)
09:40 <larsks> Right. THe question was simply whether the current behavior of cloud-init was going to be problematic.
09:40 <larsks> I think the answer is "could be".
09:41 <thaller> yes "could be". To be sure, drop a configuration snippet with "dns=none" to /etc/NetworkManager/conf.d
09:41 <larsks> RIght. Or correctly configure the interface config files.
09:41 <thaller> or (rc-manager=unmanaged)


Thinking about this for a bit, the problem would seem to exist at a level higher than cloud-init.  Take a look at your network_data.json; you'll note that the DNS nameserver information is *not* interface scoped.  That means that is simply not possible for cloud-init to correctly add the nameserver information to the ifcfg-eth* files, because there is no way to associate the nameservers with a particular interface.

I think the correct short-term solution is to add the dns=none configuration setting to NetworkManager.  I've opened upstream bug https://bugs.launchpad.net/cloud-init/+bug/1693251 with that request.

The longer-term solution would be to fix Nova to provide interface-scoped nameserver information.

Comment 6 Lars Kellogg-Stedman 2017-05-24 15:12:45 UTC
See also:

https://bugs.launchpad.net/nova/+bug/1693265

Comment 7 Graeme Gillies 2017-05-28 23:12:04 UTC
Hi Lars,

So what you are saying does make sense, however I can provide a bit more context for our specific use case.

We are attempting to install Openshift on Openstack using provider networks. This means that the network has no dhcp agent, so relies entirely on config drive to configure the networking correctly.

Initially I was working around this issue by manually writing the dns entries to /etc/resolv.conf, but the team installing Openshift came back to me and said that this is not a satisfactory solution, as the Openshift installer restarts and reconfigures the networking (to use OVS for Openshifts internal networking), which then causes either NetworkManager or something else to remove those entries from /etc/resolv.conf. In fact, according to them the only correct way is to have the dns entries written into /etc/sysconfig/network-scripts/ifcfg* as DNS1 and DNS2 so that they correctly survive and apply regardless of what Openshift does with the networking.

This makes sense to me, but your point about dns information being not scoped to an interface also makes sense, so unfortunately we might be in between a rock and a hard place. That being said, I'm sure you can appreciate the motivation for us to have Openshift on Openstack be a first class citizen, so we unfortunately might need to figure something out.

Comment 8 Ryan McCabe 2017-06-12 18:10:46 UTC
Fix accepted by upstream in launchpad commit 67bab5bb804e2346673430868935f6bbcdb88f13

Comment 18 Graeme Gillies 2017-09-26 00:50:35 UTC
Can we resolve this? Looks like it did in fact make it into 7.4

Comment 36 Udi Shkalim 2018-02-11 16:02:30 UTC
Verified on: cloud-init-0.7.9-23.el7


fedora@fedora-5084 ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0 
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=static
DEFROUTE=yes
DEVICE=eth0
GATEWAY=192.168.100.1
HWADDR=fa:16:3e:4b:45:ea
IPADDR=192.168.100.10
MTU=1450
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet
USERCTL=no


[fedora@fedora-5084 ~]$ cat /etc/resolv.conf 
; Created by cloud-init on instance boot automatically, do not edit.
;
nameserver 10.35.28.28
search localdomain

[fedora@fedora-5084 ~]$ cat /etc/NetworkManager/
conf.d/       dispatcher.d/ 
[fedora@fedora-5084 ~]$ cat /etc/NetworkManager/conf.d/99-cloud-init.conf 
# Created by cloud-init on instance boot automatically, do not edit.
#
[main]
dns = none

Comment 39 errata-xmlrpc 2018-04-10 14:05:07 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, 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/RHEA-2018:0806


Note You need to log in before you can comment on or make changes to this bug.