Skip to content

fix(cdn): recover Fastly certificates and preserve DNS failure details - #222

Closed
HarshMN2345 wants to merge 5 commits into
mainfrom
codex/fix-fastly-orphan-domains
Closed

HarshMN2345 wants to merge 5 commits into
mainfrom
codex/fix-fastly-orphan-domains

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Fastly can return service_id: null for both classic domains and unlinked versionless domains. The managed provider previously treated both as classic, so an orphan could remain without a service association or TLS subscription indefinitely. It now links a confirmed orphan to the configured service before requesting TLS.

Ownership checks preserve classic exact and wildcard routes across services, existing routing configurations, and TLS-first transfers between services. Repair requires unrestricted token and user visibility through /tokens/self, /current_user, and the complete service inventory. Failed lookups, malformed responses, incomplete results, and insufficient permissions stop mutation.

Certificate polling now reads the subscription's referenced TLS authorizations. An explicit failed subscription or blocked authorization throws Utopia\Cdn\Exception\Certificate, carrying its status, provider instructions, and relevant DNS record types, names, and values. Pending warnings remain pending; an issued subscription stays issued even if an included authorization is stale. Unrelated authorization details are excluded.

Deletion removes owned orphan records before their TLS subscription so retries can finish partial cleanup. It preserves domains belonging to other services, routing configurations, and wildcard routes, and refuses to delete shared TLS subscriptions. Missing-domain cleanup also checks classic ownership before removing TLS.

Validation:

  • Full CDN suite: 203 tests, 432 assertions.
  • bin/monorepo check cdn: Pint, PHPStan, and Rector pass.
  • bin/monorepo validate and git diff --check pass.
  • Regression coverage includes orphan issuance and renewal, ownership and permissions, incomplete or malformed provider responses, blocked DNS instructions, stale authorizations, shared subscriptions, and retrying partial deletion.

The CDN suite uses scripted HTTP responses; it does not perform live Fastly, DNS, or CA E2E requests.

Companion Appwrite retry handling: appwrite/appwrite#13467. Cloud status handling: https://github.com/appwrite-labs/cloud/pull/5639.

@HarshMN2345 HarshMN2345 changed the title fix(cdn): repair unlinked Fastly domains before TLS issuance fix(cdn): recover Fastly certificates and preserve DNS failure details Sep 7, 2026
@HarshMN2345
HarshMN2345 marked this pull request as ready for review September 7, 2026 13:01
* @param array{resource:array<string, mixed>,included:array<int, array<string, mixed>>} $subscription
* @return list<string>|null
*/
private function getSubscriptionDomains(array $subscription): ?array

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.

Lets have exact params

Drops the parts of this branch that #300 and #304 already landed on main,
and keeps only what is still unique to it.

Superseded, now taken from main:
- `Exception\Certificate`: main's carries `Challenge` objects, `getWarnings()`
  and `isBlocked()` where this branch had a raw `getDnsRecords()` array.
- `Status::BLOCKED` and the `Provider::getCertificateStatus()` `@throws`.
- `FastlyTls::getCertificateStatus()` blocked-authorization reporting, the
  `tls_authorizations` include, and the ~210 lines of tests covering them.
- The README paragraph describing the old `getDnsRecords()` shape.

Kept from this branch:
- `Fastly`: unlinked and classic-route domain ownership, `fqdn_match=exact`
  with a truncation guard, and `stdClass` response handling.
- `FastlyTls`: the exclusive-ownership check before a `force=true` delete,
  and the `findSubscription()` hardening.

`Fastly::issueCertificate()` now uses main's `catch (Certificate)` around
`getCertificateStatus()` on the reassignment path, since that call throws
on a blocked authorization rather than returning a status.

`bin/monorepo check cdn` passes; 204 CDN tests pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The PR is not safe to merge until shared-subscription deletion is made atomic and the implementation-coupled tests are brought into compliance with the repository requirement.

Fix All in Claude CodeFindings

  1. P2 Tests mirror request internals ▶
Fix with agent prompt
### Issue 1
packages/cdn/tests/Cdn/Certificates/Provider/FastlyTest.php:32-42
These assertions hard-code the exact request count, lookup order, numeric call indexes, and endpoint sequence. This violates the repository directive to test observable behavior instead of mirroring source code or configuration: a harmless refactor of the preliminary reads will fail even when domain linking and TLS creation still work correctly. The same pattern appears in the pagination test around lines 116–118 and the deletion test around lines 649–652. Assert the required mutation requests and public outcome without fixing every request to a specific array position. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR adds recovery for unassociated Fastly domains, cross-service classic-route ownership checks, safer TLS subscription deletion, stricter provider-response validation, and extensive scripted HTTP coverage.

  • Links confirmed orphan domains to the configured service before requesting TLS.
  • Preserves classic, wildcard, routing-configuration, and foreign-service ownership.
  • Rejects deletion of TLS subscriptions that are shared or whose ownership cannot be established.
  • Documents credential and staging-validation requirements.
  • Introduces a partial-deletion failure for shared subscriptions and substantial implementation-coupled test assertions.

Reviews (1) · Last reviewed commit: "Merge main into codex/fix-fastly-orphan-..."

Comment on lines +32 to +42
$this->assertCount(8, $client->calls);
$this->assertSame('https://api.fastly.com/service/service_1/details', $client->calls[1]['url']);
$this->assertSame('https://api.fastly.com/tokens/self', $client->calls[2]['url']);
$this->assertSame('https://api.fastly.com/current_user', $client->calls[3]['url']);
$this->assertSame('https://api.fastly.com/service?page=1&per_page=20', $client->calls[4]['url']);
$this->assertSame('PATCH', $client->calls[5]['method']);
$this->assertSame('https://api.fastly.com/domain-management/v1/domains/domain_1', $client->calls[5]['url']);
$this->assertSame(['service_id' => 'service_1'], $client->calls[5]['body']);
$this->assertSame('POST', $client->calls[7]['method']);
$this->assertSame('https://api.fastly.com/tls/subscriptions', $client->calls[7]['url']);
$this->assertSame('example.com', $client->calls[7]['body']['data']['relationships']['tls_domains']['data'][0]['id']);

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.

P2 Tests mirror request internals

These assertions hard-code the exact request count, lookup order, numeric call indexes, and endpoint sequence. This violates the repository directive to test observable behavior instead of mirroring source code or configuration: a harmless refactor of the preliminary reads will fail even when domain linking and TLS creation still work correctly. The same pattern appears in the pagination test around lines 116–118 and the deletion test around lines 649–652. Assert the required mutation requests and public outcome without fixing every request to a specific array position. This repository requirement must be satisfied before merging.

Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cdn/tests/Cdn/Certificates/Provider/FastlyTest.php
Line: 32-42

Comment:
**Tests mirror request internals**

These assertions hard-code the exact request count, lookup order, numeric call indexes, and endpoint sequence. This violates the repository directive to test observable behavior instead of mirroring source code or configuration: a harmless refactor of the preliminary reads will fail even when domain linking and TLS creation still work correctly. The same pattern appears in the pagination test around lines 116–118 and the deletion test around lines 649–652. Assert the required mutation requests and public outcome without fixing every request to a specific array position. This repository requirement must be satisfied before merging.

**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings sit on lines the diff does not cover, so they could not be posted inline. Each one leaves this list once its file changes.

  • P1 Deletion leaves partial state packages/cdn/src/Cdn/Certificates/Provider/Fastly.php:262 ▶

    When an owned versionless domain uses a shared or unreadable TLS subscription, this code deletes the domain record before checking whether the subscription can be removed. The ownership check then throws, so the operation reports failure after partially succeeding. Retries continue to fail because the shared subscription remains non-exclusive. Check subscription ownership before deleting the domain record to avoid leaving cleanup in this state.

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