Skip to content

Commit

Permalink
many: do not use runtime nss when looking up for users/groups from sn…
Browse files Browse the repository at this point in the history
…apd snap

When snapd runs as a snap, it has its own runtime. This may not have
NSS plugins needed for the host. For example to get users from
AD/LDAP/Kerberos, or systemd-homed, or custom user databses.  In
general we can use tag `osusergo` to make go not to use the local
configuration (i.e. `/etc/nsswitch.conf`), however, even if it is fine
for most databases, we really need users and groups to be resolved
with the host configuration.

To be able to load correctly plugins, we expect the host system to
provide `getent`. And we query `passwd` and `group` databases through
this command.

In the future we should connect the systemd-userdb if it is
running and use `getent` only as fallback.
  • Loading branch information
valentindavid committed Jul 10, 2024
1 parent 35964cf commit 44bf5f1
Show file tree
Hide file tree
Showing 54 changed files with 476 additions and 53 deletions.
6 changes: 2 additions & 4 deletions build-aux/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ parts:
- squashfs-tools
- xdelta3
- zlib1g
# This is needed for using os/user on Ubuntu Core
# TODO: do not use os/user, but io.systemd.NameServiceSwitch through dbus
- libnss-extrausers
stage:
- -usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/ld*.so*
- -lib32
Expand All @@ -112,9 +109,9 @@ parts:
- -usr/share/man
- -usr/share/lintian
- -usr/share/lintian/**
- -usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/libnss_*.so.2
override-build: |
craftctl default
mv "${CRAFT_PART_INSTALL}/usr/lib/libnss_extrausers.so.2" "${CRAFT_PART_INSTALL}/usr/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR}/"
cp -rT "${CRAFT_PART_INSTALL}/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR}" "${CRAFT_PART_INSTALL}/usr/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR}"
rm -rf "${CRAFT_PART_INSTALL}/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR}"
rm -f "${CRAFT_PART_INSTALL}/lib/${DYNAMIC_LINKER}"
Expand Down Expand Up @@ -305,6 +302,7 @@ parts:
esac
;;
esac
TAGS+=(snap osusergo)
# FIPS specific build tags
if [ -f fips-build ]; then
Expand Down
2 changes: 1 addition & 1 deletion client/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"errors"
"fmt"
"net/url"
"os/user"
"strconv"
"strings"
"time"

"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/snap"
)

Expand Down
2 changes: 1 addition & 1 deletion client/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ package client_test
import (
"encoding/json"
"fmt"
"os/user"
"strconv"
"strings"

"gopkg.in/check.v1"

"github.com/snapcore/snapd/client"
"github.com/snapcore/snapd/osutil/user"
)

func mksvc(snap, app string) *client.AppInfo {
Expand Down
2 changes: 1 addition & 1 deletion client/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"encoding/json"
"fmt"
"os"
"os/user"
"path/filepath"

"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/sys"
"github.com/snapcore/snapd/osutil/user"
)

// User holds logged in user information.
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/cmd_routine_file_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"fmt"
"net/http"
"net/url"
"os/user"
"path/filepath"
"strings"

. "gopkg.in/check.v1"

"github.com/snapcore/snapd/client"
snap "github.com/snapcore/snapd/cmd/snap"
"github.com/snapcore/snapd/osutil/user"
)

type SnapRoutineFileAccessSuite struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"net"
"os"
"os/exec"
"os/user"
"path/filepath"
"regexp"
"strconv"
Expand All @@ -49,6 +48,7 @@ import (
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/strace"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/sandbox/cgroup"
"github.com/snapcore/snapd/sandbox/selinux"
"github.com/snapcore/snapd/snap"
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"fmt"
"net/http"
"os"
"os/user"
"path/filepath"
"strings"
"time"
Expand All @@ -40,6 +39,7 @@ import (
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/strace"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/sandbox/cgroup"
"github.com/snapcore/snapd/sandbox/selinux"
"github.com/snapcore/snapd/snap"
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/cmd_userd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"net"
"net/http"
"os"
"os/user"
"path"
"path/filepath"
"strings"
Expand All @@ -38,6 +37,7 @@ import (
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/testutil"
"github.com/snapcore/snapd/usersession/autostart"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"fmt"
"go/doc"
"os"
"os/user"
"strings"
"text/tabwriter"

Expand All @@ -35,6 +34,7 @@ import (
"github.com/snapcore/snapd/i18n"
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/snap/channel"
"github.com/snapcore/snapd/strutil"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package main
import (
"context"
"os"
"os/user"
"time"

"github.com/jessevdk/go-flags"
Expand All @@ -31,6 +30,7 @@ import (
"github.com/snapcore/snapd/cmd/snaplock/runinhibit"
"github.com/snapcore/snapd/image"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/sandbox/cgroup"
"github.com/snapcore/snapd/sandbox/selinux"
"github.com/snapcore/snapd/seed/seedwriter"
Expand Down
2 changes: 1 addition & 1 deletion daemon/api_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
"io"
"net/http"
"net/url"
"os/user"
"sort"
"strconv"
"strings"

"github.com/snapcore/snapd/client/clientutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord/auth"
"github.com/snapcore/snapd/overlord/servicestate"
"github.com/snapcore/snapd/overlord/state"
Expand Down
2 changes: 1 addition & 1 deletion daemon/api_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"math"
"net/http"
"net/http/httptest"
"os/user"
"sort"
"strconv"
"strings"
Expand All @@ -39,6 +38,7 @@ import (
"github.com/snapcore/snapd/client"
"github.com/snapcore/snapd/client/clientutil"
"github.com/snapcore/snapd/daemon"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord/hookstate"
"github.com/snapcore/snapd/overlord/servicestate"
"github.com/snapcore/snapd/overlord/snapstate"
Expand Down
2 changes: 1 addition & 1 deletion daemon/api_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"fmt"
"net/http"
"os"
"os/user"
"path/filepath"
"time"

Expand All @@ -41,6 +40,7 @@ import (
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/interfaces/ifacetest"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord"
"github.com/snapcore/snapd/overlord/assertstate"
"github.com/snapcore/snapd/overlord/assertstate/assertstatetest"
Expand Down
2 changes: 1 addition & 1 deletion daemon/api_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"bytes"
"fmt"
"net/http"
"os/user"
"time"

"gopkg.in/check.v1"
Expand All @@ -32,6 +31,7 @@ import (
"github.com/snapcore/snapd/asserts/assertstest"
"github.com/snapcore/snapd/client"
"github.com/snapcore/snapd/daemon"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord/assertstate/assertstatetest"
"github.com/snapcore/snapd/overlord/auth"
"github.com/snapcore/snapd/overlord/configstate/config"
Expand Down
3 changes: 1 addition & 2 deletions daemon/export_api_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
package daemon

import (
"os/user"

"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord/hookstate"
"github.com/snapcore/snapd/overlord/servicestate"
"github.com/snapcore/snapd/overlord/state"
Expand Down
2 changes: 1 addition & 1 deletion daemon/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ package daemon
import (
"context"
"net/http"
"os/user"
"time"

"github.com/gorilla/mux"

"github.com/snapcore/snapd/asserts/snapasserts"
"github.com/snapcore/snapd/boot"
"github.com/snapcore/snapd/client/clientutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord"
"github.com/snapcore/snapd/overlord/assertstate"
"github.com/snapcore/snapd/overlord/restart"
Expand Down
2 changes: 1 addition & 1 deletion desktop/portal/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ package portal

import (
"fmt"
"os/user"
"path/filepath"
"strings"

"github.com/snapcore/snapd/dbusutil"
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/i18n"
"github.com/snapcore/snapd/osutil/user"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion desktop/portal/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ package portal_test
import (
"errors"
"os"
"os/user"
"path/filepath"
"sync"

"github.com/godbus/dbus"
. "gopkg.in/check.v1"

"github.com/snapcore/snapd/desktop/portal"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/testutil"
)

Expand Down
2 changes: 1 addition & 1 deletion desktop/portal/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
package portal

import (
"os/user"
"time"

"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/osutil/user"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion osutil/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"io"
"os"
"os/exec"
"os/user"
"syscall"
"time"

"github.com/snapcore/snapd/osutil/sys"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/strutil"
"github.com/snapcore/snapd/testutil"
)
Expand Down
3 changes: 2 additions & 1 deletion osutil/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ package osutil
import (
"bytes"
"fmt"
"os/user"
"strconv"

"github.com/snapcore/snapd/osutil/user"
)

// FindUid returns the identifier of the given UNIX user name. It will
Expand Down
2 changes: 1 addition & 1 deletion osutil/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ package osutil_test

import (
"fmt"
"os/user"

"gopkg.in/check.v1"

"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/testutil"
)

Expand Down
2 changes: 1 addition & 1 deletion osutil/strace/strace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ package strace
import (
"fmt"
"os/exec"
"os/user"
"path/filepath"
"runtime"

"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
)

// These syscalls are excluded because they make strace hang on all or
Expand Down
2 changes: 1 addition & 1 deletion osutil/strace/strace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ package strace_test

import (
"os"
"os/user"
"path/filepath"
"testing"

. "gopkg.in/check.v1"

"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/osutil/strace"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/testutil"
)

Expand Down
2 changes: 1 addition & 1 deletion osutil/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"fmt"
"os"
"os/exec"
"os/user"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"

"github.com/snapcore/snapd/osutil/sys"
"github.com/snapcore/snapd/osutil/user"
)

var (
Expand Down
Loading

0 comments on commit 44bf5f1

Please sign in to comment.