Skip to content

Commit

Permalink
fscrypt: fsync encrypted dir after setting policy [workaround]
Browse files Browse the repository at this point in the history
Revert once our google/fscrypt dependency is upgraded to a version
that includes google/fscrypt#359 gets accepted

Signed-off-by: Marcel Lauhoff <marcel.lauhoff@suse.com>
  • Loading branch information
Marcel Lauhoff committed Aug 30, 2022
1 parent d15ddec commit b66c700
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/util/fscrypt/fscrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ func createKeyFuncFromVolumeEncryption(
return keyFunc, nil
}

func fsyncEncryptedDirectory(dirPath string) error {
dir, err := os.Open(dirPath)
if err != nil {
return err
}
defer dir.Close()

err = dir.Sync()
if err != nil {
return err
}

return nil
}

// unlockExisting tries to unlock an already set up fscrypt directory using keys from Ceph CSI.
func unlockExisting(
ctx context.Context,
Expand Down Expand Up @@ -225,6 +240,12 @@ func initializeAndUnlock(
return err
}

if err = fsyncEncryptedDirectory(encryptedPath); err != nil {
log.ErrorLog(ctx, "fscrypt: fsync encrypted dir - to flush kernel policy to disk failed %v", err)

return err
}

return nil
}

Expand Down

0 comments on commit b66c700

Please sign in to comment.