@intentius/chant 0.124.44 → 0.124.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/capabilities/aws.paths +148 -0
  2. package/dist/capabilities/base-mappings.json +122 -0
  3. package/dist/capabilities/catalog.d.ts +89 -0
  4. package/dist/capabilities/catalog.d.ts.map +1 -0
  5. package/dist/capabilities/catalog.js +204 -0
  6. package/dist/capabilities/language.d.ts +103 -0
  7. package/dist/capabilities/language.d.ts.map +1 -0
  8. package/dist/capabilities/language.js +335 -0
  9. package/dist/capabilities/matcher.d.ts +65 -0
  10. package/dist/capabilities/matcher.d.ts.map +1 -0
  11. package/dist/capabilities/matcher.js +299 -0
  12. package/dist/capabilities/view.d.ts +207 -0
  13. package/dist/capabilities/view.d.ts.map +1 -0
  14. package/dist/capabilities/view.js +484 -0
  15. package/dist/ci-identity.d.ts +183 -12
  16. package/dist/ci-identity.d.ts.map +1 -1
  17. package/dist/ci-identity.js +362 -53
  18. package/dist/cli/commands/lint.d.ts.map +1 -1
  19. package/dist/cli/commands/lint.js +1 -0
  20. package/dist/cli/handlers/build.d.ts.map +1 -1
  21. package/dist/cli/handlers/build.js +17 -1
  22. package/dist/cli/handlers/declared-graph.d.ts +44 -0
  23. package/dist/cli/handlers/declared-graph.d.ts.map +1 -0
  24. package/dist/cli/handlers/declared-graph.js +87 -0
  25. package/dist/cli/handlers/graph.d.ts +25 -0
  26. package/dist/cli/handlers/graph.d.ts.map +1 -1
  27. package/dist/cli/handlers/graph.js +93 -87
  28. package/dist/cli/handlers/pr-env.d.ts +8 -2
  29. package/dist/cli/handlers/pr-env.d.ts.map +1 -1
  30. package/dist/cli/handlers/pr-env.js +127 -225
  31. package/dist/cli/handlers/pr.d.ts +3 -0
  32. package/dist/cli/handlers/pr.d.ts.map +1 -1
  33. package/dist/cli/handlers/pr.js +1 -0
  34. package/dist/cli/handlers/search-count.d.ts +89 -0
  35. package/dist/cli/handlers/search-count.d.ts.map +1 -0
  36. package/dist/cli/handlers/search-count.js +132 -0
  37. package/dist/cli/handlers/search.d.ts +358 -6
  38. package/dist/cli/handlers/search.d.ts.map +1 -1
  39. package/dist/cli/handlers/search.js +1065 -155
  40. package/dist/cli/main.d.ts.map +1 -1
  41. package/dist/cli/main.js +23 -3
  42. package/dist/cli/mcp/server.d.ts.map +1 -1
  43. package/dist/cli/mcp/server.js +3 -0
  44. package/dist/cli/mcp/tools/capabilities.d.ts +7 -0
  45. package/dist/cli/mcp/tools/capabilities.d.ts.map +1 -0
  46. package/dist/cli/mcp/tools/capabilities.js +27 -0
  47. package/dist/cli/mcp/workspace-tools.d.ts +3 -1
  48. package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
  49. package/dist/cli/mcp/workspace-tools.js +47 -2
  50. package/dist/cli/parse-args.d.ts.map +1 -1
  51. package/dist/cli/parse-args.js +64 -17
  52. package/dist/cli/registry.d.ts +22 -0
  53. package/dist/cli/registry.d.ts.map +1 -1
  54. package/dist/components/cli-support.d.ts +2 -0
  55. package/dist/components/cli-support.d.ts.map +1 -1
  56. package/dist/components/cli-support.js +4 -2
  57. package/dist/components/fan-out-support.d.ts +3 -0
  58. package/dist/components/fan-out-support.d.ts.map +1 -1
  59. package/dist/components/fan-out-support.js +1 -1
  60. package/dist/components/pr-env-ports.d.ts +29 -0
  61. package/dist/components/pr-env-ports.d.ts.map +1 -0
  62. package/dist/components/pr-env-ports.js +77 -0
  63. package/dist/components/pr-env-run.d.ts +254 -0
  64. package/dist/components/pr-env-run.d.ts.map +1 -0
  65. package/dist/components/pr-env-run.js +376 -0
  66. package/dist/components/pr-environment.d.ts +91 -15
  67. package/dist/components/pr-environment.d.ts.map +1 -1
  68. package/dist/components/pr-environment.js +95 -9
  69. package/dist/components/pr-pipeline.d.ts +10 -1
  70. package/dist/components/pr-pipeline.d.ts.map +1 -1
  71. package/dist/config-environments.d.ts +92 -0
  72. package/dist/config-environments.d.ts.map +1 -0
  73. package/dist/config-environments.js +102 -0
  74. package/dist/config.d.ts +24 -84
  75. package/dist/config.d.ts.map +1 -1
  76. package/dist/config.js +9 -96
  77. package/dist/graph-detail.d.ts.map +1 -1
  78. package/dist/graph-detail.js +15 -3
  79. package/dist/graph-effective.d.ts +33 -2
  80. package/dist/graph-effective.d.ts.map +1 -1
  81. package/dist/graph-effective.js +215 -68
  82. package/dist/graph-ir.d.ts +23 -0
  83. package/dist/graph-ir.d.ts.map +1 -1
  84. package/dist/graph-ir.js +130 -0
  85. package/dist/graph-sub-template.d.ts +11 -0
  86. package/dist/graph-sub-template.d.ts.map +1 -0
  87. package/dist/graph-sub-template.js +19 -0
  88. package/dist/lexicon.d.ts +9 -0
  89. package/dist/lexicon.d.ts.map +1 -1
  90. package/dist/lifecycle/observe.d.ts +28 -0
  91. package/dist/lifecycle/observe.d.ts.map +1 -1
  92. package/dist/lifecycle/observe.js +23 -1
  93. package/dist/lint/rule.d.ts +6 -0
  94. package/dist/lint/rule.d.ts.map +1 -1
  95. package/dist/live-endpoint.d.ts +1 -1
  96. package/dist/live-endpoint.d.ts.map +1 -1
  97. package/dist/live-endpoint.js +1 -1
  98. package/dist/observation.d.ts +48 -1
  99. package/dist/observation.d.ts.map +1 -1
  100. package/dist/observation.js +21 -5
  101. package/dist/op/activities/activity-contracts.d.ts +4 -4
  102. package/dist/op/op-waves.d.ts +17 -0
  103. package/dist/op/op-waves.d.ts.map +1 -1
  104. package/dist/op/op-waves.js +23 -1
  105. package/dist/pr-forge.d.ts +15 -1
  106. package/dist/pr-forge.d.ts.map +1 -1
  107. package/dist/pr-forge.js +28 -16
  108. package/dist/pr-requires.d.ts +5 -1
  109. package/dist/pr-requires.d.ts.map +1 -1
  110. package/dist/wave-runtime.mjs +251 -250
  111. package/dist/workspace/capabilities-contract.d.ts +66 -0
  112. package/dist/workspace/capabilities-contract.d.ts.map +1 -0
  113. package/dist/workspace/capabilities-contract.js +107 -0
  114. package/dist/workspace/capabilities.schema.json +229 -0
  115. package/dist/workspace/ci-cloud-identity.d.ts +3 -1
  116. package/dist/workspace/ci-cloud-identity.d.ts.map +1 -1
  117. package/dist/workspace/ci-cloud-identity.js +16 -1
  118. package/dist/workspace/ci-run.d.ts +35 -8
  119. package/dist/workspace/ci-run.d.ts.map +1 -1
  120. package/dist/workspace/ci-run.js +95 -21
  121. package/dist/workspace/ci-secrets.d.ts.map +1 -1
  122. package/dist/workspace/ci-secrets.js +4 -3
  123. package/dist/workspace/compose-graph.d.ts +9 -0
  124. package/dist/workspace/compose-graph.d.ts.map +1 -1
  125. package/dist/workspace/compose-graph.js +3 -1
  126. package/dist/workspace/conformance/index.d.ts +1 -1
  127. package/dist/workspace/conformance/index.d.ts.map +1 -1
  128. package/dist/workspace/conformance/index.js +39 -2
  129. package/dist/workspace/declaration.d.ts +10 -0
  130. package/dist/workspace/declaration.d.ts.map +1 -1
  131. package/dist/workspace/declaration.js +17 -1
  132. package/dist/workspace/declaration.schema.json +36 -1
  133. package/dist/workspace/graph-cache.d.ts +8 -0
  134. package/dist/workspace/graph-cache.d.ts.map +1 -1
  135. package/dist/workspace/graph-cache.js +27 -3
  136. package/dist/workspace/graph-cli.d.ts +39 -2
  137. package/dist/workspace/graph-cli.d.ts.map +1 -1
  138. package/dist/workspace/graph-cli.js +66 -24
  139. package/dist/workspace/graph.schema.json +148 -0
  140. package/dist/workspace/kind-readers.d.ts +3 -0
  141. package/dist/workspace/kind-readers.d.ts.map +1 -1
  142. package/dist/workspace/kind-readers.js +7 -1
  143. package/dist/workspace/member-commands.d.ts +10 -1
  144. package/dist/workspace/member-commands.d.ts.map +1 -1
  145. package/dist/workspace/member-commands.js +17 -1
  146. package/dist/workspace/nested-graph.d.ts +2 -0
  147. package/dist/workspace/nested-graph.d.ts.map +1 -1
  148. package/dist/workspace/nested-graph.js +32 -1
  149. package/dist/workspace/reason-codes.d.ts +10 -0
  150. package/dist/workspace/reason-codes.d.ts.map +1 -1
  151. package/dist/workspace/reason-codes.js +12 -0
  152. package/dist/workspace/search-cli.d.ts +204 -0
  153. package/dist/workspace/search-cli.d.ts.map +1 -0
  154. package/dist/workspace/search-cli.js +466 -0
  155. package/dist/workspace/search-contract.d.ts +56 -0
  156. package/dist/workspace/search-contract.d.ts.map +1 -0
  157. package/dist/workspace/search-contract.js +70 -0
  158. package/dist/workspace/search.schema.json +822 -0
  159. package/package.json +1 -1
  160. package/src/__snapshots__/okf.test.ts.snap +10 -0
  161. package/src/capabilities/aws.paths +148 -0
  162. package/src/capabilities/base-mappings.json +122 -0
  163. package/src/capabilities/catalog.ts +230 -0
  164. package/src/capabilities/language.test.ts +191 -0
  165. package/src/capabilities/language.ts +373 -0
  166. package/src/capabilities/matcher.ts +315 -0
  167. package/src/capabilities/view-compose.test.ts +76 -0
  168. package/src/capabilities/view.ts +631 -0
  169. package/src/ci-identity-targets.test.ts +275 -0
  170. package/src/ci-identity.ts +394 -61
  171. package/src/cli/commands/lint.ts +1 -0
  172. package/src/cli/handlers/build.ts +15 -1
  173. package/src/cli/handlers/declared-graph.ts +99 -0
  174. package/src/cli/handlers/graph.test.ts +94 -3
  175. package/src/cli/handlers/graph.ts +123 -96
  176. package/src/cli/handlers/pr-env.ts +135 -227
  177. package/src/cli/handlers/pr.ts +4 -0
  178. package/src/cli/handlers/search-build-roots.test.ts +144 -0
  179. package/src/cli/handlers/search-count.test.ts +191 -0
  180. package/src/cli/handlers/search-count.ts +165 -0
  181. package/src/cli/handlers/search-json.test.ts +333 -0
  182. package/src/cli/handlers/search-live.test.ts +387 -0
  183. package/src/cli/handlers/search-paths.test.ts +235 -0
  184. package/src/cli/handlers/search.ts +1312 -166
  185. package/src/cli/main.test.ts +28 -3
  186. package/src/cli/main.ts +23 -3
  187. package/src/cli/mcp/server.test.ts +3 -3
  188. package/src/cli/mcp/server.ts +3 -0
  189. package/src/cli/mcp/tools/capabilities.ts +32 -0
  190. package/src/cli/mcp/workspace-tools.e2e.test.ts +21 -1
  191. package/src/cli/mcp/workspace-tools.ts +47 -2
  192. package/src/cli/parse-args.ts +52 -13
  193. package/src/cli/registry.ts +22 -0
  194. package/src/components/cli-support.ts +6 -1
  195. package/src/components/fan-out-support.ts +4 -1
  196. package/src/components/pr-env-ports.ts +89 -0
  197. package/src/components/pr-env-run-bundle.test.ts +54 -0
  198. package/src/components/pr-env-run.test.ts +290 -0
  199. package/src/components/pr-env-run.ts +563 -0
  200. package/src/components/pr-environment.ts +161 -13
  201. package/src/components/pr-pipeline.ts +10 -1
  202. package/src/config-environments.ts +133 -0
  203. package/src/config.ts +37 -124
  204. package/src/graph-detail.ts +15 -3
  205. package/src/graph-effective.ts +226 -75
  206. package/src/graph-ir.test.ts +163 -0
  207. package/src/graph-ir.ts +147 -0
  208. package/src/graph-sub-template.ts +22 -0
  209. package/src/lexicon.ts +10 -0
  210. package/src/lifecycle/observe.test.ts +27 -1
  211. package/src/lifecycle/observe.ts +43 -1
  212. package/src/lint/rule.ts +6 -0
  213. package/src/live-endpoint.ts +1 -1
  214. package/src/observation.test.ts +25 -0
  215. package/src/observation.ts +69 -5
  216. package/src/op/op-waves.ts +38 -1
  217. package/src/pr-forge-bundle.test.ts +1 -1
  218. package/src/pr-forge.ts +44 -17
  219. package/src/pr-requires.test.ts +43 -6
  220. package/src/pr-requires.ts +5 -1
  221. package/src/workspace/capabilities-contract.test.ts +88 -0
  222. package/src/workspace/capabilities-contract.ts +132 -0
  223. package/src/workspace/capabilities.schema.json +229 -0
  224. package/src/workspace/ci-cloud-identity.test.ts +20 -0
  225. package/src/workspace/ci-cloud-identity.ts +14 -1
  226. package/src/workspace/ci-run.test.ts +74 -1
  227. package/src/workspace/ci-run.ts +122 -29
  228. package/src/workspace/ci-secrets.test.ts +1 -1
  229. package/src/workspace/ci-secrets.ts +4 -3
  230. package/src/workspace/compose-graph.ts +10 -1
  231. package/src/workspace/conformance/conformance.e2e.test.ts +14 -1
  232. package/src/workspace/conformance/index.ts +31 -2
  233. package/src/workspace/declaration.schema.json +36 -1
  234. package/src/workspace/declaration.test.ts +7 -0
  235. package/src/workspace/declaration.ts +24 -2
  236. package/src/workspace/graph-cache.ts +27 -3
  237. package/src/workspace/graph-cli.ts +96 -24
  238. package/src/workspace/graph.schema.json +148 -0
  239. package/src/workspace/kind-readers.e2e.test.ts +28 -0
  240. package/src/workspace/kind-readers.test.ts +1 -1
  241. package/src/workspace/kind-readers.ts +7 -1
  242. package/src/workspace/member-commands.ts +22 -1
  243. package/src/workspace/nested-graph.ts +32 -1
  244. package/src/workspace/reason-codes.test.ts +7 -0
  245. package/src/workspace/reason-codes.ts +12 -0
  246. package/src/workspace/search-cli.e2e.test.ts +305 -0
  247. package/src/workspace/search-cli.ts +591 -0
  248. package/src/workspace/search-contract.ts +95 -0
  249. package/src/workspace/search.schema.json +822 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.124.44",
3
+ "version": "0.124.46",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -16,6 +16,10 @@ composite_instance: app
16
16
  ---
17
17
  Declared in \`main.ts\`.
18
18
 
19
+ ## Depends on
20
+
21
+ - [environment](/aws/environment.md)
22
+
19
23
  ## Referenced by
20
24
 
21
25
  - [appBucketPolicy](/aws/appBucketPolicy.md)
@@ -60,6 +64,7 @@ Declared in \`main.ts\`.
60
64
 
61
65
  - [appBucket](/aws/appBucket.md)
62
66
  - [appRole](/aws/appRole.md)
67
+ - [environment](/aws/environment.md)
63
68
  ",
64
69
  "path": "aws/appFunc.md",
65
70
  },
@@ -112,6 +117,11 @@ kind: resource
112
117
  source: params.ts
113
118
  ---
114
119
  Declared in \`params.ts\`.
120
+
121
+ ## Referenced by
122
+
123
+ - [appBucket](/aws/appBucket.md)
124
+ - [appFunc](/aws/appFunc.md)
115
125
  ",
116
126
  "path": "aws/environment.md",
117
127
  },
@@ -0,0 +1,148 @@
1
+ # Capabilities over AWS resources (#4375, ruled on #4361).
2
+ #
3
+ # Rules read the lexicon-neutral view, not the IR. Labels (Instance, Role,
4
+ # SecurityGroup) and edge names (subnet, sg, statement) come from each
5
+ # lexicon's mapping, so this one file serves CloudFormation (the aws lexicon)
6
+ # and Terraform's AWS provider (the terraform lexicon) alike.
7
+ #
8
+ # name(x) is a node set, tested with [@name]. name(a, b) is an edge, followed
9
+ # with ->name. Parameters follow `;`. The language is in language.ts.
10
+ #
11
+ # `## key: value` lines describe the capability that follows them, for the
12
+ # `capabilities` document: meaning, answers (one per line), depth, search,
13
+ # not-evaluated, and a line per parameter (param-<name>). A rule with no
14
+ # `## meaning` is a helper: other rules use it, the catalog doesn't list it.
15
+
16
+ # ------------------------------------------------------------------ helpers
17
+
18
+ in-sg(x, g) := x ->{0,1}template ->sg g:SecurityGroup
19
+ ingress-of(x, r) := x ->in-sg ->ingress r:IngressRule
20
+ world-open(r) := r:IngressRule[cidrs in ("0.0.0.0/0", "::/0")]
21
+ allows(r, x; action?) := r:Role <-{0,1}attachedTo ->statement :Statement[doc = "permission", effect = "Allow", actions ~ $action] ->resource x
22
+ | r:Role <-principal :Statement[doc = "resource", effect = "Allow", actions ~ $action] ->resource x
23
+ denies(r, x; action?) := r:Role <-{0,1}attachedTo ->statement :Statement[doc = "permission", effect = "Deny", actions ~ $action] ->resource x
24
+ | r:Role <-principal :Statement[doc = "resource", effect = "Deny", actions ~ $action] ->resource x
25
+ pivot(a, b) := a ->(runs-as|can-assume|network) b
26
+
27
+ # ------------------------------------------------------------------ network
28
+
29
+ ## meaning: its subnet routes 0.0.0.0/0 to an internet gateway
30
+ ## answers: which instances are in a public subnet
31
+ ## answers: what sits in a subnet that routes to the internet
32
+ ## depth: either
33
+ ## not-evaluated: a subnet on its VPC's main route table (no explicit association) is not followed
34
+ internet-facing(c) := c:Instance ->subnet :Subnet <-subnet :RouteTableAssociation ->table :RouteTable <-table :Route[dest in ("0.0.0.0/0", "::/0", null)] ->gateway :InternetGateway
35
+ | c:Instance[internetFacing = true]
36
+
37
+ ## meaning: a security group reaching it, directly or through a launch template, admits 0.0.0.0/0 or ::/0
38
+ ## param-port: a port the open rule must cover, such as 22
39
+ ## param-proto: a protocol the open rule must allow, such as tcp; a rule for every protocol (-1) always does
40
+ ## answers: what admits SSH from anywhere
41
+ ## answers: which instances have a security group open to the world
42
+ ## depth: declared
43
+ ## not-evaluated: network ACLs; prefix lists
44
+ open-ingress(c; port?, proto?) := c:Instance|Database|Function|Service ->ingress-of r:IngressRule[@world-open, from <= $port, to >= $port, proto in ($proto, "-1")]
45
+
46
+ ## meaning: internet-facing and open-ingress, or a Lambda function URL with no auth. Load balancers and API gateways come later
47
+ ## param-port: a port the open rule must cover, such as 22
48
+ ## answers: what in prod can be reached on SSH from the internet
49
+ ## answers: which instances are SSH-reachable from the internet
50
+ ## depth: either
51
+ ## not-evaluated: load balancers; API gateways; network ACLs
52
+ internet-reachable(c; port?) := c[@internet-facing, @open-ingress($port)]
53
+ | c:Function <-function :FunctionUrl[authType = "NONE"]
54
+
55
+ ## meaning: no member, attachment or route references it
56
+ ## answers: which security groups are unused
57
+ ## answers: which subnets have no instances or network interfaces
58
+ ## answers: which policies are attached to nothing
59
+ ## depth: either
60
+ attached-to-nothing(x) := x:SecurityGroup !<-sg
61
+ | x:Subnet !<-subnet
62
+ | x:Policy !->attachedTo
63
+ | x:InternetGateway !<-gateway
64
+
65
+ ## meaning: in the account's default VPC
66
+ ## answers: which instances run in the default VPC
67
+ ## answers: which instances are not in the default VPC (negate it: !cap:in-default-vpc)
68
+ ## depth: either
69
+ in-default-vpc(x) := x ->{1,2}(subnet|vpc) :Vpc[isDefault = true]
70
+
71
+ ## meaning: host to host through security-group-to-group ingress
72
+ ## answers: what can this instance reach on the network
73
+ ## depth: declared
74
+ ## not-evaluated: CIDR-to-CIDR reachability inside the VPC; network ACLs
75
+ network(a, y) := a:Instance|Database|Function|Service ->in-sg <-source :IngressRule <-ingress :SecurityGroup <-in-sg y:Instance|Database|Function|Service
76
+
77
+ # ------------------------------------------------------------------ data
78
+
79
+ ## meaning: a bucket, table, database, queue, file system or secret
80
+ ## answers: where is our data
81
+ ## depth: declared
82
+ stores-data(x) := x:Bucket|Table|Database|Queue|FileSystem|Secret|Parameter
83
+
84
+ ## meaning: a secret, an SSM SecureString, or a data store tagged as restricted (the tag keys are the lexicon mapping's classificationTags)
85
+ ## answers: which stores hold secrets or restricted data
86
+ ## depth: declared
87
+ holds-secret(x) := x:Secret
88
+ | x:Parameter[paramType = "SecureString"]
89
+ | x:Bucket|Table|Database|Queue|FileSystem[classification in ("restricted", "secret", "confidential")]
90
+
91
+ ## meaning: encrypted at rest: a database, file system or volume whose encryption attribute is set; S3 buckets, DynamoDB tables, SQS queues and secrets always are
92
+ ## answers: which data stores are not encrypted at rest (negate it: !cap:encrypted-at-rest)
93
+ ## depth: declared
94
+ ## not-evaluated: account-level EBS encryption by default; which key (AWS-owned, AWS-managed or customer-managed)
95
+ encrypted-at-rest(x) := x:Database|FileSystem|Volume[encrypted = true]
96
+ | x:Bucket|Table|Queue|Secret
97
+
98
+ ## meaning: a bucket whose policy allows principal * and no public-access block stops it, or a public ACL
99
+ ## answers: what is public
100
+ ## answers: which buckets can anyone read
101
+ ## depth: declared
102
+ ## not-evaluated: IAM Condition keys; account-level public-access blocks
103
+ publicly-readable(x) := x:Bucket[!blockPublicPolicy = true] !<-blocks :PublicAccessBlock[blockPublicPolicy = true] <-policyOf :ResourcePolicy ->statement :Statement[doc = "resource", effect = "Allow", principals in ("*")]
104
+ | x:Bucket[acl in ("public-read", "public-read-write")]
105
+
106
+ # ------------------------------------------------------------------ identity
107
+
108
+ ## meaning: compute to the role it runs as (instance profile, also through a launch template; Lambda role; ECS task role)
109
+ ## answers: what identity does this instance run as
110
+ ## depth: declared
111
+ runs-as(c, r) := c:Instance|Function|Service|TaskDefinition ->{0,1}template ->{0,1}(profile|task) ->role r:Role
112
+
113
+ ## meaning: role to role, where both the caller's permission and the target's trust allow sts:AssumeRole
114
+ ## answers: which roles can this role become
115
+ ## depth: declared
116
+ ## not-evaluated: IAM Condition keys; Resource "*"; a trust policy that names the account root
117
+ can-assume(a, b) := a:Role <-{0,1}attachedTo ->statement :Statement[doc = "permission", effect = "Allow", actions ~ "sts:AssumeRole"] ->resource b:Role ->statement :Statement[doc = "trust", actions ~ "sts:AssumeRole"] ->principal a
118
+
119
+ ## meaning: role to resource, by an identity policy or a resource policy, with no explicit Deny on the same pair
120
+ ## param-action: an IAM action the grant must cover, such as dynamodb:GetItem
121
+ ## answers: what can this role touch
122
+ ## answers: what can reach the customer database (read it in reverse: <-[cap=grants])
123
+ ## depth: declared
124
+ ## not-evaluated: IAM Condition keys; Resource "*"; NotAction and NotResource; permission boundaries and SCPs; AWS-managed policies, named by ARN only; resources the graph holds but can't resolve, such as an expression naming nothing declared
125
+ grants(r, x; action?) := r:Role ->allows($action) x !<-denies($action) r
126
+
127
+ ## meaning: can-assume any number of times, then grants
128
+ ## param-action: an IAM action the grant must cover, such as s3:GetObject
129
+ ## answers: if this role is compromised, what data can it reach
130
+ ## answers: what can reach the customer database (read it in reverse: <-[cap=reaches])
131
+ ## depth: declared
132
+ ## not-evaluated: IAM Condition keys; Resource "*"; NotAction and NotResource; permission boundaries and SCPs; AWS-managed policies, named by ARN only; resources the graph holds but can't resolve, such as an expression naming nothing declared
133
+ reaches(r, x; action?) := r:Role ->{0,}can-assume ->grants($action) x
134
+
135
+ # ------------------------------------------------------------------ paths
136
+
137
+ ## meaning: internet-reachable compute that runs as a role that reaches a store holding a secret
138
+ ## answers: is there an exfiltration path from the internet to our data
139
+ ## answers: which internet-facing hosts can read restricted data
140
+ ## depth: declared
141
+ ## not-evaluated: IAM Condition keys; Resource "*"; load balancers and API gateways; resources the graph holds but can't resolve, such as an expression naming nothing declared
142
+ exfiltrates(c, x) := c[@internet-reachable] ->runs-as ->reaches x[@holds-secret]
143
+
144
+ ## meaning: what a compromise of it reaches: runs-as, can-assume and network any number of times, then what each identity is granted
145
+ ## answers: what is the blast radius if this host is compromised
146
+ ## depth: declared
147
+ ## not-evaluated: IAM Condition keys; Resource "*"; CIDR-to-CIDR reachability; resources the graph holds but can't resolve, such as an expression naming nothing declared
148
+ blast(s, x) := s ->{0,}pivot ->{0,1}grants x
@@ -0,0 +1,122 @@
1
+ {
2
+ "$comment": "The kinds core's effective-topology folds read (#1139, #4362), as data. These were constants in graph-effective.ts; they stay in core so the folds work on a graph read without its lexicon's plugin. Each lexicon's own mapping (src/capabilities/mapping.json) extends its entry here.",
3
+ "mappings": [
4
+ {
5
+ "lexicon": "aws",
6
+ "types": "kind",
7
+ "refs": "cloudformation",
8
+ "labels": {
9
+ "AWS::EC2::Instance": "Instance",
10
+ "AWS::EC2::LaunchTemplate": "LaunchTemplate",
11
+ "AWS::EC2::SecurityGroup": "SecurityGroup",
12
+ "AWS::EC2::SecurityGroupIngress": { "label": "IngressRule", "style": "cfn" },
13
+ "AWS::EC2::Subnet": "Subnet",
14
+ "AWS::EC2::SubnetRouteTableAssociation": "RouteTableAssociation",
15
+ "AWS::EC2::RouteTable": "RouteTable",
16
+ "AWS::EC2::Route": "Route",
17
+ "AWS::EC2::InternetGateway": "InternetGateway"
18
+ },
19
+ "edges": {
20
+ "Instance": {
21
+ "SecurityGroupIds": "sg",
22
+ "SecurityGroupId": "sg",
23
+ "LaunchTemplate": "template",
24
+ "LaunchTemplateId": "template",
25
+ "SubnetId": "subnet"
26
+ },
27
+ "LaunchTemplate": {
28
+ "LaunchTemplateData": { "SecurityGroup": "sg" },
29
+ "SecurityGroupIds": "sg",
30
+ "SecurityGroupId": "sg"
31
+ },
32
+ "IngressRule": { "GroupId": "-ingress", "SourceSecurityGroupId": "source" },
33
+ "RouteTableAssociation": { "SubnetId": "subnet", "RouteTableId": "table" },
34
+ "Route": { "RouteTableId": "table", "GatewayId": "gateway" }
35
+ },
36
+ "attrs": {
37
+ "Route": { "dest": "DestinationCidrBlock" },
38
+ "IngressRule": { "proto": "IpProtocol", "from": "FromPort", "to": "ToPort", "cidrs": { "all": ["CidrIp", "CidrIpv6"] } }
39
+ },
40
+ "blocks": {
41
+ "SecurityGroup": [
42
+ {
43
+ "attr": "SecurityGroupIngress",
44
+ "label": "IngressRule",
45
+ "edge": "ingress",
46
+ "style": "cfn",
47
+ "attrs": { "proto": "IpProtocol", "from": "FromPort", "to": "ToPort", "cidrs": { "all": ["CidrIp", "CidrIpv6"] } },
48
+ "refs": { "SourceSecurityGroupId": "source" }
49
+ }
50
+ ]
51
+ }
52
+ },
53
+ {
54
+ "lexicon": "terraform",
55
+ "types": "terraform",
56
+ "body": "body",
57
+ "refs": "terraform",
58
+ "labels": {
59
+ "aws_instance": "Instance",
60
+ "aws_launch_template": "LaunchTemplate",
61
+ "aws_security_group": "SecurityGroup",
62
+ "aws_security_group_rule": { "label": "IngressRule", "when": { "type": "ingress" }, "style": "tf-sg-rule" },
63
+ "aws_vpc_security_group_ingress_rule": { "label": "IngressRule", "style": "tf-vpc-rule" },
64
+ "aws_subnet": "Subnet",
65
+ "aws_route_table_association": "RouteTableAssociation",
66
+ "aws_route_table": "RouteTable",
67
+ "aws_route": "Route",
68
+ "aws_internet_gateway": "InternetGateway"
69
+ },
70
+ "edges": {
71
+ "Instance": {
72
+ "vpc_security_group_ids": "sg",
73
+ "security_groups": "sg",
74
+ "launch_template": "template",
75
+ "subnet_id": "subnet"
76
+ },
77
+ "LaunchTemplate": {
78
+ "vpc_security_group_ids": "sg",
79
+ "security_group_names": "sg",
80
+ "network_interfaces": { "SecurityGroup": "sg" }
81
+ },
82
+ "IngressRule": {
83
+ "security_group_id": "-ingress",
84
+ "source_security_group_id": "source",
85
+ "referenced_security_group_id": "source"
86
+ },
87
+ "RouteTableAssociation": { "subnet_id": "subnet", "route_table_id": "table" },
88
+ "Route": { "route_table_id": "table", "gateway_id": "gateway" }
89
+ },
90
+ "attrs": {
91
+ "Route": { "dest": ["destination_cidr_block", "destination_ipv6_cidr_block"] },
92
+ "IngressRule": {
93
+ "proto": ["ip_protocol", "protocol"],
94
+ "from": "from_port",
95
+ "to": "to_port",
96
+ "cidrs": { "all": ["cidr_blocks", "ipv6_cidr_blocks", "cidr_ipv4", "cidr_ipv6"] }
97
+ }
98
+ },
99
+ "blocks": {
100
+ "SecurityGroup": [
101
+ {
102
+ "attr": "ingress",
103
+ "label": "IngressRule",
104
+ "edge": "ingress",
105
+ "style": "tf-inline",
106
+ "attrs": { "proto": "protocol", "from": "from_port", "to": "to_port", "cidrs": { "all": ["cidr_blocks", "ipv6_cidr_blocks"] } },
107
+ "refs": { "security_groups": "source" }
108
+ }
109
+ ],
110
+ "RouteTable": [
111
+ {
112
+ "attr": "route",
113
+ "label": "Route",
114
+ "edge": "-table",
115
+ "attrs": { "dest": ["cidr_block", "ipv6_cidr_block"] },
116
+ "refs": { "gateway_id": "gateway" }
117
+ }
118
+ ]
119
+ }
120
+ }
121
+ ]
122
+ }
@@ -0,0 +1,230 @@
1
+ /**
2
+ * The capability catalog (#4375): the rule files core ships, the packs
3
+ * lexicons contribute, and the engine that evaluates one over a graph.
4
+ *
5
+ * Rules are data: `aws.paths` beside this module, read at run time. It serves
6
+ * every lexicon that maps AWS resources onto the view (the aws lexicon's
7
+ * CloudFormation kinds and the terraform lexicon's AWS provider types), so it
8
+ * lives here rather than in either lexicon. Each lexicon ships its mapping
9
+ * (data) and, where it needs one, an adapter (code), as a `CapabilityPack` on
10
+ * its plugin.
11
+ */
12
+ import { readFileSync } from "node:fs";
13
+ import type { GraphIR } from "../graph-ir";
14
+ import { parseRules, ruleDependencies, type Literal, type Rule } from "./language";
15
+ import { CapabilityEngine } from "./matcher";
16
+ import { buildView, mergeMappings, type CapabilityMapping, type CapabilityPack, type View } from "./view";
17
+ import base from "./base-mappings.json" with { type: "json" };
18
+
19
+ /** The rule files core ships, by name. */
20
+ const RULE_FILES = ["aws.paths"] as const;
21
+
22
+ let rulesCache: { rules: Rule[]; sources: Map<string, string> } | undefined;
23
+
24
+ /** Every rule core ships, parsed, with the file each came from. */
25
+ export function shippedRules(): { rules: Rule[]; sources: Map<string, string> } {
26
+ if (rulesCache) return rulesCache;
27
+ const rules: Rule[] = [];
28
+ const sources = new Map<string, string>();
29
+ for (const file of RULE_FILES) {
30
+ const text = readFileSync(new URL(`./${file}`, import.meta.url), "utf-8");
31
+ for (const r of parseRules(text)) {
32
+ rules.push(r);
33
+ sources.set(r.name, file);
34
+ }
35
+ }
36
+ rulesCache = { rules, sources };
37
+ return rulesCache;
38
+ }
39
+
40
+ /** The mappings core's folds need, for a graph read without its lexicon's plugin. */
41
+ export function basePacks(): CapabilityPack[] {
42
+ return (base as unknown as { mappings: CapabilityMapping[] }).mappings.map((mapping) => ({ mapping }));
43
+ }
44
+
45
+ const registered: CapabilityPack[] = [];
46
+
47
+ /**
48
+ * Register a lexicon's pack for callers that hold no plugin list (the folds,
49
+ * a test). A plugin's `capabilityPack` reaches search without this.
50
+ */
51
+ export function registerCapabilityPack(pack: CapabilityPack): void {
52
+ if (!registered.includes(pack)) registered.push(pack);
53
+ }
54
+
55
+ /** Base packs, registered packs, then the packs given: later ones extend earlier ones. */
56
+ export function resolvePacks(packs: CapabilityPack[] = []): CapabilityPack[] {
57
+ return [...basePacks(), ...registered, ...packs.filter((p) => !registered.includes(p))];
58
+ }
59
+
60
+ const engines = new WeakMap<GraphIR, CapabilityEngine>();
61
+
62
+ /**
63
+ * The capability engine for a graph, built once per graph object. Packs
64
+ * passed on the first call for a graph are the ones it uses.
65
+ */
66
+ export function capabilityEngine(ir: GraphIR, packs: CapabilityPack[] = []): CapabilityEngine {
67
+ let e = engines.get(ir);
68
+ if (!e) {
69
+ e = new CapabilityEngine(buildView(ir, resolvePacks(packs)), shippedRules().rules);
70
+ engines.set(ir, e);
71
+ }
72
+ return e;
73
+ }
74
+
75
+ /** Bind a graph to the packs its search was given, before anything asks for a capability. */
76
+ export function attachCapabilities(ir: GraphIR, packs: CapabilityPack[]): CapabilityEngine {
77
+ engines.delete(ir);
78
+ return capabilityEngine(ir, packs);
79
+ }
80
+
81
+ /**
82
+ * Bind a graph to a view built elsewhere (#4378): a workspace's composed
83
+ * view, which each member's own chant mapped. The rules are this chant's.
84
+ */
85
+ export function attachView(ir: GraphIR, view: View): CapabilityEngine {
86
+ const e = new CapabilityEngine(view, shippedRules().rules);
87
+ engines.set(ir, e);
88
+ return e;
89
+ }
90
+
91
+ /**
92
+ * Read `name` or `name(arg, ...)`, as a search term or an edge qualifier
93
+ * spells a capability. An argument is a number, `true`/`false`, or text,
94
+ * quoted or not.
95
+ */
96
+ export function parseCapabilityCall(text: string): { name: string; args: (Literal | undefined)[] } | undefined {
97
+ const m = /^([A-Za-z_][\w-]*)(?:\((.*)\))?$/.exec(text.trim());
98
+ if (!m) return undefined;
99
+ const args = m[2] === undefined || m[2].trim() === ""
100
+ ? []
101
+ : m[2].split(",").map((a) => {
102
+ const s = a.trim();
103
+ if (s === "" || s === "_") return undefined;
104
+ if (/^-?\d+(\.\d+)?$/.test(s)) return Number(s);
105
+ if (s === "true" || s === "false") return s === "true";
106
+ return s.replace(/^"(.*)"$/, "$1");
107
+ });
108
+ return { name: m[1], args };
109
+ }
110
+
111
+ /** Public capabilities: those whose rule carries a `## meaning`. Helpers carry none. */
112
+ export function isPublic(rule: Rule): boolean {
113
+ return rule.meta.meaning !== undefined;
114
+ }
115
+
116
+ /** Every label a rule needs, through the capabilities it uses, per alternative: any one alternative suffices. */
117
+ function labelsNeeded(rule: Rule, byName: Map<string, Rule>, seen = new Set<string>()): string[][] {
118
+ if (seen.has(rule.name)) return [[]];
119
+ seen.add(rule.name);
120
+ const out: string[][] = [];
121
+ for (const alt of rule.alts) {
122
+ // A node of any one of its labels will do, so each label is an option.
123
+ let options: string[][] = alt.head.labels ? alt.head.labels.map((l) => [l]) : [[]];
124
+ const add = (more: string[][]): void => {
125
+ options = options.flatMap((o) => more.map((m) => [...o, ...m]));
126
+ };
127
+ for (const t of alt.head.tests) if (t.kind === "cap" && !t.negated) add(labelsNeeded(byName.get(t.cap)!, byName, new Set(seen)));
128
+ for (const s of alt.steps) {
129
+ if (s.negated) continue;
130
+ if (s.node.labels && s.min > 0) add(s.node.labels.map((l) => [l]));
131
+ for (const t of s.node.tests) if (t.kind === "cap" && !t.negated) add(labelsNeeded(byName.get(t.cap)!, byName, new Set(seen)));
132
+ if (s.min > 0) {
133
+ const edgeRules = s.names.map((n) => byName.get(n.name)).filter((r): r is Rule => !!r);
134
+ if (edgeRules.length === s.names.length) add(edgeRules.flatMap((r) => labelsNeeded(r, byName, new Set(seen))));
135
+ }
136
+ }
137
+ out.push(...options);
138
+ }
139
+ return out;
140
+ }
141
+
142
+ /**
143
+ * Whether a lexicon can supply a capability: its own statement when its
144
+ * mapping makes one, otherwise whether every label one alternative needs
145
+ * is one the mapping labels.
146
+ */
147
+ export function lexiconSupport(
148
+ rule: Rule,
149
+ mapping: CapabilityMapping | undefined,
150
+ lexicon: string,
151
+ ): "supported" | { code: string; message: string } {
152
+ if (!mapping) {
153
+ return { code: "lexicon-has-no-mapping", message: `the ${lexicon} lexicon ships no capability mapping` };
154
+ }
155
+ const stated = mapping.unsupported?.[rule.name];
156
+ if (stated) return stated;
157
+ // A lexicon's mapping extends core's base mapping for it (the folds' kinds).
158
+ const own = mapping;
159
+ const baseFor = basePacks().find((p) => p.mapping.lexicon === own.lexicon)?.mapping;
160
+ if (baseFor) mapping = mergeMappings(baseFor, own);
161
+ const { rules } = shippedRules();
162
+ const byName = new Map(rules.map((r) => [r.name, r]));
163
+ const labels = new Set(
164
+ Object.values(mapping.labels ?? {}).map((s) => (typeof s === "string" ? s : s.label)),
165
+ );
166
+ // Statements and inline blocks are the adapter's own nodes.
167
+ labels.add("Statement");
168
+ for (const specs of Object.values(mapping.blocks ?? {})) for (const b of specs) labels.add(b.label);
169
+ const options = labelsNeeded(rule, byName);
170
+ if (options.some((o) => o.every((l) => labels.has(l)))) return "supported";
171
+ const missing = [...new Set(options.flatMap((o) => o.filter((l) => !labels.has(l))))];
172
+ return {
173
+ code: "capability-not-derivable",
174
+ message: `the ${lexicon} mapping labels no ${missing.join(" or ")}`,
175
+ };
176
+ }
177
+
178
+ /** The capabilities a rule uses, directly. */
179
+ export function usesOf(rule: Rule): string[] {
180
+ const { rules } = shippedRules();
181
+ const names = new Set(rules.map((r) => r.name));
182
+ return [...ruleDependencies(rule)].filter((n) => names.has(n));
183
+ }
184
+
185
+ /** One capability as the `capabilities` document lists it (#4375). */
186
+ export interface CapabilityEntry {
187
+ name: string;
188
+ meaning: string;
189
+ shape: "set" | "edge";
190
+ params: { name: string; optional: boolean; meaning: string }[];
191
+ /** The search term that asks for it: `cap:<name>` for a set, `->[cap=<name>]` for an edge. */
192
+ search: string;
193
+ answers: string[];
194
+ depth: "declared" | "live" | "either";
195
+ lexicons: Record<string, "supported" | { code: string; message: string }>;
196
+ notEvaluated: string[];
197
+ /** The capabilities and helpers its rule uses. */
198
+ uses: string[];
199
+ rule: string;
200
+ }
201
+
202
+ /**
203
+ * The catalog as the `capabilities` document carries it: every public
204
+ * capability, with whether each lexicon given can supply it, and the helper
205
+ * rules they use. `lexicons` maps each lexicon to its mapping, or to
206
+ * undefined when it ships none.
207
+ */
208
+ export function capabilityCatalog(lexicons: Record<string, CapabilityMapping | undefined>): {
209
+ capabilities: CapabilityEntry[];
210
+ helpers: { name: string; rule: string }[];
211
+ } {
212
+ const { rules } = shippedRules();
213
+ const list = (s: string | undefined): string[] =>
214
+ (s ?? "").split(/\n|;/).map((x) => x.trim()).filter(Boolean);
215
+ const capabilities = rules.filter(isPublic).map((r): CapabilityEntry => ({
216
+ name: r.name,
217
+ meaning: r.meta.meaning,
218
+ shape: r.vars.length === 1 ? "set" : "edge",
219
+ params: r.params.map((p) => ({ name: p.name, optional: p.optional, meaning: r.meta[`param-${p.name}`] ?? "" })),
220
+ search: r.vars.length === 1 ? `cap:${r.name}` : `->[cap=${r.name}]`,
221
+ answers: (r.meta.answers ?? "").split("\n").map((x) => x.trim()).filter(Boolean),
222
+ depth: (r.meta.depth ?? "declared") as CapabilityEntry["depth"],
223
+ lexicons: Object.fromEntries(Object.entries(lexicons).map(([lex, m]) => [lex, lexiconSupport(r, m, lex)])),
224
+ notEvaluated: list(r.meta["not-evaluated"]),
225
+ uses: usesOf(r),
226
+ rule: r.text,
227
+ }));
228
+ const helpers = rules.filter((r) => !isPublic(r)).map((r) => ({ name: r.name, rule: r.text }));
229
+ return { capabilities, helpers };
230
+ }