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

auto create home folder if it is missing in eos #436

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/fatih/color v1.7.0 // indirect
github.com/go-openapi/strfmt v0.19.2 // indirect
github.com/gofrs/uuid v3.2.0+incompatible
github.com/gogo/protobuf v1.2.0 // indirect
github.com/golang/protobuf v1.3.2
github.com/gomodule/redigo v2.0.0+incompatible
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4
Expand All @@ -24,17 +25,20 @@ require (
github.com/pkg/errors v0.8.1
github.com/pkg/xattr v0.4.1
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 // indirect
github.com/rs/cors v1.7.0
github.com/rs/zerolog v1.17.2
go.opencensus.io v0.22.1
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421
google.golang.org/grpc v1.26.0
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.27 // indirect
gopkg.in/ldap.v2 v2.5.1
gopkg.in/square/go-jose.v2 v2.2.2 // indirect
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
)

go 1.13
29 changes: 29 additions & 0 deletions pkg/eosclient/eosclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,35 @@ func (c *Client) Touch(ctx context.Context, username, path string) error {
return err
}

// Chown given path
func (c *Client) Chown(ctx context.Context, username, chownUser, path string) error {
unixUser, err := c.getUnixUser(username)
if err != nil {
return err
}

unixChownUser, err := c.getUnixUser(chownUser)
if err != nil {
return err
}

cmd := exec.CommandContext(ctx, c.opt.EosBinary, "-r", unixUser.Uid, unixUser.Gid, "chown", unixChownUser.Uid+":"+unixChownUser.Gid, path)
_, _, err = c.executeEOS(ctx, cmd)
return err
}

// Chmod given path
func (c *Client) Chmod(ctx context.Context, username, mode, path string) error {
unixUser, err := c.getUnixUser(username)
if err != nil {
return err
}

cmd := exec.CommandContext(ctx, c.opt.EosBinary, "-r", unixUser.Uid, unixUser.Gid, "chmod", mode, path)
_, _, err = c.executeEOS(ctx, cmd)
return err
}

// CreateDir creates a directory at the given path
func (c *Client) CreateDir(ctx context.Context, username, path string) error {
unixUser, err := c.getUnixUser(username)
Expand Down
43 changes: 42 additions & 1 deletion pkg/storage/fs/eos/eos.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type eosStorage struct {
}

func parseConfig(m map[string]interface{}) (*config, error) {
c := &config{}
c := &config{Autocreate: true}
if err := mapstructure.Decode(m, c); err != nil {
return nil, err
}
Expand Down Expand Up @@ -108,6 +108,9 @@ type config struct {
// UseKeyTabAuth changes will authenticate requests by using an EOS keytab.
UseKeytab bool `mapstrucuture:"use_keytab"`

// Autocreate home if missing
Autocreate bool `mapstructure:"autocreate"`

// SecProtocol specifies the xrootd security protocol to use between the server and EOS.
SecProtocol string `mapstructure:"sec_protocol"`

Expand Down Expand Up @@ -508,6 +511,13 @@ func (fs *eosStorage) GetMD(ctx context.Context, ref *provider.Reference) (*prov
return nil, errors.Wrap(err, "eos: error resolving reference")
}

if fs.conf.Autocreate && ref.GetPath() == "/"+u.Username {
err := fs.CreateUserHome(ctx, u.Username, fn)
if err != nil {
return nil, err
}
}

eosFileInfo, err := fs.c.GetFileInfoByPath(ctx, u.Username, fn)
if err != nil {
return nil, err
Expand All @@ -527,6 +537,13 @@ func (fs *eosStorage) ListFolder(ctx context.Context, ref *provider.Reference) (
return nil, errors.Wrap(err, "eos: error resolving reference")
}

if fs.conf.Autocreate && ref.GetPath() == "/"+u.Username {
err := fs.CreateUserHome(ctx, u.Username, fn)
if err != nil {
return nil, err
}
}

eosFileInfos, err := fs.c.List(ctx, u.Username, fn)
if err != nil {
return nil, errors.Wrap(err, "eos: error listing")
Expand Down Expand Up @@ -555,6 +572,30 @@ func (fs *eosStorage) GetQuota(ctx context.Context) (int, int, error) {
return fs.c.GetQuota(ctx, u.Username, fs.conf.Namespace)
}

func (fs *eosStorage) CreateUserHome(ctx context.Context, username, fn string) error {
log := appctx.GetLogger(ctx)

_, err := fs.c.GetFileInfoByPath(ctx, username, fn)
if err != nil {
err = fs.c.CreateDir(ctx, "root", fn)
if err != nil {
//Dont stop on error, dir might exist already
log.Debug().Msg("eos: CreateDir issue, continuing")
}
err = fs.c.Chown(ctx, "root", username, fn)
if err != nil {
log.Debug().Msg("eos: Chown issue/failed")
return err
}
err = fs.c.Chmod(ctx, "root", "2770", fn)
if err != nil {
log.Debug().Msg("eos: Chmod issue/failed")
return err
}
}
return err
}

func (fs *eosStorage) CreateDir(ctx context.Context, fn string) error {
u, err := getUser(ctx)
if err != nil {
Expand Down