Skip to content

Commit aa193ab

Browse files
authored
fix(cli): improved support for native sidecar servers in linkerd authz (#14780)
(Extracted from #14566) The logic behind the `linkerd authz` command wasn't accounting for ports in init containers, so authorization policies pointing to those ports were not reported by the command. Say for example you had a strict auth policy for the `linkerd-admin` port, allowing only access from prometheus. For emojivoto's web workload you could set that up like this: ```yaml apiVersion: policy.linkerd.io/v1beta3 kind: Server metadata: annotations: name: admin namespace: emojivoto spec: accessPolicy: deny podSelector: matchLabels: app: web-svc port: linkerd-admin proxyProtocol: HTTP/1 --- apiVersion: policy.linkerd.io/v1alpha1 kind: MeshTLSAuthentication metadata: namespace: emojivoto name: prometheus spec: identities: - "prometheus.linkerd-viz.serviceaccount.identity.linkerd.cluster.local" --- apiVersion: policy.linkerd.io/v1alpha1 kind: AuthorizationPolicy metadata: namespace: emojivoto name: web-http-sa spec: targetRef: group: policy.linkerd.io kind: Server name: admin requiredAuthenticationRefs: - name: prometheus kind: MeshTLSAuthentication group: policy.linkerd.io ``` Invoking `linkerd authz` would return nothing, but after this change we can see the auth: ``` $ linkerd authz -n emojivoto deploy/web ROUTE SERVER AUTHORIZATION_POLICY SERVER_AUTHORIZATION * admin web-http-sa ```
1 parent 7a1a06c commit aa193ab

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pkg/k8s/policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func serverIncludesPod(server serverv1beta3.Server, pods []corev1.Pod) bool {
247247

248248
for _, pod := range pods {
249249
if selector.Matches(labels.Set(pod.Labels)) {
250-
for _, container := range pod.Spec.Containers {
250+
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
251251
for _, p := range container.Ports {
252252
if server.Spec.Port.IntVal == p.ContainerPort || server.Spec.Port.StrVal == p.Name {
253253
return true

0 commit comments

Comments
 (0)