@intentius/chant-lexicon-k8s 0.124.97 → 0.124.98

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 (228) hide show
  1. package/dist/application-paths.d.ts +4 -0
  2. package/dist/application-paths.d.ts.map +1 -0
  3. package/dist/application-paths.js +95 -0
  4. package/dist/application-set.d.ts +46 -0
  5. package/dist/application-set.d.ts.map +1 -0
  6. package/dist/application-set.js +303 -0
  7. package/dist/cluster-secret.d.ts +36 -0
  8. package/dist/cluster-secret.d.ts.map +1 -0
  9. package/dist/cluster-secret.js +55 -0
  10. package/dist/components/kustomize-apply.d.ts +6 -0
  11. package/dist/components/kustomize-apply.d.ts.map +1 -1
  12. package/dist/components/kustomize-apply.js +1 -1
  13. package/dist/config-schema.d.ts +8 -0
  14. package/dist/config-schema.d.ts.map +1 -1
  15. package/dist/config-schema.js +6 -2
  16. package/dist/config.d.ts +26 -3
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/helm-references.d.ts +113 -0
  19. package/dist/helm-references.d.ts.map +1 -0
  20. package/dist/helm-references.js +389 -0
  21. package/dist/import/generator.d.ts +11 -2
  22. package/dist/import/generator.d.ts.map +1 -1
  23. package/dist/import/generator.js +37 -55
  24. package/dist/import/parser.d.ts.map +1 -1
  25. package/dist/import/parser.js +34 -5
  26. package/dist/import/typed-classes.d.ts +57 -0
  27. package/dist/import/typed-classes.d.ts.map +1 -0
  28. package/dist/import/typed-classes.js +126 -0
  29. package/dist/integrity.json +41 -41
  30. package/dist/kustomize/render.d.ts +41 -2
  31. package/dist/kustomize/render.d.ts.map +1 -1
  32. package/dist/kustomize/render.js +114 -7
  33. package/dist/kustomize/root.d.ts +3 -3
  34. package/dist/kustomize/root.d.ts.map +1 -1
  35. package/dist/kustomize/root.js +6 -1
  36. package/dist/lint/post-synth/argo-helpers.d.ts +3 -0
  37. package/dist/lint/post-synth/argo-helpers.d.ts.map +1 -1
  38. package/dist/lint/post-synth/argo-helpers.js +8 -2
  39. package/dist/lint/post-synth/argo002.d.ts.map +1 -1
  40. package/dist/lint/post-synth/argo002.js +2 -1
  41. package/dist/lint/post-synth/argo003.d.ts.map +1 -1
  42. package/dist/lint/post-synth/argo003.js +2 -1
  43. package/dist/lint/post-synth/argo005.d.ts.map +1 -1
  44. package/dist/lint/post-synth/argo005.js +36 -9
  45. package/dist/lint/post-synth/crd-schema-helpers.d.ts +1 -1
  46. package/dist/lint/post-synth/crd-schema-helpers.d.ts.map +1 -1
  47. package/dist/lint/post-synth/crd-schema-helpers.js +3 -3
  48. package/dist/lint/post-synth/flux002.d.ts.map +1 -1
  49. package/dist/lint/post-synth/flux002.js +2 -1
  50. package/dist/lint/post-synth/flux003.d.ts.map +1 -1
  51. package/dist/lint/post-synth/flux003.js +2 -1
  52. package/dist/lint/post-synth/k8s-helpers.d.ts +32 -0
  53. package/dist/lint/post-synth/k8s-helpers.d.ts.map +1 -1
  54. package/dist/lint/post-synth/k8s-helpers.js +57 -10
  55. package/dist/lint/post-synth/wk8005.d.ts +9 -0
  56. package/dist/lint/post-synth/wk8005.d.ts.map +1 -1
  57. package/dist/lint/post-synth/wk8005.js +53 -3
  58. package/dist/lint/post-synth/wk8006.d.ts.map +1 -1
  59. package/dist/lint/post-synth/wk8006.js +4 -2
  60. package/dist/lint/post-synth/wk8041.d.ts.map +1 -1
  61. package/dist/lint/post-synth/wk8041.js +3 -2
  62. package/dist/lint/post-synth/wk8042.js +2 -2
  63. package/dist/lint/post-synth/wk8101.js +2 -2
  64. package/dist/lint/post-synth/wk8102.d.ts.map +1 -1
  65. package/dist/lint/post-synth/wk8102.js +7 -3
  66. package/dist/lint/post-synth/wk8103.d.ts.map +1 -1
  67. package/dist/lint/post-synth/wk8103.js +3 -2
  68. package/dist/lint/post-synth/wk8104.d.ts.map +1 -1
  69. package/dist/lint/post-synth/wk8104.js +3 -2
  70. package/dist/lint/post-synth/wk8105.d.ts.map +1 -1
  71. package/dist/lint/post-synth/wk8105.js +3 -2
  72. package/dist/lint/post-synth/wk8201.d.ts.map +1 -1
  73. package/dist/lint/post-synth/wk8201.js +3 -2
  74. package/dist/lint/post-synth/wk8202.d.ts.map +1 -1
  75. package/dist/lint/post-synth/wk8202.js +3 -2
  76. package/dist/lint/post-synth/wk8203.d.ts.map +1 -1
  77. package/dist/lint/post-synth/wk8203.js +3 -2
  78. package/dist/lint/post-synth/wk8204.d.ts.map +1 -1
  79. package/dist/lint/post-synth/wk8204.js +5 -2
  80. package/dist/lint/post-synth/wk8205.d.ts.map +1 -1
  81. package/dist/lint/post-synth/wk8205.js +3 -2
  82. package/dist/lint/post-synth/wk8207.js +2 -2
  83. package/dist/lint/post-synth/wk8208.js +2 -2
  84. package/dist/lint/post-synth/wk8209.js +2 -2
  85. package/dist/lint/post-synth/wk8301.d.ts.map +1 -1
  86. package/dist/lint/post-synth/wk8301.js +3 -2
  87. package/dist/lint/post-synth/wk8302.js +2 -2
  88. package/dist/lint/post-synth/wk8303.js +2 -2
  89. package/dist/lint/post-synth/wk8304.js +2 -2
  90. package/dist/lint/post-synth/wk8305.js +2 -2
  91. package/dist/lint/post-synth/wk8306.d.ts.map +1 -1
  92. package/dist/lint/post-synth/wk8306.js +3 -2
  93. package/dist/lint/post-synth/wk8401.js +2 -2
  94. package/dist/lint/post-synth/wk8402.js +2 -2
  95. package/dist/lint/post-synth/wk8403.js +2 -2
  96. package/dist/lint/post-synth/wk8404.d.ts.map +1 -1
  97. package/dist/lint/post-synth/wk8404.js +2 -2
  98. package/dist/lint/post-synth/wk8405.js +2 -2
  99. package/dist/lint/post-synth/wk8406.d.ts.map +1 -1
  100. package/dist/lint/post-synth/wk8406.js +3 -2
  101. package/dist/lint/post-synth/wk8407.js +2 -2
  102. package/dist/lint/post-synth/wk8503.js +2 -2
  103. package/dist/manifest.json +1 -1
  104. package/dist/reference-catalog.d.ts +3 -1
  105. package/dist/reference-catalog.d.ts.map +1 -1
  106. package/dist/reference-catalog.js +283 -15
  107. package/dist/rules/argo-helpers.ts +9 -2
  108. package/dist/rules/argo002.ts +2 -1
  109. package/dist/rules/argo003.ts +2 -1
  110. package/dist/rules/argo005.ts +36 -10
  111. package/dist/rules/crd-schema-helpers.ts +3 -3
  112. package/dist/rules/flux002.ts +2 -1
  113. package/dist/rules/flux003.ts +2 -1
  114. package/dist/rules/k8s-helpers.ts +56 -11
  115. package/dist/rules/wk8005.ts +56 -3
  116. package/dist/rules/wk8006.ts +4 -2
  117. package/dist/rules/wk8041.ts +3 -2
  118. package/dist/rules/wk8042.ts +2 -2
  119. package/dist/rules/wk8101.ts +2 -2
  120. package/dist/rules/wk8102.ts +7 -3
  121. package/dist/rules/wk8103.ts +3 -2
  122. package/dist/rules/wk8104.ts +3 -2
  123. package/dist/rules/wk8105.ts +3 -2
  124. package/dist/rules/wk8201.ts +3 -2
  125. package/dist/rules/wk8202.ts +3 -2
  126. package/dist/rules/wk8203.ts +3 -2
  127. package/dist/rules/wk8204.ts +5 -2
  128. package/dist/rules/wk8205.ts +3 -2
  129. package/dist/rules/wk8207.ts +2 -2
  130. package/dist/rules/wk8208.ts +2 -2
  131. package/dist/rules/wk8209.ts +2 -2
  132. package/dist/rules/wk8301.ts +3 -2
  133. package/dist/rules/wk8302.ts +2 -2
  134. package/dist/rules/wk8303.ts +2 -2
  135. package/dist/rules/wk8304.ts +2 -2
  136. package/dist/rules/wk8305.ts +2 -2
  137. package/dist/rules/wk8306.ts +3 -2
  138. package/dist/rules/wk8401.ts +2 -2
  139. package/dist/rules/wk8402.ts +2 -2
  140. package/dist/rules/wk8403.ts +2 -2
  141. package/dist/rules/wk8404.ts +2 -1
  142. package/dist/rules/wk8405.ts +2 -2
  143. package/dist/rules/wk8406.ts +3 -2
  144. package/dist/rules/wk8407.ts +2 -2
  145. package/dist/rules/wk8503.ts +2 -2
  146. package/dist/workspace-member.d.ts +15 -3
  147. package/dist/workspace-member.d.ts.map +1 -1
  148. package/dist/workspace-member.js +151 -21
  149. package/package.json +5 -5
  150. package/src/application-paths.ts +96 -0
  151. package/src/application-set.test.ts +130 -0
  152. package/src/application-set.ts +336 -0
  153. package/src/cluster-secret.test.ts +117 -0
  154. package/src/cluster-secret.ts +76 -0
  155. package/src/components/kustomize-apply.ts +7 -1
  156. package/src/config-schema.ts +6 -2
  157. package/src/config.ts +24 -4
  158. package/src/helm-references.test.ts +149 -0
  159. package/src/helm-references.ts +425 -0
  160. package/src/import/generator.test.ts +57 -0
  161. package/src/import/generator.ts +35 -61
  162. package/src/import/parser.test.ts +59 -0
  163. package/src/import/parser.ts +38 -5
  164. package/src/import/roundtrip-build.test.ts +91 -0
  165. package/src/import/typed-classes.ts +168 -0
  166. package/src/kustomize/helm.test.ts +183 -0
  167. package/src/kustomize/render.ts +142 -6
  168. package/src/kustomize/root.ts +8 -3
  169. package/src/lint/post-synth/argo-helpers.ts +9 -2
  170. package/src/lint/post-synth/argo002.ts +2 -1
  171. package/src/lint/post-synth/argo003.ts +2 -1
  172. package/src/lint/post-synth/argo005.ts +36 -10
  173. package/src/lint/post-synth/audit-identity.test.ts +65 -0
  174. package/src/lint/post-synth/crd-schema-helpers.ts +3 -3
  175. package/src/lint/post-synth/flux002.ts +2 -1
  176. package/src/lint/post-synth/flux003.ts +2 -1
  177. package/src/lint/post-synth/k8s-helpers.ts +56 -11
  178. package/src/lint/post-synth/post-synth.test.ts +144 -0
  179. package/src/lint/post-synth/wk8005.ts +56 -3
  180. package/src/lint/post-synth/wk8006.ts +4 -2
  181. package/src/lint/post-synth/wk8041.ts +3 -2
  182. package/src/lint/post-synth/wk8042.ts +2 -2
  183. package/src/lint/post-synth/wk8101.ts +2 -2
  184. package/src/lint/post-synth/wk8102.ts +7 -3
  185. package/src/lint/post-synth/wk8103.ts +3 -2
  186. package/src/lint/post-synth/wk8104.ts +3 -2
  187. package/src/lint/post-synth/wk8105.ts +3 -2
  188. package/src/lint/post-synth/wk8201.ts +3 -2
  189. package/src/lint/post-synth/wk8202.ts +3 -2
  190. package/src/lint/post-synth/wk8203.ts +3 -2
  191. package/src/lint/post-synth/wk8204.ts +5 -2
  192. package/src/lint/post-synth/wk8205.ts +3 -2
  193. package/src/lint/post-synth/wk8207.ts +2 -2
  194. package/src/lint/post-synth/wk8208.ts +2 -2
  195. package/src/lint/post-synth/wk8209.ts +2 -2
  196. package/src/lint/post-synth/wk8301.ts +3 -2
  197. package/src/lint/post-synth/wk8302.ts +2 -2
  198. package/src/lint/post-synth/wk8303.ts +2 -2
  199. package/src/lint/post-synth/wk8304.ts +2 -2
  200. package/src/lint/post-synth/wk8305.ts +2 -2
  201. package/src/lint/post-synth/wk8306.ts +3 -2
  202. package/src/lint/post-synth/wk8401.ts +2 -2
  203. package/src/lint/post-synth/wk8402.ts +2 -2
  204. package/src/lint/post-synth/wk8403.ts +2 -2
  205. package/src/lint/post-synth/wk8404.ts +2 -1
  206. package/src/lint/post-synth/wk8405.ts +2 -2
  207. package/src/lint/post-synth/wk8406.ts +3 -2
  208. package/src/lint/post-synth/wk8407.ts +2 -2
  209. package/src/lint/post-synth/wk8503.ts +2 -2
  210. package/src/reference-catalog.test.ts +78 -0
  211. package/src/reference-catalog.ts +297 -16
  212. package/src/testdata/helm-chart-missing/kustomization.yaml +8 -0
  213. package/src/testdata/helm-chart-root/charts/webchart/Chart.yaml +3 -0
  214. package/src/testdata/helm-chart-root/charts/webchart/templates/configmap.yaml +6 -0
  215. package/src/testdata/helm-chart-root/charts/webchart/values.yaml +1 -0
  216. package/src/testdata/helm-chart-root/kustomization.yaml +9 -0
  217. package/src/testdata/helm-chart-root/values.yaml +1 -0
  218. package/src/testdata/workspace-members/argo-clusters/clusters.yaml +34 -0
  219. package/src/testdata/workspace-members/argo-set/all.yaml +43 -0
  220. package/src/testdata/workspace-members/plain/deploy.yaml +27 -0
  221. package/src/testdata/workspace-members/plain/es.yaml +15 -0
  222. package/src/testdata/workspace-members/templated/block.yaml +6 -0
  223. package/src/testdata/workspace-members/templated/chart-cm.yaml +4 -0
  224. package/src/testdata/workspace-members/templated/cm.yaml +6 -0
  225. package/src/workspace-kinds.test.ts +9 -1
  226. package/src/workspace-member.test.ts +69 -3
  227. package/src/workspace-member.ts +165 -24
  228. package/workspace-kinds.json +45 -6
@@ -1,4 +1,9 @@
1
- import type { IdentityRule, ReferenceCatalog, RefRule } from "@intentius/chant/graph-refs";
1
+ import type { IRNode } from "@intentius/chant/graph-ir";
2
+ import { k8sDeclaredNode, registersCluster } from "./cluster-secret";
3
+ import { APPLICATION, APPLICATION_SET, generateApplications } from "./application-set";
4
+ import { applicationPathRules } from "./application-paths";
5
+ import { generatedValuesNodes } from "./helm-references";
6
+ import { readPath, type GenerateRule, type IdentityRule, type JoinedRef, type ReferenceCatalog, type RefRule, type ScopeRule } from "@intentius/chant/graph-refs";
2
7
 
3
8
  /**
4
9
  * Kubernetes reference catalog (#4535): how Kubernetes objects name each
@@ -17,9 +22,12 @@ import type { IdentityRule, ReferenceCatalog, RefRule } from "@intentius/chant/g
17
22
  * object's location is its namespace (behold#1025), so the scoped join key
18
23
  * (behold#1023's ruling) keeps a `serviceAccountName: default` inside its own
19
24
  * namespace, and a namespaced holder also reaches cluster-scoped objects (a
20
- * `Namespace`, a `ClusterRole`, a `StorageClass`). A declared graph is one
21
- * scope, so two `default` service accounts in two namespaces make that
22
- * reference ambiguous there, and it draws no edge.
25
+ * `Namespace`, a `ClusterRole`, a `StorageClass`). On a declared graph,
26
+ * `chant workspace graph`'s catalog pass (#5097) reads the namespace from
27
+ * `metadata.namespace` through `scopes`, so a name joins across members
28
+ * inside one namespace, and a namespaced object that names none stays inside
29
+ * its own member. Two objects that match one name in one namespace make the
30
+ * reference ambiguous, and it draws no edge.
23
31
  *
24
32
  * ## Multi-kind fields
25
33
  *
@@ -35,17 +43,87 @@ import type { IdentityRule, ReferenceCatalog, RefRule } from "@intentius/chant/g
35
43
  * env-value rules join such a value to an `AWS::S3::Bucket` of that name, and
36
44
  * are `optional`, since most env values name nothing. Over an index the
37
45
  * cluster and the AWS account are two scopes, so the join only draws on a
38
- * declared graph (one scope), which is where behold's matcher drew it.
46
+ * declared graph, where a cloud resource sits in the scope every namespace
47
+ * reaches, which is where behold's matcher drew it.
48
+ *
49
+ * ## External Secrets (#5098)
50
+ *
51
+ * An `ExternalSecret` names a store, and through it a secret in a cloud
52
+ * secret manager. Both are rules with a `join`, since neither is one value
53
+ * naming one node. The store rule reads `spec.secretStoreRef.name` as a
54
+ * `SecretStore` in the holder's namespace or a cluster-scoped
55
+ * `ClusterSecretStore`, as `spec.secretStoreRef.kind` says (absent is
56
+ * `SecretStore`, the operator's default): one rule per kind, each reading
57
+ * only the references of its own. The secret rule reads
58
+ * `spec.data[].remoteRef.key` and `spec.dataFrom[].extract.key` and joins
59
+ * the key to the cloud secret inside the scope the store names: a GCP store's
60
+ * `projectID` with a `google_secret_manager_secret`'s `secret_id` and
61
+ * `project`, an AWS Secrets Manager store's `region` with an
62
+ * `aws_secretsmanager_secret`'s `name`. The edge's `viaAttr` is
63
+ * `remoteRef.key via <store name>`, and a key that names no secret is
64
+ * dangling with the store's node as `through`. A store that is not found
65
+ * is dangling under the store rule, and its keys are not read. A Terraform
66
+ * argument that is not literal is not read (the pass counts it), so a secret
67
+ * whose `secret_id` or `project` is a variable matches nothing. An AWS secret
68
+ * matches on its name alone when it sets no literal `region`.
69
+ *
70
+ * ## Argo CD clusters (#5101)
71
+ *
72
+ * An Application's `spec.destination.name` or `.server` joins the cluster
73
+ * Secret whose `name` or `server` it is, and a cluster Secret's `name` joins
74
+ * the managed Kubernetes cluster block of that literal name in the terraform
75
+ * catalog. The Secret's values are read from `argoCluster` (./cluster-secret.ts),
76
+ * which only a cluster Secret has, decoded from `data` when it wrote them
77
+ * there. Application is scoped by `metadata.namespace` like the Secret, but is
78
+ * not a named kind, so it has no containment rule to a Namespace.
79
+ *
80
+ * ## ApplicationSets (#5102)
81
+ *
82
+ * An ApplicationSet's `list` and `clusters` generators are expanded into the
83
+ * Applications they generate (./application-set.ts), one node each, under the
84
+ * `generates` rule. An Application a `clusters` generator made for a cluster
85
+ * Secret joins that Secret under `generators[].clusters`, since the
86
+ * generator selected it; the destination rules draw no second edge for the
87
+ * pair. The other rules read a generated Application as one written by hand. The path rules
88
+ * (./application-paths.ts) read the directories and values files every
89
+ * Application names, and the pass lists one the repository does not have as
90
+ * dangling.
39
91
  *
40
92
  * ## What this does not do
41
93
  *
42
- * - Label selectors. A Service selects pods by labels, and the standard keys
43
- * (`app.kubernetes.io/name`) contain dots, which `readPath` reads as path
44
- * separators. Only the bare `app` label is matched: a Service's
45
- * `spec.selector.app` to a workload whose pod template carries the same
46
- * `app` label. behold's own k8s pass (src/k8s-edges.ts) still joins full
94
+ * - Stores other than GCP and AWS Secrets Manager (IBM, Vault), the legacy
95
+ * `kubernetes-client.io` ExternalSecret, and the Secret an ExternalSecret
96
+ * writes (`spec.target.name`).
97
+ * - Label selectors. A Service selects pods by a set of labels, and a rule
98
+ * matches one value at one path, so a selector on the standard keys
99
+ * (`app.kubernetes.io/name`) is not read. Only the bare `app` label is
100
+ * matched: a Service's `spec.selector.app` to a workload whose pod
101
+ * template carries the same `app` label. behold's own k8s pass (src/k8s-edges.ts) still joins full
47
102
  * selectors on behold's side.
48
- * - Annotations, for the same reason (`eks.amazonaws.com/role-arn`).
103
+ *
104
+ * Annotation keys are reachable since #5097, as a quoted step:
105
+ * `metadata.annotations["eks.amazonaws.com/role-arn"]`. Rules that read them
106
+ * come with the issues that need them.
107
+ *
108
+ * ## Helm values files (#5100)
109
+ *
110
+ * An Argo CD Application or ApplicationSet and a kustomization with
111
+ * `helmCharts` name their values files in `helmReferences.valuesFiles[]`, a
112
+ * key the reader stamps with each file's workspace-relative path
113
+ * (./helm-references.ts). A file that exists and parses is a `Helm::Values`
114
+ * node identified by that path, so a name with no node is dangling with the
115
+ * path. The edges to the charts are not rules here: a chart is shared by every
116
+ * member that names it, so the helm lexicon's catalog makes the node.
117
+ *
118
+ * ## Adding a rule
119
+ *
120
+ * A rule is one entry in `refs`: the holder kind, the path, the target kind
121
+ * and a label, through `ref` (or `anyOf` for a field that can name several
122
+ * kinds). Its id is `k8s:<holder kind>:<path>`, which every edge, dangling
123
+ * entry and ambiguous entry it makes carries as `rule`. A target kind that
124
+ * other objects name by `metadata.name` goes in `NAMED_KINDS`, and a
125
+ * namespaced one in `NAMESPACED_KINDS` too. The test "each rule draws its
126
+ * edge" covers a new rule with no test of its own.
49
127
  */
50
128
 
51
129
  /** Workload kinds and the path to their pod spec. */
@@ -75,23 +153,49 @@ const NAMESPACED_KINDS = [
75
153
  "K8s::Rbac::RoleBinding",
76
154
  ];
77
155
 
156
+ /**
157
+ * Namespaced kinds that are scoped and named but draw no `in namespace`
158
+ * containment (#5098): an ExternalSecret and a SecretStore reach a store by
159
+ * name inside their namespace, and a report of every one whose Namespace is
160
+ * declared nowhere would bury the references this catalog is for.
161
+ */
162
+ const SCOPED_KINDS = ["K8s::ExternalSecrets::ExternalSecret", "K8s::ExternalSecrets::SecretStore"];
163
+
78
164
  /** Kinds other objects name by `metadata.name`. */
79
165
  const NAMED_KINDS = [
80
166
  ...NAMESPACED_KINDS,
167
+ ...SCOPED_KINDS,
81
168
  "K8s::Core::Namespace",
82
169
  "K8s::Core::PersistentVolume",
83
170
  "K8s::Networking::IngressClass",
84
171
  "K8s::Storage::StorageClass",
85
172
  "K8s::Rbac::ClusterRole",
173
+ "K8s::ExternalSecrets::ClusterSecretStore",
86
174
  ];
87
175
 
88
176
  /** Workloads whose pod template a Service's `app` selector can match. */
89
177
  const SELECTED_WORKLOADS = ["K8s::Apps::Deployment", "K8s::Apps::StatefulSet", "K8s::Apps::DaemonSet"];
90
178
 
91
- const identities: IdentityRule[] = NAMED_KINDS.map((kind) => ({
92
- kind,
93
- ids: SELECTED_WORKLOADS.includes(kind) ? ["metadata.name", "spec.template.metadata.labels.app"] : ["metadata.name"],
94
- }));
179
+ /**
180
+ * What else names a kind, beyond `metadata.name`: a workload by its pod
181
+ * template's `app` label, and a Secret by the `name` and `server` an Argo CD
182
+ * cluster registration holds (#5101). `k8sDeclaredNode` (./cluster-secret.ts)
183
+ * puts them under `argoCluster` on a cluster Secret and on no other, so a
184
+ * Secret with a `stringData.name` of its own is not read as one.
185
+ */
186
+ const EXTRA_IDS: Record<string, string[]> = {
187
+ ...Object.fromEntries(SELECTED_WORKLOADS.map((kind) => [kind, ["spec.template.metadata.labels.app"]])),
188
+ "K8s::Core::Secret": ["argoCluster.name", "argoCluster.server"],
189
+ };
190
+
191
+ /** Objects that can name a chart and the values files for it (#5100); the reader stamps `helmReferences` on them (./helm-references.ts). */
192
+ const HELM_HOLDERS = ["K8s::Argo::Application", "K8s::Argo::ApplicationSet", "K8s::Kustomize::Kustomization"];
193
+
194
+ const identities: IdentityRule[] = [
195
+ ...NAMED_KINDS.map((kind) => ({ kind, ids: ["metadata.name", ...(EXTRA_IDS[kind] ?? [])] })),
196
+ // A values file is the helm lexicon's node, read by this lexicon's reader and named by its workspace-relative path (#5100).
197
+ { kind: "Helm::Values", ids: ["path"] },
198
+ ];
95
199
 
96
200
  type Rel = RefRule["relation"];
97
201
 
@@ -122,6 +226,147 @@ function podSpecRules(kind: string, p: string): RefRule[] {
122
226
  ];
123
227
  }
124
228
 
229
+ const EXTERNAL_SECRET = "K8s::ExternalSecrets::ExternalSecret";
230
+ const STORE_KINDS = ["K8s::ExternalSecrets::SecretStore", "K8s::ExternalSecrets::ClusterSecretStore"] as const;
231
+ const SECRET_KEY_PATHS = ["spec.data[].remoteRef.key", "spec.dataFrom[].extract.key"] as const;
232
+
233
+ const first = (node: IRNode, path: string): string | undefined => readPath(node.attrs, path).find((v) => v !== "");
234
+
235
+ /** The store kind an ExternalSecret names: `SecretStore` unless it says otherwise. */
236
+ const storeKindOf = (holder: IRNode): string => `K8s::ExternalSecrets::${first(holder, "spec.secretStoreRef.kind") ?? "SecretStore"}`;
237
+
238
+ /** The store rule for one store kind: reads only the ExternalSecrets that name a store of that kind. */
239
+ function storeRule(targetKind: (typeof STORE_KINDS)[number]): RefRule {
240
+ return {
241
+ from: EXTERNAL_SECRET,
242
+ path: "spec.secretStoreRef.name",
243
+ targetKind,
244
+ relation: "reference",
245
+ label: "reads through",
246
+ join(holder, find) {
247
+ const name = first(holder, "spec.secretStoreRef.name");
248
+ if (name === undefined || storeKindOf(holder) !== targetKind) return [];
249
+ return [{ value: name, targets: find(name).filter((n) => n.kind === targetKind), via: "secretStoreRef" }];
250
+ },
251
+ };
252
+ }
253
+
254
+ /** The one store an ExternalSecret reads through, or undefined when it is missing or ambiguous (the store rule reports that). */
255
+ function storeOf(holder: IRNode, find: (value: string) => readonly IRNode[]): IRNode | undefined {
256
+ const name = first(holder, "spec.secretStoreRef.name");
257
+ if (name === undefined) return undefined;
258
+ const stores = find(name).filter((n) => n.kind === storeKindOf(holder));
259
+ return stores.length === 1 ? stores[0] : undefined;
260
+ }
261
+
262
+ /**
263
+ * The secret rule for one key path and one secret manager: the cloud secret a
264
+ * key names inside the scope its store names, `inScope` deciding what counts
265
+ * as inside. Reads only the ExternalSecrets whose store is of `provider`.
266
+ */
267
+ function secretRule(path: string, targetKind: string, provider: (store: IRNode) => string | undefined, inScope: (secret: IRNode, scope: string) => boolean): RefRule {
268
+ return {
269
+ from: EXTERNAL_SECRET,
270
+ path,
271
+ targetKind,
272
+ relation: "reference",
273
+ label: "reads secret",
274
+ join(holder, find) {
275
+ const store = storeOf(holder, find);
276
+ const scope = store && provider(store);
277
+ if (!store || scope === undefined) return [];
278
+ const refs: JoinedRef[] = [];
279
+ for (const key of new Set(readPath(holder.attrs, path))) {
280
+ const targets = find(key).filter((n) => n.kind === targetKind && inScope(n, scope));
281
+ refs.push({ value: key, targets, via: `remoteRef.key via ${first(store, "metadata.name") ?? store.id}`, through: store });
282
+ }
283
+ return refs;
284
+ },
285
+ };
286
+ }
287
+
288
+ const gcpProject = (store: IRNode) => first(store, "spec.provider.gcpsm.projectID");
289
+ const awsRegion = (store: IRNode) => (first(store, "spec.provider.aws.service") === "SecretsManager" ? first(store, "spec.provider.aws.region") : undefined);
290
+
291
+ const externalSecretRules: RefRule[] = [
292
+ ...STORE_KINDS.map(storeRule),
293
+ ...SECRET_KEY_PATHS.flatMap((path) => [
294
+ secretRule(path, "google_secret_manager_secret", gcpProject, (secret, project) => first(secret, "project") === project),
295
+ // The resource sets `region` only when it is not the provider's, so an AWS secret without one matches on its name.
296
+ secretRule(path, "aws_secretsmanager_secret", awsRegion, (secret, region) => (first(secret, "region") ?? region) === region),
297
+ ]),
298
+ ];
299
+ /**
300
+ * The cloud kinds a cluster Secret's `name` can be the literal name of (#5101).
301
+ * The `registers` rule has one entry per kind under one id, so the Secret
302
+ * dangles only when no kind matches.
303
+ */
304
+ const CLUSTER_KINDS = ["google_container_cluster", "aws_eks_cluster", "azurerm_kubernetes_cluster"];
305
+
306
+ const SERVICE_ACCOUNT = "K8s::Core::ServiceAccount";
307
+ export const GKE_ANNOTATION = 'metadata.annotations["iam.gke.io/gcp-service-account"]';
308
+ export const EKS_ANNOTATION = 'metadata.annotations["eks.amazonaws.com/role-arn"]';
309
+
310
+ const GCP_EMAIL = /^([a-z][a-z0-9-]*)@([a-z][a-z0-9-]*)\.iam\.gserviceaccount\.com$/i;
311
+ const AWS_ROLE_ARN = /^arn:aws[a-z-]*:iam::(\d{12}):role\/(?:(.*)\/)?([^/]+)$/;
312
+
313
+ /**
314
+ * The cloud identity a ServiceAccount's annotation names (#5099). Neither
315
+ * value is one identifier a target carries, so both are rules with a `join`:
316
+ *
317
+ * - GKE Workload Identity, `iam.gke.io/gcp-service-account`. The email is
318
+ * `<account_id>@<project>.iam.gserviceaccount.com`, and a
319
+ * `google_service_account` declares those two arguments while its email is
320
+ * computed. The rule finds the account by `account_id` and keeps the ones
321
+ * whose literal `project` is the email's, so two accounts of one id in
322
+ * different projects are told apart.
323
+ * - EKS IRSA, `eks.amazonaws.com/role-arn`. The role is found by the last
324
+ * segment of the ARN, kept when its literal `path` agrees with the ARN's
325
+ * and, if its literal `arn` is set, the account id agrees too. Terraform
326
+ * does not hold the account id otherwise, so a role with no `arn` argument
327
+ * is matched on its name and path.
328
+ *
329
+ * A value of another shape names no node, so it is dangling.
330
+ */
331
+ const identityRules: RefRule[] = [
332
+ {
333
+ from: SERVICE_ACCOUNT,
334
+ path: GKE_ANNOTATION,
335
+ targetKind: "google_service_account",
336
+ relation: "reference",
337
+ label: "acts as",
338
+ join(holder, find) {
339
+ const email = first(holder, GKE_ANNOTATION);
340
+ if (email === undefined) return [];
341
+ const m = GCP_EMAIL.exec(email);
342
+ const targets = m ? find(m[1]).filter((n) => n.kind === "google_service_account" && first(n, "account_id") === m[1] && first(n, "project") === m[2]) : [];
343
+ return [{ value: email, targets, via: "iam.gke.io/gcp-service-account" }];
344
+ },
345
+ },
346
+ {
347
+ from: SERVICE_ACCOUNT,
348
+ path: EKS_ANNOTATION,
349
+ targetKind: "aws_iam_role",
350
+ relation: "reference",
351
+ label: "acts as",
352
+ join(holder, find) {
353
+ const arn = first(holder, EKS_ANNOTATION);
354
+ if (arn === undefined) return [];
355
+ const m = AWS_ROLE_ARN.exec(arn);
356
+ const targets = m
357
+ ? find(m[3]).filter((n) => {
358
+ if (n.kind !== "aws_iam_role" || first(n, "name") !== m[3]) return false;
359
+ const path = first(n, "path");
360
+ if (path !== undefined && path.replace(/^\/|\/$/g, "") !== (m[2] ?? "")) return false;
361
+ const own = first(n, "arn")?.match(/^arn:aws[a-z-]*:iam::(\d{12}):/);
362
+ return own === null || own === undefined || own[1] === m[1];
363
+ })
364
+ : [];
365
+ return [{ value: arn, targets, via: "eks.amazonaws.com/role-arn" }];
366
+ },
367
+ },
368
+ ];
369
+
125
370
  const refs: RefRule[] = [
126
371
  // ── containment: the namespace an object is in ──
127
372
  ...NAMESPACED_KINDS.map((kind) => ref(kind, "metadata.namespace", "K8s::Core::Namespace", "in namespace", "containment")),
@@ -141,6 +386,11 @@ const refs: RefRule[] = [
141
386
  ref("K8s::Networking::Ingress", "spec.tls[].secretName", "K8s::Core::Secret", "tls"),
142
387
  ref("K8s::Networking::Ingress", "spec.ingressClassName", "K8s::Networking::IngressClass", "class"),
143
388
 
389
+ // ── Argo CD (#5101): where an Application deploys, and the cluster a registration names ──
390
+ ...anyOf("K8s::Argo::Application", "spec.destination.name", ["K8s::Core::Secret"], "deploys to"),
391
+ ...anyOf("K8s::Argo::Application", "spec.destination.server", ["K8s::Core::Secret"], "deploys to"),
392
+ ...CLUSTER_KINDS.map((kind) => ref("K8s::Core::Secret", "argoCluster.name", kind, "registers")),
393
+
144
394
  // ── scaling, storage, RBAC ──
145
395
  ...anyOf("K8s::Autoscaling::HorizontalPodAutoscaler", "spec.scaleTargetRef.name", ["K8s::Apps::Deployment", "K8s::Apps::StatefulSet", "K8s::Apps::ReplicaSet"], "scales"),
146
396
  ref("K8s::Core::PersistentVolumeClaim", "spec.volumeName", "K8s::Core::PersistentVolume", "bound to"),
@@ -152,6 +402,37 @@ const refs: RefRule[] = [
152
402
  ...anyOf("K8s::Rbac::ClusterRoleBinding", "subjects[].name", ["K8s::Core::ServiceAccount"], "grants"),
153
403
  ref("K8s::Core::ServiceAccount", "secrets[].name", "K8s::Core::Secret", "token"),
154
404
  ref("K8s::Core::ServiceAccount", "imagePullSecrets[].name", "K8s::Core::Secret", "pulls with"),
405
+
406
+ // ── External Secrets: the store, and the cloud secret through it ──
407
+ ...externalSecretRules,
408
+
409
+ // ── cloud identity: the account a ServiceAccount acts as ──
410
+ ...identityRules,
411
+
412
+ // ── Helm values files (#5100): a path that names no file is dangling ──
413
+ ...HELM_HOLDERS.map((kind) => ref(kind, "helmReferences.valuesFiles[]", "Helm::Values", "values")),
414
+ ];
415
+
416
+ /** A namespaced object's names are unique inside its namespace (#5097). */
417
+ const scopes: ScopeRule[] = [
418
+ ...[...NAMESPACED_KINDS, ...SCOPED_KINDS, "K8s::Argo::Application"].map((kind) => ({ kind, path: "metadata.namespace" })),
419
+ // A values file is read once per member that names it, and is held by that member alone: every holder reaches the one in its own member (#5100).
420
+ { kind: "Helm::Values" },
421
+ ];
422
+
423
+ /** An ApplicationSet's generated Applications (#5102). */
424
+ const generates: GenerateRule[] = [
425
+ {
426
+ from: APPLICATION_SET,
427
+ path: "spec.generators",
428
+ targetKind: APPLICATION,
429
+ label: "generates",
430
+ generate: generateApplications,
431
+ // A clusters generator selected the Secret, so the generated Application deploys to it whatever namespace either sits in.
432
+ cluster: { path: "generators[].clusters", targetKind: "K8s::Core::Secret", label: "deploys to" },
433
+ // A generated Application is stamped as the reader stamps one written by hand, so its values files and their extraObjects are nodes too (#5094).
434
+ files: generatedValuesNodes,
435
+ },
155
436
  ];
156
437
 
157
- export const k8sReferenceCatalog: ReferenceCatalog = { identities, refs };
438
+ export const k8sReferenceCatalog: ReferenceCatalog = { identities, refs, scopes, declaredNode: k8sDeclaredNode, registersCluster, generates, pathRefs: applicationPathRules };
@@ -0,0 +1,8 @@
1
+ apiVersion: kustomize.config.k8s.io/v1beta1
2
+ kind: Kustomization
3
+
4
+ helmCharts:
5
+ - name: absent
6
+ repo: https://charts.invalid.example
7
+ releaseName: absent
8
+ version: 9.9.9
@@ -0,0 +1,3 @@
1
+ apiVersion: v2
2
+ name: webchart
3
+ version: 0.1.0
@@ -0,0 +1,6 @@
1
+ apiVersion: v1
2
+ kind: ConfigMap
3
+ metadata:
4
+ name: {{ .Release.Name }}-config
5
+ data:
6
+ message: {{ .Values.message | quote }}
@@ -0,0 +1 @@
1
+ message: default
@@ -0,0 +1,9 @@
1
+ apiVersion: kustomize.config.k8s.io/v1beta1
2
+ kind: Kustomization
3
+ namespace: web
4
+
5
+ helmCharts:
6
+ - name: webchart
7
+ releaseName: web
8
+ version: 0.1.0
9
+ valuesFile: values.yaml
@@ -0,0 +1 @@
1
+ message: hello from values
@@ -0,0 +1,34 @@
1
+ apiVersion: v1
2
+ kind: Secret
3
+ metadata:
4
+ name: cluster-prod
5
+ namespace: argocd
6
+ labels:
7
+ argocd.argoproj.io/secret-type: cluster
8
+ type: Opaque
9
+ stringData:
10
+ name: prod
11
+ server: https://10.0.0.1
12
+ config: |
13
+ {"bearerToken": "not-a-real-token", "tlsClientConfig": {"caData": "not-a-real-ca"}}
14
+ ---
15
+ apiVersion: v1
16
+ kind: Secret
17
+ metadata:
18
+ name: cluster-staging
19
+ namespace: argocd
20
+ labels:
21
+ argocd.argoproj.io/secret-type: cluster
22
+ data:
23
+ name: c3RhZ2luZw==
24
+ server: aHR0cHM6Ly8xMC4wLjAuMg==
25
+ config: eyJiZWFyZXJUb2tlbiI6Im5vdC1hLXJlYWwtdG9rZW4ifQ==
26
+ ---
27
+ apiVersion: v1
28
+ kind: Secret
29
+ metadata:
30
+ name: db-login
31
+ namespace: argocd
32
+ stringData:
33
+ name: orders
34
+ password: not-a-real-password
@@ -0,0 +1,43 @@
1
+ apiVersion: argoproj.io/v1alpha1
2
+ kind: Application
3
+ metadata:
4
+ name: guestbook
5
+ namespace: argocd
6
+ spec:
7
+ project: team-a
8
+ source:
9
+ repoURL: https://github.com/example/guestbook
10
+ path: deploy
11
+ destination:
12
+ server: https://kubernetes.default.svc
13
+ namespace: guestbook
14
+ ---
15
+ apiVersion: argoproj.io/v1alpha1
16
+ kind: ApplicationSet
17
+ metadata:
18
+ name: services
19
+ namespace: argocd
20
+ spec:
21
+ generators:
22
+ - list:
23
+ elements:
24
+ - name: payments
25
+ template:
26
+ metadata:
27
+ name: "{{name}}"
28
+ spec:
29
+ project: team-a
30
+ source:
31
+ repoURL: https://github.com/example/services
32
+ path: "services/{{name}}"
33
+ destination:
34
+ server: https://kubernetes.default.svc
35
+ ---
36
+ apiVersion: argoproj.io/v1alpha1
37
+ kind: AppProject
38
+ metadata:
39
+ name: team-a
40
+ namespace: argocd
41
+ spec:
42
+ sourceRepos:
43
+ - "*"
@@ -0,0 +1,27 @@
1
+ apiVersion: apps/v1
2
+ kind: Deployment
3
+ metadata:
4
+ name: web
5
+ spec:
6
+ replicas: 2
7
+ selector:
8
+ matchLabels:
9
+ app: web
10
+ template:
11
+ metadata:
12
+ labels:
13
+ app: web
14
+ spec:
15
+ containers:
16
+ - name: web
17
+ image: example/web:1
18
+ ---
19
+ apiVersion: v1
20
+ kind: Service
21
+ metadata:
22
+ name: web
23
+ spec:
24
+ selector:
25
+ app: web
26
+ ports:
27
+ - port: 80
@@ -0,0 +1,15 @@
1
+ apiVersion: external-secrets.io/v1
2
+ kind: ExternalSecret
3
+ metadata:
4
+ name: web-creds
5
+ spec:
6
+ refreshInterval: 1h
7
+ secretStoreRef:
8
+ kind: ClusterSecretStore
9
+ name: main-store
10
+ target:
11
+ name: web-creds
12
+ data:
13
+ - secretKey: password
14
+ remoteRef:
15
+ key: web/password
@@ -0,0 +1,6 @@
1
+ {{- if .Values.enabled }}
2
+ apiVersion: v1
3
+ kind: ConfigMap
4
+ metadata:
5
+ name: gated
6
+ {{- end }}
@@ -0,0 +1,4 @@
1
+ apiVersion: v1
2
+ kind: ConfigMap
3
+ metadata:
4
+ name: {{ .Values.x }}
@@ -0,0 +1,6 @@
1
+ apiVersion: v1
2
+ kind: ConfigMap
3
+ metadata:
4
+ name: settings
5
+ data:
6
+ mode: plain
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The kustomize, argo-app and flux-kustomization member kinds this lexicon
2
+ * The kustomize, argo-app, flux-kustomization and manifests member kinds this lexicon
3
3
  * supplies to a chant workspace (#3179): data in `workspace-kinds.json`,
4
4
  * exported at `./workspace-kinds`.
5
5
  */
@@ -28,6 +28,14 @@ describeWorkspaceKindConformance({
28
28
  { name: "an Argo Application beside a kustomization.yaml", kind: "argo-app", files: { "kustomization.yaml": kustomization, "app.yaml": argo }, claims: true },
29
29
  { name: "a Deployment", kind: "argo-app", files: { "deploy.yaml": "apiVersion: apps/v1\nkind: Deployment\n" }, claims: false },
30
30
  { name: "an Application of another group", kind: "argo-app", files: { "app.yaml": "apiVersion: app.k8s.io/v1beta1\nkind: Application\n" }, claims: false },
31
+ { name: "an ApplicationSet alone", kind: "argo-app", files: { "set.yaml": "apiVersion: argoproj.io/v1alpha1\nkind: ApplicationSet\nmetadata:\n name: s\n" }, claims: true },
32
+ { name: "an AppProject alone", kind: "argo-app", files: { "project.yaml": "apiVersion: argoproj.io/v1alpha1\nkind: AppProject\nmetadata:\n name: p\n" }, claims: true },
33
+ // Plain manifests (305) rank below every other kind that reads YAML.
34
+ { name: "a Deployment", kind: "manifests", files: { "deploy.yaml": "apiVersion: apps/v1\nkind: Deployment\n" }, claims: true },
35
+ { name: "a custom resource", kind: "manifests", files: { "es.yml": "apiVersion: external-secrets.io/v1\nkind: ExternalSecret\n" }, claims: true },
36
+ { name: "a values file", kind: "manifests", files: { "values.yaml": "replicas: 2\nimage: web\n" }, claims: false },
37
+ { name: "a chart template with a block action", kind: "manifests", files: { "cm.yaml": "{{- if .Values.x }}\napiVersion: v1\nkind: ConfigMap\n{{- end }}\n" }, claims: false },
38
+ { name: "manifests beside a kustomization.yaml are claimed by kustomize", kind: "kustomize", files: { "kustomization.yaml": kustomization, "deploy.yaml": "apiVersion: apps/v1\nkind: Deployment\n" }, claims: true },
31
39
  { name: "a Flux Kustomization", kind: "flux-kustomization", files: { "sync.yaml": flux }, claims: true },
32
40
  { name: "kustomize's own kustomization.yaml is not a Flux one", kind: "flux-kustomization", files: { "kustomization.yaml": kustomization }, claims: false },
33
41
  { name: "a manifest that is not YAML", kind: "flux-kustomization", files: { "sync.yaml": "{{ not: [yaml" }, claims: false },