Skip to content

validation: Require tenantId in subscriptions#4819

Open
mbarnes wants to merge 1 commit intomainfrom
1p/ensure-tenantid-in-subscriptions
Open

validation: Require tenantId in subscriptions#4819
mbarnes wants to merge 1 commit intomainfrom
1p/ensure-tenantid-in-subscriptions

Conversation

@mbarnes
Copy link
Copy Markdown
Collaborator

@mbarnes mbarnes commented Apr 9, 2026

Followup to a comment in #4784

What

This changes subscription validation to require the TenantId field.

Why

In a subscription PUT request, the TenantId field is optional according to the Resource Provider Contract but the ARO-HCP backend relies on it for cluster creation. Therefore we want to make sure we never write a subscription document to Cosmos without a TenantId value. The frontend tries to ensure its presence before validating, filling it in from the X-Ms-Home-Tenant-Id request header if necessary.

It's unclear whether a subscription registration without a TenantId value would ever actually occur outside of test environments. This may be purely academic, but it ensures an invariant in our Cosmos DB data.

Testing

Several existing integration tests were updated to reflect the automatic addition of a tenant ID value from request headers.

@openshift-ci openshift-ci bot requested review from deads2k and roivaz April 9, 2026 13:22
@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 9, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

TenantId is optional according to the Resource Provider Contract but
the ARO-HCP backend relies on it for cluster creation. The frontend
tries to ensure its presence, cherry-picking from request headers if
necessary.
@mbarnes mbarnes force-pushed the 1p/ensure-tenantid-in-subscriptions branch from 50040f6 to f9ccb18 Compare April 9, 2026 13:45
// TenantId is optional according to the Resource Provider Contract but the
// ARO-HCP backend relies on it for cluster creation. The frontend tries to
// ensure its presence, cherry-picking from request headers if necessary.
errs = append(errs, validate.RequiredValue(ctx, op, fldPath.Child("tenantId"), &newObj.TenantId, nil)...)
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.

are there ways newObj can be null?
i know you populate it in frontend.go but other paths might lead to here eventually via ValidateSubscriptionCreate

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.

check for RequiredPointer as well

if requestSubscription.Properties == nil {
requestSubscription.Properties = &arm.SubscriptionProperties{}
}
if requestSubscription.Properties.TenantId == nil || len(*requestSubscription.Properties.TenantId) == 0 {
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.

so the request data can send various invalid states? properties nil but also properties not nil and tenant nil or tenant empty? this this a known ARM inconsistency?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The RPC states that Properties is a required field in subscription payloads but Properties.TenantId is optional. For better or worse we have the subscription model defined entirely as pointer fields, so I'm just being careful here to avoid a panic. Such inconsistencies would be more likely, I think, in a test scenario than an actual request from ARM.

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 16, 2026

@mbarnes: The following test 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/cspr f9ccb18 link true /test cspr

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants