Skip to content

feat: update API - #2678

Open
bouskaJ wants to merge 1 commit into
mainfrom
declarative_tuf_api
Open

bouskaJ wants to merge 1 commit into
mainfrom
declarative_tuf_api

Conversation

@bouskaJ

@bouskaJ bouskaJ commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Prepare the TUF API for declarative trust-root management. Bindings can specify a target name and validity window, and the API can represent multiple bindings per component and a snapshot of the published trust root.

TUF now skips components whose binding lists are empty. This disables implicit autoloading for omitted bindings. Namespace-wide discovery can select trust material from an unintended component, so the desired trust root should identify its sources explicitly. SecureSign supplies sibling refs for the components it manages.

Compatibility

Potentially breaking for standalone TUF resources that rely on autoloading. New standalone resources should declare each desired binding using a component ref or a secretRef with an explicit service URL. Existing standalone resources that previously resolved their keys have Secret references recorded in status.keys. A follow-up PR will use those references to migrate them to explicit bindings.

Legacy bindings without a secretRef relied on autoloading for trust material. When conversion assigns a sibling ref to such a binding on a SecureSign-managed TUF, it clears the legacy URL. TUF then reads the endpoint and trust material from the referenced component.

Changing bindings on an already initialized repository did not reliably update the published trust root. This PR introduces the API for declarative updates as new functionality.

@qodo-for-securesign

qodo-for-securesign Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Multi-entry TUF trust root bindings with TargetName and validity

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Changes TUF ctlog, fulcio, rekor and tsa from single-entry to list bindings (max 64 each).
• Adds per-binding targetName and validFor fields, plus a TrustRoot publication status and
 Components snapshot.
• Converts TSA from pointer-to-slice to slice and rewrites v1alpha1 conversion to match bindings by
 TargetName.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • Binding defaults and activation determine which TUF trust materials are resolved and passed to initialization or migration; resolver, status, FIPS and jobs are implementation hops of the same repository-publication behavior.
  • Conversion produces the component bindings later consumed by the same TUF resolver and repository jobs; conversion and publication are one end-to-end trust-root behavior, not independent functional scopes.
Sources

internal/controller/tuf/trustroot/resolver.go[42-55]

func ActiveKeys(instance *rhtasv1.Tuf) []ComponentKey {
	keys := make([]ComponentKey, 0, 4)
	if len(instance.Spec.Tsa) > 0 {
		keys = append(keys, TSA)
	}
	if len(instance.Spec.Fulcio) > 0 {
		keys = append(keys, Fulcio)
	}
	if len(instance.Spec.Rekor) > 0 {
		keys = append(keys, Rekor)
	}
	if len(instance.Spec.Ctlog) > 0 {
		keys = append(keys, CTFE)
	}
Behavioral complexity 🟡 Medium 🧩 Interacting branches, Compatibility cases

  • Before, TSA used nil versus non-nil state and managed objects could rely on autodiscovery.
  • After, all components use list presence and eligible legacy managed bindings are materialized explicitly.
  • New correctness condition: standalone empty-list exclusion, legacy upgrade, defaulting, status conditions, FIPS validation and initialization/migration must agree.
  • Compatibility handling is nontrivial; the list loops themselves are straightforward.
Sources

internal/controller/tuf/trustroot/resolver.go[42-55]

func ActiveKeys(instance *rhtasv1.Tuf) []ComponentKey {
	keys := make([]ComponentKey, 0, 4)
	if len(instance.Spec.Tsa) > 0 {
		keys = append(keys, TSA)
	}
	if len(instance.Spec.Fulcio) > 0 {
		keys = append(keys, Fulcio)
	}
	if len(instance.Spec.Rekor) > 0 {
		keys = append(keys, Rekor)
	}
	if len(instance.Spec.Ctlog) > 0 {
		keys = append(keys, CTFE)
	}
Potential damage 🟡 Medium 🩹 Temporary loss

  • If a required component remains absent from a standalone or converted binding list, resolution or repository initialization can omit that trust target.
  • Managed legacy single bindings are narrowed by explicit upgrade handling, but already-persisted standalone empty lists remain possible.
  • Reverting code restores future selection; affected resources may require reconciliation or rerunning initialization or migration, and no automatic repair worker is established.
  • Reverting stops new incorrect activation decisions, but an already initialized or failed repository may need reconciliation, initialization or migration reruns; external repository state is not automatically repaired.
Sources

internal/controller/tuf/trustroot/resolver.go[42-55]

func ActiveKeys(instance *rhtasv1.Tuf) []ComponentKey {
	keys := make([]ComponentKey, 0, 4)
	if len(instance.Spec.Tsa) > 0 {
		keys = append(keys, TSA)
	}
	if len(instance.Spec.Fulcio) > 0 {
		keys = append(keys, Fulcio)
	}
	if len(instance.Spec.Rekor) > 0 {
		keys = append(keys, Rekor)
	}
	if len(instance.Spec.Ctlog) > 0 {
		keys = append(keys, CTFE)
	}
Assessed commit 9dc7084
High-Level Assessment

The following are alternative approaches to this PR:

1. Keep single-entry bindings and add a separate TrustRoot CR
  • ➕ Avoids breaking the TSA pointer-to-slice type change
  • ➕ Keeps the existing MaxItems contract intact
  • ➖ Adds another CRD and reconciliation loop
  • ➖ Does not solve per-component multi-instance support
2. Use a map keyed by targetName instead of a list
  • ➕ Uniqueness of targetName is enforced by the type
  • ➕ Simpler lookup in conversion code
  • ➖ Map types are not well supported by CRD structural schemas
  • ➖ Changes the wire format again

Recommendation: The list-based design with TargetName as the join key is reasonable for multi-instance trust roots, and the PR already applies it consistently across conversion, defaulting and controller code. The main risk is that the per-binding Keys status is now deprecated while the controller still writes it, so the migration path should be confirmed before merge.

Files changed (19) +1251 / -236

Enhancement (5) +260 / -70
securesign_defaults.goSimplify TSA defaulting for slice-typed binding +3/-5

Simplify TSA defaulting for slice-typed binding

• TSA defaulting now checks len(Tuf.Tsa) == 0 and assigns a sibling ref slice, replacing the pointer-based nil check. The nil-means-excluded comment is removed because the field is no longer a pointer.

api/v1/securesign_defaults.go

tuf_defaults.goAdd per-binding TargetName defaulting for TUF components +39/-0

Add per-binding TargetName defaulting for TUF components

• Adds SetDefaults on TrustRootBinding to fill TargetName with component key plus date when empty. Adds defaulting loops over ctlog, fulcio, rekor and tsa in both TufSpec and Components.

api/v1/tuf_defaults.go

tuf_types.goMake TUF bindings lists and add validity, target name and status types +88/-20

Make TUF bindings lists and add validity, target name and status types

• Raises MaxItems to 64 on all four binding lists and changes Tsa from a pointer to a slice. Adds TargetName and ValidFor to TrustRootBinding, plus Components and TrustRootStatus types, and a TrustRoot field on TufStatus. Keys is marked deprecated in a comment, and small accessor methods are added.

api/v1/tuf_types.go

tuf_conversion.goMatch TUF bindings by TargetName during v1alpha1 conversion +118/-39

Match TUF bindings by TargetName during v1alpha1 conversion

• Spoke conversion picks the legacy-named binding by TargetName instead of index 0 in both directions. New restoreBindings and restoreBindingWithOIDC helpers merge annotation data by name, and ValidFor and TrustRoot status are carried through.

api/v1alpha1/tuf_conversion.go

resolver.goDerive active trust root keys from non-empty binding lists +12/-6

Derive active trust root keys from non-empty binding lists

• ActiveKeys includes each component only when its binding list is non-empty, and TSA is included only when the list has entries. Binding for TSA now reads the first element of a slice directly.

internal/controller/tuf/trustroot/resolver.go

Bug fix (1) +33 / -17
securesign_conversion.goSet sibling refs for legacy TUF bindings during conversion +33/-17

Set sibling refs for legacy TUF bindings during conversion

• When no restore annotation exists, ConvertTo now fills sibling Ref bindings for ctlog, fulcio and tsa. It also replaces the old restoreBindingRef calls with restoreBindings.

api/v1alpha1/securesign_conversion.go

Tests (9) +308 / -96
tuf_types_test.goUpdate webhook tests for list-based bindings +2/-10

Update webhook tests for list-based bindings

• Removes the test that rejected more than one ctlog binding, since that limit no longer exists. Updates the TSA tests to assign a slice instead of a pointer.

api/v1/tuf_types_test.go

conversion_roundtrip_test.goExtend round-trip fuzzers for multi-binding TUF fields +60/-18

Extend round-trip fuzzers for multi-binding TUF fields

• Fuzzers now generate TargetName and optional ValidFor, and sometimes produce a second custom-named binding. Keys get a random SecretRef, and TSA is generated as a slice.

api/v1alpha1/conversion_roundtrip_test.go

conversion_unit_test.goAdd legacy TUF binding conversion and TargetName tests +176/-11

Add legacy TUF binding conversion and TargetName tests

• Adds TestLegacySecuresignTufBindings to check legacy-to-hub binding generation and overrides. Adds TestTufCustomTargetNameRoundTrip to verify TargetName-based matching in both directions. Updates expected fixtures to include TargetName.

api/v1alpha1/conversion_unit_test.go

resolve_keys_test.goRewrite resolve-keys tests around referenced components +62/-49

Rewrite resolve-keys tests around referenced components

• Tests now build TUF instances from a TufSpec with explicit Ref bindings. Cases cover missing and not-ready components, mixed references, and TSA presence, and status key assertions are tightened.

internal/controller/tuf/actions/resolve_keys_test.go

namespaced_test.goUpdate namespaced e2e for slice-typed Tsa +2/-2

Update namespaced e2e for slice-typed Tsa

• Assigns the Tsa field as a slice literal and drops the pointer dereference when setting the URL.

test/e2e/install/namespaced_test.go

provided_certs_test.goUpdate provided-certs e2e for slice-typed Tsa +1/-1

Update provided-certs e2e for slice-typed Tsa

• Assigns the Tsa field as a slice literal instead of taking the address of a slice.

test/e2e/install/provided_certs_test.go

securesign_1855_test.goUpdate lifecycle e2e fixture for slice-typed Tsa +1/-1

Update lifecycle e2e fixture for slice-typed Tsa

• Sets Tsa to a slice literal rather than a pointer to one.

test/e2e/lifecycle/securesign_1855_test.go

tuf.goRefresh TUF e2e helper for slice-typed Tsa +3/-3

Refresh TUF e2e helper for slice-typed Tsa

• Checks len(Tsa) for emptiness and seeds an empty binding slice when needed. Sets Tsa[0].URL directly without dereferencing.

test/e2e/support/tas/tuf/tuf.go

tsa_test.goUpdate TSA update e2e for slice-typed Tsa +1/-1

Update TSA update e2e for slice-typed Tsa

• Assigns Tsa as a slice literal in the update step, replacing the pointer-to-slice form.

test/e2e/update/tsa_test.go

Other (4) +650 / -53
zz_generated.deepcopy.goRegenerate deepcopy for new types and Tsa slice +103/-7

Regenerate deepcopy for new types and Tsa slice

• Adds deepcopy functions for Components, TrustRootStatus and ValidFor. Updates TrustRootBinding, TufSpec and TufStatus deepcopy for the new fields and the slice-typed Tsa.

api/v1/zz_generated.deepcopy.go

zz_generated.conversion.goUpdate generated conversion warnings for Tsa and TrustRoot +3/-2

Update generated conversion warnings for Tsa and TrustRoot

• Updates the generated warning comments to reflect the slice-typed Tsa and the new TrustRoot status field. No runtime logic changes.

api/v1alpha1/zz_generated.conversion.go

rhtas.redhat.com_securesigns.yamlRegenerate Securesign CRD for list-based TUF bindings +96/-22

Regenerate Securesign CRD for list-based TUF bindings

• Raises maxItems to 64 on ctlog, fulcio, rekor and tsa. Adds targetName and validFor properties to the binding schema and removes the 'at most one entry' wording from descriptions.

config/crd/bases/rhtas.redhat.com_securesigns.yaml

rhtas.redhat.com_tufs.yamlRegenerate Tuf CRD with trustRoot status and binding fields +448/-22

Regenerate Tuf CRD with trustRoot status and binding fields

• Applies the same maxItems and binding schema changes as the Securesign CRD. Adds the status.trustRoot schema with the published Components snapshot, last publish time and targets version.

config/crd/bases/rhtas.redhat.com_tufs.yaml

@qodo-for-securesign

qodo-for-securesign Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Code Review by Qodo


Action required

1. Additional trust bindings disappear 🔗 Cross-repo conflict
Description
TufSpec permits up to 64 bindings per component, but Binding and FulcioBinding select only the
first, leaving the init job with one material path per component. When a user configures a second
key or certificate authority, key resolution and the repository init job do not receive it, so
tufcli cannot include it in the published trust root.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The API accepts multiple bindings per component, but reconciliation resolves only the first and the operator-to-tufcli publication path sends only one material path per component.

## Fix Focus Areas
- api/v1/tuf_types.go[49-72]
- internal/controller/tuf/trustroot/resolver.go[48-91]
- internal/controller/tuf/actions/resolve_keys.go[47-95]
- internal/controller/tuf/utils/tuf_init_job.go[28-57]

## Recommended Fix
Iterate over and resolve every accepted binding, using its target name to distinguish the results. Stage each binding and invoke a tufcli publication flow that adds each distinct target and authority to the same repository, coordinating any needed CLI or initialization-script changes in securesign/tufcli. Cover two bindings of one component in an integration test. If publication cannot support multiple bindings yet, retain the single-entry API limit.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

2. Custom target names never publish 🔗 Cross-repo conflict
Description
TrustRootBinding.TargetName is accepted as the requested TUF target name, but the operator
continues to pass fixed component-key filenames to tufcli rather than that value. Even with a single
explicitly named binding, tufcli publishes under the input file's basename, so consumers requesting
the configured target name cannot retrieve it.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new targetName field does not reach tufcli, which derives published names from fixed input filenames.

## Fix Focus Areas
- api/v1/tuf_types.go[93-97]
- internal/controller/tuf/utils/tuf_init_job.go[36-56]

## Recommended Fix
Stage material using each binding's validated target name, or coordinate a securesign/tufcli CLI change that accepts an explicit target name. Ensure target lookup using a configured custom name succeeds, without changing legacy target names unexpectedly.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

3. Configured trust validity is ignored 🔗 Cross-repo conflict
Description
TrustRootBinding.ValidFor accepts start and end timestamps, but the resolution path does not read
them and the operator does not pass them to tufcli, which instead derives trusted-root validity from
status and the current time. A binding with a future start or past end is processed like one without
an interval, and Cosign retrieves the status-derived timestamps from the published TUF repository.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`TrustRootBinding.ValidFor` is accepted, but its timestamps have no effect on resolved or published trust material; tufcli publishes status-derived timestamps instead.

## Fix Focus Areas
- api/v1/tuf_types.go[90-106]
- internal/controller/tuf/actions/resolve_keys.go[47-95]
- internal/controller/tuf/utils/tuf_init_job.go[28-60]

## Recommended Fix
Carry each binding's validity interval through resolution and the operator publication job, and coordinate explicit start/end support in securesign/tufcli rather than relying on status-derived defaults. Enforce the configured start and end as intended and verify that the published trusted_root.json retains the requested timestamps; avoid exposing the field as effective configuration until that path exists.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Remediation recommended

4. Successful publication has no status 🐞 Bug
Description
TufStatus.TrustRoot declares a record of the last successful trust-root publication, but no TUF
reconciliation action assigns its published bindings, version, or time. Even after the operator
processes trust material, the new status remains unset and cannot report the publication described
by the API.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new publication status is never populated by the TUF controller.
## Fix Focus Areas
- api/v1/tuf_types.go[141-155]
- internal/controller/tuf/tuf_controller.go[103-145]
## Recommended Fix
Update the status after confirmed publication, recording the published bindings, targets version, and time; otherwise defer exposing fields described as active publication status.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


@codecov-commenter

codecov-commenter commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.75486% with 106 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.46%. Comparing base (08b510b) to head (9dc7084).

Files with missing lines Patch % Lines
api/v1/zz_generated.deepcopy.go 4.41% 63 Missing and 2 partials ⚠️
api/v1/tuf_defaults.go 48.57% 14 Missing and 4 partials ⚠️
api/v1alpha1/tuf_conversion.go 87.05% 5 Missing and 6 partials ⚠️
api/v1/tuf_types.go 0.00% 10 Missing ⚠️
api/v1alpha1/securesign_conversion.go 86.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2678      +/-   ##
==========================================
- Coverage   59.54%   59.46%   -0.09%     
==========================================
  Files         302      302              
  Lines       17543    17715     +172     
==========================================
+ Hits        10446    10534      +88     
- Misses       6338     6417      +79     
- Partials      759      764       +5     
Flag Coverage Δ
e2e 75.65% <68.75%> (+<0.01%) ⬆️
unit 42.30% <55.25%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bouskaJ
bouskaJ force-pushed the declarative_tuf_api branch 4 times, most recently from d227e57 to c533cb8 Compare December 3, 2026 09:49
@bouskaJ
bouskaJ added this pull request to stack #2680 December 3, 2026 10:04
@bouskaJ
bouskaJ force-pushed the declarative_tuf_api branch from c533cb8 to 777b2eb Compare December 3, 2026 12:22
@bouskaJ
bouskaJ force-pushed the declarative_tuf_api branch from 777b2eb to 9dc7084 Compare December 4, 2026 09:39

@fghanmi fghanmi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tested on a live deployment: the sample deploys to Ready, the TUF repo serves all targets, and cosign initialize works, so the happy path is fine.
I added comments for few concerns.

func ActiveKeys(instance *rhtasv1.Tuf) []ComponentKey {
keys := []ComponentKey{Rekor, CTFE, Fulcio}
if instance.Spec.Tsa != nil {
keys := make([]ComponentKey, 0, 4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The PR description says the follow-up will use status.keys to migrate existing standalone Tufs. This change deletes that data first.

ActiveKeys now returns no keys when the spec has no bindings. ResolveKeys (not changed here) then replaces status.keys with an empty list. I tested this on a live instance: a Tuf had 4 secret references in status.keys. After the binding lists were removed, it had none and stayed Ready.

Could we leave status.keys as it is until the migration reads it, for example by not writing when no binding resolves?

if err := serviceReferenceToAddressPort(&in.Rekor[0].ServiceReference, &out.Rekor.Address, &out.Rekor.Port); err != nil {
// v1alpha1 has a single slot per component. Populate it only from the
// legacy-named binding; differently named keys stay annotation-only.
if i := slices.IndexFunc(in.Rekor, func(b rhtasv1.TrustRootBinding) bool { return b.TargetName == rhtasv1.TufKeyRekor }); i >= 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

v1alpha1 only shows a binding when its name is exactly rekor.pub, ctfe.pub and so on. Defaulted bindings are named like rekor-<ref>.pub, so a normal v1 object shows no keys.

The v1alpha1 CRD adds four keys when none are given. After a full update through v1alpha1, converting back creates a TSA binding. I tested this on a Tuf with no TSA. It got a tsa.certchain.pem binding with no source, and stays Pending with a "no TimestampAuthority" error.

Could conversion remember which bindings existed, including when none are visible in v1alpha1?

name := r.GetName()
if spoke, ok := spokeByName[name]; ok {
out = append(out, restore(spoke, r))
} else if name != legacyName {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The loop only goes through the saved list. If a v1alpha1 client adds a new legacy entry such as rekor.pub with its own secret, nothing visits it and it is silently dropped. I reproduced this live.

Could we merge entries that are new in the v1alpha1 object, and keep edits to visible fields?

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.

3 participants