Skip to content

[TT-17176] PRM auto-migration — deprecate legacy struct, pin runtime guarantees#8247

Merged
lghiur merged 3 commits into
TT-17175-prm-new-structurefrom
TT-17176-prm-migration
Jun 8, 2026
Merged

[TT-17176] PRM auto-migration — deprecate legacy struct, pin runtime guarantees#8247
lghiur merged 3 commits into
TT-17175-prm-new-structurefrom
TT-17176-prm-migration

Conversation

@lghiur

@lghiur lghiur commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Companion gateway PR for the Story 05 PRM auto-migration in tyk-analytics. The dashboard migration (TT-17176 PR #5657) is non-destructive — it leaves the deprecated top-level authentication.protectedResourceMetadata in place and adds the new securitySchemes[<name>].oauth2.protectedResourceMetadata alongside, so the gateway must continue to honour both shapes during the transition.

This PR:

  • Marks the legacy struct deprecated at both Go and JSON-Schema level so IDEs, staticcheck SA1019, OpenAPI Generator, Stoplight, Redocly, and the dashboard form generator all surface the deprecation. Authentication.ProtectedResourceMetadata and the ProtectedResourceMetadata type each carry // Deprecated: doc comments; all four x-tyk-api-gateway schema variants (apidef/oas/schema/x-tyk-api-gateway.json, …strict.json, apidef/mcp/schema/x-tyk-api-gateway.json, apidef/streams/schema/x-tyk-api-gateway.json) carry "deprecated": true on the legacy type definition.
  • Pins runtime guarantees the migration depends on:
    • PRM serves when the OAuth2 master is disabled — what lets the dashboard produce oauth2.enabled: false + oauth2.protectedResourceMetadata.enabled: true without silently turning on authentication that wasn't there before.
    • Legacy block fallback when the new per-scheme PRM sub-block is absent — what makes downgrade safe (operator removes the new block → gateway serves from the legacy top-level block).

No behaviour change. Pure backwards-compatible documentation + test surface.

Story

Companion PRs

  • tyk-analytics#5657 — dashboard startup migration + Python e2e.
  • tyk-analytics-ui (webclient) — no PR for this story; the optional UI banner / read-only legacy form is deferred.

Test plan

  • go test ./apidef/oas/... -run TestProtectedResourceMetadata_SchemaMarkedDeprecated -count=1
  • go test ./apidef/oas/... -run TestOAS_PRMBothBlocksRoundTrip -count=1 — both blocks survive marshal/unmarshal with the OAuth2 master staying false.
  • go test ./gateway/... -run TestOAuth2PRM_ServesWhenOAuth2MasterDisabled -count=1
  • go test ./gateway/... -run TestOAuth2PRM_FallsBackToLegacyWhenNewBlockAbsent -count=1

Risk

  • Behaviour-neutral. No runtime code path changes — the new tests pin existing behaviour the migration relies on. Schema-level "deprecated": true is advisory metadata; clients that don't read it see no change.
  • The earlier #8212 on this branch carried an Authentication.PRMMigratedToOAuth2 marker field that has since been removed in favour of presence-based idempotency on the dashboard side — that PR was closed; this PR replaces it with a strictly narrower scope (deprecation + runtime-guarantee tests, no marker field).

🤖 Generated with Claude Code

Ticket Details

TT-17176
Status Ready for Testing
Summary Protected Resource Metadata — auto-migration of existing customers

Generated at: 2026-05-27 18:07:46

@probelabs

probelabs Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

This pull request prepares the gateway to support a non-destructive, automated migration of Protected Resource Metadata (PRM) configuration. It accomplishes this by formally deprecating the legacy top-level PRM structure and adding a suite of tests to guarantee specific runtime behaviors, ensuring a safe transition for users upgrading and the ability to downgrade without data loss.

Files Changed Analysis

The changes are focused entirely on API definitions and testing, with no modifications to the core runtime logic:

  • API Schemas (apidef/{mcp,oas,streams}/schema/*.json): All four x-tyk-api-gateway.json schema variants have been updated. The legacy X-Tyk-ProtectedResourceMetadata type is now marked with "deprecated": true and includes a description pointing to the new location. This provides a clear signal for deprecation to UIs and other schema-aware tools.
  • Go Definitions (apidef/oas/authentication.go): The legacy ProtectedResourceMetadata struct and its corresponding field on the Authentication struct are now marked with // Deprecated: comments. This will trigger warnings in IDEs and static analysis tools, guiding developers to use the new structure.
  • Testing (apidef/oas/authentication_test.go, gateway/mw_protected_resource_oauth2_test.go): The majority of the changes consist of new tests that codify and lock in existing behavior. These tests verify:
    1. The deprecation flag is correctly set in all JSON schemas.
    2. Both legacy and new PRM blocks can coexist and round-trip through JSON serialization without side effects.
    3. PRM continues to be served even when the main OAuth2 authentication is disabled.
    4. The gateway correctly falls back to the legacy PRM block if the new per-scheme block is absent.

Architecture & Impact Assessment

  • What this PR accomplishes: It ensures the gateway can safely handle API definitions that have been auto-migrated by the Tyk Dashboard. By deprecating the old structure and guaranteeing fallback behavior, it provides both forward and backward compatibility, which is critical for a smooth user experience during upgrades and potential downgrades.

  • Key technical changes introduced:

    1. Formal Deprecation: The legacy top-level PRM configuration is officially marked as deprecated in both the Go code (// Deprecated:) and the JSON schemas ("deprecated": true).
    2. Behavioral Guarantees via Tests: New tests are added to prevent future regressions by codifying existing gateway behaviors that the migration strategy relies upon.
  • Affected system components:

    • API Definitions (apidef): Impacts developers and schema-based tooling by signaling the deprecation of the old PRM location.
    • Gateway (gateway): While no runtime code is changed, its behavior regarding PRM fallback and independence from the main OAuth2 switch is now explicitly tested and guaranteed.

Configuration Migration Flow

This PR supports the transition from a single, top-level PRM block to a more flexible, per-security-scheme definition. During the migration, both can coexist, with the gateway prioritizing the new structure but falling back to the legacy one for safety.

graph TD
    subgraph "Old Structure"
        A["authentication"] -- contains --> B["protectedResourceMetadata"];
    end

    subgraph "Migrated Structure (Coexistence)"
        C["authentication"] -- contains --> D["protectedResourceMetadata (legacy, deprecated)"];
        C -- contains --> E["securitySchemes"];
        E --|scheme_name|--> F["OAuth2"];
        F -- contains --> G["protectedResourceMetadata (new)"];
    end

    style D fill:#f9f,stroke:#333,stroke-width:2px

Loading

Scope Discovery & Context Expansion

This PR is a companion to a migration feature in the tyk-analytics (Dashboard) repository. Its scope is strictly limited to the gateway's role in supporting this migration. The gateway does not perform the migration itself; rather, the Dashboard handles the non-destructive copy of the PRM configuration from the old location to the new one.

The key context is that the migration is non-destructive, meaning the original data is left in place for downgrade safety. This PR ensures the gateway handles this dual-state correctly by:

  1. Prioritizing the new per-scheme PRM block if it exists.
  2. Falling back to the legacy top-level block if the new one is absent.

The changes introduce no new runtime behavior and carry minimal risk, as they consist solely of documentation, schema updates, and tests that enforce existing functionality.

Metadata
  • Review Effort: 2 / 5
  • Primary Label: enhancement

Powered by Visor from Probelabs

Last updated: 2026-06-08T10:52:45.219Z | Triggered by: pr_updated | Commit: f56cfb0

💡 TIP: You can chat with Visor using /visor ask <your question>

@probelabs

probelabs Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

✅ Security Check Passed

No security issues found – changes LGTM.

✅ Performance Check Passed

No performance issues found – changes LGTM.

✅ Quality Check Passed

No quality issues found – changes LGTM.


Powered by Visor from Probelabs

Last updated: 2026-06-08T10:52:37.892Z | Triggered by: pr_updated | Commit: f56cfb0

💡 TIP: You can chat with Visor using /visor ask <your question>

@edsonmichaque edsonmichaque left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lghiur
lghiur force-pushed the TT-17175-prm-new-structure branch from e2c1512 to 79c1105 Compare May 27, 2026 18:07
@lghiur
lghiur force-pushed the TT-17176-prm-migration branch from f537eee to 59e142a Compare May 27, 2026 18:07
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🎯 Recommended Merge Targets

Based on JIRA ticket TT-17176: Protected Resource Metadata — auto-migration of existing customers

Fix Version: Tyk 5.14.0

⚠️ Warning: Expected release branches not found in repository

Required:

  • master - No matching release branches found. Fix will be included in future releases.

📋 Workflow

  1. Merge this PR to master first

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🚨 Jira Linter Failed

Commit: f56cfb0
Failed at: 2026-06-08 10:51:42 UTC

The Jira linter failed to validate your PR. Please check the error details below:

🔍 Click to view error details
failed to get Jira issue: failed to fetch Jira issue TT-17176: Issue does not exist or you do not have permission to see it.: request failed. Please analyze the request body for more details. Status code: 404

Next Steps

  • Ensure your branch name contains a valid Jira ticket ID (e.g., ABC-123)
  • Verify your PR title matches the branch's Jira ticket ID
  • Check that the Jira ticket exists and is accessible

This comment will be automatically deleted once the linter passes.

@lghiur
lghiur merged commit 93e234f into TT-17175-prm-new-structure Jun 8, 2026
20 of 25 checks passed
@lghiur
lghiur deleted the TT-17176-prm-migration branch June 8, 2026 12:41
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