-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from ibuildthecloud/rootless
rootless
- Loading branch information
Showing
233 changed files
with
8,868 additions
and
2,278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package rootless | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func setupMounts(stateDir string) error { | ||
mountMap := [][]string{ | ||
{"/run", ""}, | ||
{"/var/run", ""}, | ||
{"/var/log", filepath.Join(stateDir, "logs")}, | ||
{"/var/lib/cni", filepath.Join(stateDir, "cni")}, | ||
} | ||
|
||
for _, v := range mountMap { | ||
if err := setupMount(v[0], v[1]); err != nil { | ||
return errors.Wrapf(err, "failed to setup mount %s => %s", v[0], v[1]) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func setupMount(target, dir string) error { | ||
toCreate := target | ||
for { | ||
if toCreate == "/" { | ||
return fmt.Errorf("missing /%s on the root filesystem", strings.Split(target, "/")[0]) | ||
} | ||
|
||
if err := os.MkdirAll(toCreate, 0700); err == nil { | ||
break | ||
} | ||
|
||
toCreate = filepath.Base(toCreate) | ||
} | ||
|
||
logrus.Debug("Mounting none ", toCreate, " tmpfs") | ||
if err := unix.Mount("none", toCreate, "tmpfs", 0, ""); err != nil { | ||
return errors.Wrapf(err, "failed to mount tmpfs to %s", toCreate) | ||
} | ||
|
||
if err := os.MkdirAll(target, 0700); err != nil { | ||
return errors.Wrapf(err, "failed to create directory %s") | ||
} | ||
|
||
if dir == "" { | ||
return nil | ||
} | ||
|
||
if err := os.MkdirAll(dir, 0700); err != nil { | ||
return errors.Wrapf(err, "failed to create directory %s") | ||
} | ||
|
||
logrus.Debug("Mounting ", dir, target, " none bind") | ||
return unix.Mount(dir, target, "none", unix.MS_BIND, "") | ||
} |
Oops, something went wrong.