diff --git a/internal/observabilityproxy/route.go b/internal/observabilityproxy/route.go index 49a7c1770..bc12c6276 100644 --- a/internal/observabilityproxy/route.go +++ b/internal/observabilityproxy/route.go @@ -132,10 +132,14 @@ func ParseRoute(escapedPath string) (Route, *HTTPError) { } // Reviews lists every access a request on the route needs. An application -// root also needs read access to its namespace root: its pod and PVC -// branches match by name across the window, so a name another application -// held earlier reaches that application's series, and a grant narrowed by -// resourceNames would read more than it names. +// root also needs read access to its namespace root, because its scope +// narrows within the namespace but does not isolate: on both roots the +// identity comes from lineage labels that the lineage webhook keeps as set +// on an object it finds no owner for, so anyone who can create a pod there +// can label it as the application; on the metrics root the pod and PVC +// branches also match by name across the window, so a name another +// application held earlier reaches that application's series. A grant +// narrowed by resourceNames would read more than it names. func (r Route) Reviews() []authorizationv1.ResourceAttributes { switch r.Kind { case ApplicationLog: diff --git a/internal/observabilityproxy/server_app_test.go b/internal/observabilityproxy/server_app_test.go index 7afaa3618..461cbc16d 100644 --- a/internal/observabilityproxy/server_app_test.go +++ b/internal/observabilityproxy/server_app_test.go @@ -282,9 +282,10 @@ func TestServerApplicationMetricsBranches(t *testing.T) { // A grant narrowed to application "a" by resourceNames must not reach "b" // through any endpoint of either root. Without read access to the -// namespace roots it does not reach "a" either: the pod and PVC branches -// match by name, and a name another application used earlier in the -// window would pull its series in. +// namespace roots it does not reach "a" either: an ownerless pod keeps the +// lineage labels its creator set, so it can claim to be "a" on both roots, +// and on the metrics root the pod and PVC branches match by name, so a name +// another application used earlier in the window would pull its series in. func TestServerApplicationNarrowedGrant(t *testing.T) { h := newPolicyHarness(t, Config{}, appMetricsUpstream([]string{"a-0"}, nil, http.StatusOK), appPolicy, nil) paths := []string{ diff --git a/packages/system/observability-proxy/templates/tenant-clusterroles.yaml b/packages/system/observability-proxy/templates/tenant-clusterroles.yaml index a2bf94f3c..ff5f3b987 100644 --- a/packages/system/observability-proxy/templates/tenant-clusterroles.yaml +++ b/packages/system/observability-proxy/templates/tenant-clusterroles.yaml @@ -1,7 +1,11 @@ # Aggregated into cozy-tenant-view (and consequently use, admin, super-admin). # No API server serves cozystack.io logs or metrics: the rule exists only for # the SubjectAccessReview the observability proxy asks before it answers a -# read under /apis/cozystack.io/v1alpha1/namespaces//{logs,metrics}/. +# read under /apis/cozystack.io/v1alpha1/namespaces//{logs,metrics}/, +# and before a read under an application root, +# /apis/apps.cozystack.io/v1alpha1/namespaces////{log,metrics}/, +# which needs the namespace root too. Narrowing this role also cuts off the +# application roots. apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: