Skip to content

Separate home directories for each toolbox #1044

Closed

Description

@hunger

I already have a container based development workflow (using manually created systemd.nspawn containers) but would like to switch over to a properly maintained solution like toolbox.

I have several customers that I need to keep separate from each other. In my current workflow I have a root-owned folder in ~/.local/share/machines, with sub-folders owned by my user.

When I start my development container, it checks for ~/.local/share/machine/<CONTAINER_NAME> and if that exists, then it bind-mounts that as my home directory into the container. It also bind-mounts the ~/Download folder into all container images, so that I can (ab-)use that to transfer data between different containers;-) That way I can have private keys and whatever other customer related information separate from each other and not even available to programs that can access my home directory (as they can not enter ~/-local/share/machines as that is only accessible by root:-)

If there is no folder with the same name as the container in ~/.local/share/machines, then I mount the normal /home/USERNAME (much less sophisticated than what toolboox does!)

Would a similar setup be possible somehow using toolbox? I did not find anything in the manual pages, so I think this can be considered a feature request;-)

Activity

  1. nodefourtytwo commented on Jun 13, 2022

    @nodefourtytwo

    If you wrote a script for your workflow, would you care sharing it?

  2. hunger commented on Jun 17, 2022

    @hunger
    Author

    I doubt it is useful anywhere but in my specific setup: I generate container filesystems from a configuration file and the same file also generates systemd-nspawn settings and a start script.

    My setup is strictly less useful than toolbox: I have to restart my containers whenever the network changes:-/

  3. jonleivent commented on Jul 26, 2022

    @jonleivent

    Would using bubblewrap outside toolbox to do the bind mounting work for you? Something like:

    bwrap --bind $HOME/.local/share/machine/<CONTAINER_NAME> $HOME toolbox enter ...
    

    Actually, since the toolboxes are themselves stored in the home dir, I think under .config/toolbox and .local/share/containers, you'd have your choice of either starting out with those within your container -- meaning, you created the toolbox with:

    bwrap --bind $HOME/.local/share/machine/<CONTAINER_NAME> $HOME toolbox create ...
    

    Or, first bind mounting your own .config/toolbox and .local/share/containers into your container with initial --bind options to that bwrap toolbox enter call. I'd probably choose the create-toolbox-within-bwrap case because I don't have a clue what sharing those toolbox folders across multiple users would do - so one per container seems safest.

    I also have container-based systems I'm in the process of testing out with toolbox. I'm not sure bwrap and toolbox work together, but I might try something like this myself.

  4. jonleivent commented on Jul 26, 2022

    @jonleivent

    Oh - sorry - those bwrap calls should all have --dev-bind / / first. I keep forgetting that.

  5. inikishev commented on Sep 6, 2022

    @inikishev

    #348 so in this thread there seems to be a programming code that you can add into your ".bashrc" before "unset rc" line, and it will work. Although I don't know if using this approach has any disadvantages.

  6. debarshiray commented on Oct 27, 2022

    @debarshiray
    Member

    Yes, this is something that has come up before several times. Unfortunately, doing this properly is going to be a lot of work.

    Various people have come up with various hacks that work for their specific use-case. eg., some folks run toolbox with a overriden HOME.

    I am going to close this issue so that the list of open issues doesn't balloon out of control, and continues to roughly reflect the items that are on the current to-do list. However, it will still be around for future reference.

  7. debarshiray commented on Oct 27, 2022

    @debarshiray
    Member

    Thanks for your interest in Toolbx.

  8. mjlbach commented on Mar 25, 2023

    @mjlbach
    Contributor

    Hey @debarshiray, I'm interested in working on this. I don't think this is a duplicate of #183

    For example there are many local configuration files that are useful to have unique across different containers (apart from any security concerns), you might want to test a containerfile without any configuration from the system home interfering, etc. I find myself using distrobox for that purpose.

    Do you have thoughts on the design/concerns about a simple approach that just binds a configurable home directory as a flag? I'm happy to file a PR and iterate on this.

  9. ErrorNoInternet commented on Apr 23, 2023

    @ErrorNoInternet

    Any updates on this? I create .spec files for COPR in a toolbox (some build packages are conflicting with my host packages). However, a bunch of programs I use within the container keep creating cache files in my home directory, which is really annoying. rpmbuild also creates a rpmbuild directory in my home directory (I know its possible to use a different directory, but sometimes I forget to do that). I would love to be able to set a custom home directory, or automatically use a different home directory for each container (with an option to just share the user's home directory, of course).

  10. debarshiray commented on Jun 28, 2023

    @debarshiray
    Member

    Any updates on this? I create .spec files for COPR in a toolbox (some build packages are conflicting with my host packages). However, a bunch of programs I use within the container keep creating cache files in my home directory, which is really annoying. rpmbuild also creates a rpmbuild directory in my home directory (I know its possible to use a different directory, but sometimes I forget to do that). I would love to be able to set a custom home directory, or automatically use a different home directory for each container (with an option to just share the user's home directory, of course).

    What if you temporarily overrode HOME when using the Toolbx container?

    $ HOME=/path/to/custom/home toolbox create
    ...
    
  11. ErrorNoInternet commented on Jun 29, 2023

    @ErrorNoInternet

    Yes, that's my current solution but I have to manually do it every time for toolbox enter, and I sometimes forget.
    Some apps still use /home/ instead of $HOME though.

  12. ffimnsr commented on Oct 26, 2023

    @ffimnsr

    I think it's simple to create a wrapper script for the problem above. It is not the best design but that works great for me.

  13. juhp commented on Oct 30, 2023

    @juhp
    Contributor

    Doesn't seem to work for me (only seems to duplicate the podman/toolbox configs now):

    $ mkdir -p toolbox39
    $ HOME=~/toolbox39 toolbox list
    $ HOME=~/toolbox39 toolbox enter
    :
    ⬢[petersen@toolbox ~]$ echo $HOME
    /home/petersen
    $ distrobox create -H ~/toolbox39
    $ distrobox enter
    [distrobox petersen]$ echo $HOME
    /home/petersen/toolbox39

    I feel this highly requested feature could be implemented and polished incrementally:
    it doesn't have to be perfect out of the door IMHO.

  14. debarshiray commented on Feb 1, 2024

    @debarshiray
    Member

    It looks like Go's os/user isn't respecting the HOME environment variable:

    package main
    
    import (
    	"fmt"
    	"os/user"
    )
    
    func main() {
    	user, _ := user.Current()
    	fmt.Printf("%s\n", user.HomeDir)
    }
    $ HOME=/tmp go run user.go 
    /home/rishi
  15. christiansam commented on Mar 10, 2024

    @christiansam
  16. superuser-miguel commented on Jun 18, 2024

    @superuser-miguel

    please mention the info to override the $HOME env-variable,
    along with a general note - that actions inside a toolbox's bind-mounted paths , e.g. ~/.dot-directories like ~/.cache/fontconfig/ - might cause sideeffects for the user in the host env.

    From the Quick Docs

    • Containers are a good way to isolate and organise the dependencies needed for different projects.

    Which is misleading as the use of /home would not keep it organized. . .

  17. SolarLune commented on Aug 18, 2024

    @SolarLune

    It looks like Go's os/user isn't respecting the HOME environment variable:

    user.Current() gives the current user information with their uisual home directory. os.UserHomeDir() gives the current user's home directory as it's been set or overridden.

    Running this, for example:

    package main
    
    import (
    	"fmt"
    	"os"
    )
    
    func main() {
    	fmt.Println(os.UserHomeDir())
    }
    

    with the command HOME=~/test/ go run ./main.go works.

    So, replacing user.HomeDir at

    workDir = currentUser.HomeDir
    and
    homeDirEvaled, err := filepath.EvalSymlinks(currentUser.HomeDir)
    with os.UserHomeDir() might resolve the issue?

  18. debarshiray commented on Oct 10, 2024

    @debarshiray
    Member

    It looks like Go's os/user isn't respecting the HOME environment variable:

    user.Current() gives the current user information with their uisual home directory. os.UserHomeDir() gives the current user's home directory as it's been set or overridden.

    Bingo! That might be it. Thank you for figuring it out.

    I have filed a new issue to track this: #1564

    Do you want to submit a pull request for it?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions