Skip to content

Conversation

@xbharani
Copy link

  • Checks for fscryptctl binary presence
  • Creates a random sw encryption key
  • Applies and verifies encryption policy
  • Confirms functionality with a test file


log_info "Checking if dependency binary is available"
check_dependencies fscryptctl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kernel/filesystem precheck: Add check_kernel_config CONFIG_FS_ENCRYPTION (and optional CONFIG_FS_VERITY if you care) to SKIP gracefully on kernels without fscrypt. Also verify that the mount backing $MOUNT_DIR is ext4/f2fs with encryption support (or at least that add_key succeeds on that mountpoint).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for add_key success exists,

key_id=$("$FSCRYPTCTL" add_key "$FS_PATH" < "$KEY_FILE" 2>/dev/null)
if [ -z "$key_id" ]; then
log_fail "$TESTNAME : Failed to add encryption key"

@github-actions
Copy link

This pull request has been marked as stale due to 30 days of inactivity. To prevent automatic closure in 7 days, remove the stale label or add a comment. You can reopen a closed pull request at any time.

@github-actions github-actions bot added the Stale label Sep 12, 2025
@smuppand
Copy link
Contributor

@xbharani Any update on the requested changes?

@github-actions github-actions bot removed the Stale label Sep 13, 2025
@github-actions
Copy link

This pull request has been marked as stale due to 30 days of inactivity. To prevent automatic closure in 7 days, remove the stale label or add a comment. You can reopen a closed pull request at any time.

TESTNAME="UserDataEncryption"
test_path=$(find_test_case_by_name "$TESTNAME")
cd "$test_path" || exit 1
res_file="./$TESTNAME.res"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result file isn’t written for some early exits (e.g., not root / init_env missing).
If your CI expects a .res, write it before exiting anywhere you can. Minimal way: define res_file early and use it in early failures:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only early exits where res_file is not created is script root & init_env, we cannot create res_file for these as the res_file path is created post init_env.
No code change for fixing this.

- Checks for fscryptctl binary presence
- Creates a random sw encryption key
- Applies and verifies encryption policy
- Confirms functionality with a test file
- Added yaml config

Signed-off-by: Bharani Bhuvanagiri <[email protected]>
# Ensure script runs as root
if [ "$(id -u)" -ne 0 ]; then
echo "[ERROR] This script must be run as root." >&2
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use exit 0 as in Lava. If the script uses exit 1, it will not proceed to the remaining tests.

check_dependencies "$FSCRYPTCTL"

if ! command -v "$FSCRYPTCTL" >/dev/null 2>&1; then
log_fail "$FSCRYPTCTL binary was not found. Skipping $TESTNAME."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use log_warn

log_fail "Path not found for $TESTNAME test. Falling back to SCRIPT_DIR: $SCRIPT_DIR"
test_path="$SCRIPT_DIR"

echo "$TESTNAME FAIL" > "$SCRIPT_DIR/$TESTNAME.res"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nicer if every test always write the .res in test_path, not in SCRIPT_DIR


# Globals that cleanup will use
key_id=""
KEY_FILE=""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's slightly safer to inititalize globals before trap so they're always defined.
MOUNT_DIR=""
FS_PATH=""

fi

if [ -d "$MOUNT_DIR" ]; then
rmdir "$MOUNT_DIR" 2>/dev/null || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you always log "Removed mount directory" even if it failed. Better add precise logs, check the return code.

if ! echo "$status" | grep -q "^Present"; then
log_fail "$TESTNAME : Key is not usable (status: $status)"
echo "$TESTNAME FAIL" > "$res_file"
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

if ! "$FSCRYPTCTL" set_policy "$key_id" "$MOUNT_DIR"; then
log_fail "$TESTNAME : Failed to set encryption policy"
echo "$TESTNAME FAIL" > "$res_file"
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

else
log_fail "$TESTNAME : Failed to create temporary key file"
echo "[ERROR] Failed to create temporary key file" >&2
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

if ! head -c 64 /dev/urandom > "$KEY_FILE"; then
log_fail "$TESTNAME : Failed to generate encryption key"
echo "$TESTNAME FAIL" > "$res_file"
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

else
log_fail "$TESTNAME : Test Failed"
echo "$TESTNAME FAIL" > "$res_file"
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants