Skip to content

Commit

Permalink
fix: bentoml permission (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Nov 21, 2024
1 parent 01fa7d1 commit bc3131d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bento-image-snapshotter/fs/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ func NewS3FileSystem() S3FileSystem {
return S3FileSystem{}
}

func chownRecursive(ctx context.Context, root string, uid, gid int) error {
return errors.Wrap(filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return errors.Wrap(err, "failed to walk the directory")
}
// Change ownership of the file/directory
err = os.Chown(path, uid, gid)
if err != nil {
log.G(ctx).Errorf("failed to chown %s: %v", path, err)
return errors.Wrap(err, "failed to chown the file/directory")
}
return nil
}), "failed to walk the directory")
}

func (o S3FileSystem) Mount(ctx context.Context, mountpoint string, labels map[string]string) error {
if err := os.MkdirAll(mountpoint, 0755); err != nil {
return errors.Wrap(err, "failed to create mountpoint")
Expand All @@ -36,6 +51,14 @@ func (o S3FileSystem) Mount(ctx context.Context, mountpoint string, labels map[s
if err := o.downloadLayerFromS3(ctx, bucketName, objectKey, mountpoint); err != nil {
return errors.Wrap(err, "failed to download layer from S3")
}
isBentoLayer := labels[IsBentoLayerLabel] == "true"
if isBentoLayer {
logger.Info("chowning the /home/bentoml directory")
if err := chownRecursive(ctx, filepath.Join(mountpoint, "home", "bentoml"), 1034, 1034); err != nil {
return errors.Wrap(err, "failed to chown /home/bentoml directory")
}
logger.Info("successfully chowned the /home/bentoml directory")
}
logger.Info("layer downloaded from S3")
return nil
}
Expand Down

0 comments on commit bc3131d

Please sign in to comment.