Skip to content

HYPERFLEET-1147 - feat: add caller identity support for audit attribution#120

Open
kuudori wants to merge 1 commit into
openshift-hyperfleet:mainfrom
kuudori:HYPERFLEET-1147-caller-identity
Open

HYPERFLEET-1147 - feat: add caller identity support for audit attribution#120
kuudori wants to merge 1 commit into
openshift-hyperfleet:mainfrom
kuudori:HYPERFLEET-1147-caller-identity

Conversation

@kuudori

@kuudori kuudori commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Inject caller identity headers into all E2E API requests so tests work against an API with identity enforcement enabled (production default).

  • Add IdentityConfig (header/value/token) to config with CLI flags, env vars (HYPERFLEET_IDENTITY_*), and config.yaml support
  • Inject identity via OpenAPI RequestEditorFn in helper.newHelper()
  • Add HaveAuditIdentity matcher and ExpectedIdentity() helper
  • Add created_by assertion in cluster creation, deleted_by in deletion
  • Deploy API with identity_header enabled in local kind setup
  • Update AGENTS.md, getting-started, and local-kind-setup docs

Summary

Test Plan

  • Unit tests added/updated
  • make test-all passes
  • make lint passes
  • Helm chart changes validated with make test-helm (if applicable)
  • Deployed to a development cluster and verified (if Helm/config changes)
  • E2E tests passed (if cross-component or major changes)

@openshift-ci openshift-ci Bot requested review from ciaranRoche and rh-amarin June 8, 2026 23:49
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 7b8dbb38-d5a0-4b1e-8e07-5d0aba6b65c1

📥 Commits

Reviewing files that changed from the base of the PR and between 5d8c6b8 and 9fe3db5.

📒 Files selected for processing (14)
  • AGENTS.md
  • cmd/hyperfleet-e2e/main.go
  • cmd/hyperfleet-e2e/test/cmd.go
  • configs/config.yaml
  • deploy-scripts/lib/api.sh
  • docs/getting-started.md
  • docs/local-kind-setup.md
  • e2e/cluster/creation.go
  • e2e/cluster/delete.go
  • pkg/client/client.go
  • pkg/config/config.go
  • pkg/helper/helper.go
  • pkg/helper/matchers.go
  • pkg/helper/suite.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift-hyperfleet/architecture (manual)
  • openshift-hyperfleet/hyperfleet-api (manual)
  • openshift-hyperfleet/hyperfleet-sentinel (manual)
  • openshift-hyperfleet/hyperfleet-adapter (manual)
  • openshift-hyperfleet/hyperfleet-broker (manual)
✅ Files skipped from review due to trivial changes (3)
  • docs/local-kind-setup.md
  • docs/getting-started.md
  • AGENTS.md
🚧 Files skipped from review as they are similar to previous changes (11)
  • deploy-scripts/lib/api.sh
  • pkg/client/client.go
  • pkg/helper/helper.go
  • cmd/hyperfleet-e2e/main.go
  • cmd/hyperfleet-e2e/test/cmd.go
  • configs/config.yaml
  • pkg/helper/suite.go
  • pkg/helper/matchers.go
  • e2e/cluster/creation.go
  • e2e/cluster/delete.go
  • pkg/config/config.go

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Added caller identity configuration for mutating API requests, including configurable identity header/value and optional bearer token support.
    • Added identity-aware audit assertions in E2E tests for cluster creation and deletion attribution (run only when identity is configured).
    • Introduced persistent E2E CLI flags to provide identity settings, and extended deployment automation to configure the API identity header.
  • Documentation

    • Updated getting-started and local setup guides with a new “Configure caller identity” step and required environment variables.
    • Expanded E2E instructions with identity “source of truth” and assertion guidance.

Walkthrough

Caller identity configuration was added for mutating E2E requests. The OpenAPI client path now supports request editors that inject an identity header and optional bearer token. Helper code exposes the expected identity and adds an audit-identity matcher. Cluster creation and deletion tests now assert audit attribution when identity is configured. CWE-319 and CWE-200 are relevant to transport/header handling and token redaction.

Sequence Diagram(s)

sequenceDiagram
  participant TestRunner as E2E test
  participant HelperSuite as pkg/helper/suite.go
  participant OpenAPIClient as openapi client
  participant API as HyperFleet API
  participant Helper as pkg/helper
  TestRunner->>HelperSuite: build client from config
  HelperSuite->>OpenAPIClient: request editor injects identity header/token
  OpenAPIClient->>API: send mutating request
  API->>OpenAPIClient: return resource with audit fields
  TestRunner->>Helper: ExpectedIdentity()
  TestRunner->>Helper: HaveAuditIdentity(expected)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 9 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
No Pii Or Sensitive Data In Logs ⚠️ Warning FAIL: config.Validate() logs raw identity.value in the validation error, and cmd/test prints that error via log.Printf, leaking caller identity (CWE-532). Redact identity.value in the validation error or return a generic error; keep log.Printf from emitting raw identity data.
✅ Passed checks (9 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding caller identity support for audit attribution.
Description check ✅ Passed The description matches the changeset and covers the identity config, request injection, matchers, assertions, and docs.
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.
Sec-02: Secrets In Log Output ✅ Passed PASS: No non-test log statements emit raw token/password/credential values; the only token-adjacent config log uses redactToken() (CWE-532).
No Hardcoded Secrets ✅ Passed PASS: No hardcoded credentials or base64 blobs were added; identity.token stays empty and token/header values are injected from config/env, not literals (CWE-798).
No Weak Cryptography ✅ Passed No CWE-327/CWE-208 issues: searches found no md5/des/rc4/SHA1/ECB or secret/HMAC comparisons; only sha256/rand in non-security code.
No Injection Vectors ✅ Passed PASS: changed non-test files add flags/config/header wiring only; no CWE-89/78/79/502 sinks found, and test fmt.Sprintf uses are assertions.
No Privileged Containers ✅ Passed PR diff touches only Go/docs/scripts/config; no manifests, Helm templates, or Dockerfiles changed, and no privileged/root settings appear in the diff.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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

@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: 5

🤖 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 `@cmd/hyperfleet-e2e/main.go`:
- Around line 33-34: Add a new CLI flag binding for the identity token so
token-only usage is supported: declare or reuse the variable identityToken and
register it with pfs.StringVar(&identityToken, "identity-token", "", "Caller
identity token (alternative to identity-header/identity-value)"), and add the
same binding in the other flagset where identityHeader/identityValue are
registered (the other pfs.StringVar calls referenced in the comment). Update any
flag parsing logic that constructs request identity to prefer identityToken when
set (instead of header/value).

In `@cmd/hyperfleet-e2e/test/cmd.go`:
- Around line 60-67: The viper.BindPFlag calls for binding parent flags are
ignoring returned errors; update the block that calls viper.BindPFlag (for
config.API.URL, config.Log.Level, config.Log.Format, config.Log.Output,
config.Identity.Header, config.Identity.Value using parentFlags.Lookup("..."))
to check each error and handle it (e.g., return the error from the surrounding
function or log/fatal with context) instead of discarding; ensure you capture
the returned error from each viper.BindPFlag call and include a clear message
referencing the flag/key when reporting the failure.

In `@e2e/cluster/delete.go`:
- Around line 56-58: When h.ExpectedIdentity() returns a non-empty expected
identity, don't just assert deletedCluster.DeletedBy is non-nil — assert it
equals the expected identity for end-to-end attribution. Update the test in
delete.go to (1) fetch expected := h.ExpectedIdentity(), (2) ensure
deletedCluster.DeletedBy is present, and then (3) compare the DeletedBy value
against expected (use the appropriate field/representation on
deletedCluster.DeletedBy) so the assertion fails if the API attributes deletion
to the wrong caller.

In `@pkg/config/config.go`:
- Around line 497-499: The log currently emits c.Identity.Value as
"identity_value" in plaintext using valueOrNotSet; change this to a redacted
form (reuse or add a helper like redactValue similar to redactToken) so
identity_value does not reveal emails/identifiers in logs; update the call in
the block that builds the map (replace valueOrNotSet(c.Identity.Value) with a
redaction helper) and ensure redactToken(c.Identity.Token) remains unchanged.
- Around line 462-465: In Validate(), after the existing header/value presence
check (the block referencing c.Identity.Header and c.Identity.Value), add a
format validation for c.Identity.Value so malformed audit identities fail fast;
call or implement a small validator (e.g., parseAuditIdentity(...) or a tailored
regexp) and return a descriptive error from Validate() if it doesn't match the
expected audit-identity format (include the invalid value in the fmt.Errorf
message) so config loading fails early rather than at API runtime.
🪄 Autofix (Beta)

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: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: f6bf6e8a-4652-469d-9a0d-4495a6cd0f70

📥 Commits

Reviewing files that changed from the base of the PR and between 0e5ebcc and e286b25.

📒 Files selected for processing (14)
  • AGENTS.md
  • cmd/hyperfleet-e2e/main.go
  • cmd/hyperfleet-e2e/test/cmd.go
  • configs/config.yaml
  • deploy-scripts/lib/api.sh
  • docs/getting-started.md
  • docs/local-kind-setup.md
  • e2e/cluster/creation.go
  • e2e/cluster/delete.go
  • pkg/client/client.go
  • pkg/config/config.go
  • pkg/helper/helper.go
  • pkg/helper/matchers.go
  • pkg/helper/suite.go

Comment thread cmd/hyperfleet-e2e/main.go
Comment thread cmd/hyperfleet-e2e/test/cmd.go
Comment thread e2e/cluster/delete.go
Comment thread pkg/config/config.go
Comment thread pkg/config/config.go
@kuudori kuudori force-pushed the HYPERFLEET-1147-caller-identity branch from e286b25 to 5d8c6b8 Compare June 9, 2026 00:00
@kuudori kuudori force-pushed the HYPERFLEET-1147-caller-identity branch from 5d8c6b8 to 9fe3db5 Compare June 24, 2026 18:21
@openshift-ci

openshift-ci Bot commented Jun 24, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign rafabene 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

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.

1 participant