Skip to content

HPCDATAMGM-2244: Refactor HpcUtil.exec to run external commands with argument lists instead of a shell command string - #239

Open
eranrosenberg wants to merge 8 commits into
releases/3.32.0from
features/HPCDATAMGM-2244
Open

eranrosenberg wants to merge 8 commits into
releases/3.32.0from
features/HPCDATAMGM-2244

Conversation

@eranrosenberg

@eranrosenberg eranrosenberg commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

HpcUtil.exec ran commands as a single string through /bin/sh -c, so paths, file names or account values containing spaces or special characters could be split or reinterpreted. This change runs external commands with argument lists and replaces shell utilities with Java file APIs where possible.

Changes

  • HpcUtil.exec: replaced the string-based method with exec(List<String> command, String sudoPassword, Map<String, String> environment, File workingDirectory) based on ProcessBuilder (no shell). Sudo runs as sudo -S -p "" -- <command> with the password written to stdin. stdout and stderr are read on background threads while the caller waits in waitFor(), so interrupts work; the process is destroyed on interrupt or error. Invalid environment variables are rejected without echoing their values.
  • Aspera download: Java file APIs instead of mkdir, ln -s and rm -rf; ascp invoked with an argument list, password passed via ASPERA_SCP_PASS, working directory set to the staging directory. Any failure, including unexpected runtime errors, is reported via transferFailed so the task doesn't stay in progress.
  • POSIX/Globus archive: Java equivalents for cp, md5sum, rm and install -d; chown runs with argument lists. New archive directories get mode 755 (as install -d did), regardless of umask.
  • setArchivePermissions: sudo chown/chmod remain external commands, now invoked with argument lists.
  • Validation (HpcDomainValidator):
    • Aspera user: letters, digits and _ . @ + -, not starting with -.
    • Aspera host: hostname, IPv4, or bracketed IPv6.
    • Aspera password: no NUL character.
    • Aspera destination: container ID can't start with -; no control characters; for data object downloads the file name can't be empty, ., .. or start with -.
    • callerObjectId: no .. path segments or control characters.
    • Permission group name: non-empty, no leading -, no : or /.
  • Postman: added "Download to Aspera" and "Get Aspera Download Task Status" requests to Data Object Registration / Sync Upload, plus aspera-host, aspera-user, aspera-folder globals. The password is read from the Postman Vault ({{vault:aspera-password}}).
    • Added "Register Data Object - POSIX Archive" (with a posixDataObjectPath Dev1 environment variable) and renamed the existing sync request to "Register Data Object - S3 Archive".
    • Sync upload requests reference attachments by file name relative to the Postman working directory (src/hpc-postman/files) instead of absolute local paths.

Testing

  • New unit tests: HpcUtilTest, HpcDomainValidatorTest, and Aspera / Globus HpcDataTransferProxyImplTest (Aspera uses a fake ascp script). Added JUnit test dependencies to hpc-common and hpc-integration-impl.
  • mvn -o package in src/hpc-server succeeds with all tests passing.
  • DEV1 (build 864::origin/features/HPCDATAMGM-2244):
    • Aspera download: COMPLETED, 370,759 bytes.
    • POSIX (Globus) sync upload to a new folder: ARCHIVED; new archive directory created 755 and owned by the service account.
    • Updated Postman sync upload requests (S3 and POSIX) tested successfully with relative attachment paths.
    • Details: DEV1 test results.

Jira: HPCDATAMGM-2244

…argument lists instead of a shell command string

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@eranrosenberg
eranrosenberg requested review from dinhys and menons and a balanced review from Copilot October 15, 2026 21:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Validation and request-encoding issues remain, and real Aspera transfers and sudo commands still require deployment verification.

3 open findings
What changed in this PR

Replaces shell command strings with argument lists and Java file operations to handle paths and account values safely.

Changes:

  • Refactors command execution and Aspera/POSIX transfer operations.
  • Adds input validation and unit tests.
  • Adds Postman requests for Aspera downloads and status checks.
File Description
src/​hpc-server/​hpc-integration-impl/​src/​test/​java/​gov/​nih/​nci/​hpc/​integration/​globus/​impl/​HpcDataTransferProxyImplTest.java Tests POSIX file operations.
src/​hpc-server/​hpc-integration-impl/​src/​test/​java/​gov/​nih/​nci/​hpc/​integration/​aspera/​impl/​HpcDataTransferProxyImplTest.java Tests Aspera arguments and cleanup.
src/​hpc-server/​hpc-integration-impl/​src/​main/​java/​gov/​nih/​nci/​hpc/​integration/​globus/​impl/​HpcDataTransferProxyImpl.java Replaces shell file utilities.
src/​hpc-server/​hpc-integration-impl/​src/​main/​java/​gov/​nih/​nci/​hpc/​integration/​aspera/​impl/​HpcDataTransferProxyImpl.java Uses argument lists and Java staging operations.
src/​hpc-server/​hpc-integration-impl/​pom.xml Adds JUnit dependencies.
src/​hpc-server/​hpc-common/​src/​test/​java/​gov/​nih/​nci/​hpc/​util/​HpcUtilTest.java Tests command execution behavior.
src/​hpc-server/​hpc-common/​src/​main/​java/​gov/​nih/​nci/​hpc/​util/​HpcUtil.java Introduces shell-free process execution.
src/​hpc-server/​hpc-common/​pom.xml Adds JUnit dependencies.
src/​hpc-server/​hpc-app-service-impl/​src/​test/​java/​gov/​nih/​nci/​hpc/​service/​impl/​HpcDomainValidatorTest.java Tests new validation rules.
src/​hpc-server/​hpc-app-service-impl/​src/​main/​java/​gov/​nih/​nci/​hpc/​service/​impl/​HpcDomainValidator.java Validates accounts, destinations, and identifiers.
src/​hpc-server/​hpc-app-service-impl/​src/​main/​java/​gov/​nih/​nci/​hpc/​service/​impl/​HpcDataTransferServiceImpl.java Applies validation and permission-command changes.
src/​hpc-postman/​postman/​globals/​workspace.globals.yaml Adds Aspera settings.
src/​hpc-postman/​postman/​collections/​HPC Server API/​Data Object Registration/​Sync Upload/​Get Aspera Download Task Status.request.yaml Adds download status retrieval.
src/​hpc-postman/​postman/​collections/​HPC Server API/​Data Object Registration/​Sync Upload/​Download to Aspera.request.yaml Adds an Aspera download request.
src/​hpc-postman/​postman/​collections/​HPC Server API/​.resources/​definition.yaml Adds transfer tracking variables.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…argument lists instead of a shell command string

Create the fake ascp test script under the build directory, since the
system temp directory may be mounted noexec (Jenkins).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@dinhys dinhys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It looks like there are two valid copilot suggestions remaining. Please take a look.

@eranrosenberg
eranrosenberg requested a review from dinhys October 16, 2026 19:55
…argument lists instead of a shell command string

Address Copilot review comments:
- HpcUtil.exec: allow empty arguments; reject only an empty executable or null arguments
- HpcDomainValidator: accept fully qualified Aspera host names with a trailing dot
- Postman Download to Aspera: build the request body with JSON.stringify and read the password via pm.vault.get

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Real Aspera transfers and privileged permission commands still need dev-server verification against the deployed binaries and existing sudoers configuration.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

dinhys
dinhys previously approved these changes Oct 27, 2026

@dinhys dinhys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for addressing the remaining copilot suggestions. Reviewed.

@menons
menons requested a review from a team October 30, 2026 20:36
@menons
menons force-pushed the features/HPCDATAMGM-2244 branch from 8d34257 to 178ed85 Compare October 30, 2026 20:36
@eranrosenberg
eranrosenberg changed the base branch from releases/3.31.0 to releases/3.32.0 November 3, 2026 22:24
@eranrosenberg
eranrosenberg requested a balanced review from Copilot November 3, 2026 22:24
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@eranrosenberg
eranrosenberg requested a balanced review from Copilot and removed request for Copilot November 3, 2026 22:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Reading subprocess stdout on the calling thread is not interruptible, so long-running Aspera transfers keep executor workers blocked during shutdown until ascp exits.

1 open issue

Review effort: Balanced

…argument lists instead of a shell command string

Read subprocess stdout on a reader thread so the caller waits in interruptible waitFor(), and terminate the command when interrupted.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@eranrosenberg
eranrosenberg requested a balanced review from Copilot and removed request for Copilot November 3, 2026 22:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because directory creation can alter archive access permissions, and unhandled environment-validation failures can leave downloads stuck in progress.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

…argument lists instead of a shell command string

Report all Aspera download failures (incl. unchecked exceptions) so tasks don't stay in progress; reject invalid exec() environment values without exposing them; reject NUL in Aspera passwords. Set POSIX archive directories created on upload to rwxr-xr-x regardless of umask, as 'install -d' did.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@eranrosenberg
eranrosenberg requested a balanced review from Copilot and removed request for Copilot November 3, 2026 23:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Real Aspera transfers and privileged chown/chmod compatibility with deployed sudoers remain unverified, requiring dev-server validation before approval.

No open issues 🎉

Review effort: Balanced

@eranrosenberg

eranrosenberg commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

DEV1 test results ✅

Build under test: 864::origin/features/HPCDATAMGM-2244 (566dc12e4), deployed to DEV1 fsdsgl-dmeap01d (deploys #894 and #896).

✅ Aspera download (ascp with an argument list and ASPERA_SCP_PASS)

Request:

{
  "taskId": "3f54c16b-93d7-4554-bf4a-7aae7676854d",
  "destinationLocation": { "fileContainerId": "test", "fileId": "file-download-11-04-2026-10-05-11" },
  "size": 370759
}

Task status:

{
  "inProgress": false,
  "path": "/FNL_SF_Archive/eran-pi-lab/eran-project/eran-flowcell/eran-sample/eran-data-object-sync-11-04-2026-10-02-11",
  "destinationType": "ASPERA",
  "result": "COMPLETED",
  "size": 370759,
  "dataSize": 370759,
  "created": "2026-11-04T10:05:15.871-05:00",
  "completed": "2026-11-04T10:06:45.646-05:00"
}

✅ POSIX (Globus) sync upload: new directory creation plus chown with argument lists

Registered /FS_ARCHIVE/eran-test/eran-data-object-sync-11-04-2026-18-30-52 into a new folder (eran-test), so the archive directories had to be created. GET data object:

{
  "id": 2902385,
  "absolutePath": "/FS_ARCHIVE/eran-test/eran-data-object-sync-11-04-2026-18-30-52",
  "data_transfer_status": "ARCHIVED",
  "data_transfer_type": "GLOBUS",
  "data_transfer_method": "SYNC",
  "configuration_id": "41ff9b3a-dfb1-11e7-80c1-9a214cf093ae",
  "archive_caller_object_id": "eran-base-sync",
  "archive_file_id": "/FS_ARCHIVE/eran-base-sync/FS_ARCHIVE/eran-test/eran-data-object-sync-11-04-2026-18-30-52",
  "source_file_size": 370759,
  "checksum": "33d98fa064cb3f14c4ab94582fcf9ebc",
  "data_transfer_started": "11-04-2026 18:30:53",
  "data_transfer_completed": "11-04-2026 18:30:53"
}

Archive directory on disk. The new eran-test directory has 755 permissions and is owned by the service account, the same as collection, which the old install -d code created:

fsdsgl-dmeap01d:/mnt/DMEDataStage/GlobusUAT/FS_ARCHIVE/eran-base-sync/FS_ARCHIVE$ ls -l
drwxr-xr-x 2 ncif-hpcdm-svc nci-frederick_dme_irods_sagrp 1024 May 28  2025 collection
drwxr-xr-x 2 ncif-hpcdm-svc nci-frederick_dme_irods_sagrp 1024 Nov  4 18:30 eran-test
drwxr-xr-x 2 ncif-hpcdm-svc nci-frederick_dme_irods_sagrp 1024 Nov  4 18:30 fs-demo
DEV1 environment issue found and fixed during testing (not caused by this PR)

The first POSIX attempts failed in saveFile on chown -R ncif-hpcdm-svc /mnt/DMEDataStage/GlobusUAT/FS_ARCHIVE with Operation not permitted. The cause was the stale test directory FS_ARCHIVE/eran-base-globus, owned by dinhys instead of ncif-hpcdm-svc.

  • Not caused by this PR: releases/3.32.0 (deploy #895) failed the same way at the same call.
  • Fix: removed the stale directory. Root couldn't chown it because of NFS root_squash, so it was removed as its owner, then rmdir as ncif-hpcdm-svc. After that, the PR build passed.
  • Follow-up, separate ticket: the recursive chown covers the whole shared archive root, so any file owned by another account blocks every POSIX upload. Consider limiting it to the newly created directories and the file.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 23:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Developer-specific absolute attachment paths in the S3 and POSIX registration requests prevent Postman from locating files in other checkouts and need to be replaced with relative filenames.

No open issues 🎉

Review effort: Balanced

Replace developer-specific absolute attachment paths with bare filenames
resolved from the Postman working directory (src/hpc-postman/files).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 13:43
@eranrosenberg
eranrosenberg requested a review from dinhys November 5, 2026 13:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because shared upload-path state can redirect later presigned-download and Aspera requests to a POSIX archive that does not support those operations.

No open issues 🎉

Review effort: Balanced

@eranrosenberg

Copy link
Copy Markdown
Collaborator Author

Re: Copilot review of 79385c842 ("shared upload-path state"): this is intentional. The POSIX and S3 sync-upload requests both set lastSyncUploadPath so that the follow-up requests in the folder act on the object just registered. Testers pick the follow-ups that the archive supports (e.g. Get / Download to Aspera after a POSIX upload). No collection change needed.

@menons
menons force-pushed the features/HPCDATAMGM-2244 branch from 4666968 to c3e9246 Compare November 6, 2026 20:26
Copilot AI balanced review requested due to automatic review settings November 6, 2026 20:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the shell-free command execution refactor.

No open issues 🎉

Review effort: Balanced

@dinhys dinhys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed. Thank you.

This branch has not been deployed

No deployments
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