diff --git a/docs/agents/overview.md b/docs/agents/overview.md index c1bec109d..e4a06a985 100644 --- a/docs/agents/overview.md +++ b/docs/agents/overview.md @@ -52,15 +52,14 @@ Every package is a Helm chart following the umbrella chart pattern: ```text packages/// -├── Chart.yaml # Chart definition and parameter docs -├── Makefile # Development workflow targets -├── charts/ # Vendored upstream charts -├── images/ # Dockerfiles and image build context -├── patches/ # Optional upstream chart patches -├── templates/ # Additional manifests -├── templates/dashboard-resourcemap.yaml # Dashboard resource mapping -├── values.yaml # Override values for upstream -└── values.schema.json # JSON schema for validation and UI +├── Chart.yaml # Chart definition and parameter docs +├── Makefile # Development workflow targets +├── charts/ # Vendored upstream charts +├── images/ # Dockerfiles and image build context +├── patches/ # Optional upstream chart patches +├── templates/ # Additional manifests +├── values.yaml # Override values for upstream +└── values.schema.json # JSON schema for validation and UI ``` ## Build and Development Commands diff --git a/hack/check-nats-rd-secrets.bats b/hack/check-nats-rd-secrets.bats index 855cb6fb1..10e300251 100644 --- a/hack/check-nats-rd-secrets.bats +++ b/hack/check-nats-rd-secrets.bats @@ -13,15 +13,12 @@ # object the controller itself produced, whereas a name grant conveys whatever # happens to occupy the name. # -# These assertions exist because both halves are one edit away from breaking -# with a fully green chart suite, for two different reasons. The -# ResourceDefinition is rendered, by the nats-rd chart inlining cozyrds/*, but -# that chart carries neither a tests directory nor the test target -# hack/helm-unit-tests.sh looks for. -# The dashboard Role is rendered by a chart that has both, and no suite under -# packages/apps/nats/tests/ asserts on it. +# These assertions exist because the grant is one edit away from breaking with +# a fully green chart suite. The ResourceDefinition is rendered by the nats-rd +# chart inlining cozyrds/*, but that chart carries neither a tests directory nor +# the test target hack/helm-unit-tests.sh looks for. # -# The grants are asserted as WHITELISTS against rendered output rather than as +# The grants are asserted as WHITELISTS against whole values rather than as # a blacklist of forbidden names over source text. A blacklist grepping for # "{{ .Release.Name }}-ca" is defeated by quoting the scalar, by $.Release.Name, # or by a fullname helper -- all of which grant the CA private key while the @@ -31,7 +28,6 @@ load test_helper REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)" COZYRDS="$REPO_ROOT/packages/system/nats-rd/cozyrds/nats.yaml" -CHART="$REPO_ROOT/packages/apps/nats" # The complete set of grants the tenant holds, asserted as one value rather than # per-dimension: a name whitelist alone passes an added label selector, and a @@ -40,16 +36,6 @@ CHART="$REPO_ROOT/packages/apps/nats" # them, so a selector on it is a one-line grant of the CA private key. EXPECTED_RD_INCLUDE='[{"resourceNames":["nats-{{ .name }}-credentials"]},{"matchLabels":{"internal.cozystack.io/tenant-ca":"true"}}]' -# The dashboard template's entire RBAC output: every rule of the Role, and the -# kinds it renders. Asserted whole rather than filtered down to the rules that mention -# secrets, because every filter admits the spelling it did not anticipate: a rule -# with no resourceNames names no Secret, a rule with resources ["*"] names no -# resource, and a ClusterRole is not a Role. Each of those reaches both -# key-bearing Secrets. There is no filter that is right for all of them, and one -# comparison against the whole output needs none. -EXPECTED_ROLE_RULES='[{"apiGroups":[""],"resources":["services"],"resourceNames":["nats-test"],"verbs":["get","list","watch"]},{"apiGroups":[""],"resources":["secrets"],"resourceNames":["nats-test-credentials"],"verbs":["get","list","watch"]},{"apiGroups":["cozystack.io"],"resources":["workloadmonitors"],"resourceNames":["nats-test"],"verbs":["get","list","watch"]}]' -EXPECTED_RBAC_KINDS='["Role","RoleBinding"]' - # Subsumed by the whitelist below, which cannot match without this entry. Kept # because the runner stops at the first failing test, so this one fires first # and says what the loss costs rather than printing two JSON blobs to diff. @@ -86,50 +72,3 @@ EXPECTED_RBAC_KINDS='["Role","RoleBinding"]' exit 1 fi } - -# Asserted against RENDERED output, so the spelling used in the template -- -# quoted, helper-derived, or otherwise -- cannot smuggle a name past the check. -@test "nats dashboard Role renders exactly the grants it is supposed to" { - if [ ! -d "$CHART" ]; then - echo "Chart not found at $CHART -- did it move?" >&2 - exit 1 - fi - - # stderr is deliberately not discarded: when the render breaks, helm's own - # message is the only thing that says why, and a CI red showing just - # "helm template failed" sends the reader back here to rerun it by hand. - rendered=$(helm template nats-test "$CHART" \ - --namespace tenant-test \ - --set '_cluster.cluster-domain=cozy.local' \ - --show-only templates/dashboard-resourcemap.yaml) || { - echo "helm template failed for $CHART" >&2 - exit 1 - } - - # eval-all aggregates the documents into one result, so the Role may sit at any - # position among them. - kinds=$(printf '%s\n' "$rendered" | yq eval-all --output-format=json --indent=0 \ - '[.kind]' -) || exit 1 - - if [ "$kinds" != "$EXPECTED_RBAC_KINDS" ]; then - echo "Unexpected RBAC kinds rendered by the nats dashboard template: $kinds" >&2 - echo "Expected exactly: $EXPECTED_RBAC_KINDS" >&2 - echo "A ClusterRole here would grant across namespaces and is not covered by" >&2 - echo "the rule comparison below, which reads the namespaced Role." >&2 - exit 1 - fi - - # Fails closed on an empty list: a Role that stopped granting anything, or a - # render that silently produced nothing, does not match the expected rules. - rules=$(printf '%s\n' "$rendered" | yq eval-all --output-format=json --indent=0 \ - '[select(.kind == "Role") | .rules[]]' -) || exit 1 - - if [ "$rules" != "$EXPECTED_ROLE_RULES" ]; then - echo "Unexpected rules in the nats dashboard Role: $rules" >&2 - echo "Expected exactly: $EXPECTED_ROLE_RULES" >&2 - echo "nats--ca holds the CA PRIVATE KEY and nats--tls the" >&2 - echo "server private key. The trust anchor reaches the tenant as the key-free" >&2 - echo ".tenant-ca projection via tenantsecrets, not by a Role grant." >&2 - exit 1 - fi -} diff --git a/hack/check-opensearch-readme.bats b/hack/check-opensearch-readme.bats index 695b74dd2..c0a2b3b4e 100644 --- a/hack/check-opensearch-readme.bats +++ b/hack/check-opensearch-readme.bats @@ -46,8 +46,7 @@ COZYRDS="$REPO_ROOT/packages/system/opensearch-rd/cozyrds/opensearch.yaml" # The key-free trust anchor the CA-extraction controller publishes, selected by # label rather than by name. This entry is the whole tenant read path: it drives the # lineage webhook's tenantresource verdict, and the tenant reads the projection - # through core.cozystack.io/tenantsecrets, which the base tenant roles grant. The - # chart Role grants no name for it — tests/dashboard-resourcemap_test.yaml pins that. + # through core.cozystack.io/tenantsecrets, which the base tenant roles grant. grep -q "internal.cozystack.io/tenant-ca" "$COZYRDS" } diff --git a/hack/check-rabbitmq-rd-secrets.bats b/hack/check-rabbitmq-rd-secrets.bats index 2fe8a5be9..869f42111 100644 --- a/hack/check-rabbitmq-rd-secrets.bats +++ b/hack/check-rabbitmq-rd-secrets.bats @@ -14,11 +14,9 @@ # sentinel. The label selected on below is stamped by the CA-extraction # controller on the projection it writes, never on the CA Secret. # -# These assertions exist because both halves are one edit away from breaking with +# These assertions exist because the grant is one edit away from breaking with # a fully green chart suite. The ResourceDefinition is rendered by the rabbitmq-rd -# chart inlining cozyrds/*, and that chart carries no tests directory; the -# dashboard Role is rendered by a chart that has one, but no suite there asserts -# on the whole Role. +# chart inlining cozyrds/*, and that chart carries no tests directory. # # The grants are asserted as WHITELISTS against whole values rather than as a # blacklist of forbidden names over source text. A blacklist grepping for @@ -30,7 +28,6 @@ load test_helper REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)" COZYRDS="$REPO_ROOT/packages/system/rabbitmq-rd/cozyrds/rabbitmq.yaml" -CHART="$REPO_ROOT/packages/apps/rabbitmq" # The complete set of grants the tenant holds, asserted as one value rather than # per-dimension: a name whitelist alone passes an added label selector, and a @@ -44,31 +41,6 @@ EXPECTED_RD_INCLUDE='[{"resourceNames":["rabbitmq-{{ .name }}-default-user"]},{" # reason as the include: dropping one entry is the edit that has to be caught. EXPECTED_RD_EXCLUDE='[{"resourceNames":["rabbitmq-{{ .name }}-ca","rabbitmq-{{ .name }}-tls","rabbitmq-{{ .name }}-erlang-cookie"]}]' -# The dashboard template's entire RBAC output: every rule of the Role, and the -# kinds it renders. Asserted whole rather than filtered down to the rules that -# mention secrets, because every filter admits the spelling it did not anticipate: -# a rule with no resourceNames names no Secret, a rule with resources ["*"] names -# no resource, and a ClusterRole is not a Role. Each of those reaches both -# key-bearing Secrets, and one comparison against the whole output needs no filter. -EXPECTED_RBAC_KINDS='["Role","RoleBinding"]' -EXPECTED_ROLE_RULES='[{"apiGroups":[""],"resources":["secrets"],"resourceNames":["rabbitmq-test-default-user"],"verbs":["get","list","watch"]},{"apiGroups":[""],"resources":["services"],"resourceNames":["rabbitmq-test"],"verbs":["get","list","watch"]},{"apiGroups":["cozystack.io"],"resources":["workloadmonitors"],"resourceNames":["rabbitmq-test"],"verbs":["get","list","watch"]}]' - -# The secrets rule is the one place in this Role that grows from values, so the -# whole-value assertion above only covers it while users is empty. This pins what -# a declared user is allowed to add: its own credentials Secret and nothing else. -EXPECTED_ROLE_RULES_WITH_USER='[{"apiGroups":[""],"resources":["secrets"],"resourceNames":["rabbitmq-test-default-user","rabbitmq-test-alice-credentials"],"verbs":["get","list","watch"]},{"apiGroups":[""],"resources":["services"],"resourceNames":["rabbitmq-test"],"verbs":["get","list","watch"]},{"apiGroups":["cozystack.io"],"resources":["workloadmonitors"],"resourceNames":["rabbitmq-test"],"verbs":["get","list","watch"]}]' - -render_rbac() { - # stderr is deliberately not discarded: when the render breaks, helm's own - # message is the only thing that says why, and a CI red showing just - # "helm template failed" sends the reader back here to rerun it by hand. - helm template rabbitmq-test "$CHART" \ - --namespace tenant-test \ - --set '_cluster.cluster-domain=cozy.local' \ - "$@" \ - --show-only templates/dashboard-resourcemap.yaml -} - # Subsumed by the whitelist below, which cannot match without this entry. Kept # because the runner stops at the first failing test, so this one fires first and # says what the loss costs rather than printing two JSON blobs to diff. @@ -122,68 +94,3 @@ render_rbac() { exit 1 fi } - -# Asserted against RENDERED output, so the spelling used in the template -- -# quoted, helper-derived, or otherwise -- cannot smuggle a name past the check. -@test "rabbitmq dashboard Role renders exactly the grants it is supposed to" { - if [ ! -d "$CHART" ]; then - echo "Chart not found at $CHART -- did it move?" >&2 - exit 1 - fi - - rendered=$(render_rbac) || { - echo "helm template failed for $CHART" >&2 - exit 1 - } - - # eval-all aggregates the documents into one result, so the Role may sit at any - # position among them. - kinds=$(printf '%s\n' "$rendered" | yq eval-all --output-format=json --indent=0 \ - '[.kind]' -) - - if [ "$kinds" != "$EXPECTED_RBAC_KINDS" ]; then - echo "Unexpected RBAC kinds rendered by the rabbitmq dashboard template: $kinds" >&2 - echo "Expected exactly: $EXPECTED_RBAC_KINDS" >&2 - echo "A ClusterRole here would grant across namespaces and is not covered by" >&2 - echo "the rule comparison below, which reads the namespaced Role." >&2 - exit 1 - fi - - # Fails closed on an empty list: a Role that stopped granting anything, or a - # render that silently produced nothing, does not match the expected rules. - rules=$(printf '%s\n' "$rendered" | yq eval-all --output-format=json --indent=0 \ - '[select(.kind == "Role") | .rules[]]' -) - - if [ "$rules" != "$EXPECTED_ROLE_RULES" ]; then - echo "Unexpected rules in the rabbitmq dashboard Role: $rules" >&2 - echo "Expected exactly: $EXPECTED_ROLE_RULES" >&2 - echo "rabbitmq--ca holds the CA PRIVATE KEY, rabbitmq--tls the" >&2 - echo "server private key, and rabbitmq--erlang-cookie the cluster secret." >&2 - echo "The trust anchor reaches the tenant as the key-free .tenant-ca" >&2 - echo "projection via tenantsecrets, not by a Role grant." >&2 - exit 1 - fi -} - -@test "a declared rabbitmq user adds only its own credentials Secret to the Role" { - if [ ! -d "$CHART" ]; then - echo "Chart not found at $CHART -- did it move?" >&2 - exit 1 - fi - - rendered=$(render_rbac --set 'users.alice.password=placeholder') || { - echo "helm template failed for $CHART" >&2 - exit 1 - } - - rules=$(printf '%s\n' "$rendered" | yq eval-all --output-format=json --indent=0 \ - '[select(.kind == "Role") | .rules[]]' -) - - if [ "$rules" != "$EXPECTED_ROLE_RULES_WITH_USER" ]; then - echo "Unexpected rules with one declared user: $rules" >&2 - echo "Expected exactly: $EXPECTED_ROLE_RULES_WITH_USER" >&2 - echo "The secrets rule is the only part of this Role that grows from values," >&2 - echo "so a name reaching it from the users loop is granted to the tenant." >&2 - exit 1 - fi -} diff --git a/hack/check-tenant-secret-grants.bats b/hack/check-tenant-secret-grants.bats new file mode 100644 index 000000000..41289cf74 --- /dev/null +++ b/hack/check-tenant-secret-grants.bats @@ -0,0 +1,114 @@ +#!/usr/bin/env bats +# Unit test: no application chart grants tenant subjects read on core Secrets. +# +# Tenants read the Secrets an application exposes through +# core.cozystack.io/tenantsecrets. cozystack-api serves that resource with its +# own identity and only for Secrets the ApplicationDefinition's +# secrets.include admits, so the allowlist lives in one place, the -rd package. +# A Role in an application chart that grants core `secrets` to the tenant's +# groups or ServiceAccount bypasses that allowlist entirely. The per-chart +# dashboard Roles did exactly that, and one of them rendered an empty +# resourceNames list, which RBAC reads as every Secret in the namespace. +# +# The check renders every chart under packages/apps and packages/extra and +# inspects the rendered output rather than the template source: a grant can be +# spelled through a helper, a quoted scalar or a range, and only the rendered +# object says what RBAC will see. A chart that fails to render fails the test, +# so a chart cannot drop out of the check unnoticed. +# +# What this does not reach: a grant gated on a value the fixtures leave unset, +# and a grant behind a lookup or a .Capabilities check, since helm template has +# no cluster. + +load test_helper + +FIXTURE_DIR="hack/testdata/render-fixtures" + +# A subject is a tenant's when it is one of the groups cozy-lib's +# subjectsForTenantAndAccessLevel emits or the tenant ServiceAccount, all of +# which are named after a tenant-* namespace. A rule grants Secrets when it +# names the core group (or every group) and the secrets resource (or every +# resource); the verbs do not matter, since get alone is a read of the value. +OFFENDING_GRANTS_JQ=' + def tenant_subject: (.kind == "Group" or .kind == "ServiceAccount") and ((.name // "") | startswith("tenant-")); + def grants_secrets: ((.apiGroups // []) | any(. == "" or . == "*")) and ((.resources // []) | any(. == "secrets" or . == "*")); + map(select(. != null)) as $docs + | [$docs[] | select(.kind == "RoleBinding" or .kind == "ClusterRoleBinding") + | select((.subjects // []) | any(tenant_subject)) | .roleRef | {kind, name}] as $refs + | [$docs[] | select(.kind == "Role" or .kind == "ClusterRole") + | select(({kind, name: .metadata.name} as $r | $refs | index([$r])) + or ((.metadata.labels // {}) | keys | any(startswith("rbac.cozystack.io/aggregate-to-tenant")))) + | {kind, name: .metadata.name, rules: [(.rules // [])[] | select(grants_secrets)]} + | select(.rules | length > 0)] +' + +# render +# Release names and values satisfy each chart's own render-time contract +# (fixed release name, fixed namespace, a required value, or a cluster lookup +# that sizing by resources avoids). Output is a JSON array of documents. +render() { + # Called inside a command substitution, so this reaches only that subshell. + # Without it a failed render feeds yq nothing and reads as a chart with no RBAC. + set -o pipefail + chart=$1 fixture=$2 + name=$(basename "$chart") + namespace=tenant-test + case "$name" in + bootbox) set -- bootbox; namespace=tenant-root ;; + computeplane|etcd|info|ingress|monitoring|seaweedfs|gateway) set -- "$name" ;; + external-dns) set -- external-dns --set provider=inmemory ;; + kubernetes-nodes) set -- kubernetes-nodes-render-check --set-string cluster=render \ + --set-string resources.cpu=2 --set-string resources.memory=4Gi ;; + tenant) set -- tenant-sub --api-versions v1.edp.epam.com/v1 ;; + vm-instance) set -- vm-instance-render-check --set-string instanceType= \ + --set-string instanceProfile= --set-string resources.cpu=1 \ + --set-string resources.sockets=1 --set-string resources.memory=1Gi ;; + *) set -- "$name-render-check" ;; + esac + helm template "$@" "$chart" --namespace "$namespace" --values "$fixture" \ + | yq eval-all --output-format=json --indent=0 '[.]' - +} + +@test "the detector flags a Role that grants tenant groups core Secrets" { + # Guards the guard: a jq filter that silently matched nothing would keep the + # repository-wide check below green forever. + manifest='[ + {"kind":"Role","metadata":{"name":"x-dashboard-resources"},"rules":[{"apiGroups":[""],"resources":["secrets"],"verbs":["get"]}]}, + {"kind":"RoleBinding","metadata":{"name":"x-dashboard-resources"},"subjects":[{"kind":"Group","name":"tenant-test-use"}],"roleRef":{"kind":"Role","name":"x-dashboard-resources"}} + ]' + found=$(printf '%s' "$manifest" | jq --compact-output "$OFFENDING_GRANTS_JQ") + if [ "$found" = "[]" ]; then + echo "The detector missed a Role granting core secrets to a tenant group" >&2 + exit 1 + fi +} + +@test "no chart under packages/apps or packages/extra grants tenant subjects core Secrets" { + failed=0 checked=0 + for chart in packages/apps/*/ packages/extra/*/; do + for fixture in "$FIXTURE_DIR"/*.yaml; do + state=$(basename "$fixture" .yaml) + if ! docs=$(render "$chart" "$fixture"); then + echo "FAIL $chart ($state): render failed" >&2 + failed=1 + continue + fi + found=$(printf '%s' "$docs" | jq --compact-output "$OFFENDING_GRANTS_JQ") || { + echo "FAIL $chart ($state): could not evaluate the rendered RBAC" >&2 + failed=1 + continue + } + if [ "$found" != "[]" ]; then + echo "FAIL $chart ($state) grants tenant subjects core Secrets: $found" >&2 + echo "Expose the Secret through the -rd secrets.include instead; tenants read it as a tenantsecret." >&2 + failed=1 + fi + checked=$((checked + 1)) + done + done + if [ "$checked" -eq 0 ]; then + echo "No chart was rendered; did packages/apps or $FIXTURE_DIR move?" >&2 + exit 1 + fi + [ "$failed" -eq 0 ] +} diff --git a/hack/e2e-chainsaw/_lib/run-kubernetes.sh b/hack/e2e-chainsaw/_lib/run-kubernetes.sh index 2b03b0681..d13ec5a31 100644 --- a/hack/e2e-chainsaw/_lib/run-kubernetes.sh +++ b/hack/e2e-chainsaw/_lib/run-kubernetes.sh @@ -6868,8 +6868,7 @@ EOF # Server-side dry-run executes Helm `lookup` against the live cluster and # renders the real storageClasses map. rc is captured separately (no pipe) so # the management-cluster state is always restored before any assertion exits. - # The release namespace must be a valid tenant identifier (the chart's - # dashboard-resourcemap template enforces this), so render under tenant-test. + # Render under tenant-test, the kind of namespace a tenant release lives in. # # `|| rc=$?` rather than a bare assignment followed by `rc=$?`: the caller runs # under `set -e`, so a failed render would exit the function on the assignment diff --git a/hack/e2e-chainsaw/mongodb/chainsaw-test.yaml b/hack/e2e-chainsaw/mongodb/chainsaw-test.yaml index 77fb02c4f..8ebdd384b 100644 --- a/hack/e2e-chainsaw/mongodb/chainsaw-test.yaml +++ b/hack/e2e-chainsaw/mongodb/chainsaw-test.yaml @@ -133,41 +133,9 @@ spec: (length(metadata.ownerReferences[?kind == 'PerconaServerMongoDB'] || `[]`)): 1 # The Secrets the operator creates for TLS all carry private key material and - # must never be reachable by a tenant. The chart tests pin this at render - # time; this pins the object that is actually deployed. - # - # Asserted as an exact list rather than as the absence of forbidden names, - # because a rule granting `secrets` with no resourceNames at all grants every - # Secret in the namespace while containing no forbidden name to match on. - # - # Two counts are asserted alongside it and neither is redundant. An - # ADDITIONAL rule naming secrets contributes no entries to the flattened name - # list, so the equality alone would still hold while every Secret became - # readable — the secrets-rule count catches that. An ADDED rule with resources - # ["*"] grants every Secret without containing the string "secrets" at all, so - # it is invisible to both — the total rule count catches that one. An existing - # rule MUTATED to ["*"] drops the secrets-rule count to zero and empties the - # flattened name list, so both assertions below fail on it as well. - - name: verify-tenant-role-grants-no-key-material - try: - - assert: - timeout: 2m - resource: - apiVersion: rbac.authorization.k8s.io/v1 - kind: Role - metadata: - name: mongodb-test-dashboard-resources - (length(rules)): 3 - (length(rules[?contains(resources, 'secrets')])): 1 - (rules[?contains(resources, 'secrets')].resourceNames[]): - - mongodb-test-credentials - # The Role is read-only by intent; verbs is the fourth RBAC axis and - # widening it is the same class as widening the other three. - (length(rules[?verbs != ['get', 'list', 'watch']])): 0 - - # The Role above is only one of the two paths a Secret can reach a tenant by. - # The other is core.cozystack.io/tenantsecrets, which surfaces whatever the - # lineage webhook stamped internal.cozystack.io/tenantresource=true from this + # must never be reachable by a tenant. A tenant reads Secrets only through + # core.cozystack.io/tenantsecrets, which surfaces whatever the lineage + # webhook stamped internal.cozystack.io/tenantresource=true from this # application's ApplicationDefinition selectors. That is the path the # secrets.include selector drives, and it is the one that would leak the CA # private key if the selector ever named the operator's Secrets instead of diff --git a/hack/e2e-chainsaw/redis/chainsaw-test.yaml b/hack/e2e-chainsaw/redis/chainsaw-test.yaml index 6f6e9ba84..2945e8351 100644 --- a/hack/e2e-chainsaw/redis/chainsaw-test.yaml +++ b/hack/e2e-chainsaw/redis/chainsaw-test.yaml @@ -190,32 +190,17 @@ spec: name: redis-secure.ca-cert type: Opaque - # Two paths carry a Secret to a tenant and both are asserted. The dashboard - # Role grants by name; core.cozystack.io/tenantsecrets serves whatever the - # lineage webhook stamped tenantresource=true from the ApplicationDefinition - # selectors, and that label-driven path is the one that would leak a - # private key if the selector ever named the cert-manager Secrets instead of - # the projection. + # A tenant reads Secrets only through core.cozystack.io/tenantsecrets, which + # serves whatever the lineage webhook stamped tenantresource=true from the + # ApplicationDefinition selectors. That label-driven path is the one that + # would leak a private key if the selector ever named the cert-manager + # Secrets instead of the projection. - name: verify-tenant-ca-projection try: - # The name-granting path, on the deployed object rather than the render: - # the Role must reach exactly the auth Secret. The unit tests pin the same - # rule, but only against the template, so a Role that fails to apply or - # gets widened in the cluster is invisible to them. - - assert: - timeout: 2m - resource: - apiVersion: rbac.authorization.k8s.io/v1 - kind: Role - metadata: - name: redis-secure-dashboard-resources - (length(rules[?contains(resources, 'secrets')])): 1 - (rules[?contains(resources, 'secrets')].resourceNames[]): - - redis-secure-auth # Positive control, and it comes first: the negatives below are satisfied # by an ABSENT label, which is also what a webhook that stamped nothing # this run looks like. The auth Secret is chart-rendered, traces to the - # Redis CR and is granted by name, so it MUST be stamped. + # Redis CR and is included by name, so it MUST be stamped. - assert: timeout: 2m resource: diff --git a/hack/helm-release-size.bats b/hack/helm-release-size.bats index 400bf295a..391c1fc8a 100644 --- a/hack/helm-release-size.bats +++ b/hack/helm-release-size.bats @@ -35,24 +35,14 @@ packages/apps/bucket packages/apps/clickhouse packages/apps/foundationdb packages/apps/harbor -packages/apps/kafka packages/apps/kubernetes packages/apps/kubernetes-nodes -packages/apps/mariadb packages/apps/mongodb packages/apps/nats -packages/apps/openbao -packages/apps/opensearch packages/apps/postgres -packages/apps/qdrant -packages/apps/rabbitmq -packages/apps/redis packages/apps/tenant -packages/apps/valkey -packages/apps/vm-disk packages/apps/vm-instance packages/apps/vpc -packages/apps/vpn packages/core/platform packages/extra/bootbox packages/extra/computeplane diff --git a/packages/apps/bucket/templates/dashboard-resourcemap.yaml b/packages/apps/bucket/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 11a033aec..000000000 --- a/packages/apps/bucket/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,34 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - secrets - resourceNames: - {{- range $name, $user := .Values.users }} - - {{ $.Release.Name }}-{{ $name }}-credentials - {{- end }} - verbs: ["get", "list", "watch"] -{{- if .Values.ui }} -- apiGroups: - - networking.k8s.io - resources: - - ingresses - resourceNames: - - {{ .Release.Name }}-ui - verbs: ["get", "list", "watch"] -{{- end }} ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/bucket/tests/ui_toggle_test.yaml b/packages/apps/bucket/tests/ui_toggle_test.yaml index eb90cc886..78c18c8b2 100644 --- a/packages/apps/bucket/tests/ui_toggle_test.yaml +++ b/packages/apps/bucket/tests/ui_toggle_test.yaml @@ -1,7 +1,6 @@ suite: bucket ui flag templates: - templates/helmrelease.yaml - - templates/dashboard-resourcemap.yaml release: name: bucket-my-bucket @@ -23,28 +22,3 @@ tests: - equal: path: spec.values.ui value: false - - - it: grants dashboard read access to the UI Ingress by default - template: templates/dashboard-resourcemap.yaml - documentIndex: 0 - asserts: - - contains: - path: rules - content: - apiGroups: ["networking.k8s.io"] - resources: ["ingresses"] - resourceNames: ["bucket-my-bucket-ui"] - verbs: ["get", "list", "watch"] - - - it: drops the Ingress rule when ui is false - template: templates/dashboard-resourcemap.yaml - documentIndex: 0 - set: - ui: false - asserts: - - lengthEqual: - path: rules - count: 1 - - notContains: - path: rules[0].resources - content: ingresses diff --git a/packages/apps/clickhouse/templates/dashboard-resourcemap.yaml b/packages/apps/clickhouse/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 042f6de6f..000000000 --- a/packages/apps/clickhouse/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,40 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - chendpoint-{{ .Release.Name }} - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-credentials - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - {{- if .Values.clickhouseKeeper.enabled }} - - {{ .Release.Name }}-keeper - {{- end }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/foundationdb/README.md b/packages/apps/foundationdb/README.md index bcbf2298a..bb70e5ab2 100644 --- a/packages/apps/foundationdb/README.md +++ b/packages/apps/foundationdb/README.md @@ -107,6 +107,16 @@ securityContext: 2. Deploy this application package with your desired configuration 3. The cluster will be automatically provisioned and configured +## Connecting a client + +The cluster file is in the `cluster-file` key of the `-config` ConfigMap, also shown on the ConfigMaps tab of the application in the console: + +```bash +kubectl get configmap -config --output jsonpath='{.data.cluster-file}' > fdb.cluster +``` + +Point the client at it with `FDB_CLUSTER_FILE=fdb.cluster`. Tenant users with the `use` level and above can read it. + ## Monitoring This package includes WorkloadMonitor integration for cluster health monitoring and resource tracking. Monitoring can be disabled by setting: diff --git a/packages/apps/foundationdb/templates/dashboard-resourcemap.yaml b/packages/apps/foundationdb/templates/dashboard-resourcemap.yaml index 4126f0e69..f74a7b083 100644 --- a/packages/apps/foundationdb/templates/dashboard-resourcemap.yaml +++ b/packages/apps/foundationdb/templates/dashboard-resourcemap.yaml @@ -1,3 +1,9 @@ +{{- /* +TODO: remove this file once Cozystack has an interface that serves +application ConfigMaps to tenants, the way tenantsecrets serves Secrets. +Until then it is the only way a tenant can read the FoundationDB cluster +file in -config. It grants ConfigMaps only, never Secrets. +*/}} --- apiVersion: v1 kind: ConfigMap @@ -13,14 +19,6 @@ data: - apiVersion: v1 kind: ConfigMap name: {{ .Release.Name }}-config - - apiVersion: apps.foundationdb.org/v1beta2 - kind: FoundationDBCluster - name: {{ .Release.Name }} - {{- if .Values.backup.enabled }} - - apiVersion: apps.foundationdb.org/v1beta2 - kind: FoundationDBBackup - name: {{ .Release.Name }}-backup - {{- end }} --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role diff --git a/packages/apps/foundationdb/tests/dashboard-resourcemap_test.yaml b/packages/apps/foundationdb/tests/dashboard-resourcemap_test.yaml index 215b1e9a6..a5847de31 100644 --- a/packages/apps/foundationdb/tests/dashboard-resourcemap_test.yaml +++ b/packages/apps/foundationdb/tests/dashboard-resourcemap_test.yaml @@ -72,6 +72,18 @@ tests: path: data.resources pattern: "apiVersion: v1\n kind: ConfigMap\n name: foundationdb-example-config" + - it: lists only the configuration in the resource map + documentSelector: + path: kind + value: ConfigMap + asserts: + - equal: + path: data.resources + value: | + - apiVersion: v1 + kind: ConfigMap + name: foundationdb-example-config + - it: renders only the existing map and the two access objects asserts: - hasDocuments: diff --git a/packages/apps/harbor/templates/dashboard-resourcemap.yaml b/packages/apps/harbor/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 89416d9e6..000000000 --- a/packages/apps/harbor/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,47 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-credentials - verbs: ["get", "list", "watch"] -- apiGroups: - - networking.k8s.io - resources: - - ingresses - resourceNames: - - {{ .Release.Name }}-ingress - - {{ .Release.Name }}-registry-ingress - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }}-core - - {{ .Release.Name }}-registry - - {{ .Release.Name }}-portal - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "super-admin" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/harbor/tests/ingress_management_whitelist_test.yaml b/packages/apps/harbor/tests/ingress_management_whitelist_test.yaml index b5d14fd7e..f0b4c3e19 100644 --- a/packages/apps/harbor/tests/ingress_management_whitelist_test.yaml +++ b/packages/apps/harbor/tests/ingress_management_whitelist_test.yaml @@ -2,7 +2,6 @@ suite: harbor managementWhitelist restricts everything but the registry paths templates: - templates/ingress.yaml - templates/httproute.yaml - - templates/dashboard-resourcemap.yaml release: name: harbor @@ -253,21 +252,3 @@ tests: - equal: path: kind value: HTTPRoute - - - it: lets the dashboard read both Ingress objects - template: templates/dashboard-resourcemap.yaml - documentSelector: - path: kind - value: Role - asserts: - - contains: - path: rules - content: - apiGroups: - - networking.k8s.io - resources: - - ingresses - resourceNames: - - harbor-ingress - - harbor-registry-ingress - verbs: ["get", "list", "watch"] diff --git a/packages/apps/kafka/templates/dashboard-resourcemap.yaml b/packages/apps/kafka/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 64af3f082..000000000 --- a/packages/apps/kafka/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,46 +0,0 @@ -{{- $showExternal := .Values.external | default false -}} -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }}-kafka-bootstrap - {{- if $showExternal }} - - {{ .Release.Name }}-kafka-external-bootstrap - {{- end }} - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-clients-ca-cert - - {{ .Release.Name }}-cluster-ca-cert - {{- range $user, $u := .Values.users }} - - {{ $.Release.Name }}.{{ $user }} - {{- end }} - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - - {{ .Release.Name }}-controller - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/kafka/tests/dashboard-resourcemap_test.yaml b/packages/apps/kafka/tests/dashboard-resourcemap_test.yaml deleted file mode 100644 index 88da0d69a..000000000 --- a/packages/apps/kafka/tests/dashboard-resourcemap_test.yaml +++ /dev/null @@ -1,215 +0,0 @@ -suite: dashboard resourcemap tests - -templates: - - templates/dashboard-resourcemap.yaml - -tests: - # Always renders Role and RoleBinding - - it: renders Role and RoleBinding - release: - name: test-kafka - namespace: tenant-test - asserts: - - hasDocuments: - count: 2 - - isKind: - of: Role - documentIndex: 0 - - isKind: - of: RoleBinding - documentIndex: 1 - - # Role naming - - it: uses correct Role name - release: - name: my-kafka - namespace: tenant-test - asserts: - - equal: - path: metadata.name - value: my-kafka-dashboard-resources - documentIndex: 0 - - # RoleBinding naming - - it: uses correct RoleBinding name - release: - name: my-kafka - namespace: tenant-test - asserts: - - equal: - path: metadata.name - value: my-kafka-dashboard-resources - documentIndex: 1 - - # Internal bootstrap service always in RBAC - - it: grants access to internal bootstrap service - release: - name: test-kafka - namespace: tenant-test - asserts: - - contains: - path: rules[0].resourceNames - content: test-kafka-kafka-bootstrap - documentIndex: 0 - - # External bootstrap service absent when external is false - - it: does not grant access to external bootstrap service when external is false - release: - name: test-kafka - namespace: tenant-test - set: - external: false - asserts: - # Anchor the rule before asserting about it. notContains passes whenever - # its path resolves to something that lacks the content, and a different - # rule at [0] qualifies, so reordering the Role would leave this green - # while the external bootstrap Service came back on the rule it names. - # A rule has no name to pin, so the anchor is the Service this rule must - # keep. - - contains: - path: rules[0].resourceNames - content: test-kafka-kafka-bootstrap - documentIndex: 0 - - notContains: - path: rules[0].resourceNames - content: test-kafka-kafka-external-bootstrap - documentIndex: 0 - - # External bootstrap service present when external is true - - it: grants access to external bootstrap service when external is true - release: - name: test-kafka - namespace: tenant-test - set: - external: true - asserts: - - contains: - path: rules[0].resourceNames - content: test-kafka-kafka-external-bootstrap - documentIndex: 0 - - # Role grants access to CA secrets - - it: grants access to clients CA cert secret - release: - name: test-kafka - namespace: tenant-test - asserts: - - contains: - path: rules[1].resourceNames - content: test-kafka-clients-ca-cert - documentIndex: 0 - - notContains: - path: rules[1].resourceNames - content: test-kafka-clients-ca - documentIndex: 0 - - - it: grants access to cluster CA cert secret - release: - name: test-kafka - namespace: tenant-test - asserts: - - contains: - path: rules[1].resourceNames - content: test-kafka-cluster-ca-cert - documentIndex: 0 - - # Role grants access to broker and controller workloadmonitors - - it: grants access to WorkloadMonitor - release: - name: test-kafka - namespace: tenant-test - asserts: - - contains: - path: rules[2].resourceNames - content: test-kafka - documentIndex: 0 - - contains: - path: rules[2].resourceNames - content: test-kafka-controller - documentIndex: 0 - - equal: - path: rules[2].apiGroups[0] - value: cozystack.io - documentIndex: 0 - - # KRaft: no ZooKeeper WorkloadMonitor is referenced - - it: does not reference zookeeper workloadmonitor - release: - name: test-kafka - namespace: tenant-test - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[2].resourceNames - content: test-kafka-zookeeper - - # External bootstrap service absent when external=false, regardless of tls.enabled - - it: does not grant access to external bootstrap service when tls.enabled=true and external=false - release: - name: test-kafka - namespace: tenant-test - set: - external: false - tls: - enabled: true - asserts: - # Anchor the rule before asserting about it. notContains passes whenever - # its path resolves to something that lacks the content, and a different - # rule at [0] qualifies, so reordering the Role would leave this green - # while the external bootstrap Service came back on the rule it names. - # A rule has no name to pin, so the anchor is the Service this rule must - # keep. - - contains: - path: rules[0].resourceNames - content: test-kafka-kafka-bootstrap - documentIndex: 0 - - notContains: - path: rules[0].resourceNames - content: test-kafka-kafka-external-bootstrap - documentIndex: 0 - - # External bootstrap service absent when both external=false and tls.enabled=false - - it: does not grant access to external bootstrap when tls.enabled is explicitly false and external is false - release: - name: test-kafka - namespace: tenant-test - set: - external: false - tls: - enabled: false - asserts: - # Anchor the rule before asserting about it. notContains passes whenever - # its path resolves to something that lacks the content, and a different - # rule at [0] qualifies, so reordering the Role would leave this green - # while the external bootstrap Service came back on the rule it names. - # A rule has no name to pin, so the anchor is the Service this rule must - # keep. - - contains: - path: rules[0].resourceNames - content: test-kafka-kafka-bootstrap - documentIndex: 0 - - notContains: - path: rules[0].resourceNames - content: test-kafka-kafka-external-bootstrap - documentIndex: 0 - - # RoleBinding references correct Role - - it: RoleBinding references correct Role - release: - name: test-kafka - namespace: tenant-test - asserts: - - equal: - path: roleRef.kind - value: Role - documentIndex: 1 - - equal: - path: roleRef.name - value: test-kafka-dashboard-resources - documentIndex: 1 - - equal: - path: roleRef.apiGroup - value: rbac.authorization.k8s.io - documentIndex: 1 diff --git a/packages/apps/kafka/tests/external_authentication_test.yaml b/packages/apps/kafka/tests/external_authentication_test.yaml index c9539b6d1..f176fd999 100644 --- a/packages/apps/kafka/tests/external_authentication_test.yaml +++ b/packages/apps/kafka/tests/external_authentication_test.yaml @@ -7,7 +7,6 @@ suite: external listener requires SCRAM-SHA-512 credentials templates: - templates/kafka.yaml - templates/users.yaml - - templates/dashboard-resourcemap.yaml release: name: kafka-test @@ -100,26 +99,6 @@ tests: path: metadata.name pattern: ^kafka-test\.(analytics|app)$ - - it: lets the tenant read each user's generated credentials Secret - template: templates/dashboard-resourcemap.yaml - set: - users: - app: {} - documentSelector: - path: kind - value: Role - asserts: - - contains: - path: rules - content: - apiGroups: [""] - resources: [secrets] - resourceNames: - - kafka-test-clients-ca-cert - - kafka-test-cluster-ca-cert - - kafka-test.app - verbs: ["get", "list", "watch"] - - it: refuses a user name that is not a valid object name template: templates/users.yaml set: diff --git a/packages/apps/kubernetes-nodes/templates/dashboard-resourcemap.yaml b/packages/apps/kubernetes-nodes/templates/dashboard-resourcemap.yaml deleted file mode 100644 index c438fe7b0..000000000 --- a/packages/apps/kubernetes-nodes/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,25 +0,0 @@ -{{- $clusterName := include "kubernetes-nodes.clusterName" . }} -{{- $groupName := include "kubernetes-nodes.groupName" . }} -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ $clusterName }}-{{ $groupName }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/kubernetes/README.md b/packages/apps/kubernetes/README.md index b2192a646..1f13a1d5b 100644 --- a/packages/apps/kubernetes/README.md +++ b/packages/apps/kubernetes/README.md @@ -33,7 +33,7 @@ It can be done via UI or a `kubectl` request: - Run the following command (using the management cluster kubeconfig): ```bash - kubectl get secret -n tenant- kubernetes--admin-kubeconfig -o go-template='{{ printf "%s\n" (index .data "admin.conf" | base64decode) }}' > admin.conf + kubectl get tenantsecret -n tenant- kubernetes--admin-kubeconfig -o go-template='{{ printf "%s\n" (index .data "admin.conf" | base64decode) }}' > admin.conf ``` There are several kubeconfig options available: diff --git a/packages/apps/kubernetes/templates/NOTES.txt b/packages/apps/kubernetes/templates/NOTES.txt index e78d90cae..6ddc2a058 100644 --- a/packages/apps/kubernetes/templates/NOTES.txt +++ b/packages/apps/kubernetes/templates/NOTES.txt @@ -1,6 +1,6 @@ To get the static admin kubeconfig (break-glass) for this cluster: - kubectl get secret -n {{ .Release.Namespace }} {{ .Release.Name }}-admin-kubeconfig -o go-template='{{`{{ printf "%s\n" (index .data "super-admin.conf" | base64decode) }}`}}' + kubectl get tenantsecret -n {{ .Release.Namespace }} {{ .Release.Name }}-admin-kubeconfig -o go-template='{{`{{ printf "%s\n" (index .data "super-admin.conf" | base64decode) }}`}}' {{- if ne .Values.oidc.mode "None" }} @@ -10,7 +10,7 @@ OIDC is enabled for this cluster (spec.oidc.mode={{ .Values.oidc.mode }}). Per-user kubeconfig wired to `kubectl oidc-login` (one-shot install of the plugin is a prerequisite — `kubectl krew install oidc-login`): - kubectl get secret -n {{ .Release.Namespace }} {{ .Release.Name }}-oidc-kubeconfig -o jsonpath='{.data.kubeconfig}' | base64 -d > {{ .Release.Name }}.kubeconfig + kubectl get tenantsecret -n {{ .Release.Namespace }} {{ .Release.Name }}-oidc-kubeconfig -o jsonpath='{.data.kubeconfig}' | base64 -d > {{ .Release.Name }}.kubeconfig kubectl --kubeconfig {{ .Release.Name }}.kubeconfig get pods --all-namespaces The first command writes the OIDC-ready kubeconfig to disk; the diff --git a/packages/apps/kubernetes/templates/dashboard-resourcemap.yaml b/packages/apps/kubernetes/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 89a5f94aa..000000000 --- a/packages/apps/kubernetes/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,50 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - networking.k8s.io - resources: - - ingresses - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] -{{- /* withholdAdminKubeconfig is internal wiring, deliberately absent from - values.yaml and the schema: a wrapper that keeps the cluster-admin - credential from the tenant (the computeplane module) sets it in its own - HelmRelease values, out of tenant reach. */}} -{{- if not .Values.withholdAdminKubeconfig }} -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-admin-kubeconfig - verbs: ["get", "list", "watch"] -{{- end }} -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/kubernetes/tests/dashboard_resourcemap_test.yaml b/packages/apps/kubernetes/tests/dashboard_resourcemap_test.yaml deleted file mode 100644 index 388fc3ca9..000000000 --- a/packages/apps/kubernetes/tests/dashboard_resourcemap_test.yaml +++ /dev/null @@ -1,44 +0,0 @@ -suite: dashboard resource Role and the admin kubeconfig Secret - -values: - - values-ci.yaml - -templates: - - templates/dashboard-resourcemap.yaml - -tests: - - it: grants the tenant read on the admin kubeconfig of its own cluster - release: - name: kubernetes-foo - namespace: tenant-alice - documentSelector: - path: kind - value: Role - asserts: - - lengthEqual: - path: rules - count: 4 - - equal: - path: rules[?(@.resources[0]=="secrets")].resourceNames - value: - - kubernetes-foo-admin-kubeconfig - - - it: grants no read on the admin kubeconfig when the wrapper withholds it - release: - name: computeplane-cluster - namespace: tenant-alice - set: - withholdAdminKubeconfig: true - documentSelector: - path: kind - value: Role - asserts: - - lengthEqual: - path: rules - count: 3 - - notExists: - path: rules[?(@.resources[0]=="secrets")] - - equal: - path: rules[?(@.resources[0]=="services")].resourceNames - value: - - computeplane-cluster diff --git a/packages/apps/mariadb/README.md b/packages/apps/mariadb/README.md index 1ff195d95..98fff28c1 100644 --- a/packages/apps/mariadb/README.md +++ b/packages/apps/mariadb/README.md @@ -265,7 +265,7 @@ users: maxUserConnections: 1000 ``` -Passwords cannot be set here — they (and the `root` account) are auto-generated and stored in the `-credentials` Secret. Read a user's password with `kubectl get secret -credentials -o json | jq -r '.data["user1"]' | base64 -d` (a username may contain a `.`, which `jsonpath` would treat as a path step and return nothing). +Passwords cannot be set here — they (and the `root` account) are auto-generated and stored in the `-credentials` Secret. Read a user's password with `kubectl get tenantsecret -credentials -o json | jq -r '.data["user1"]' | base64 -d` (a username may contain a `.`, which `jsonpath` would treat as a path step and return nothing). ### databases diff --git a/packages/apps/mariadb/templates/dashboard-resourcemap.yaml b/packages/apps/mariadb/templates/dashboard-resourcemap.yaml deleted file mode 100644 index f790a25d3..000000000 --- a/packages/apps/mariadb/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,56 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - # The bare service exists in both topologies; -primary/-secondary - # only when replication is on (replicas>1). Grant exactly what exists so the - # RBAC matches the services the ApplicationDefinition (mariadb-rd) lists. - - {{ .Release.Name }} - {{- if gt (int .Values.replicas) 1 }} - - {{ .Release.Name }}-primary - - {{ .Release.Name }}-secondary - {{- end }} - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-credentials - verbs: ["get", "list", "watch"] -# The TLS Secrets are deliberately NOT granted here, key-bearing or not. -# .ca-tls and the operator's own -ca hold the CA private key, .tls holds the -# server private key, and -ca-bundle — while key-free — is still an operator -# Secret exposed by name rather than through the platform-vouched-for path. -# -# The trust anchor reaches the tenant as the key-free .tenant-ca -# projection instead, through core.cozystack.io/tenantsecrets — which the base -# tenant roles already grant and which gates on the internal.cozystack.io/ -# tenantresource label the lineage webhook stamps. Granting that projection by -# NAME here would be wrong too: a name grant conveys whatever occupies the -# name, whereas the label path conveys only what the platform vouched for. A -# name grant is gated on a string; the label path is gated on provenance. -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/mariadb/tests/tls_test.yaml b/packages/apps/mariadb/tests/tls_test.yaml index ac7b8ae79..02c19499f 100644 --- a/packages/apps/mariadb/tests/tls_test.yaml +++ b/packages/apps/mariadb/tests/tls_test.yaml @@ -516,83 +516,6 @@ tests: path: spec.duration value: "8760h" - # ------------------------------------------------------------------- - # NB6: dashboard-resourcemap.yaml exposure is TLS-state independent. - # - # The tenant grant used to follow the issuer and hand out the - # cert-manager Secrets whenever TLS was on. Those Secrets carry private - # keys, so the grant is now a flat invariant instead: no TLS state may put - # them in the Role. All four issuer/external combinations are checked so a - # regression cannot hide in the branch that happens to enable TLS. - # ------------------------------------------------------------------- - - it: "RBAC excludes TLS secrets when external=false and tls.issuer unset" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: false - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[1].resourceNames - content: my-mariadb.tls - - notContains: - path: rules[1].resourceNames - content: my-mariadb.ca-tls - - - it: "RBAC excludes TLS secrets when external=true and tls.issuer unset" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: true - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[1].resourceNames - content: my-mariadb.tls - - notContains: - path: rules[1].resourceNames - content: my-mariadb.ca-tls - - - it: "RBAC excludes TLS secrets when tls.issuer=operator even if external=true" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: true - tls: - issuer: operator - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[1].resourceNames - content: my-mariadb.tls - - notContains: - path: rules[1].resourceNames - content: my-mariadb.ca-tls - - - it: "RBAC excludes TLS secrets when tls.issuer=cert-manager even if external=false" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: false - tls: - issuer: cert-manager - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[1].resourceNames - content: my-mariadb.tls - - notContains: - path: rules[1].resourceNames - content: my-mariadb.ca-tls - # ------------------------------------------------------------------- # B2: issuer resolution must survive explicit tls=null without panic # ------------------------------------------------------------------- @@ -1165,55 +1088,6 @@ tests: - hasDocuments: count: 0 - # ------------------------------------------------------------------- - # Tenant exposure. The dashboard Role is the tenant-facing grant, so no CA - # Secret — key-bearing or not — may appear in it under any TLS state. The - # tenant gets the key-free tenant-ca projection instead (tenant_projection_ - # test.yaml), never a name grant on an operator Secret. - # ------------------------------------------------------------------- - - it: "dashboard Role never grants any CA Secret by name" - templates: - - templates/dashboard-resourcemap.yaml - documentIndex: 0 - set: - tls: - issuer: cert-manager - asserts: - - notContains: - path: rules[1].resourceNames - content: my-mariadb.ca-tls - - notContains: - path: rules[1].resourceNames - content: my-mariadb.tls - - notContains: - path: rules[1].resourceNames - content: my-mariadb-ca-bundle - - contains: - path: rules[1].resourceNames - content: my-mariadb-credentials - - # The absence holds regardless of issuer: this is a flat invariant, not a - # branch that happens to be untested under the operator issuer. - - it: "dashboard Role never grants the CA bundle even when TLS is unmanaged" - templates: - - templates/dashboard-resourcemap.yaml - documentSelector: - path: kind - value: Role - set: - tls: - issuer: operator - asserts: - - notContains: - path: rules[1].resourceNames - content: my-mariadb-ca-bundle - - notContains: - path: rules[1].resourceNames - content: my-mariadb.ca-tls - - notContains: - path: rules[1].resourceNames - content: my-mariadb.tls - # The CR must not advertise enforcement the server does not apply. The # operator treats an absent required as false, so a schema default of true # would make `kubectl get mariadb` claim plaintext is refused on an unmanaged diff --git a/packages/apps/mongodb/README.md b/packages/apps/mongodb/README.md index 044dafded..7790b3b75 100644 --- a/packages/apps/mongodb/README.md +++ b/packages/apps/mongodb/README.md @@ -76,7 +76,7 @@ kubectl --context --namespace \ --output jsonpath='{.data.ca\.crt}' | base64 --decode > ca.crt kubectl --context --namespace \ - get secret mongodb--credentials \ + get tenantsecret mongodb--credentials \ --output jsonpath='{.data.uri}' | base64 --decode ``` diff --git a/packages/apps/mongodb/templates/dashboard-resourcemap.yaml b/packages/apps/mongodb/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 0b3868a27..000000000 --- a/packages/apps/mongodb/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,52 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }}-rs0 - - {{ .Release.Name }}-mongos - - {{ .Release.Name }}-external - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-credentials - verbs: ["get", "list", "watch"] -# The TLS Secrets the PSMDB operator creates are deliberately NOT granted here. -# Both carry private key material: -ca-cert holds the CA private key -# (full trust-chain compromise if leaked) and -ssl holds the server -# private key (impersonation / MITM). A tenant verifying the endpoint needs -# ca.crt and nothing more, so neither belongs in a tenant-facing Role. -# -# The trust anchor reaches the tenant as the key-free .tenant-ca -# projection instead, through core.cozystack.io/tenantsecrets — which the base -# tenant roles already grant and which gates on the internal.cozystack.io/ -# tenantresource LABEL stamped by the lineage webhook. Granting that projection -# by NAME here would be wrong too: a name grant conveys whatever occupies the -# name, whereas the label path conveys only what the platform vouched for. A -# name grant is gated on a string; the label path is gated on provenance. -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/mongodb/tests/dashboard-resourcemap_test.yaml b/packages/apps/mongodb/tests/dashboard-resourcemap_test.yaml deleted file mode 100644 index d1151786f..000000000 --- a/packages/apps/mongodb/tests/dashboard-resourcemap_test.yaml +++ /dev/null @@ -1,238 +0,0 @@ -suite: dashboard resourcemap tests - -templates: - - templates/dashboard-resourcemap.yaml - -tests: - # Always renders Role and RoleBinding - - it: renders Role and RoleBinding - release: - name: test-mongodb - namespace: tenant-test - asserts: - - hasDocuments: - count: 2 - - isKind: - of: Role - documentIndex: 0 - - isKind: - of: RoleBinding - documentIndex: 1 - - # Role naming - - it: uses correct Role name - release: - name: mydb - namespace: tenant-test - asserts: - - equal: - path: metadata.name - value: mydb-dashboard-resources - documentIndex: 0 - - # RoleBinding naming - - it: uses correct RoleBinding name - release: - name: mydb - namespace: tenant-test - asserts: - - equal: - path: metadata.name - value: mydb-dashboard-resources - documentIndex: 1 - - # Role grants access to services - - it: grants access to MongoDB services - release: - name: test-mongodb - namespace: tenant-test - asserts: - - contains: - path: rules[0].resourceNames - content: test-mongodb-rs0 - documentIndex: 0 - - contains: - path: rules[0].resourceNames - content: test-mongodb-mongos - documentIndex: 0 - - contains: - path: rules[0].resourceNames - content: test-mongodb-external - documentIndex: 0 - - # Role grants access to credentials secret - - it: grants access to credentials secret - release: - name: test-mongodb - namespace: tenant-test - asserts: - - contains: - path: rules[1].resourceNames - content: test-mongodb-credentials - documentIndex: 0 - - # Role grants access to workloadmonitor - - it: grants access to WorkloadMonitor - release: - name: test-mongodb - namespace: tenant-test - asserts: - - contains: - path: rules[2].resourceNames - content: test-mongodb - documentIndex: 0 - - equal: - path: rules[2].apiGroups[0] - value: cozystack.io - documentIndex: 0 - - # RoleBinding references correct Role - - it: RoleBinding references correct Role - release: - name: test-mongodb - namespace: tenant-test - asserts: - - equal: - path: roleRef.kind - value: Role - documentIndex: 1 - - equal: - path: roleRef.name - value: test-mongodb-dashboard-resources - documentIndex: 1 - - equal: - path: roleRef.apiGroup - value: rbac.authorization.k8s.io - documentIndex: 1 - - # The operator's TLS Secrets both carry private key material: -ca-cert - # holds the CA private key, -ssl holds the server private key. Neither - # may ever be granted to a tenant. The trust anchor is delivered instead as the - # key-free .tenant-ca projection, via core.cozystack.io/tenantsecrets - # — a label-gated path, so it needs no grant in this Role either. - # - # The four tests below pick the Role with documentSelector rather than - # documentIndex, and each pairs its notContains with a positive assertion on - # the same path. Both halves are load-bearing and neither substitutes for the - # other: notContains passes when the path does not resolve, so on its own it - # goes green against the WRONG document (reorder the template) and green when - # the path moves (reorder the rules). Indexing survives neither; selecting - # survives the first; the positive anchor catches the second. - - - it: Role does not grant the key-bearing TLS secrets - release: - name: test-mongodb - namespace: tenant-test - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[1].resourceNames - content: test-mongodb-ca-cert - - notContains: - path: rules[1].resourceNames - content: test-mongodb-ssl - - equal: - path: rules[1].resourceNames - value: - - test-mongodb-credentials - - - it: Role does not grant the key-bearing TLS secrets when external is enabled - release: - name: test-mongodb - namespace: tenant-test - documentSelector: - path: kind - value: Role - set: - external: true - asserts: - - notContains: - path: rules[1].resourceNames - content: test-mongodb-ca-cert - - notContains: - path: rules[1].resourceNames - content: test-mongodb-ssl - - equal: - path: rules[1].resourceNames - value: - - test-mongodb-credentials - - - it: Role does not grant the tenant-ca projection by name - release: - name: test-mongodb - namespace: tenant-test - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[1].resourceNames - content: test-mongodb.tenant-ca - - equal: - path: rules[1].resourceNames - value: - - test-mongodb-credentials - - - it: Role has exactly three rules - release: - name: test-mongodb - namespace: tenant-test - documentSelector: - path: kind - value: Role - asserts: - # The secret assertions above are all anchored to rules[1]. Without this, - # a fourth rule granting secrets by name would satisfy every one of them - # while reopening the leak. - - lengthEqual: - path: rules - count: 3 - - - it: the secrets rule grants secrets and nothing wider - release: - name: test-mongodb - namespace: tenant-test - documentSelector: - path: kind - value: Role - asserts: - # Every other assertion here constrains resourceNames. None constrained - # `resources`, so mutating this rule to ["*"] would grant every resource - # kind in the namespace — Secrets included, whatever their names — while - # leaving the whole suite green. - - equal: - path: rules[1].resources - value: - - secrets - - equal: - path: rules[1].apiGroups - value: - - "" - # The other two rules are pinned for the same reason. Neither names a - # key-bearing Secret today, so widening one leaks nothing immediately — - # but a rule mutated to ["*"] would grant every resource kind for the - # names it lists, and closing the class costs no more than closing the - # one instance. - - equal: - path: rules[0].resources - value: - - services - - equal: - path: rules[2].resources - value: - - workloadmonitors - # verbs is the fourth axis of an RBAC rule and the last one left open. - # Widening it does not leak a key while resourceNames stays narrow, but - # it is the same widening class the assertions above close, and the Role - # is read-only by intent. - - equal: - path: rules[0].verbs - value: ["get", "list", "watch"] - - equal: - path: rules[1].verbs - value: ["get", "list", "watch"] - - equal: - path: rules[2].verbs - value: ["get", "list", "watch"] diff --git a/packages/apps/nats/templates/dashboard-resourcemap.yaml b/packages/apps/nats/templates/dashboard-resourcemap.yaml deleted file mode 100644 index af40a6fae..000000000 --- a/packages/apps/nats/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-credentials - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/openbao/templates/dashboard-resourcemap.yaml b/packages/apps/openbao/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 452a07db8..000000000 --- a/packages/apps/openbao/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,31 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }} - - {{ .Release.Name }}-internal - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/opensearch/templates/dashboard-resourcemap.yaml b/packages/apps/opensearch/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 20301a75a..000000000 --- a/packages/apps/opensearch/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,55 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }} - - {{ .Release.Name }}-external - {{- if .Values.dashboards.enabled }} - - {{ .Release.Name }}-dashboards - - {{ .Release.Name }}-dashboards-external - {{- end }} - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-credentials - verbs: ["get", "list", "watch"] -{{- /* -The trust anchor is deliberately absent from that list. It reaches the tenant as -the key-free .tenant-ca projection through core.cozystack.io/tenantsecrets, -which the base tenant roles already grant and which gates on the -internal.cozystack.io/tenantresource label the lineage webhook stamps. A name grant -here would answer a different question: it conveys whatever occupies the name, and -it keeps conveying it after the webhook has withdrawn the verdict, so it would -bypass the platform's only revocation channel for the anchor. - -The three Secrets of the TLS chain — .http-ca, -http-server and --dashboards-server — each hold a private key and belong in no tenant-facing Role at -all. -*/}} -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/opensearch/tests/dashboard-resourcemap_test.yaml b/packages/apps/opensearch/tests/dashboard-resourcemap_test.yaml deleted file mode 100644 index ed8ac2d65..000000000 --- a/packages/apps/opensearch/tests/dashboard-resourcemap_test.yaml +++ /dev/null @@ -1,84 +0,0 @@ -suite: opensearch tenant RBAC for dashboard resources - -# The Role is the direct read grant for tenant subjects, and the credentials Secret is -# the only Secret that needs one. The trust anchor takes the other path: the -# ApplicationDefinition's spec.secrets.include drives the lineage webhook's -# tenantresource label, and the tenant reads the projection through -# core.cozystack.io/tenantsecrets, which the base tenant roles grant. Every converged -# engine delivers it that way and none name-grants it; mongodb's Role says why. - -release: - name: os-test - namespace: tenant-test - -set: - _cluster: - scheduling: {} - cluster-domain: cozy.local - -templates: - - templates/dashboard-resourcemap.yaml - -tests: - - it: grants the tenant the credentials Secret and nothing else - documentIndex: 0 - asserts: - - isKind: - of: Role - - contains: - path: rules[1].resourceNames - content: os-test-credentials - - equal: - path: rules[1].resources - value: - - secrets - - # Every Secret of the TLS chain carries a private key — the cert-manager CA under - # tls.key, and both leaves the same — so granting any of them would hand the tenant - # key material. The count is what makes this exhaustive rather than a list of the - # three names someone happened to think of, the projection included: it reaches the - # tenant through tenantsecrets, so a name grant for it here would be a bypass of the - # webhook's verdict rather than a convenience. - - it: never grants the tenant a Secret beyond the credentials - documentIndex: 0 - asserts: - - notContains: - path: rules[1].resourceNames - content: os-test.http-ca - - notContains: - path: rules[1].resourceNames - content: os-test-http-server - - notContains: - path: rules[1].resourceNames - content: os-test-dashboards-server - - notContains: - path: rules[1].resourceNames - content: os-test.tenant-ca - - lengthEqual: - path: rules[1].resourceNames - count: 1 - # And the rule count, because the assertion above is exhaustive only within - # rules[1]: a second rule granting secrets at another index satisfies every - # other assertion in this file. - - lengthEqual: - path: rules - count: 3 - - - it: grants read only, never write - documentIndex: 0 - asserts: - - equal: - path: rules[1].verbs - value: - - get - - list - - watch - - - it: binds the Role to tenant use subjects - documentIndex: 1 - asserts: - - isKind: - of: RoleBinding - - equal: - path: roleRef.name - value: os-test-dashboard-resources diff --git a/packages/apps/opensearch/tests/tenant_projection_test.yaml b/packages/apps/opensearch/tests/tenant_projection_test.yaml index 0471c7d19..b097b6790 100644 --- a/packages/apps/opensearch/tests/tenant_projection_test.yaml +++ b/packages/apps/opensearch/tests/tenant_projection_test.yaml @@ -6,11 +6,9 @@ suite: opensearch TenantProjection sentinel # # This is the only thing that creates that projection. The tenant reads it through # core.cozystack.io/tenantsecrets, which the base tenant roles grant and which the -# ApplicationDefinition's label selector admits it to; templates/dashboard- -# resourcemap.yaml deliberately grants no name for it, and -# tests/dashboard-resourcemap_test.yaml pins that absence. Both paths are inert -# until the sentinel exists, so losing this template costs the tenant its trust -# anchor with no error anywhere. +# ApplicationDefinition's label selector admits it to. That path is inert until +# the sentinel exists, so losing this template costs the tenant its trust anchor +# with no error anywhere. # # The source is named .http-ca, with a dot: the operator reserves -ca for # its own transport CA, and the hyphenated form is exactly that name for the sibling diff --git a/packages/apps/postgres/README.md b/packages/apps/postgres/README.md index d1a0882f1..50aeb4729 100644 --- a/packages/apps/postgres/README.md +++ b/packages/apps/postgres/README.md @@ -361,7 +361,7 @@ users: replication: true ``` -Passwords cannot be set here — they are auto-generated and stored in the `-credentials` Secret. Read a user's password with `kubectl get secret -credentials -o json | jq -r '.data["user1"]' | base64 -d` (a username may contain a `.`, which `jsonpath` would treat as a path step and return nothing). +Passwords cannot be set here — they are auto-generated and stored in the `-credentials` Secret. Read a user's password with `kubectl get tenantsecret -credentials -o json | jq -r '.data["user1"]' | base64 -d` (a username may contain a `.`, which `jsonpath` would treat as a path step and return nothing). ### databases diff --git a/packages/apps/postgres/templates/dashboard-resourcemap.yaml b/packages/apps/postgres/templates/dashboard-resourcemap.yaml deleted file mode 100644 index d979289fc..000000000 --- a/packages/apps/postgres/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,40 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }}-r - - {{ .Release.Name }}-ro - - {{ .Release.Name }}-rw - - {{ .Release.Name }}-external-write - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-credentials - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/qdrant/templates/dashboard-resourcemap.yaml b/packages/apps/qdrant/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 0986951fb..000000000 --- a/packages/apps/qdrant/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,53 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }} - - {{ .Release.Name }}-headless - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-apikey - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io ---- -apiVersion: cozystack.io/v1alpha1 -kind: WorkloadMonitor -metadata: - name: {{ .Release.Name }} - labels: - workloads.cozystack.io/resource-preset: {{ .Values.resourcesPreset | quote }} -spec: - minReplicas: 1 - replicas: {{ .Values.replicas }} - kind: qdrant - type: qdrant - selector: - app.kubernetes.io/instance: {{ .Release.Name }}-system - version: {{ .Chart.Version }} diff --git a/packages/apps/qdrant/templates/workloadmonitor.yaml b/packages/apps/qdrant/templates/workloadmonitor.yaml new file mode 100644 index 000000000..09038d5a0 --- /dev/null +++ b/packages/apps/qdrant/templates/workloadmonitor.yaml @@ -0,0 +1,14 @@ +apiVersion: cozystack.io/v1alpha1 +kind: WorkloadMonitor +metadata: + name: {{ .Release.Name }} + labels: + workloads.cozystack.io/resource-preset: {{ .Values.resourcesPreset | quote }} +spec: + minReplicas: 1 + replicas: {{ .Values.replicas }} + kind: qdrant + type: qdrant + selector: + app.kubernetes.io/instance: {{ .Release.Name }}-system + version: {{ .Chart.Version }} diff --git a/packages/apps/qdrant/tests/dashboard-resourcemap_test.yaml b/packages/apps/qdrant/tests/dashboard-resourcemap_test.yaml deleted file mode 100644 index 79ef3bbb4..000000000 --- a/packages/apps/qdrant/tests/dashboard-resourcemap_test.yaml +++ /dev/null @@ -1,338 +0,0 @@ -suite: qdrant dashboard resourcemap tests - -# The Role bound here is what a tenant subject can actually read. Two of the -# Secrets this chart creates must never appear in it: -ca carries the -# CA private key under tls.key, -tls the server key. Read access to -# the former is enough to issue certificates for anything. -# -# So the rules array is pinned WHOLE rather than checked for known-bad names. -# A name-by-name check misses a rule that grants secrets with NO resourceNames -# at all, which is not a narrow grant but an unrestricted one — "an empty set -# means that everything is allowed" — and so adds no name to notice while -# granting every Secret in the namespace. Pinning the whole array also makes -# the template's spelling irrelevant, since the assertion runs on rendered -# output. -# -# Pinning one document is not enough, because a grant need not live in it. A -# second RBAC object rendered beside it reaches the same subjects, and a -# selector addressing the Role looks straight past it. So each permutation -# also pins the document COUNT, catching an added object, and pins the kind in -# every slot, catching a substituted one — a count alone is satisfied by -# swapping the WorkloadMonitor for a binding onto cluster-admin. The -# RoleBinding is pinned across the same permutations for the same reason: its -# roleRef is one conditional away from pointing at cluster-admin. -# -# Documents are addressed by kind rather than by index. An index follows the -# slot, so inserting a document above the Role would quietly move these -# assertions onto something else and pass green. A second Role, or none, makes -# the selector error rather than silently pick a first match. -# -# What this does NOT reach, and why it is a guard rather than a proof: -# -# - a grant rendered from a DIFFERENT template file, since the suite-level -# `templates` key scopes what is rendered; -# - a grant behind a `.Capabilities` check this suite does not declare. -# helm-unittest populates `.Capabilities`, but its default APIVersions set -# is empty, so `.Capabilities.APIVersions.Has "cert-manager.io/v1"` is -# false here and true on any cluster running cert-manager; -# - a grant comparing a value against a third point not sampled, e.g. -# `replicas` greater than two or `resourcesPreset` equal to one specific -# preset. The permutations below sample each value at the points that -# change behaviour — for `tls.enabled`, a tri-state, that means all three -# — which settles presence and boolean gates and nothing more. - -templates: - - templates/dashboard-resourcemap.yaml - -release: - name: test-qdrant - namespace: tenant-test - -tests: - ################################################### - # The document set: nothing added, nothing swapped - ################################################### - - # The baseline. A grant that renders only while a value is unset shows up - # here and in no other permutation. - - it: renders three documents with default values - asserts: &documentSet - - hasDocuments: - count: 3 - - - it: renders three documents with TLS enabled - set: &tlsOn - tls: - enabled: true - asserts: *documentSet - - - it: renders three documents with TLS implied by external access - set: &externalOn - external: true - asserts: *documentSet - - # Every value a tenant can set, plus the two the platform injects, moved off - # their defaults at once, so a grant gated on the presence of any single one - # renders here. - - it: renders three documents with every settable value set - set: &allValues - replicas: 2 - resources: - cpu: 500m - memory: 1Gi - resourcesPreset: u1.large - size: 20Gi - storageClass: replicated - external: true - tls: - enabled: true - _namespace: - host: example.com - _cluster: - cluster-domain: cozy.local - asserts: *documentSet - - # Chart.yaml carries version 0.0.0, and it stays 0.0.0 on the path that - # ships: the installer pushes packages/ verbatim as an OCI artifact, and the - # `helm package --version` target that would stamp a real version has no - # caller. Sampling a second version costs one test and means a grant gated - # on .Chart.Version cannot hide if that ever changes. - - it: renders three documents with a different chart version - chart: &packagedChart - version: 1.2.3 - asserts: *documentSet - - # tls.enabled is tri-state: unset means "follow external", so an explicit - # false is a distinct state from leaving it out, and a grant gated on it - # renders in neither case above. - - it: renders three documents with TLS explicitly disabled - set: &tlsOff - tls: - enabled: false - asserts: *documentSet - - - it: renders three documents with TLS explicitly disabled despite external access - set: &externalTlsOff - external: true - tls: - enabled: false - asserts: *documentSet - - # helm-controller upgrades whenever the release is not up to date, so any - # values or chart change puts a release on the upgrade path. A grant behind - # .Release.IsUpgrade is live on essentially every release while rendering - # false in every case above. - - it: renders three documents on upgrade - release: &upgraded - name: test-qdrant - namespace: tenant-test - upgrade: true - asserts: *documentSet - - # The WorkloadMonitor itself. Without this the count above is satisfied by - # any replacement, including one binding the tenant to cluster-admin. - - it: keeps the WorkloadMonitor as the third document with default values - documentSelector: &workloadMonitor - path: kind - value: WorkloadMonitor - asserts: &workloadMonitorPinned - - equal: - path: metadata.name - value: test-qdrant - - - it: keeps the WorkloadMonitor with TLS enabled - set: *tlsOn - documentSelector: *workloadMonitor - asserts: *workloadMonitorPinned - - - it: keeps the WorkloadMonitor with TLS implied by external access - set: *externalOn - documentSelector: *workloadMonitor - asserts: *workloadMonitorPinned - - - it: keeps the WorkloadMonitor with every settable value set - set: *allValues - documentSelector: *workloadMonitor - asserts: *workloadMonitorPinned - - - it: keeps the WorkloadMonitor with a different chart version - chart: *packagedChart - documentSelector: *workloadMonitor - asserts: *workloadMonitorPinned - - - it: keeps the WorkloadMonitor with TLS explicitly disabled - set: *tlsOff - documentSelector: *workloadMonitor - asserts: *workloadMonitorPinned - - - it: keeps the WorkloadMonitor with TLS explicitly disabled despite external access - set: *externalTlsOff - documentSelector: *workloadMonitor - asserts: *workloadMonitorPinned - - - it: keeps the WorkloadMonitor on upgrade - release: *upgraded - documentSelector: *workloadMonitor - asserts: *workloadMonitorPinned - - ################################################### - # The grant itself - ################################################### - - - it: names the dashboard Role after the release - documentSelector: &role - path: kind - value: Role - asserts: - - equal: - path: apiVersion - value: rbac.authorization.k8s.io/v1 - - equal: - path: metadata.name - value: test-qdrant-dashboard-resources - - # Default values leave tls.enabled unset and external false, which the - # chart's helper resolves to TLS off, so the CA Secret does not exist here. - # Pinned to catch a grant that renders only while a value is unset. - - it: grants no Secret beyond the API key with default values - documentSelector: *role - asserts: &pinnedRules - - equal: - path: rules - value: - - apiGroups: [""] - resources: [services] - resourceNames: [test-qdrant, test-qdrant-headless] - verbs: [get, list, watch] - - apiGroups: [""] - resources: [secrets] - resourceNames: [test-qdrant-apikey] - verbs: [get, list, watch] - - apiGroups: [cozystack.io] - resources: [workloadmonitors] - resourceNames: [test-qdrant] - verbs: [get, list, watch] - - # The case that matters. With TLS on the chart mints -ca and - # -tls, so this is the permutation where a leaked grant has - # something to leak. A grant added inside the same `if` that creates the CA - # renders only here, and would sail past a check that runs on defaults. - - it: grants no Secret beyond the API key with TLS enabled - set: *tlsOn - documentSelector: *role - asserts: *pinnedRules - - # TLS is also reachable by implication: leaving tls.enabled unset makes it - # follow external. Pinned separately because a grant gated on `external` - # rather than on the TLS helper renders in neither case above. - - it: grants no Secret beyond the API key with TLS implied by external access - set: *externalOn - documentSelector: *role - asserts: *pinnedRules - - - it: grants no Secret beyond the API key with every settable value set - set: *allValues - documentSelector: *role - asserts: *pinnedRules - - - it: grants no Secret beyond the API key with a different chart version - chart: *packagedChart - documentSelector: *role - asserts: *pinnedRules - - - it: grants no Secret beyond the API key with TLS explicitly disabled - set: *tlsOff - documentSelector: *role - asserts: *pinnedRules - - - it: grants no Secret beyond the API key with TLS explicitly disabled despite external access - set: *externalTlsOff - documentSelector: *role - asserts: *pinnedRules - - - it: grants no Secret beyond the API key on upgrade - release: *upgraded - documentSelector: *role - asserts: *pinnedRules - - ################################################### - # The binding: who the Role is handed to - ################################################### - - # Pinning the Role's rules is worth nothing if the binding points somewhere - # else, so roleRef and the subject list are pinned across the same - # permutations. A conditional swapping roleRef for cluster-admin renders in - # exactly the case a default-values check would miss. - - it: binds the tenant subjects to the dashboard Role with default values - documentSelector: &roleBinding - path: kind - value: RoleBinding - asserts: &roleBindingPinned - - equal: - path: roleRef - value: - kind: Role - name: test-qdrant-dashboard-resources - apiGroup: rbac.authorization.k8s.io - - equal: - path: subjects - value: - - kind: ServiceAccount - name: tenant-test - namespace: tenant-test - - kind: Group - name: tenant-test-admin - apiGroup: rbac.authorization.k8s.io - - kind: Group - name: tenant-test-super-admin - apiGroup: rbac.authorization.k8s.io - - kind: Group - name: tenant-test-use - apiGroup: rbac.authorization.k8s.io - - kind: ServiceAccount - name: tenant-root - namespace: tenant-root - - kind: Group - name: tenant-root-admin - apiGroup: rbac.authorization.k8s.io - - kind: Group - name: tenant-root-super-admin - apiGroup: rbac.authorization.k8s.io - - kind: Group - name: tenant-root-use - apiGroup: rbac.authorization.k8s.io - - - it: binds the tenant subjects to the dashboard Role with TLS enabled - set: *tlsOn - documentSelector: *roleBinding - asserts: *roleBindingPinned - - - it: binds the tenant subjects to the dashboard Role with TLS implied by external access - set: *externalOn - documentSelector: *roleBinding - asserts: *roleBindingPinned - - - it: binds the tenant subjects to the dashboard Role with every settable value set - set: *allValues - documentSelector: *roleBinding - asserts: *roleBindingPinned - - - it: binds the tenant subjects to the dashboard Role with a different chart version - chart: *packagedChart - documentSelector: *roleBinding - asserts: *roleBindingPinned - - - it: binds the tenant subjects to the dashboard Role with TLS explicitly disabled - set: *tlsOff - documentSelector: *roleBinding - asserts: *roleBindingPinned - - - it: binds the tenant subjects to the dashboard Role with TLS explicitly disabled despite external access - set: *externalTlsOff - documentSelector: *roleBinding - asserts: *roleBindingPinned - - - it: binds the tenant subjects to the dashboard Role on upgrade - release: *upgraded - documentSelector: *roleBinding - asserts: *roleBindingPinned diff --git a/packages/apps/rabbitmq/templates/dashboard-resourcemap.yaml b/packages/apps/rabbitmq/templates/dashboard-resourcemap.yaml deleted file mode 100644 index dc25476d7..000000000 --- a/packages/apps/rabbitmq/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,46 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-default-user - {{- /* No TLS Secret is granted here, in either TLS state. Both objects carrying - ca.crt also carry a private key — -tls the server key, -ca - the CA key — and RBAC has no key-level filter, so granting read to deliver a - trust anchor would deliver the key with it. The tenant reads the key-free - .tenant-ca projection through core.cozystack.io/tenantsecrets, which - cozy:tenant:use:base already grants. */}} - {{- range $name, $u := .Values.users }} - - {{ $.Release.Name }}-{{ kebabcase $name }}-credentials - {{- end }} - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/rabbitmq/tests/dashboard_resourcemap_test.yaml b/packages/apps/rabbitmq/tests/dashboard_resourcemap_test.yaml deleted file mode 100644 index 023fa51db..000000000 --- a/packages/apps/rabbitmq/tests/dashboard_resourcemap_test.yaml +++ /dev/null @@ -1,202 +0,0 @@ -suite: RabbitMQ dashboard Role resource access - -templates: - - templates/dashboard-resourcemap.yaml - -tests: - # ----------------------------------------------------------------------- - # Baseline: Role always grants access to default-user secret - # ----------------------------------------------------------------------- - - - it: Role always grants access to default-user secret - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: false - external: false - documentIndex: 0 - asserts: - - isKind: - of: Role - - contains: - path: rules[0].resourceNames - content: myrabbitmq-default-user - - # ----------------------------------------------------------------------- - # B: no key-bearing Secret is ever granted, in any TLS state. - # - # Both objects that carry ca.crt also carry a private key: -tls holds - # the server key and -ca holds the CA key. RBAC cannot filter by key, - # so granting either to deliver a trust anchor delivers a key with it. The - # tenant reads the key-free .tenant-ca projection through - # core.cozystack.io/tenantsecrets instead, which the base tenant roles already - # grant — so it is deliberately absent from this core/v1 Role too. - # ----------------------------------------------------------------------- - - - it: Role never grants the leaf TLS secret when tls.enabled is true - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: true - external: false - documentIndex: 0 - asserts: - - isKind: - of: Role - - notContains: - path: rules[0].resourceNames - content: myrabbitmq-tls - - - it: Role never grants the CA secret when tls.enabled is true - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: true - external: false - documentIndex: 0 - asserts: - - isKind: - of: Role - - notContains: - path: rules[0].resourceNames - content: myrabbitmq-ca - - - it: Role never grants key-bearing secrets on the external TLS path - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: true - external: true - _namespace.host: example.com - documentIndex: 0 - asserts: - - isKind: - of: Role - - notContains: - path: rules[0].resourceNames - content: myrabbitmq-tls - - notContains: - path: rules[0].resourceNames - content: myrabbitmq-ca - - - it: Role does not grant the tenant-ca projection by name either - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: true - external: false - documentIndex: 0 - asserts: - - isKind: - of: Role - # Delivered through core.cozystack.io/tenantsecrets, not as a core/v1 - # Secret, so a resourceNames entry here would grant nothing. - - notContains: - path: rules[0].resourceNames - content: myrabbitmq.tenant-ca - - - it: Role still grants the default-user secret when TLS is on - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: true - external: false - documentIndex: 0 - asserts: - - isKind: - of: Role - - contains: - path: rules[0].resourceNames - content: myrabbitmq-default-user - - - it: Role does NOT grant access to TLS secret when TLS is disabled - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: false - external: false - documentIndex: 0 - asserts: - - isKind: - of: Role - - notContains: - path: rules[0].resourceNames - content: myrabbitmq-tls - - - it: Role does NOT grant access to TLS secret when tls.enabled is explicitly false even if external is true - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: false - external: true - _namespace.host: example.com - documentIndex: 0 - asserts: - - isKind: - of: Role - - notContains: - path: rules[0].resourceNames - content: myrabbitmq-tls - - # ----------------------------------------------------------------------- - # Verify RoleBinding is also rendered - # ----------------------------------------------------------------------- - - - it: RoleBinding is rendered as second document - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: false - external: false - documentIndex: 1 - asserts: - - isKind: - of: RoleBinding - - equal: - path: roleRef.name - value: myrabbitmq-dashboard-resources - - # ----------------------------------------------------------------------- - # Pin the complete list, not just the absence of known-bad names. Every other - # assertion here is a notContains, so a Role that gained the erlang cookie or - # any future Secret would satisfy all of them. This is the actual contract. - # ----------------------------------------------------------------------- - - - it: grants exactly the intended Secrets and nothing else, TLS on - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: true - external: false - documentIndex: 0 - asserts: - - equal: - path: rules[0].resourceNames - value: - - myrabbitmq-default-user - - - it: grants exactly the intended Secrets and nothing else, with users defined - release: - name: myrabbitmq - namespace: tenant-test - set: - tls.enabled: true - external: false - users.alice.password: hackme - documentIndex: 0 - asserts: - - equal: - path: rules[0].resourceNames - value: - - myrabbitmq-default-user - - myrabbitmq-alice-credentials diff --git a/packages/apps/rabbitmq/tests/tenant_projection_test.yaml b/packages/apps/rabbitmq/tests/tenant_projection_test.yaml index 01337cc67..4983e7445 100644 --- a/packages/apps/rabbitmq/tests/tenant_projection_test.yaml +++ b/packages/apps/rabbitmq/tests/tenant_projection_test.yaml @@ -4,9 +4,7 @@ suite: RabbitMQ TenantProjection sentinel # declaration that tells the CA-extraction controller to lift ca.crt out of the # key-bearing -ca into the tenant-readable .tenant-ca # projection. Without this sentinel the controller has no source to read, so -# .tenant-ca is never created and the Role's careful exclusion of the -# key-bearing Secrets (dashboard_resourcemap_test.yaml) buys the tenant no -# actual path to the CA. +# .tenant-ca is never created and the tenant has no path to the CA. # # The load-bearing invariant is the ABSENCE of ownerReferences. The sentinel must # carry none — it owns the projection, and it is itself owned only through the diff --git a/packages/apps/redis/templates/dashboard-resourcemap.yaml b/packages/apps/redis/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 82b582223..000000000 --- a/packages/apps/redis/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,60 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - rfs-{{ .Release.Name }} - - rfrm-{{ .Release.Name }} - - rfrs-{{ .Release.Name }} - - "{{ .Release.Name }}-external-lb" - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - {{- /* - No TLS Secret of this release is granted here, whatever tls.enabled and - tls.authClients are set to. The trust anchor a client needs travels to the - tenant as the key-free .tenant-ca projection instead - (templates/tenant-projection.yaml), which the platform's CA-extraction - controller writes and vouches for; a grant on a Secret name would convey - whatever occupies that name. - - The three Secrets deliberately absent: - - .ca-tls, the CA certificate and its private key. Anyone holding - the key can mint certificates that every client trusting this release's - CA accepts. - - .tls, the server leaf and its private key. Anyone holding it can - impersonate this release's Redis and Sentinel endpoints. - - .ca-cert, the CA-only copy the operator publishes. Key-free - today, but the operator holds create and update on Secrets cluster-wide, - so what lands under that name is the operator's choice rather than the - platform's, and RBAC cannot filter by key. - */}} - - "{{ .Release.Name }}-auth" - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }}-redis - - {{ .Release.Name }}-sentinel - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/redis/tests/tls_test.yaml b/packages/apps/redis/tests/tls_test.yaml index c8f55ee91..60716cefe 100644 --- a/packages/apps/redis/tests/tls_test.yaml +++ b/packages/apps/redis/tests/tls_test.yaml @@ -56,30 +56,6 @@ tests: - notExists: path: spec.tls - - it: "external=true alone grants the tenant no TLS secrets" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: true - documentSelector: - path: kind - value: Role - asserts: - # The negatives below address rules[1] by index, and notContains is - # fail-open on a path that does not exist, so a SECOND secrets rule - # granting the key-bearing Secrets would satisfy every one of them. - # Pin the rule count: the Role renders services, secrets and - # workloadmonitors, and nothing else. - - lengthEqual: - path: rules - count: 3 - - notContains: - path: rules[1].resourceNames - content: "my-redis.ca-cert" - - notContains: - path: rules[1].resourceNames - content: "my-redis.tls" - - it: "redisfailover.yaml does not have spec.tls when tls.enabled is unset" templates: - templates/redisfailover.yaml @@ -92,30 +68,6 @@ tests: - notExists: path: spec.tls - - it: "dashboard-resourcemap.yaml does not list TLS secrets when tls.enabled is unset" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: false - documentSelector: - path: kind - value: Role - asserts: - # The negatives below address rules[1] by index, and notContains is - # fail-open on a path that does not exist, so a SECOND secrets rule - # granting the key-bearing Secrets would satisfy every one of them. - # Pin the rule count: the Role renders services, secrets and - # workloadmonitors, and nothing else. - - lengthEqual: - path: rules - count: 3 - - notContains: - path: rules[1].resourceNames - content: "my-redis.tls" - - notContains: - path: rules[1].resourceNames - content: "my-redis.ca-cert" - # ------------------------------------------------------------------ # Case 2: tls.enabled=true -> the full cert-manager chain # ------------------------------------------------------------------ @@ -389,110 +341,6 @@ tests: path: spec.ipAddresses content: "::1" - - it: "dashboard-resourcemap.yaml grants no TLS secret in RBAC when authClients defaults to no" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: true - tls: - enabled: true - documentSelector: - path: kind - value: Role - asserts: - # The negatives below address rules[1] by index, and notContains is - # fail-open on a path that does not exist, so a SECOND secrets rule - # granting the key-bearing Secrets would satisfy every one of them. - # Pin the rule count: the Role renders services, secrets and - # workloadmonitors, and nothing else. - - lengthEqual: - path: rules - count: 3 - # The trust anchor reaches the tenant as the .tenant-ca - # projection, not as a grant on a Secret name, so the Role lists exactly - # the auth Secret and nothing TLS-related. - - equal: - path: rules[1].resourceNames - value: - - my-redis-auth - # The CA-only Secret the operator publishes. Key-free today, but the name - # is the operator's to fill and RBAC cannot filter by key. - - notContains: - path: rules[1].resourceNames - content: "my-redis.ca-cert" - # CA certificate and private key. - - notContains: - path: rules[1].resourceNames - content: "my-redis.ca-tls" - # Server leaf and private key. - - notContains: - path: rules[1].resourceNames - content: "my-redis.tls" - - - it: "dashboard-resourcemap.yaml withholds both key-bearing secrets in RBAC when authClients=yes" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: true - tls: - enabled: true - authClients: "yes" - documentSelector: - path: kind - value: Role - asserts: - # The negatives below address rules[1] by index, and notContains is - # fail-open on a path that does not exist, so a SECOND secrets rule - # granting the key-bearing Secrets would satisfy every one of them. - # Pin the rule count: the Role renders services, secrets and - # workloadmonitors, and nothing else. - - lengthEqual: - path: rules - count: 3 - - notContains: - path: rules[1].resourceNames - content: "my-redis.ca-cert" - # The server leaf carries tls.key. Granting it would let the tenant - # impersonate this release's Redis and Sentinel endpoints, so it stays - # withheld even though authClients=yes leaves the tenant without a - # client certificate the CA would accept. - - notContains: - path: rules[1].resourceNames - content: "my-redis.tls" - - notContains: - path: rules[1].resourceNames - content: "my-redis.ca-tls" - - - it: "dashboard-resourcemap.yaml withholds both key-bearing secrets in RBAC when authClients=optional" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: true - tls: - enabled: true - authClients: "optional" - documentSelector: - path: kind - value: Role - asserts: - # The negatives below address rules[1] by index, and notContains is - # fail-open on a path that does not exist, so a SECOND secrets rule - # granting the key-bearing Secrets would satisfy every one of them. - # Pin the rule count: the Role renders services, secrets and - # workloadmonitors, and nothing else. - - lengthEqual: - path: rules - count: 3 - - notContains: - path: rules[1].resourceNames - content: "my-redis.ca-cert" - - notContains: - path: rules[1].resourceNames - content: "my-redis.tls" - - notContains: - path: rules[1].resourceNames - content: "my-redis.ca-tls" - # ------------------------------------------------------------------ # Case 3: external=true, tls.enabled=false -> TLS explicitly off # ------------------------------------------------------------------ @@ -789,29 +637,6 @@ tests: path: spec.tls.caCertSecretName value: my-redis.ca-cert - - it: "the tenant is not granted the operator's CA-only secret by name" - templates: - - templates/dashboard-resourcemap.yaml - set: - external: true - tls: - enabled: true - documentSelector: - path: kind - value: Role - asserts: - # The negatives below address rules[1] by index, and notContains is - # fail-open on a path that does not exist, so a SECOND secrets rule - # granting the key-bearing Secrets would satisfy every one of them. - # Pin the rule count: the Role renders services, secrets and - # workloadmonitors, and nothing else. - - lengthEqual: - path: rules - count: 3 - - notContains: - path: rules[1].resourceNames - content: "my-redis.ca-cert" - # The chart creates -external-lb itself when external is on. It # resolves in-cluster like any Service, so a client dialing it by name needs # it in the SAN list; without it the handshake fails hostname verification diff --git a/packages/apps/valkey/templates/dashboard-resourcemap.yaml b/packages/apps/valkey/templates/dashboard-resourcemap.yaml deleted file mode 100644 index e2e27d287..000000000 --- a/packages/apps/valkey/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,41 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - rfs-{{ .Release.Name }} - - rfrm-{{ .Release.Name }} - - rfrs-{{ .Release.Name }} - - "{{ .Release.Name }}-external-lb" - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - "{{ .Release.Name }}-auth" - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }}-valkey - - {{ .Release.Name }}-sentinel - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/vm-disk/templates/dashboard-resourcemap.yaml b/packages/apps/vm-disk/templates/dashboard-resourcemap.yaml deleted file mode 100644 index b7276bb4a..000000000 --- a/packages/apps/vm-disk/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - cdi.kubevirt.io - resources: - - datavolumes - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/apps/vm-instance/templates/dashboard-resourcemap.yaml b/packages/apps/vm-instance/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 95e354018..000000000 --- a/packages/apps/vm-instance/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,44 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ include "virtual-machine.fullname" . }} - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io ---- -apiVersion: cozystack.io/v1alpha1 -kind: WorkloadMonitor -metadata: - name: {{ $.Release.Name }} - namespace: {{ $.Release.Namespace }} -spec: - replicas: 1 - minReplicas: 1 - kind: virtual-machine - type: virtual-machine - selector: - app.kubernetes.io/instance: {{ .Release.Name }} - version: {{ $.Chart.Version }} diff --git a/packages/apps/vm-instance/templates/workloadmonitor.yaml b/packages/apps/vm-instance/templates/workloadmonitor.yaml new file mode 100644 index 000000000..2179ab11b --- /dev/null +++ b/packages/apps/vm-instance/templates/workloadmonitor.yaml @@ -0,0 +1,13 @@ +apiVersion: cozystack.io/v1alpha1 +kind: WorkloadMonitor +metadata: + name: {{ $.Release.Name }} + namespace: {{ $.Release.Namespace }} +spec: + replicas: 1 + minReplicas: 1 + kind: virtual-machine + type: virtual-machine + selector: + app.kubernetes.io/instance: {{ .Release.Name }} + version: {{ $.Chart.Version }} diff --git a/packages/apps/vpn/templates/dashboard-resourcemap.yaml b/packages/apps/vpn/templates/dashboard-resourcemap.yaml deleted file mode 100644 index a4c3b4ec0..000000000 --- a/packages/apps/vpn/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - {{ .Release.Name }}-urls - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ .Release.Name }}-vpn - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "use" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/extra/bootbox/templates/dashboard-resourcemap.yaml b/packages/extra/bootbox/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 628025f61..000000000 --- a/packages/extra/bootbox/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,44 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - networking.k8s.io - resources: - - ingresses - resourceNames: - - bootbox - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - grafana-admin-password - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - services - resourceNames: - - bootbox - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - bootbox-matchbox - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "super-admin" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/extra/computeplane/templates/cluster.yaml b/packages/extra/computeplane/templates/cluster.yaml index 9c598d1af..529653e1e 100644 --- a/packages/extra/computeplane/templates/cluster.yaml +++ b/packages/extra/computeplane/templates/cluster.yaml @@ -111,8 +111,10 @@ spec: # merges spec.values after valuesFrom, so nothing injected via # cozystack-values can disable these pins. values: - # The wrapped chart otherwise lets the tenant's "use" subjects read - # computeplane-cluster-admin-kubeconfig through its dashboard Role. + # The kubernetes chart no longer reads this. It stays one release so + # that the previous kubernetes chart, still served by the ExternalArtifact + # until it catches up, does not render its dashboard Role with the admin + # kubeconfig again. Remove it in the next release. withholdAdminKubeconfig: true addons: certManager: diff --git a/packages/extra/computeplane/tests/cluster_test.yaml b/packages/extra/computeplane/tests/cluster_test.yaml index 66e326566..496b179fc 100644 --- a/packages/extra/computeplane/tests/cluster_test.yaml +++ b/packages/extra/computeplane/tests/cluster_test.yaml @@ -40,7 +40,7 @@ tests: path: spec.chartRef.kind value: ExternalArtifact - - it: withholds the admin kubeconfig from the tenant's dashboard Role + - it: keeps withholding the admin kubeconfig from the previous kubernetes chart documentSelector: path: metadata.name value: computeplane-cluster diff --git a/packages/extra/etcd/templates/dashboard-resourcemap.yaml b/packages/extra/etcd/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 8057b56d7..000000000 --- a/packages/extra/etcd/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - etcd - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "super-admin" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/extra/etcd/tests/no-post-upgrade-hook_test.yaml b/packages/extra/etcd/tests/no-post-upgrade-hook_test.yaml index 0e4f5aa3a..f41aabccb 100644 --- a/packages/extra/etcd/tests/no-post-upgrade-hook_test.yaml +++ b/packages/extra/etcd/tests/no-post-upgrade-hook_test.yaml @@ -6,7 +6,6 @@ release: templates: - templates/check-release-name.yaml - - templates/dashboard-resourcemap.yaml - templates/datastore.yaml - templates/etcd-defrag.yaml - templates/hook/job.yaml diff --git a/packages/extra/external-dns/templates/dashboard-resourcemap.yaml b/packages/extra/external-dns/templates/dashboard-resourcemap.yaml deleted file mode 100644 index edd96b74a..000000000 --- a/packages/extra/external-dns/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - helm.toolkit.fluxcd.io - resources: - - helmreleases - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "admin" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/extra/info/templates/dashboard-resourcemap.yaml b/packages/extra/info/templates/dashboard-resourcemap.yaml deleted file mode 100644 index aa8b7641b..000000000 --- a/packages/extra/info/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,34 +0,0 @@ -{{- $oidcEnabled := index .Values._cluster "oidc-enabled" }} -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: info-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - secrets - resourceNames: - {{- if eq $oidcEnabled "true" }} - - kubeconfig-{{ .Release.Namespace }} - {{- else }} - - {{ .Release.Namespace }} - {{- end }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{- if eq $oidcEnabled "true" }} -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "view" .Release.Namespace) }} -{{- else }} -- kind: ServiceAccount - name: tenant-{{ .Release.Namespace }} - namespace: tenant-{{ .Release.Namespace }} -{{- end }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/extra/ingress/templates/dashboard-resourcemap.yaml b/packages/extra/ingress/templates/dashboard-resourcemap.yaml deleted file mode 100644 index 487b0d62c..000000000 --- a/packages/extra/ingress/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ trimPrefix "tenant-" .Release.Namespace }}-ingress-controller - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ .Release.Name }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "admin" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/extra/monitoring/templates/dashboard-resourcemap.yaml b/packages/extra/monitoring/templates/dashboard-resourcemap.yaml deleted file mode 100644 index fab86a4e0..000000000 --- a/packages/extra/monitoring/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,70 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -- apiGroups: - - networking.k8s.io - resources: - - ingresses - resourceNames: - - grafana-ingress - - alerta - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - secrets - resourceNames: - - grafana-admin-password - verbs: ["get", "list", "watch"] -- apiGroups: - - "" - resources: - - services - resourceNames: - - grafana-service - - alerta - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - alerta - - grafana - - grafana-db - - alerta-db - - alertmanager - {{- range .Values.metricsStorages }} - - {{ .name }}-vmstorage - - {{ .name }}-vmselect - - {{ .name }}-vminsert - {{- end }} - {{- range .Values.logsStorages }} - - {{ .name }}-vlstorage - - {{ .name }}-vlselect - - {{ .name }}-vlinsert - {{- end }} - {{- range .Values.metricsStorages }} - - vmalert-{{ .name }} - {{- break }} - {{- end }} - {{- if and .Values.tracingCollector.enabled (or (include "monitoring.tracingCentral" .) (not (empty .Values.tracingStorages))) }} - - otel-traces - {{- end }} - {{- if include "monitoring.tracingCentralStore" . }} - - vmauth-traces-central - {{- end }} - verbs: ["get", "list", "watch"] ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "admin" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/extra/monitoring/tests/workloadmonitors_traces_test.yaml b/packages/extra/monitoring/tests/workloadmonitors_traces_test.yaml index b4f3048e9..6285b319d 100644 --- a/packages/extra/monitoring/tests/workloadmonitors_traces_test.yaml +++ b/packages/extra/monitoring/tests/workloadmonitors_traces_test.yaml @@ -1,13 +1,11 @@ suite: OTLP trace collector is accounted for in tenant workload monitoring # Every workload the monitoring chart ships is enumerated in workloadmonitors.yaml -# (so tenant workload health is tracked) and whitelisted in the dashboard-resources -# Role (so the tenant dashboard may read its WorkloadMonitor). The OTLP collector -# must be covered the same way — under the same gate it renders on +# so tenant workload health is tracked. The OTLP collector must be covered the +# same way — under the same gate it renders on # (tracingCollector.enabled AND a configured tracingStorages backend) and not when # tracing is off. templates: - templates/workloadmonitors.yaml - - templates/dashboard-resourcemap.yaml release: name: monitoring @@ -108,26 +106,6 @@ tests: - hasDocuments: count: 0 - - it: whitelists the central collector's WorkloadMonitor with no local backend - template: templates/dashboard-resourcemap.yaml - release: - namespace: tenant-foo - set: - _namespace: - tracingCentral: true - tracingCollector: - enabled: true - replicas: 1 - samplingPercentage: 10 - tracingStorages: [] - documentSelector: - path: kind - value: Role - asserts: - - contains: - path: rules[3].resourceNames - content: otel-traces - - it: accounts for the shared-store vmauth where tenant-root hosts it template: templates/workloadmonitors.yaml release: @@ -220,93 +198,18 @@ tests: - hasDocuments: count: 0 - - it: whitelists the shared-store vmauth WorkloadMonitor in the dashboard-resources Role - template: templates/dashboard-resourcemap.yaml - release: - namespace: tenant-root - set: - tracingCentralHost: true - tracingStorages: - - name: generic - mode: cluster - retentionPeriod: "14d" - storage: 10Gi - storageClassName: replicated + - it: renders no collector WorkloadMonitor when tracing is off (empty tracingStorages) + template: templates/workloadmonitors.yaml documentSelector: - path: kind - value: Role + path: metadata.name + value: otel-traces + skipEmptyTemplates: true asserts: - - contains: - path: rules[3].resourceNames - content: vmauth-traces-central + - hasDocuments: + count: 0 - - it: whitelists no vmauth WorkloadMonitor where tenant-root does not host - template: templates/dashboard-resourcemap.yaml - release: - namespace: tenant-root - set: - tracingStorages: - - name: generic - mode: cluster - retentionPeriod: "14d" - storage: 10Gi - storageClassName: replicated - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[3].resourceNames - content: vmauth-traces-central - - - it: whitelists the collector WorkloadMonitor in the dashboard-resources Role - template: templates/dashboard-resourcemap.yaml - set: - tracingCollector: - enabled: true - replicas: 1 - samplingPercentage: 10 - tracingStorages: - - name: generic - mode: cluster - retentionPeriod: "14d" - storage: 10Gi - storageClassName: replicated - documentSelector: - path: kind - value: Role - asserts: - - contains: - path: rules[3].resourceNames - content: otel-traces - # The Role must whitelist each WorkloadMonitor by its real name. Guard the - # alertmanager entry, which shipped misspelled ("alermanager") so the - # alertmanager WorkloadMonitor was silently not RBAC-covered for the - # dashboard — a defect in the exact resourceNames list this PR edits. - - contains: - path: rules[3].resourceNames - content: alertmanager - - notContains: - path: rules[3].resourceNames - content: alermanager - - # Absence is asserted on the resourcemap Role (a single deterministic document) - # via notContains rather than on workloadmonitors.yaml: that template emits a - # leading `---`, which makes containsDocument+not a no-op (an empty lead doc). - # Both templates gate the collector on the identical condition, so the Role's - # resourceNames list is a faithful proxy for whether the WorkloadMonitor renders. - - it: does not whitelist the collector when tracing is off (empty tracingStorages) - template: templates/dashboard-resourcemap.yaml - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[3].resourceNames - content: otel-traces - - - it: does not whitelist the collector when the collector is disabled - template: templates/dashboard-resourcemap.yaml + - it: renders no collector WorkloadMonitor when the collector is disabled + template: templates/workloadmonitors.yaml set: tracingCollector: enabled: false @@ -319,9 +222,9 @@ tests: storage: 10Gi storageClassName: replicated documentSelector: - path: kind - value: Role + path: metadata.name + value: otel-traces + skipEmptyTemplates: true asserts: - - notContains: - path: rules[3].resourceNames - content: otel-traces + - hasDocuments: + count: 0 diff --git a/packages/extra/seaweedfs/templates/dashboard-resourcemap.yaml b/packages/extra/seaweedfs/templates/dashboard-resourcemap.yaml deleted file mode 100644 index eb038fe8f..000000000 --- a/packages/extra/seaweedfs/templates/dashboard-resourcemap.yaml +++ /dev/null @@ -1,60 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: {{ .Release.Name }}-dashboard-resources -rules: -{{- if not (eq .Values.topology "Client") }} -- apiGroups: - - "" - resources: - - services - resourceNames: - - {{ $.Release.Name }}-s3 - verbs: ["get", "list", "watch"] -- apiGroups: - - networking.k8s.io - resources: - - ingresses - resourceNames: - - ingress-{{ $.Release.Name }}-s3 - verbs: ["get", "list", "watch"] -- apiGroups: - - cozystack.io - resources: - - workloadmonitors - resourceNames: - - {{ $.Release.Name }}-master - - {{ $.Release.Name }}-filer - - {{ $.Release.Name }}-db - - {{ $.Release.Name }}-s3 - {{- if .Values.lifecycle.enabled }} - - {{ $.Release.Name }}-admin - - {{ $.Release.Name }}-worker - {{- end }} - {{- if eq .Values.topology "Simple" }} - - {{ $.Release.Name }}-volume - {{- range $poolName, $pool := .Values.volume.pools }} - - {{ $.Release.Name }}-volume-{{ $poolName }} - {{- end }} - {{- else if eq .Values.topology "MultiZone" }} - {{- range $zoneName, $zone := .Values.volume.zones }} - - {{ $.Release.Name }}-volume-{{ $zoneName }} - {{- range $poolName, $pool := (dig "pools" dict $zone) }} - - {{ $.Release.Name }}-volume-{{ $zoneName }}-{{ $poolName }} - {{- end }} - {{- end }} - {{- end }} - verbs: ["get", "list", "watch"] -{{- end }} - ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: {{ .Release.Name }}-dashboard-resources -subjects: -{{ include "cozy-lib.rbac.subjectsForTenantAndAccessLevel" (list "super-admin" .Release.Namespace) }} -roleRef: - kind: Role - name: {{ .Release.Name }}-dashboard-resources - apiGroup: rbac.authorization.k8s.io diff --git a/packages/extra/seaweedfs/tests/lifecycle_test.yaml b/packages/extra/seaweedfs/tests/lifecycle_test.yaml index 633514280..823538c82 100644 --- a/packages/extra/seaweedfs/tests/lifecycle_test.yaml +++ b/packages/extra/seaweedfs/tests/lifecycle_test.yaml @@ -7,7 +7,6 @@ suite: seaweedfs lifecycle switch reaches the data plane templates: - templates/seaweedfs.yaml - templates/admin-credentials.yaml - - templates/dashboard-resourcemap.yaml release: name: seaweedfs @@ -295,36 +294,3 @@ tests: - equal: path: spec.upgrade.remediation.retries value: -1 - - # The dashboard reads each WorkloadMonitor by name through this Role, so a - # monitor missing from it never shows up for the tenant. - - it: lets the dashboard read the admin and worker monitors - template: templates/dashboard-resourcemap.yaml - set: *enabled - documentSelector: - path: kind - value: Role - asserts: - - contains: - path: rules[2].resourceNames - content: seaweedfs-admin - - contains: - path: rules[2].resourceNames - content: seaweedfs-worker - - - it: grants no lifecycle monitors when lifecycle is off - template: templates/dashboard-resourcemap.yaml - set: - <<: *platform - lifecycle: - enabled: false - documentSelector: - path: kind - value: Role - asserts: - - notContains: - path: rules[2].resourceNames - content: seaweedfs-admin - - notContains: - path: rules[2].resourceNames - content: seaweedfs-worker