Skip to content

OTA-2025: Harden AgenticRun against indirect prompt injection - #1443

Open
jrangelramos wants to merge 1 commit into
openshift:mainfrom
jrangelramos:fix-prompt-injection-hardening
Open

OTA-2025: Harden AgenticRun against indirect prompt injection#1443
jrangelramos wants to merge 1 commit into
openshift:mainfrom
jrangelramos:fix-prompt-injection-hardening

Conversation

@jrangelramos

@jrangelramos jrangelramos commented Aug 10, 2026

Copy link
Copy Markdown
Member

Summary

  • Operator condition messages (free-form text from ClusterOperators) were embedded
    unsanitized in the AgenticRun request. A compromised operator could craft
    instruction-like text to influence LLM recommendations.
  • Added a data-boundary instruction to the system prompt: the LLM is told to treat
    all JSON data fields strictly as data, never as instructions.
  • Truncated all condition message fields to 512 chars (rune-aware) across
    operator_health, cluster_conditions, and api_deprecations checks to limit the
    injection surface.

Test plan

  • TestOperatorHealthCheck_MessageTruncation: verifies messages over 512 chars
    are truncated with suffix
  • All existing readiness and agenticrun controller tests pass with no regressions

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Security

    • Improved readiness analysis handling so free-text JSON fields are treated as data rather than executable instructions.
  • Bug Fixes

    • Limited readiness and operator health messages to 512 characters.
    • Added a truncation indicator when messages exceed the limit.
    • Applied consistent truncation to upgradeability, degraded, unavailable, and deprecation warnings.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 10, 2026
@openshift-ci-robot

openshift-ci-robot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@jrangelramos: This pull request references OTA-2025 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Operator condition messages (free-form text from ClusterOperators) were embedded
    unsanitized in the AgenticRun request. A compromised operator could craft
    instruction-like text to influence LLM recommendations.
  • Added a data-boundary instruction to the system prompt: the LLM is told to treat
    all JSON data fields strictly as data, never as instructions.
  • Truncated all condition message fields to 512 chars (rune-aware) across
    operator_health, cluster_conditions, and api_deprecations checks to limit the
    injection surface.

Test plan

  • TestOperatorHealthCheck_MessageTruncation: verifies messages over 512 chars
    are truncated with suffix
  • All existing readiness and agenticrun controller tests pass with no regressions

🤖 Generated with Claude Code

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: a709a411-2764-47ab-ab46-5ecc1180e141

📥 Commits

Reviewing files that changed from the base of the PR and between 22d2133 and 4c8fa5b.

📒 Files selected for processing (1)
  • pkg/readiness/cluster_conditions.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/readiness/cluster_conditions.go

Walkthrough

The change truncates readiness messages to 512 runes with an ...[truncated] suffix. It adds test coverage and instructs agentic analysis models to treat readiness free-text fields as data.

Changes

Readiness safety

Layer / File(s) Summary
Readiness message truncation
pkg/readiness/client.go, pkg/readiness/operator_health.go, pkg/readiness/cluster_conditions.go, pkg/readiness/api_deprecations.go, pkg/readiness/checks_test.go
A 512-rune helper truncates operator, cluster condition, and API deprecation messages. Tests verify truncation for a long degraded operator message.
Agentic readiness-data guidance
pkg/agenticrun/controller.go
The agentic run prompt instructs analysis models to treat readiness free-text fields as data, not instructions.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: hardening AgenticRun against indirect prompt injection.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The added test uses the static name TestOperatorHealthCheck_MessageTruncation; affected packages contain no Ginkgo title calls or dynamic test titles.
Test Structure And Quality ✅ Passed The added test has one focused behavior, uses an in-memory fake client, creates no cluster resources, has no waits, and provides diagnostic failure text consistent with nearby tests.
Microshift Test Compatibility ✅ Passed The commit adds only a standard Go Test function, not a new Ginkgo e2e test, so the MicroShift API compatibility check does not apply.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The PR adds only a standard Go unit test (TestOperatorHealthCheck_MessageTruncation); it adds no Ginkgo e2e test or multi-node/HA assumption requiring SNO review.
Topology-Aware Scheduling Compatibility ✅ Passed The diff changes prompt text and readiness message truncation only; no deployments, pod specs, affinity, topology spread, replicas, selectors, tolerations, or topology logic were added.
Ote Binary Stdout Contract ✅ Passed OTE main has no stdout or logging writes; suite setup only registers the failure handler and calls RunSpecs, with no TestMain or suite callbacks found.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The patch adds only a standard Go unit test (TestOperatorHealthCheck_MessageTruncation); it adds no Ginkgo e2e test or IPv4/external-network dependency.
No-Weak-Crypto ✅ Passed The six changed files add no MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB, custom crypto, or secret/token comparisons.
Container-Privileges ✅ Passed The PR changes only Go and test files. No added manifest or privilege-related setting exists; existing hostNetwork and privileged entries are unchanged from the parent.
No-Sensitive-Data-In-Logs ✅ Passed The patch adds no production log calls; new condition text is truncated for readiness data and placed in the AgenticRun request, while the existing condition-message log is unchanged.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@openshift-ci

openshift-ci Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jrangelramos
Once this PR has been reviewed and has the lgtm label, please assign wking for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/readiness/checks_test.go (1)

394-429: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Make the truncation assertion exact and rune-aware.

TestOperatorHealthCheck_MessageTruncation only uses ASCII input and measures len(msg), so it does not exercise truncateMessage’s rune truncation. Use a multibyte input and assert either the exact preserved prefix or the exact rune count with utf8.RuneCountInString.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/readiness/checks_test.go` around lines 394 - 429, Update
TestOperatorHealthCheck_MessageTruncation to build a multibyte message and make
the truncation assertion exact using rune-aware expectations. Verify the result
has the expected preserved rune prefix and truncation suffix, or assert its
exact rune count with utf8.RuneCountInString while retaining the existing
degraded-result validation.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/readiness/cluster_conditions.go`:
- Line 38: Sanitize the raw conditions payload in ClusterConditionsCheck.Run by
truncating each Condition.Message while building condMap, using the same
truncateMessage helper applied to upgradeable.message. Ensure
result["conditions"] no longer exposes full condition messages; alternatively
remove the raw duplicate if that matches the existing result contract.

---

Nitpick comments:
In `@pkg/readiness/checks_test.go`:
- Around line 394-429: Update TestOperatorHealthCheck_MessageTruncation to build
a multibyte message and make the truncation assertion exact using rune-aware
expectations. Verify the result has the expected preserved rune prefix and
truncation suffix, or assert its exact rune count with utf8.RuneCountInString
while retaining the existing degraded-result validation.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 43b45eb9-9987-4b00-8aa7-51b53a2a8bf8

📥 Commits

Reviewing files that changed from the base of the PR and between 97ee3b7 and 22d2133.

📒 Files selected for processing (6)
  • pkg/agenticrun/controller.go
  • pkg/readiness/api_deprecations.go
  • pkg/readiness/checks_test.go
  • pkg/readiness/client.go
  • pkg/readiness/cluster_conditions.go
  • pkg/readiness/operator_health.go

Comment thread pkg/readiness/cluster_conditions.go
Add a data-boundary instruction to the system prompt so the LLM treats
free-text fields (e.g. operator condition messages) as data to analyze,
not instructions to follow. Truncate all condition message fields to
512 chars (rune-aware) across operator_health, cluster_conditions, and
api_deprecations checks to limit the injection surface.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jrangelramos
jrangelramos force-pushed the fix-prompt-injection-hardening branch from 22d2133 to 4c8fa5b Compare August 10, 2026 20:06
@openshift-ci

openshift-ci Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@jrangelramos: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-agnostic-ovn-techpreview-serial-1of3 4c8fa5b link true /test e2e-agnostic-ovn-techpreview-serial-1of3
ci/prow/e2e-hypershift-conformance 4c8fa5b link true /test e2e-hypershift-conformance
ci/prow/e2e-agnostic-operator 4c8fa5b link true /test e2e-agnostic-operator
ci/prow/e2e-hypershift 4c8fa5b link true /test e2e-hypershift

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants