Skip to content

Commit

Permalink
Replaced home creation function with external script, removed shadow …
Browse files Browse the repository at this point in the history
…namespace and related code
  • Loading branch information
glpatcern committed Dec 2, 2024
1 parent 144abad commit 1e79a09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 59 deletions.
15 changes: 3 additions & 12 deletions pkg/storage/utils/eosfs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@ type Config struct {
// DefaultQuotaFiles sets the default maximum files available for a user
DefaultQuotaFiles uint64 `mapstructure:"default_quota_files"`

// ShadowNamespace for storing shadow data
ShadowNamespace string `mapstructure:"shadow_namespace"`

// UploadsNamespace for storing upload data
UploadsNamespace string `mapstructure:"uploads_namespace"`

// ShareFolder defines the name of the folder in the
// shadowed namespace. Ex: /eos/user/.shadow/h/hugo/MyShares
ShareFolder string `mapstructure:"share_folder"`

// Location of the eos binary.
// Default is /usr/bin/eos.
EosBinary string `mapstructure:"eos_binary"`
Expand Down Expand Up @@ -149,9 +142,6 @@ type Config struct {
// revisions-related operations.
ImpersonateOwnerforRevisions bool `mapstructure:"impersonate_owner_for_revisions"`

// Whether to enable the post create home hook
EnablePostCreateHomeHook bool `mapstructure:"enable_post_create_home_hook"`

// HTTP connections to EOS: max number of idle conns
MaxIdleConns int `mapstructure:"max_idle_conns"`

Expand All @@ -177,8 +167,9 @@ type Config struct {
// Default is 3600
TokenExpiry int

// Path of the script to run after an user home folder has been created
OnPostCreateHomeHook string `mapstructure:"on_post_create_home_hook"`
// Path of the script to run in order to create a user home folder
// TODO(lopresti): to be replaced by a call to the Resource Lifecycle API being developed
CreateHomeHook string `mapstructure:"create_home_hook"`

// Maximum entries count a ListRecycle call may return: if exceeded, ListRecycle
// will return a BadRequest error
Expand Down
60 changes: 13 additions & 47 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ func (c *Config) ApplyDefaults() {
c.Namespace = "/"
}

if c.ShadowNamespace == "" {
c.ShadowNamespace = path.Join(c.Namespace, ".shadow")
}

// Quota node defaults to namespace if empty
if c.QuotaNode == "" {
c.QuotaNode = c.Namespace
Expand Down Expand Up @@ -321,7 +317,7 @@ func (fs *eosfs) wrap(ctx context.Context, fn string) (internal string) {
func (fs *eosfs) unwrap(ctx context.Context, internal string) (string, error) {
log := appctx.GetLogger(ctx)
layout := fs.getLayout(ctx)
ns, err := fs.getNsMatch(internal, []string{fs.conf.Namespace, fs.conf.ShadowNamespace})
ns, err := fs.getNsMatch(internal, []string{fs.conf.Namespace})
if err != nil {
return "", err
}
Expand Down Expand Up @@ -1278,17 +1274,13 @@ func (fs *eosfs) createNominalHome(ctx context.Context) error {
if err != nil {
return errors.Wrap(err, "eosfs: no user in ctx")
}

auth, err := fs.getUserAuth(ctx, u, "")
if err != nil {
return err
}

rootAuth, err := fs.getRootAuth(ctx)
if err != nil {
return nil
}

_, err = fs.c.GetFileInfoByPath(ctx, rootAuth, home)
_, err = fs.c.GetFileInfoByPath(ctx, auth, home)
if err == nil { // home already exists
return nil
}
Expand All @@ -1297,40 +1289,23 @@ func (fs *eosfs) createNominalHome(ctx context.Context) error {
return errors.Wrap(err, "eosfs: error verifying if user home directory exists")
}

err = fs.createUserDir(ctx, u, home, false)
if err != nil {
err := errors.Wrap(err, "eosfs: error creating user dir")
return err
}

// set quota for user, depending on its type
quotaBytes := fs.conf.DefaultQuotaBytes
if u.Id.Type != userpb.UserType_USER_TYPE_PRIMARY {
quotaBytes = fs.conf.DefaultSecondaryQuotaBytes
}
quotaInfo := &eosclient.SetQuotaInfo{
Username: u.Username,
UID: auth.Role.UID,
GID: auth.Role.GID,
MaxBytes: quotaBytes,
MaxFiles: fs.conf.DefaultQuotaFiles,
QuotaNode: fs.conf.QuotaNode,
}

err = fs.c.SetQuota(ctx, rootAuth, quotaInfo)
if err != nil {
err := errors.Wrap(err, "eosfs: error setting quota")
return err
}

if fs.conf.EnablePostCreateHomeHook {
if err := fs.runPostCreateHomeHook(ctx); err != nil {
if fs.conf.CreateHomeHook != "" {
err = exec.Command(fs.conf.CreateHomeHook, u.Username, strconv.FormatUint(quotaBytes, 10), strconv.FormatUint(fs.conf.DefaultQuotaFiles, 10)).Run()
if err != nil {
return errors.Wrap(err, "eosfs: error running post create home hook")
}
} else {
return errtypes.NotFound("eosfs: create home hook not configured")
}

log := appctx.GetLogger(ctx)
log.Info().Interface("quotaInfo", quotaInfo).Interface("user", u.Id).Msg("created nominal home")
log.Info().Uint64("quotaBytes", quotaBytes).Interface("user", u.Id).Msg("created nominal home")

return nil
}
Expand All @@ -1344,18 +1319,9 @@ func (fs *eosfs) CreateHome(ctx context.Context) error {
return errors.Wrap(err, "eosfs: error creating nominal home")
}

if err := fs.createShadowHome(ctx); err != nil {
return errors.Wrap(err, "eosfs: error creating shadow home")
}

return nil
}

func (fs *eosfs) runPostCreateHomeHook(ctx context.Context) error {
user := appctx.ContextMustGetUser(ctx)
return exec.Command(fs.conf.OnPostCreateHomeHook, user.Username).Run()
}

func (fs *eosfs) createUserDir(ctx context.Context, u *userpb.User, path string, recursiveAttr bool) error {
rootAuth, err := fs.getRootAuth(ctx)
if err != nil {
Expand Down Expand Up @@ -1536,7 +1502,7 @@ func (fs *eosfs) Move(ctx context.Context, oldRef, newRef *provider.Reference) e
}

func (fs *eosfs) Download(ctx context.Context, ref *provider.Reference) (io.ReadCloser, error) {
fn, auth, err := fs.resolveRefForbidShareFolder(ctx, ref)
fn, auth, err := fs.resolveRefAndGetAuth(ctx, ref)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1568,7 +1534,7 @@ func (fs *eosfs) ListRevisions(ctx context.Context, ref *provider.Reference) ([]
return nil, errtypes.PermissionDenied("eosfs: user doesn't have permissions to list revisions")
}
} else {
fn, auth, err = fs.resolveRefForbidShareFolder(ctx, ref)
fn, auth, err = fs.resolveRefAndGetAuth(ctx, ref)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1611,7 +1577,7 @@ func (fs *eosfs) DownloadRevision(ctx context.Context, ref *provider.Reference,
return nil, errtypes.PermissionDenied("eosfs: user doesn't have permissions to download revisions")
}
} else {
fn, auth, err = fs.resolveRefForbidShareFolder(ctx, ref)
fn, auth, err = fs.resolveRefAndGetAuth(ctx, ref)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1644,7 +1610,7 @@ func (fs *eosfs) RestoreRevision(ctx context.Context, ref *provider.Reference, r
return errtypes.PermissionDenied("eosfs: user doesn't have permissions to restore revisions")
}
} else {
fn, auth, err = fs.resolveRefForbidShareFolder(ctx, ref)
fn, auth, err = fs.resolveRefAndGetAuth(ctx, ref)
if err != nil {
return err
}
Expand Down

0 comments on commit 1e79a09

Please sign in to comment.