Repository navigation
HPCDATAMGM-2244: Refactor HpcUtil.exec to run external commands with argument lists instead of a shell command string - #239
eranrosenberg wants to merge 8 commits into
Conversation
…argument lists instead of a shell command string Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 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
left a comment
There was a problem hiding this comment.
It looks like there are two valid copilot suggestions remaining. Please take a look.
…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>
There was a problem hiding this comment.
🔵 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
left a comment
There was a problem hiding this comment.
Thank you for addressing the remaining copilot suggestions. Reviewed.
d9406a1 to
3eab1e5
Compare
8d34257 to
178ed85
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…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>
There was a problem hiding this comment.
🔵 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>
DEV1 test results ✅Build under test: ✅ Aspera download (
|
There was a problem hiding this comment.
🔵 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>
|
Re: Copilot review of |
0f51b4f to
df0d973
Compare
4666968 to
c3e9246
Compare

Summary
HpcUtil.execran 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 withexec(List<String> command, String sudoPassword, Map<String, String> environment, File workingDirectory)based onProcessBuilder(no shell). Sudo runs assudo -S -p "" -- <command>with the password written to stdin. stdout and stderr are read on background threads while the caller waits inwaitFor(), so interrupts work; the process is destroyed on interrupt or error. Invalid environment variables are rejected without echoing their values.mkdir,ln -sandrm -rf;ascpinvoked with an argument list, password passed viaASPERA_SCP_PASS, working directory set to the staging directory. Any failure, including unexpected runtime errors, is reported viatransferFailedso the task doesn't stay in progress.cp,md5sum,rmandinstall -d;chownruns with argument lists. New archive directories get mode 755 (asinstall -ddid), regardless of umask.setArchivePermissions: sudochown/chmodremain external commands, now invoked with argument lists.HpcDomainValidator):_ . @ + -, not starting 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.-, no:or/.aspera-host,aspera-user,aspera-folderglobals. The password is read from the Postman Vault ({{vault:aspera-password}}).posixDataObjectPathDev1 environment variable) and renamed the existing sync request to "Register Data Object - S3 Archive".src/hpc-postman/files) instead of absolute local paths.Testing
HpcUtilTest,HpcDomainValidatorTest, and Aspera / GlobusHpcDataTransferProxyImplTest(Aspera uses a fakeascpscript). Added JUnit test dependencies tohpc-commonandhpc-integration-impl.mvn -o packageinsrc/hpc-serversucceeds with all tests passing.864::origin/features/HPCDATAMGM-2244):COMPLETED, 370,759 bytes.ARCHIVED; new archive directory created 755 and owned by the service account.Jira: HPCDATAMGM-2244