Skip to content

Commit

Permalink
(FACT-3452) Make Xen resolver more strict
Browse files Browse the repository at this point in the history
Prior to this commit, Facter could misidentify non-Xen systems as being
Xen-based.

In some circumstances, a non-Xen system will have /dev/xvd* files
present as symlinks to other devices. This was observed on an Amazon
Linux 2023 machine, which was running on a Nitro (KVM-based) hypervisor
but symlinked /dev/xvda1 to an nvme device.

This commit updates the Xen resolver to check if /dev/xvda1 is a symlink
to avoid misidentifying if a system is Xen-based.
  • Loading branch information
mhashizume committed Dec 4, 2023
1 parent c250d91 commit 3a2ac89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/facter/resolvers/xen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def detect_xen(fact_name)

def detect_xen_type
xen_type = 'xen0' if File.exist?('/dev/xen/evtchn')
xen_type = 'xenu' if !xen_type && (File.exist?('/proc/xen') || File.exist?('/dev/xvda1'))
if !xen_type && (File.exist?('/proc/xen') || (File.exist?('/dev/xvda1') && !File.symlink?('/dev/xvda1')))
xen_type = 'xenu'
end

xen_type
end
Expand Down
12 changes: 12 additions & 0 deletions spec/facter/resolvers/xen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,16 @@
expect(xen_resolver.resolve(:domains)).to be_nil
end
end

context 'when /dev/xvda1 is a symlink' do
let(:evtchn_file) { false }

before do
allow(File).to receive(:symlink?).with('/dev/xvda1').and_return(true)
end

it 'returns nil' do
expect(xen_resolver.resolve(:vm)).to be_nil
end
end
end

0 comments on commit 3a2ac89

Please sign in to comment.