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

Support per-package dummy root-owned files in sandboxed builds #2007

Open
Shados opened this issue Mar 23, 2018 · 3 comments
Open

Support per-package dummy root-owned files in sandboxed builds #2007

Shados opened this issue Mar 23, 2018 · 3 comments
Assignees
Labels
feature Feature request or proposal

Comments

@Shados
Copy link
Member

Shados commented Mar 23, 2018

Motivation

There are package-included tests that effectively have dependencies on the contents of root-owned, non-store files inside the sandboxed environment (e.g. /etc/passwd), including files where a universal dummy file may not make sense (or there may be no clear defaults). Mostly integration tests.

There may be builds that have these kinds of dependencies as well, although I don't know of any, and based on nixpkgs I doubt there would be many of them if there are any.

Example Use Case

A fairly minimal example is that libssh2's integration tests against opensshd fails in a sandboxed build on NixOS, as below.
libssh2-test.nix:

with import <nixpkgs> {};

pkgs.libssh2.overrideAttrs (oldAttrs: {
  doCheck = true;
  preConfigure = ''
    # gives `sshd -dd` output for proper debugging of integration test failure
    export DEBUG=true

    # configure the sshd integration test to run correctly
    export USER=$(id -un)
    export ac_cv_path_SSHD=${openssh}/bin/sshd
    ./buildconf
  '';
  nativeBuildInputs = [
    autoconf automake libtool which
  ];
  checkInputs = [
    openssh
  ];
})

Relevant nix-build libssh2-test.nix output, if nix.useSandbox = true;:

...
debug1: userauth-request for user nixbld service ssh-connection method none [preauth]
debug1: attempt 0 failures 0 [preauth]
debug2: parse_server_config: config reprocess config len 1
User nixbld not allowed because shell /noshell does not exist
debug2: monitor_read: 8 used once, disabling now
debug2: monitor_read: 4 used once, disabling now
debug2: input_userauth_request: try method none [preauth]
debug1: userauth-request for user nixbld service ssh-connection method publickey [preauth]
debug1: attempt 1 failures 0 [preauth]
debug2: input_userauth_request: try method publickey [preauth]
debug2: userauth_pubkey: disabled because of invalid user [preauth]
Received disconnect from 127.0.0.1 port 47812:11: Normal Shutdown [preauth]
Disconnected from invalid user nixbld 127.0.0.1 port 47812 [preauth]
debug1: do_cleanup [preauth]
debug1: monitor_read_log: child log fd closed
debug1: do_cleanup
debug1: Killing privsep child 6836
Fingerprint: 86 AD B2 21 33 60 65 3D 9A 29 86 DE 22 99 DA 18 CC BA D3 AC
Authentication methods: publickey,password,keyboard-interactive
        Authentication by public key failed!

============================================================================
Testsuite summary for libssh2 -
============================================================================
# TOTAL: 3
# PASS:  2
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0
============================================================================
See tests/test-suite.log
Please report to [email protected]
============================================================================
make[3]: *** [Makefile:723: test-suite.log] Error 1
make[3]: Leaving directory '/build/libssh2-1.8.0/tests'
make[2]: *** [Makefile:831: check-TESTS] Error 2
make[2]: Leaving directory '/build/libssh2-1.8.0/tests'
make[1]: *** [Makefile:916: check-am] Error 2
make[1]: Leaving directory '/build/libssh2-1.8.0/tests'
make: *** [Makefile:545: check-recursive] Error 1
builder for '/nix/store/h25kni38az4d7yc8wvmva0klvb5nwhjp-libssh2-1.8.0.drv' failed with exit code 2
error: build of '/nix/store/h25kni38az4d7yc8wvmva0klvb5nwhjp-libssh2-1.8.0.drv' failed

Note: User nixbld not allowed because shell /noshell does not exist

The underlying issue is that openssh will refuse to auth a user if their shell (which is ultimately resolved by the NSS mechanism) does not actually exist. This basic test works fine with nix.useSandbox = false; on NixOS because the real nixbld users have nologin as their shell, which does happen to exist.

Of course, more complex tests involving actually running commands over the connection would still fail even there, but that's just more reason for this functionality -- it could let you run such tests, albeit only in a sandboxed build.

If the builder could specify the contents of the dummy /etc/passwd file, this could be worked around pretty trivially. Without that, it would require a nasty kludge of one kind or another (e.g. patch openssh, run it with an LD_PRELOAD to intercept the NSS resolution, use a different ssh server binary with different behaviour).

Related Issues

Questions

  • Are there any security implications of allowing derivations to specify a different view of root-owned files within the sandbox environment by swapping some out for dummy files?
  • If there are, is the set of problematic files well-known enough to manage with a blacklist, or must a whilelist of allowed dummy paths be defined instead?
@7c6f434c
Copy link
Member

I would say, there is also a question whether we want ot have builds that are guaranteed to fail without sandbox builds.

If you assume NixOS-like configuration of everything, you can use unshare during the build, and if not — you are not completely guaranteed to have every kernel feature needed for sandboxing.

@Shados
Copy link
Member Author

Shados commented Mar 23, 2018

An alternative to having builds that fail without sandbox would be to have the dis/use of the sandbox be an input to the tests, although that might motivate going further than #874 suggests and actually separate tests out into their own derivation, so as to keep the same hash for the actual build output.

@shlevy shlevy added the backlog label Apr 1, 2018
@shlevy shlevy self-assigned this Apr 1, 2018
@stale
Copy link

stale bot commented Feb 14, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 14, 2021
@fricklerhandwerk fricklerhandwerk added the feature Feature request or proposal label Oct 6, 2022
@stale stale bot removed the stale label Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

5 participants