Skip to content

cluster_policies: Stop allowing Sequence types for value - #6492

Merged
Sankalp-Mittal merged 1 commit into
mainfrom
sankalp-mittal/clusterpolicies-drop-Sequence
Sep 3, 2026
Merged

Sankalp-Mittal merged 1 commit into
mainfrom
sankalp-mittal/clusterpolicies-drop-Sequence

Conversation

@Sankalp-Mittal

@Sankalp-Mittal Sankalp-Mittal commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Reject inline sequence (list) values for the cluster policy definition and policy_family_definition_overrides fields. Previously a top-level YAML sequence was marshaled to a JSON array string and sent to the backend as-is; it is now rejected during bundle validation with <field> must be a string or map, got sequence.

Why

A cluster policy definition must be a JSON object (a map of attribute paths to constraint objects). A top-level sequence is valid JSON but never a valid policy, and the backend does not validate the definition shape at create time — so without this change the broken policy is accepted and the failure is deferred.

Concretely, for:

resources:
  cluster_policies:
    my_policy:
      definition:
        - foo: bar
  jobs:
    my_job:
      ...
      policy_id: ${resources.cluster_policies.my_policy.id}
  • Before this PR: bundle deploy succeeds — the backend accepts the array definition, returns a policy_id, and stores it verbatim (it is never marked invalid), and the job is created. The failure only appears when the job runs: launching the job cluster applies the policy, and the backend rejects it with INVALID_PARAMETER_VALUE: Requests for the policy ... cannot be satisfied due to the malformed policy definition. Please contact your administrator to correct the policy definition. — an error far from the bundle config that gives no hint the cause is the list under definition.
  • After this PR: bundle validate / bundle deploy fails immediately with definition must be a string or map, got sequence, pointing straight at the offending config.

(Verified against the Azure backend and confirmed in the backend source: create-time validation only does field-presence .has(...) checks, which pass for an array; the array only fails later during enforcement in ClusterPolicyDefinition.fromJson.)

Tests

Unit tests.

This pull request and its description were written by Isaac.

@Sankalp-Mittal Sankalp-Mittal reopened this Sep 2, 2026
@Sankalp-Mittal
Sankalp-Mittal marked this pull request as draft September 2, 2026 17:10
@Sankalp-Mittal
Sankalp-Mittal marked this pull request as ready for review September 2, 2026 17:15
@janniklasrose

Copy link
Copy Markdown
Member

The backend doesn't do validation at create time and defers it till it is applied and then throws an error.

Can you be more specific how this impacts DABs users?

resources:
  cluster_policies:
    my_policy:
      definition:
        - foo: bar

  jobs:
    my_job:
      ...
        my_cluster:
          policy_id: ${resources.cluster_policies.my_policy.id}

will this fail when the job is deployed? when the job is run?

@Sankalp-Mittal
Sankalp-Mittal added this pull request to the merge queue Sep 3, 2026
Merged via the queue into main with commit 35cac17 Sep 3, 2026
39 checks passed
@Sankalp-Mittal
Sankalp-Mittal deleted the sankalp-mittal/clusterpolicies-drop-Sequence branch September 3, 2026 09:40
janniklasrose pushed a commit that referenced this pull request Sep 15, 2026
## Changes
Reject inline sequence (list) values for the cluster policy `definition`
and `policy_family_definition_overrides` fields. Previously a top-level
YAML sequence was marshaled to a JSON array string and sent to the
backend as-is; it is now rejected during bundle validation with `<field>
must be a string or map, got sequence`.

## Why
A cluster policy `definition` must be a JSON object (a map of attribute
paths to constraint objects). A top-level sequence is valid JSON but
never a valid policy, and the backend does **not** validate the
definition shape at create time — so without this change the broken
policy is accepted and the failure is deferred.

Concretely, for:

```yaml
resources:
  cluster_policies:
    my_policy:
      definition:
        - foo: bar
  jobs:
    my_job:
      ...
      policy_id: ${resources.cluster_policies.my_policy.id}
```

- **Before this PR:** `bundle deploy` **succeeds** — the backend accepts
the array definition, returns a `policy_id`, and stores it verbatim (it
is never marked invalid), and the job is created. The failure only
appears **when the job runs**: launching the job cluster applies the
policy, and the backend rejects it with `INVALID_PARAMETER_VALUE:
Requests for the policy ... cannot be satisfied due to the malformed
policy definition. Please contact your administrator to correct the
policy definition.` — an error far from the bundle config that gives no
hint the cause is the list under `definition`.
- **After this PR:** `bundle validate` / `bundle deploy` **fails
immediately** with `definition must be a string or map, got sequence`,
pointing straight at the offending config.

(Verified against the Azure backend and confirmed in the backend source:
create-time validation only does field-presence `.has(...)` checks,
which pass for an array; the array only fails later during enforcement
in `ClusterPolicyDefinition.fromJson`.)

## Tests
Unit tests.

This pull request and its description were written by Isaac.
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