Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow_superuser false blocks non admin user in Windows #16632

Open
kaisecheng opened this issue Nov 4, 2024 · 1 comment
Open

allow_superuser false blocks non admin user in Windows #16632

kaisecheng opened this issue Nov 4, 2024 · 1 comment

Comments

@kaisecheng
Copy link
Contributor

Setting allow_superuser: false is expected to run Logstash successfully with non admin user. However, on Windows, Logstash exits with an error even when the user is not an admin.

The issue occurs because Process.euid() always returns 0 in Windows.

Relates: #14089
cc @mashhurs

@donoghuc
Copy link
Member

donoghuc commented Nov 5, 2024

Puppet and Vagrant are both projects that require detecting this. Here are some ways they have approached it.

Puppet uses ffi to avoid WMI
This however is quite complex and requires ffi

https://github.com/puppetlabs/puppet/blob/e758d5c969403631810fa6385057ef0eaf03974f/lib/puppet/util/windows/user.rb#L11

Vagrant used to use WMI
Below is an example of how that looks, we could potentially cache these calls etc but it is probably going to be fraught with peril.

    running_process = WIN32OLE.connect("winmgmts://")
    process_id = Process.pid
    process = running_process.ExecQuery("Select * from Win32_Process where ProcessId = #{process_id}")
    owner = process.each.first.GetOwner

    # Check if the user is in the administrators group
    admin_group = running_process.ExecQuery("Select * from Win32_Group where LocalAccount = True and SID = 'S-1-5-32-544'")
    group_users = running_process.ExecQuery("Select * from Win32_GroupUser where GroupComponent = 'Win32_Group.Name=\"#{admin_group.each.first.Name}\",Domain=\"#{owner[1]}\"'")
    
    group_users.each do |user|
      return true if user.PartComponent.include?(owner[0])
    end
    false

Vagrant used to use registry keys

See this iteration hashicorp/vagrant@52e98ff where they replace looking up registry keys. Given that PR i'm not convinced this is the best path forward

Now Vagrant shells out to powershell:

If shelling out is acceptable here we could avoid gem dependencies and probably get the most accurate data. This however assumes we can reliably find a powershell executable.
https://github.com/hashicorp/vagrant/blob/e0161e5b0de4200001062342fb2b742acc2b7ea3/lib/vagrant/util/platform.rb#L103-L113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants