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

many: do not use nss when looking up for users/groups from snapd snap #13776

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ linters-settings:
min-len: 3
# minimal occurrences count to trigger, 3 by default
min-occurrences: 3
# depguard:
# list-type: blacklist
# include-go-root: false
# packages:
# - github.com/davecgh/go-spew/spew
depguard:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this

rules:
osuser:
files:
- "!**/osutil/user/*.go"
deny:
- pkg: "os/user"
desc: "Please use osutil/user instead. See https://github.com/canonical/snapd/pull/13776"

misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
Expand Down
6 changes: 2 additions & 4 deletions build-aux/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,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 @@ -124,9 +121,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 @@ -367,6 +364,7 @@ parts:
esac
;;
esac
TAGS+=(snapdusergo 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw. perhaps we could prevent from os/user being imported by our code, there's a depguard linter we could configure in golangci-lint: https://golangci-lint.run/usage/linters/#depguard

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not done this one...

"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_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ package main
import (
"errors"
"fmt"
"os/user"
"strconv"

"github.com/jessevdk/go-flags"

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

type svcStatus struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/cmd_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"os/user"
"sort"
"strings"
"time"
Expand All @@ -32,6 +31,7 @@ import (

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

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
Loading
Loading