Skip to content

Conversation

@alpeb
Copy link
Member

@alpeb alpeb commented Dec 4, 2025

(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:

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

(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
```
@alpeb alpeb merged commit aa193ab into main Dec 5, 2025
95 of 99 checks passed
@alpeb alpeb deleted the alpeb/nativesidecar-policy branch December 5, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants