Skip to content

Commit d571c3d

Browse files
committed
Validate multicluster access provider paths
Signed-off-by: kahirokunn <okinakahiro@gmail.com>
1 parent 7406a0a commit d571c3d

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

config/charts/knative-operator/templates/access-providers-config.yaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@
1818
{{- fail "knative_operator.multicluster.enabled is true but knative_operator.multicluster.accessProvidersConfig is empty; either provide an access-providers config or disable multi-cluster support" }}
1919
{{- end }}
2020
{{- $mountPaths := list }}
21-
{{- range ($mc.plugins | default (list)) }}
22-
{{- $mountPaths = append $mountPaths .mountPath }}
21+
{{- range $index, $plugin := ($mc.plugins | default (list)) }}
22+
{{- $mountPath := $plugin.mountPath | default "" | toString | clean }}
23+
{{- if not (hasPrefix "/" $mountPath) }}
24+
{{- fail (printf "knative_operator.multicluster.plugins[%d].mountPath must be an absolute path, got %q" $index ($plugin.mountPath | default "" | toString)) }}
25+
{{- end }}
26+
{{- $mountPaths = append $mountPaths $mountPath }}
2327
{{- end }}
2428
{{- $cfg := $mc.accessProvidersConfig | default dict }}
2529
{{- range ($cfg.providers | default (list)) }}
26-
{{- $cmd := (.execConfig | default dict).command | default "" }}
27-
{{- if $cmd }}
28-
{{- $cmdDir := dir $cmd }}
29-
{{- if not (has $cmdDir $mountPaths) }}
30-
{{- fail (printf "provider %q: command dir %q does not match any plugins[].mountPath %v" .name $cmdDir $mountPaths) }}
30+
{{- $rawCmd := (.execConfig | default dict).command | default "" | toString }}
31+
{{- $cmd := $rawCmd | clean }}
32+
{{- if $rawCmd }}
33+
{{- $matched := false }}
34+
{{- range $mountPath := $mountPaths }}
35+
{{- if hasPrefix (printf "%s/" $mountPath) $cmd }}
36+
{{- $matched = true }}
37+
{{- end }}
38+
{{- end }}
39+
{{- if not $matched }}
40+
{{- fail (printf "provider %q: command %q is not under any plugins[].mountPath %v" .name $cmd $mountPaths) }}
3141
{{- end }}
3242
{{- end }}
3343
{{- end }}

config/charts/knative-operator/templates/operator.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,13 @@ spec:
867867
- name: access-config
868868
mountPath: /etc/cluster-inventory
869869
readOnly: true
870-
{{- range ($mc.plugins | default list) }}
870+
{{- range $index, $plugin := ($mc.plugins | default list) }}
871+
{{- $mountPath := $plugin.mountPath | default "" | toString | clean }}
872+
{{- if not (hasPrefix "/" $mountPath) }}
873+
{{- fail (printf "knative_operator.multicluster.plugins[%d].mountPath must be an absolute path, got %q" $index ($plugin.mountPath | default "" | toString)) }}
874+
{{- end }}
871875
- name: {{ .name }}
872-
mountPath: {{ .mountPath }}
876+
mountPath: {{ $mountPath }}
873877
readOnly: true
874878
{{- end }}
875879
{{- end }}

config/charts/knative-operator/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ knative_operator:
1717
# command: /access-plugins/kubeconfig-secretreader/bin/kubeconfig-secretreader-plugin
1818
# interactiveMode: Never
1919
# provideClusterInfo: true
20-
# plugins[] uses the Kubernetes "image" volume type
20+
# plugins[] uses the Kubernetes "image" volume type. Each mountPath must be
21+
# absolute, and each execConfig.command must point under one of these paths.
2122
plugins: []
2223
# plugins:
2324
# - name: secretreader

docs/multicluster.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ knative_operator:
7474
```
7575

7676
The chart creates a `ConfigMap` with the provider config and mounts each
77-
plugin as a Kubernetes image volume inside the operator pod.
77+
plugin as a Kubernetes image volume inside the operator pod. Each
78+
`plugins[].mountPath` must be absolute, and each `execConfig.command` must
79+
point under a plugin mount path, not at the mount directory itself.
7880

7981
## Namespace configuration
8082

0 commit comments

Comments
 (0)