Skip to content

feat(omegaconf): confine from_file to the project - #1677

Open
Moep90 wants to merge 1 commit into
masterfrom
feat/confine-from-file
Open

Moep90 wants to merge 1 commit into
masterfrom
feat/confine-from-file

Conversation

@Moep90

@Moep90 Moep90 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Summary

${from_file:...} now only reads a file that resolves, after following symlinks, below the directory Kapitan runs in or below the inventory path. Any other path fails the inventory render.

Fixes #1639

This should land together with #1676 (reload the inventory after --fetch) or before it. #1676 lets classes fetched from someone else take effect in the same run, and without this change such a class can read any file the user running Kapitan can read.

Motivation

On master, a class with ${from_file:${oc.env:HOME}/.kube/config} or ${from_file:../outside/secret.txt} compiles with exit code 0, and both files end up in the compiled output. Same on 0.36.3.

How it works:

  • register_resolvers binds the real paths of the working directory and of the inventory path to from_file when it registers it. Each inventory worker calls it, so the roots come from the process that renders.
  • from_file compares the real path of its argument with those roots via os.path.commonpath and raises InventoryError when neither contains it. The check runs before the file is opened, so it also doesn't tell whether an outside file exists.
  • Relative paths still resolve against the working directory.
  • A project that reads outside on purpose can define its own from_file in resolvers.py. User resolvers are registered after the built-ins and replace them. I checked that by hand and wrote it into the docs.

I didn't tie this to --path-traversal-mode from #1566. That PR isn't merged, its default warn wouldn't confine anything, and it sets the mode in the compile workers, while from_file runs during the inventory render. If you'd rather have one switch for all file accessors, I can make from_file follow that flag once #1566 is in.

Affected files or URLs

  • kapitan/inventory/backends/omegaconf/resolvers.py: from_file, register_resolvers
  • tests/test_omegaconf_from_file.py (new)
  • docs/pages/inventory/omegaconf.md: Utility Resolvers

Test plan

  • Tests added: allowed relative and absolute paths in the project and a file in an inventory outside the working directory, refused absolute path, ../ path and symlink pointing out. Two of the tests run a real kapitan compile. The four refusal tests fail on master, the allowed ones pass on both.
  • Documentation updated, make docs_build (mkdocs --strict) and make docs_check pass
  • make lint passes
  • make format passes (ruff format --check and pre-commit on the changed files)
  • Full test suite passes (uv run pytest tests/ --no-cov, 764 passed, 4 skipped)
  • The repro from [feat]: confine the omegaconf from_file resolver to the project #1639 now fails with the new error and writes no compiled output.

Risk assessment

Projects that use from_file on files outside the working directory and the inventory path break with this change, for example a monorepo reading ../shared/ca.crt. The error names the path and says how to override the resolver. Revert is a single commit.

Follow-up work intentionally left out

${from_file:...} now only reads a file that resolves, after following
symlinks, below the working directory or the inventory path. Any other
path fails the inventory render with an error naming the path. A custom
from_file in resolvers.py still replaces the built-in one for projects
that read outside on purpose.

Fixes #1639

Signed-off-by: Moep90 <3042152+Moep90@users.noreply.github.com>
@Moep90
Moep90 requested review from ademariag and ramaro November 7, 2026 06:35
@github-actions github-actions Bot added documentation Anything related to documentation python Pull requests that update Python code size/m labels Nov 7, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/kapitan that referenced this pull request Nov 7, 2026
Signed-off-by: Moep90 <3042152+Moep90@users.noreply.github.com>

# Conflicts:
#	kapitan/inventory/backends/omegaconf/resolvers.py
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/kapitan that referenced this pull request Nov 7, 2026
Merged: kapicorp#1388 kapicorp#1440 kapicorp#1446 kapicorp#1449 kapicorp#1459 kapicorp#1465 kapicorp#1484 kapicorp#1486 kapicorp#1488 kapicorp#1497 kapicorp#1501 kapicorp#1516 kapicorp#1518 kapicorp#1527 kapicorp#1528 kapicorp#1529 kapicorp#1530 kapicorp#1531 kapicorp#1539 kapicorp#1540 kapicorp#1541 kapicorp#1542 kapicorp#1543 kapicorp#1544 kapicorp#1545 kapicorp#1546 kapicorp#1547 kapicorp#1554 kapicorp#1555 kapicorp#1559 kapicorp#1565 kapicorp#1566 kapicorp#1598 kapicorp#1600 kapicorp#1606 kapicorp#1609 kapicorp#1612 kapicorp#1614 kapicorp#1615 kapicorp#1623 kapicorp#1624 kapicorp#1625 kapicorp#1627 kapicorp#1629 kapicorp#1631 kapicorp#1633 kapicorp#1634 kapicorp#1635 kapicorp#1636 kapicorp#1637 kapicorp#1640 kapicorp#1642 kapicorp#1643 kapicorp#1646 kapicorp#1648 kapicorp#1650 kapicorp#1652 kapicorp#1654 kapicorp#1656 kapicorp#1659 kapicorp#1660 kapicorp#1668 kapicorp#1669 kapicorp#1670 kapicorp#1671 kapicorp#1674 kapicorp#1678

Conflicting: kapicorp#1658 kapicorp#1662 kapicorp#1664 kapicorp#1666 kapicorp#1676 kapicorp#1677

Next-Fingerprint: f03513f 169c870 1388 e047547 1440 624bbb4 1446 8600881 1449 916c63d 1459 519a90b 1465 7f6b85b 1484 2543d11 1486 6a7be30 1488 9991a7c 1497 96cdde6 1501 2706f7e 1516 2485def 1518 24bb6ad 1527 2f4e188 1528 02e2e25 1529 bb4fa93 1530 d499bb7 1531 6e6afff 1539 ee8bb7b 1540 84c0929 1541 46d0f7a 1542 4a4d562 1543 5cd2a5c 1544 d27945f 1545 ee6e895 1546 0902bbc 1547 094c999 1554 ccb0486 1555 f5cbd07 1559 79d42fa 1565 07d2b6d 1566 7ec811a 1598 570ab14 1600 5cf9875 1606 942fdeb 1609 1dccc5e 1612 9cd6b5c 1614 782afcb 1615 0beed2b 1623 9e88063 1624 872197a 1625 9267812 1627 531002f 1629 75ae30a 1631 5ef2dca 1633 4af5f87 1634 822a175 1635 7327e46 1636 b6fb808 1637 1c2d6dc 1640 b909052 1642 ea824d8 1643 67c0727 1646 5a60b7f 1648 a126868 1650 c970796 1652 8314139 1654 7f1adca 1656 a174d8e 1658 a9ec63f 1659 a59f187 1660 28869c7 1662 235ae8b 1664 929dec3 1666 4a23d70 1668 2f07d58 1669 991f82e 1670 9eb680b 1671 d761ef1 1674 2d40202 1676 f835258 1677 3bbaedf 1678 a14e904
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/kapitan that referenced this pull request Nov 7, 2026
Merged: kapicorp#1388 kapicorp#1440 kapicorp#1446 kapicorp#1449 kapicorp#1459 kapicorp#1465 kapicorp#1484 kapicorp#1486 kapicorp#1488 kapicorp#1497 kapicorp#1501 kapicorp#1516 kapicorp#1518 kapicorp#1527 kapicorp#1528 kapicorp#1529 kapicorp#1530 kapicorp#1531 kapicorp#1539 kapicorp#1540 kapicorp#1541 kapicorp#1542 kapicorp#1543 kapicorp#1544 kapicorp#1545 kapicorp#1546 kapicorp#1547 kapicorp#1554 kapicorp#1555 kapicorp#1559 kapicorp#1565 kapicorp#1566 kapicorp#1598 kapicorp#1600 kapicorp#1606 kapicorp#1609 kapicorp#1612 kapicorp#1614 kapicorp#1615 kapicorp#1623 kapicorp#1624 kapicorp#1625 kapicorp#1627 kapicorp#1629 kapicorp#1631 kapicorp#1633 kapicorp#1634 kapicorp#1635 kapicorp#1636 kapicorp#1637 kapicorp#1640 kapicorp#1642 kapicorp#1643 kapicorp#1646 kapicorp#1648 kapicorp#1650 kapicorp#1652 kapicorp#1654 kapicorp#1656 kapicorp#1659 kapicorp#1660 kapicorp#1668 kapicorp#1669 kapicorp#1670 kapicorp#1671 kapicorp#1674 kapicorp#1678

Conflicting: kapicorp#1658 kapicorp#1662 kapicorp#1664 kapicorp#1666 kapicorp#1676 kapicorp#1677

Next-Fingerprint: f03513f 169c870 1388 e047547 1440 624bbb4 1446 8600881 1449 916c63d 1459 519a90b 1465 7f6b85b 1484 2543d11 1486 6a7be30 1488 9991a7c 1497 96cdde6 1501 2706f7e 1516 2485def 1518 24bb6ad 1527 2f4e188 1528 02e2e25 1529 bb4fa93 1530 d499bb7 1531 6e6afff 1539 ee8bb7b 1540 84c0929 1541 46d0f7a 1542 4a4d562 1543 5cd2a5c 1544 d27945f 1545 ee6e895 1546 0902bbc 1547 094c999 1554 ccb0486 1555 f5cbd07 1559 79d42fa 1565 07d2b6d 1566 7ec811a 1598 570ab14 1600 5cf9875 1606 942fdeb 1609 1dccc5e 1612 9cd6b5c 1614 782afcb 1615 0beed2b 1623 9e88063 1624 872197a 1625 9267812 1627 531002f 1629 75ae30a 1631 5ef2dca 1633 4af5f87 1634 822a175 1635 7327e46 1636 b6fb808 1637 1c2d6dc 1640 b909052 1642 ea824d8 1643 67c0727 1646 5a60b7f 1648 a126868 1650 c970796 1652 8314139 1654 7f1adca 1656 a174d8e 1658 a9ec63f 1659 a59f187 1660 28869c7 1662 235ae8b 1664 929dec3 1666 4a23d70 1668 2f07d58 1669 991f82e 1670 9eb680b 1671 d761ef1 1674 2d40202 1676 f835258 1677 3bbaedf 1678 a14e904
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/kapitan that referenced this pull request Nov 7, 2026
Merged: kapicorp#1388 kapicorp#1440 kapicorp#1446 kapicorp#1449 kapicorp#1459 kapicorp#1465 kapicorp#1484 kapicorp#1486 kapicorp#1488 kapicorp#1497 kapicorp#1501 kapicorp#1516 kapicorp#1518 kapicorp#1527 kapicorp#1528 kapicorp#1529 kapicorp#1530 kapicorp#1531 kapicorp#1539 kapicorp#1540 kapicorp#1541 kapicorp#1542 kapicorp#1543 kapicorp#1544 kapicorp#1545 kapicorp#1546 kapicorp#1547 kapicorp#1554 kapicorp#1555 kapicorp#1559 kapicorp#1565 kapicorp#1566 kapicorp#1598 kapicorp#1600 kapicorp#1606 kapicorp#1609 kapicorp#1612 kapicorp#1614 kapicorp#1615 kapicorp#1623 kapicorp#1624 kapicorp#1625 kapicorp#1627 kapicorp#1629 kapicorp#1631 kapicorp#1633 kapicorp#1634 kapicorp#1635 kapicorp#1636 kapicorp#1637 kapicorp#1640 kapicorp#1642 kapicorp#1643 kapicorp#1646 kapicorp#1648 kapicorp#1650 kapicorp#1652 kapicorp#1654 kapicorp#1656 kapicorp#1659 kapicorp#1660 kapicorp#1668 kapicorp#1669 kapicorp#1670 kapicorp#1671 kapicorp#1674 kapicorp#1678

Conflicting: kapicorp#1658 kapicorp#1662 kapicorp#1664 kapicorp#1666 kapicorp#1676 kapicorp#1677

Next-Fingerprint: f03513f 169c870 1388 e047547 1440 624bbb4 1446 8600881 1449 916c63d 1459 519a90b 1465 7f6b85b 1484 2543d11 1486 6a7be30 1488 9991a7c 1497 96cdde6 1501 2706f7e 1516 2485def 1518 24bb6ad 1527 2f4e188 1528 02e2e25 1529 bb4fa93 1530 d499bb7 1531 6e6afff 1539 ee8bb7b 1540 84c0929 1541 46d0f7a 1542 4a4d562 1543 5cd2a5c 1544 d27945f 1545 ee6e895 1546 0902bbc 1547 094c999 1554 ccb0486 1555 f5cbd07 1559 79d42fa 1565 07d2b6d 1566 7ec811a 1598 570ab14 1600 5cf9875 1606 942fdeb 1609 1dccc5e 1612 9cd6b5c 1614 782afcb 1615 0beed2b 1623 9e88063 1624 872197a 1625 9267812 1627 531002f 1629 75ae30a 1631 5ef2dca 1633 4af5f87 1634 822a175 1635 7327e46 1636 b6fb808 1637 1c2d6dc 1640 b909052 1642 ea824d8 1643 67c0727 1646 5a60b7f 1648 a126868 1650 c970796 1652 8314139 1654 7f1adca 1656 a174d8e 1658 a9ec63f 1659 a59f187 1660 28869c7 1662 235ae8b 1664 929dec3 1666 4a23d70 1668 2f07d58 1669 991f82e 1670 9eb680b 1671 d761ef1 1674 2d40202 1676 f835258 1677 3bbaedf 1678 a14e904
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/kapitan that referenced this pull request Nov 7, 2026
Merged: kapicorp#1388 kapicorp#1440 kapicorp#1446 kapicorp#1449 kapicorp#1459 kapicorp#1465 kapicorp#1484 kapicorp#1486 kapicorp#1488 kapicorp#1497 kapicorp#1501 kapicorp#1516 kapicorp#1518 kapicorp#1527 kapicorp#1528 kapicorp#1529 kapicorp#1530 kapicorp#1531 kapicorp#1539 kapicorp#1540 kapicorp#1541 kapicorp#1542 kapicorp#1543 kapicorp#1544 kapicorp#1545 kapicorp#1546 kapicorp#1547 kapicorp#1554 kapicorp#1555 kapicorp#1559 kapicorp#1565 kapicorp#1566 kapicorp#1598 kapicorp#1600 kapicorp#1606 kapicorp#1609 kapicorp#1612 kapicorp#1614 kapicorp#1615 kapicorp#1623 kapicorp#1624 kapicorp#1625 kapicorp#1627 kapicorp#1629 kapicorp#1631 kapicorp#1633 kapicorp#1634 kapicorp#1635 kapicorp#1636 kapicorp#1637 kapicorp#1640 kapicorp#1642 kapicorp#1643 kapicorp#1646 kapicorp#1648 kapicorp#1650 kapicorp#1652 kapicorp#1654 kapicorp#1656 kapicorp#1659 kapicorp#1660 kapicorp#1668 kapicorp#1669 kapicorp#1670 kapicorp#1671 kapicorp#1674 kapicorp#1678

Conflicting: kapicorp#1658 kapicorp#1662 kapicorp#1664 kapicorp#1666 kapicorp#1676 kapicorp#1677

Next-Fingerprint: f03513f 169c870 1388 e047547 1440 624bbb4 1446 8600881 1449 916c63d 1459 519a90b 1465 7f6b85b 1484 2543d11 1486 6a7be30 1488 9991a7c 1497 96cdde6 1501 2706f7e 1516 2485def 1518 24bb6ad 1527 2f4e188 1528 02e2e25 1529 bb4fa93 1530 d499bb7 1531 6e6afff 1539 ee8bb7b 1540 84c0929 1541 46d0f7a 1542 4a4d562 1543 5cd2a5c 1544 d27945f 1545 ee6e895 1546 0902bbc 1547 094c999 1554 ccb0486 1555 f5cbd07 1559 79d42fa 1565 07d2b6d 1566 7ec811a 1598 570ab14 1600 5cf9875 1606 942fdeb 1609 1dccc5e 1612 9cd6b5c 1614 782afcb 1615 0beed2b 1623 9e88063 1624 872197a 1625 9267812 1627 531002f 1629 75ae30a 1631 5ef2dca 1633 4af5f87 1634 822a175 1635 7327e46 1636 b6fb808 1637 1c2d6dc 1640 b909052 1642 ea824d8 1643 67c0727 1646 5a60b7f 1648 a126868 1650 c970796 1652 8314139 1654 7f1adca 1656 a174d8e 1658 a9ec63f 1659 a59f187 1660 28869c7 1662 235ae8b 1664 929dec3 1666 4a23d70 1668 2f07d58 1669 991f82e 1670 9eb680b 1671 d761ef1 1674 2d40202 1676 f835258 1677 3bbaedf 1678 a14e904
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/kapitan that referenced this pull request Nov 7, 2026
Merged: kapicorp#1388 kapicorp#1440 kapicorp#1446 kapicorp#1449 kapicorp#1459 kapicorp#1465 kapicorp#1484 kapicorp#1486 kapicorp#1488 kapicorp#1497 kapicorp#1501 kapicorp#1516 kapicorp#1518 kapicorp#1527 kapicorp#1528 kapicorp#1529 kapicorp#1530 kapicorp#1531 kapicorp#1539 kapicorp#1540 kapicorp#1541 kapicorp#1542 kapicorp#1543 kapicorp#1544 kapicorp#1545 kapicorp#1546 kapicorp#1547 kapicorp#1554 kapicorp#1555 kapicorp#1559 kapicorp#1565 kapicorp#1566 kapicorp#1598 kapicorp#1600 kapicorp#1606 kapicorp#1609 kapicorp#1612 kapicorp#1614 kapicorp#1615 kapicorp#1623 kapicorp#1624 kapicorp#1625 kapicorp#1627 kapicorp#1629 kapicorp#1631 kapicorp#1633 kapicorp#1634 kapicorp#1635 kapicorp#1636 kapicorp#1637 kapicorp#1640 kapicorp#1642 kapicorp#1643 kapicorp#1646 kapicorp#1648 kapicorp#1650 kapicorp#1652 kapicorp#1654 kapicorp#1656 kapicorp#1659 kapicorp#1660 kapicorp#1668 kapicorp#1669 kapicorp#1670 kapicorp#1671 kapicorp#1674 kapicorp#1678

Conflicting: kapicorp#1658 kapicorp#1662 kapicorp#1664 kapicorp#1666 kapicorp#1676 kapicorp#1677

Next-Fingerprint: f03513f 169c870 1388 e047547 1440 624bbb4 1446 8600881 1449 916c63d 1459 519a90b 1465 7f6b85b 1484 2543d11 1486 6a7be30 1488 9991a7c 1497 96cdde6 1501 2706f7e 1516 2485def 1518 24bb6ad 1527 2f4e188 1528 02e2e25 1529 bb4fa93 1530 d499bb7 1531 6e6afff 1539 ee8bb7b 1540 84c0929 1541 46d0f7a 1542 4a4d562 1543 5cd2a5c 1544 d27945f 1545 ee6e895 1546 0902bbc 1547 094c999 1554 ccb0486 1555 f5cbd07 1559 79d42fa 1565 07d2b6d 1566 7ec811a 1598 570ab14 1600 5cf9875 1606 942fdeb 1609 1dccc5e 1612 9cd6b5c 1614 782afcb 1615 0beed2b 1623 9e88063 1624 872197a 1625 9267812 1627 531002f 1629 75ae30a 1631 5ef2dca 1633 4af5f87 1634 822a175 1635 7327e46 1636 b6fb808 1637 1c2d6dc 1640 b909052 1642 ea824d8 1643 67c0727 1646 5a60b7f 1648 a126868 1650 c970796 1652 8314139 1654 7f1adca 1656 a174d8e 1658 a9ec63f 1659 a59f187 1660 28869c7 1662 235ae8b 1664 929dec3 1666 4a23d70 1668 2f07d58 1669 991f82e 1670 9eb680b 1671 d761ef1 1674 2d40202 1676 f835258 1677 3bbaedf 1678 a14e904
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/kapitan that referenced this pull request Nov 8, 2026
Merged: kapicorp#1388 kapicorp#1440 kapicorp#1446 kapicorp#1449 kapicorp#1459 kapicorp#1465 kapicorp#1484 kapicorp#1486 kapicorp#1488 kapicorp#1497 kapicorp#1501 kapicorp#1516 kapicorp#1518 kapicorp#1527 kapicorp#1528 kapicorp#1529 kapicorp#1530 kapicorp#1531 kapicorp#1539 kapicorp#1540 kapicorp#1541 kapicorp#1542 kapicorp#1543 kapicorp#1544 kapicorp#1545 kapicorp#1546 kapicorp#1547 kapicorp#1554 kapicorp#1555 kapicorp#1559 kapicorp#1565 kapicorp#1566 kapicorp#1598 kapicorp#1600 kapicorp#1606 kapicorp#1609 kapicorp#1612 kapicorp#1614 kapicorp#1615 kapicorp#1623 kapicorp#1624 kapicorp#1625 kapicorp#1627 kapicorp#1629 kapicorp#1631 kapicorp#1633 kapicorp#1634 kapicorp#1635 kapicorp#1636 kapicorp#1637 kapicorp#1640 kapicorp#1642 kapicorp#1643 kapicorp#1646 kapicorp#1648 kapicorp#1650 kapicorp#1652 kapicorp#1654 kapicorp#1656 kapicorp#1659 kapicorp#1660 kapicorp#1668 kapicorp#1669 kapicorp#1670 kapicorp#1671 kapicorp#1674 kapicorp#1678

Conflicting: kapicorp#1658 kapicorp#1662 kapicorp#1664 kapicorp#1666 kapicorp#1676 kapicorp#1677

Next-Fingerprint: f03513f 169c870 1388 e047547 1440 624bbb4 1446 8600881 1449 916c63d 1459 519a90b 1465 7f6b85b 1484 2543d11 1486 6a7be30 1488 9991a7c 1497 96cdde6 1501 2706f7e 1516 2485def 1518 24bb6ad 1527 2f4e188 1528 02e2e25 1529 bb4fa93 1530 d499bb7 1531 6e6afff 1539 ee8bb7b 1540 84c0929 1541 46d0f7a 1542 4a4d562 1543 5cd2a5c 1544 d27945f 1545 ee6e895 1546 0902bbc 1547 094c999 1554 ccb0486 1555 f5cbd07 1559 79d42fa 1565 07d2b6d 1566 7ec811a 1598 570ab14 1600 5cf9875 1606 942fdeb 1609 1dccc5e 1612 9cd6b5c 1614 782afcb 1615 0beed2b 1623 9e88063 1624 872197a 1625 9267812 1627 531002f 1629 75ae30a 1631 5ef2dca 1633 4af5f87 1634 822a175 1635 7327e46 1636 b6fb808 1637 1c2d6dc 1640 b909052 1642 ea824d8 1643 67c0727 1646 5a60b7f 1648 a126868 1650 c970796 1652 8314139 1654 7f1adca 1656 a174d8e 1658 a9ec63f 1659 a59f187 1660 28869c7 1662 235ae8b 1664 929dec3 1666 4a23d70 1668 2f07d58 1669 991f82e 1670 9eb680b 1671 d761ef1 1674 2d40202 1676 f835258 1677 3bbaedf 1678 a14e904

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Anything related to documentation python Pull requests that update Python code size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat]: confine the omegaconf from_file resolver to the project

1 participant