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

kraft net almost unusable with multiple users #992

Open
craciunoiuc opened this issue Nov 10, 2023 · 2 comments
Open

kraft net almost unusable with multiple users #992

craciunoiuc opened this issue Nov 10, 2023 · 2 comments
Labels
kind/bug Something isn't working priority/medium Issue which is important, but KraftKit is usable without it also.

Comments

@craciunoiuc
Copy link
Member

Describe the bug

Trying to use the kraft net subcommands together with kraft run is almost impossible when using multiple users.

In order to create a network interface you need to use sudo, and then you should be able to use it inside kraft run.

But, to use it there, you also need to use sudo for kraft run. This means that the user is changed and the path to the config also becomes changed (effectively using the home of root).

This can prove confusing as people ca run:

  1. sudo kraft run
  2. kraft ps

And then see no output, even though they should.

Steps to reproduce

No response

Expected behavior

No response

Which architectures were you using or does this bug affect?

x86_64, arm, arm64

Which operating system were you using or does this bug affect?

linux/debian, linux/fedora, linux/alpine, linux/arch, linux/other

Relevant log output

No response

@craciunoiuc craciunoiuc added the kind/bug Something isn't working label Nov 10, 2023
@github-project-automation github-project-automation bot moved this to 🧊 Icebox in KraftKit Roadmap Nov 10, 2023
@craciunoiuc craciunoiuc changed the title kraft net unusable with multiple users kraft net almost unusable with multiple users Nov 10, 2023
@craciunoiuc craciunoiuc added the priority/medium Issue which is important, but KraftKit is usable without it also. label Feb 29, 2024
@craciunoiuc
Copy link
Member Author

craciunoiuc commented Jul 5, 2024

@LucaSeri is it okay if I assign this issue to you? I know you bumped into this recently

I'm not sure how a fix looks like, probably making kraftkit somehow ask for sudo privileges when running just for the bridge creation.

On a successful run, in my head:

  1. kraftkit fetches all info related to bridges and prepares stuff (using user user)
  2. kraftkit invokes the bridge command, or whatever it does (using user root)
  3. kraftkit reports back on the status of the bridge creation and saves info (using user user)

This ensures that info is saved in the store with the correct permissions, and also the creation works as any user. It will of course ask for the root password, but that is to be expected.

Same in the case of kraft run, only exact, problematic operations should be grnted elevation, not everything

@craciunoiuc
Copy link
Member Author

craciunoiuc commented Feb 21, 2025

One more idea brainstorm resulted in this:

I was thinking on this and I have a possible stop-gap fix #992

What if we:

  1. Ensure that all files and directories created use the permissions of the parent directory? So if I run the directory /home/cez/.local/shared/kraftkit as root, everything inside it will belong to cez, instead of a mix. This will be ensured by saving the user in the G(ctx) global context when starting.
    ^ This fixes the case of sudo, but will require people to provide a path to alternate configs

  2. Use the $USER variable and the whoami result and equivalents:

➜  ~ sudo whoami
root
➜  ~ sudo -E whoami
root
➜  ~ sudo -E echo "$USER"
cez
➜  ~ sudo echo "$USER"
cez
➜  ~ sudo su
zen# echo "$USER"
root

^ With this we can add an Info message saying:
i kraft run with sudo by 'cez' user: defaulting to 'cez' file permissions

We can do 2. in the context where we print the sudo warning should be straight-forward -> just read $USER or $SUDO_USER

then we go and do 1. by checking if this is set and chowning all files that we touch/create

Might be a bit more annoying for MkdirAll

so it will require adding a:

defer func(){
  if user, group, ok := isSudoNotRoot(); ok {
    os.Chown(file, user, group)
  }
}()
os.CreateAsUser(path, user string)
os.OpenAsUser(path, user string)
os.MkdirAsUser(path, user string)
os.mkdirAllAsUser(path, user string)

there's also the nuclear option 3.: If root, create all files with extra permissions equal to user permissions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working priority/medium Issue which is important, but KraftKit is usable without it also.
Projects
Status: Ready
Status: 🧊 Icebox
Development

No branches or pull requests

2 participants