Skip to content

Commit

Permalink
Re-adding support for the uid and gid (#50)
Browse files Browse the repository at this point in the history
Allow using `sudo` to mount the filesystem. This is discouraged, however.
  • Loading branch information
orodeh authored Apr 8, 2020
1 parent cdac5f9 commit 94dc053
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 16 deletions.
13 changes: 13 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Release Notes

## v0.22.1
- Re-adding support for the `uid` and `gid` command line flags.
- Allowing the older use of mounting with `sudo`, although, this is discouraged. The new command:
```
dxfuse MNT your_project
```

The older method:
```
sudo dxfuse -uid $(id -u) -gid $(id -g) MNT your_project
```


## v0.22
- Use github actions for continuous integration (CI/CD)
- Eliminate the use of `sudo` for starting up the filesystem. Normal user permissions are now sufficient to start and stop the filesystem. This assumes that the fuse device (`/dev/fuse`) is open for read/write access to regular users.
Expand Down
64 changes: 49 additions & 15 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ var (
debugFuseFlag = flag.Bool("debugFuse", false, "Tap into FUSE debugging information")
daemon = flag.Bool("daemon", false, "An internal flag, do not use it")
fsSync = flag.Bool("sync", false, "Sychronize the filesystem and exit")
gid = flag.Int("gid", -1, "User group id (gid)")
help = flag.Bool("help", false, "display program options")
readOnly = flag.Bool("readOnly", false, "mount the filesystem in read-only mode")
uid = flag.Int("uid", -1, "User id (uid)")
verbose = flag.Int("verbose", 0, "Enable verbose debugging")
version = flag.Bool("version", false, "Print the version and exit")
)
Expand Down Expand Up @@ -80,6 +82,17 @@ func initLog(logFile string) *os.File {
return f
}

func getUser() user.User {
user, err := user.Current()
if err != nil {
panic(err)
}
if user == nil {
panic("asking the OS for the user returned nil")
}
return *user
}

// Mount the filesystem:
// - setup the debug log to the FUSE kernel log (I think)
func fsDaemon(
Expand All @@ -99,6 +112,13 @@ func fsDaemon(
logger.Printf("starting fsDaemon")
mountOptions := make(map[string]string)

user := getUser()
if user.Uid == "0" {
// Allow users other than root to access the filesystem
logger.Printf("started the filesystem as root, allowing other users access")
mountOptions["allow_other"] = ""
}

// capture debug output from the FUSE subsystem
var fuse_logger *log.Logger
if *debugFuseFlag {
Expand Down Expand Up @@ -168,21 +188,27 @@ func waitForReady(logFile string) string {

// get the current user Uid and Gid
func initUidGid() (uint32, uint32) {
user, err := user.Current()
if err != nil {
panic(err)
}

// get the user ID
u, err := strconv.Atoi(user.Uid)
if err != nil {
panic(err)
user := getUser()

// by default, use the user id specified on the command line
var err error
u := *uid
if u == -1 {
// get the user ID
u, err = strconv.Atoi(user.Uid)
if err != nil {
panic(err)
}
}

// by default, use the group id specified on the command line
// get the group ID
g, err := strconv.Atoi(user.Gid)
if err != nil {
panic(err)
g := *gid
if g == -1 {
g, err = strconv.Atoi(user.Gid)
if err != nil {
panic(err)
}
}
return uint32(u), uint32(g)
}
Expand Down Expand Up @@ -320,13 +346,20 @@ func buildDaemonCommandLine(cfg Config, fullManifestPath string) []string {
if (*fsSync) {
daemonArgs = append(daemonArgs, "-sync")
}

if (*gid != -1) {
args := []string { "-gid", strconv.FormatInt(int64(*gid), 10) }
daemonArgs = append(daemonArgs, args...)
}
if (*readOnly) {
daemonArgs = append(daemonArgs, "-readOnly")
}
if (*uid != -1) {
args := []string { "-uid", strconv.FormatInt(int64(*uid), 10) }
daemonArgs = append(daemonArgs, args...)
}
if (*verbose > 0) {
verboseArgs := []string { "-verbose", strconv.FormatInt(int64(*verbose), 10) }
daemonArgs = append(daemonArgs, verboseArgs...)
args := []string { "-verbose", strconv.FormatInt(int64(*verbose), 10) }
daemonArgs = append(daemonArgs, args...)
}

positionalArgs := []string{ cfg.mountpoint, fullManifestPath }
Expand Down Expand Up @@ -403,6 +436,7 @@ func main() {
validateConfig(cfg)

logFile := dxfuse.MakeFSBaseDir() + "/" + dxfuse.LogFile
fmt.Printf("The log file is located at %s\n", logFile)

if *daemon {
// This will be true -only- in the child sub-process
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
MaxDirSize = 10 * 1000
MaxNumFileHandles = 1000 * 1000
NumRetriesDefault = 3
Version = "v0.22"
Version = "v0.22.1"
)
const (
InodeInvalid = 0
Expand Down

0 comments on commit 94dc053

Please sign in to comment.