Commit 1faebe6
authored
fix: identity schema data source empty content with project_id (#117)
* feat: add base_redirect_uri support to ory_social_provider
Adds the optional `base_redirect_uri` attribute to the `ory_social_provider`
resource, allowing users to override the base URL Ory uses when constructing
OIDC callback URLs (useful when using a custom domain).
The attribute maps to the global OIDC config field at
`/services/identity/config/selfservice/methods/oidc/config/base_redirect_uri`.
Documented its global nature (last applied value wins across providers).
Closes #113
* test: add base_redirect_uri to validate_config unit test schema
* fix: address Copilot review comments on base_redirect_uri
- Deduplicate provider_id in examples (corporate-sso-custom-domain)
- Validate base_redirect_uri is not an empty string
- Apply base_redirect_uri patch in Create's existingIndex branch
- Only track base_redirect_uri in Read when state has it configured;
fall back to GetProject when cache is empty
- Guard Update against unknown plan values; skip patch when unchanged
- Add removal test step to verify base_redirect_uri can be unset
* fix: reuse fetched project in Read to avoid extra GetProject call for base_redirect_uri
* fix: identity schema data source returns empty content when project_id is set
When project_id was explicitly set on the identity schema data sources,
the provider exclusively used the console API which reads from project
config. After the Ory API transforms schema URLs from base64:// to
https://, the project config has HTTPS URLs that couldn't be decoded,
resulting in empty schema bodies ("{}").
This commit fixes three issues:
1. Always prefer the Kratos API when available since identity schemas
are workspace-scoped and the Kratos API returns canonical hash-based
IDs with full schema content regardless of project_id.
2. Fetch schema content from HTTPS URLs in extractSchemasFromProjectConfig
so the console API path also returns full schema bodies for transformed
schemas.
3. Include project_id in the "Identity Schema Not Found" error message
to help users verify they're searching the correct project.
Closes #115
* fix: address Copilot review comments on identity schema data sources
- Thread caller context into fetchSchemaFromURL and
extractSchemasFromProjectConfig instead of using context.Background()
- Add SSRF protection: restrict to HTTPS only, block private/loopback
IPs, use dedicated HTTP client with redirect validation
- Update project_id attribute descriptions in both singular and plural
data sources to reflect Kratos API preference
- Omit "in project" clause from error message when project_id is empty
- Fix set_default with existing workspace schema: ensure schema is added
to project config before setting it as default_schema_id
* docs: update identity schema data source docs and examples
- Update project_id tip to reflect Kratos API preference
- Update project_id attribute descriptions in generated docs
- Add example showing project bootstrap with workspace schema as default
* fix: address second round of Copilot review comments
- Rewrite isPrivateHost using net/netip with proper CIDR range checks
(fixes false positive on 172.2.x public IPs)
- Add DNS rebinding protection: resolve hostnames and check all A/AAAA
records against private/loopback/link-local ranges
- Fix redirect comment to say "at most one redirect" (not "no redirects")
- Handle json.Marshal error explicitly instead of ignoring it
- Adjust error message: say "workspace" instead of "project" when
project_id is not set
- Fix example to use human-chosen schema_id ("customer") instead of hash
- Add unit tests for fetchSchemaFromURL, isPrivateHost, and isPrivateAddr
covering HTTPS fetch, non-200, invalid JSON, private IP rejection,
and DNS-based host validation
* fix: remove unnecessary #nosec G107 comment from fetchSchemaFromURL
gosec does not flag http.NewRequestWithContext with variable URLs,
and the SSRF protection (HTTPS-only, private IP blocking, DNS
rebinding checks) makes the suppression unnecessary.
* fix: address remaining Copilot review comments on PR #117
- Validate redirect targets against private/loopback hosts in
CheckRedirect to prevent SSRF bypass via redirects
- Thread caller context through isPrivateHost for DNS resolution so
lookups respect cancellation/timeout
- Surface HTTPS schema fetch errors instead of silently returning {}
- Add redirect test coverage (redirect to private host, redirect to HTTP)
- Fix misleading error hints to reflect workspace-scoped schema semantics
- Fix "when the project matches" comment to match actual behavior
- Clarify docs example that schema_id is human-chosen, not a hash
* fix: address new Copilot review comments on PR #117
- Add Kratos→Console fallback in plural identity schemas data source
to mirror singular data source behavior
- Handle missing schemas array in JSON Patch by creating the array
when it doesn't exist (brand-new project config)
- Add safeDialContext to validate resolved IPs at connection time,
preventing DNS rebinding (TOCTOU) attacks
- Add TrimSpace to isEmptySchemaBody for robustness
- Remove DNS-dependent test case (storage.googleapis.com) to keep
tests hermetic in restricted CI environments
- Update isPrivateHost comment to clarify it's a pre-flight check
* fix: improve DNS error reporting and add HTTPS extraction test
- Change isPrivateHost to return (bool, error) so DNS failures produce
actionable "resolving host" errors instead of misleading
"private/loopback host" messages
- Add unit test for HTTPS URL path in extractSchemasFromProjectConfig
using httptest server
- Add test case for unresolvable DNS name returning error
* fix: reuse shared HTTP client and parallelize HTTPS schema fetching
- Replace per-call newSchemaFetchClient with a shared schemaFetchClient
singleton to reuse connections and avoid resource leaks
- Use req.Context() in CheckRedirect instead of capturing outer ctx,
enabling a single shared client that still respects per-request
cancellation
- Parallelize HTTPS schema fetching in extractSchemasFromProjectConfig
with bounded concurrency (max 5) to reduce latency for projects with
multiple schemas
* fix: correct comment typo: HTTPS URLs are fetched over HTTPS, not HTTP1 parent ec31cc0 commit 1faebe6
File tree
13 files changed
+880
-66
lines changed- docs/data-sources
- examples/data-sources/ory_identity_schema
- internal
- client
- datasources
- identityschemas
- identityschema
- testdata
- resources/identityschema
- templates/data-sources
13 files changed
+880
-66
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
69 | 88 | | |
70 | 89 | | |
71 | 90 | | |
| |||
77 | 96 | | |
78 | 97 | | |
79 | 98 | | |
80 | | - | |
| 99 | + | |
81 | 100 | | |
82 | 101 | | |
83 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
1427 | 1429 | | |
1428 | 1430 | | |
1429 | 1431 | | |
1430 | | - | |
| 1432 | + | |
1431 | 1433 | | |
1432 | 1434 | | |
1433 | 1435 | | |
1434 | 1436 | | |
1435 | 1437 | | |
1436 | | - | |
1437 | | - | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
1438 | 1441 | | |
1439 | 1442 | | |
1440 | 1443 | | |
| |||
1445 | 1448 | | |
1446 | 1449 | | |
1447 | 1450 | | |
1448 | | - | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
1449 | 1461 | | |
1450 | 1462 | | |
1451 | 1463 | | |
| |||
1456 | 1468 | | |
1457 | 1469 | | |
1458 | 1470 | | |
1459 | | - | |
| 1471 | + | |
| 1472 | + | |
1460 | 1473 | | |
1461 | 1474 | | |
1462 | 1475 | | |
| |||
1466 | 1479 | | |
1467 | 1480 | | |
1468 | 1481 | | |
1469 | | - | |
1470 | | - | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
1471 | 1489 | | |
1472 | 1490 | | |
1473 | 1491 | | |
1474 | 1492 | | |
1475 | 1493 | | |
1476 | 1494 | | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
1477 | 1528 | | |
1478 | 1529 | | |
1479 | 1530 | | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
1480 | 1691 | | |
1481 | 1692 | | |
1482 | 1693 | | |
| |||
0 commit comments