Skip to content

Conversation

@kichristensen
Copy link
Contributor

What does this change

This change adds support for loading object-type parameters from JSON files using the @ prefix syntax. When passing object parameters via CLI or parameter sets, users can now reference an external JSON file instead of providing inline JSON.

Example usage:

# Install with object parameter from file
porter install --param [email protected]

# Upgrade with object parameter from file
porter upgrade --param [email protected]

# Use with parameter sets
porter install --parameter-set myparam

Where a parameter set might contain:

parameters:
  - name: config
    source:
      value: "@/path/to/config.json"

Key features:

  • Only works for parameters defined with type: object in the bundle
  • Validates that the file contains valid JSON before processing
  • Works with both --param CLI flags and parameter set value sources
  • Security: Only applies to user-provided values, not default values in bundle definitions
  • Provides clear error messages when files are not found or contain invalid JSON

What issue does it fix

Closes #3257

Notes for the reviewer

  • The @ prefix logic is implemented in pkg/porter/parameters.go:getUnconvertedValueFromRaw()
  • Security consideration: The @ prefix only works for user-provided parameter values (CLI/parameter sets), not for default values defined in bundle manifests, preventing potential security issues with malicious bundles
  • The implementation validates JSON syntax immediately after reading the file to provide clear error messages
  • Non-object parameters ignore the @ prefix, treating it as a literal string value for backward compatibility

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

Enable users to load object-type parameters from JSON files using
the @ prefix syntax, similar to curl and kubectl. This provides a
convenient way to pass complex configuration objects without inline
JSON strings.

Usage:
  porter install --param config=@/path/to/config.json
  porter install --param config='{"key": "value"}'

Parameter sets also support @ prefix:
  parameters:
    - name: config
      source:
        value: @/path/to/config.json

Security considerations:
- Only applies to user-provided values (CLI flags/parameter sets)
- Does NOT work with default values in bundle definitions
- Validates JSON structure before processing
- Clear error messages for missing files or invalid JSON

Changes:
- Add @ prefix detection in getUnconvertedValueFromRaw()
- Read and validate JSON file contents for object parameters
- Add comprehensive unit tests covering success/error cases
- Add test fixtures for valid/invalid JSON scenarios

Signed-off-by: Kim Christensen <[email protected]>
Add comprehensive integration tests for object-type parameters
loaded from files using the @ prefix syntax. Tests cover:
- CLI parameter with @ prefix reading from file
- Inline JSON parameter without @ prefix
- Parameter set with @ prefix
- Error handling for missing files
- Error handling for invalid JSON files

Also adds test bundle that uses template syntax to access
object parameter fields in bundle execution steps.

Signed-off-by: Kim <[email protected]>
Signed-off-by: Kim Christensen <[email protected]>
Update CLI help text and user documentation to describe the
@ prefix syntax for loading object parameters from JSON files.

Changes include:
- Updated --param flag help text with @ prefix example
- Added @ prefix examples to install/upgrade/invoke commands
- Added "Object Parameters from Files" section to intro docs
- Updated quickstart guide with @ prefix usage
- Enhanced parameter set file format documentation
- Added example of @ prefix in parameter set YAML

The documentation emphasizes the security constraint that
@ prefix only works for user-provided values, not defaults.

Signed-off-by: Kim <[email protected]>
Signed-off-by: Kim Christensen <[email protected]>
@kichristensen kichristensen requested a review from a team as a code owner November 18, 2025 13:35
@lbergnehr
Copy link
Contributor

In parameter sets, there's source.path in the reference documentation. Would it make sense to use that in parameter sets, where we have that ability to make the distinction? I like the @ notation as it's commonly used elsewhere on the CLI (e.g. curl).

Copy link
Member

@dgannon991 dgannon991 left a comment

Choose a reason for hiding this comment

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

LGTM, and the comments for why it's safe were useful, cheers!

@kichristensen
Copy link
Contributor Author

In parameter sets, there's source.path in the reference documentation. Would it make sense to use that in parameter sets, where we have that ability to make the distinction? I like the @ notation as it's commonly used elsewhere on the CLI (e.g. curl).

That is a really good point. It might already work I will check

@kichristensen
Copy link
Contributor Author

@lbergnehr It already works, I will update the documentation to show that configuration

Update documentation to describe the proper `path` source syntax
for parameter set definitions instead of the `@` prefix.

Changes:
- Clarify that `@` prefix is only for CLI --param flags
- Add comprehensive examples showing `path` source in both YAML
  and JSON format for parameter set definitions
- Update parameter set example to use schemaVersion 1.1.0
- Remove incorrect documentation about `@` prefix in value sources
- Distinguish between CLI usage (@Prefix) and parameter set usage
  (path source)

The `path` source is the correct way to reference files in parameter
set definitions, while the `@` prefix remains a convenient shortcut
for command-line parameter overrides.

Signed-off-by: Kim Christensen <[email protected]>
@kichristensen
Copy link
Contributor Author

@dgannon991 @lbergnehr I have update the documentation to how to use path source when using parameter sets, instead of the @ way. The @ syntax will also work in parameter sets, but path is a much better way when using parameter sets

@kichristensen kichristensen merged commit 2cfd1f4 into getporter:main Nov 20, 2025
77 of 79 checks passed
@kichristensen kichristensen deleted the objectFileParameter branch November 20, 2025 22:59
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.

Object parameters cannot be read from a file

3 participants