Skip to content

portLevelMtls does not work on PeerAuthenticationPolicy #27994

Closed

Description

@Stono

Bug description
Given the following PeerAuthenticationPolicy

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  name: default
  namespace: istio-system
spec:
  mtls:
    mode: STRICT

Adding port level overrides as per https://istio.io/v1.6/docs/reference/config/security/peer_authentication, to give:

spec:
  mtls:
    mode: STRICT
  portLevelMtls:
    9090:
      mode: DISABLE

Pods outside the mesh (in our case prometheus) are still unable to communicate with apps on 9090:

❯ kis exec -it prometheus-0 /bin/wget -- http://10.206.7.196:9090 -O /dev/stdout
Defaulting container name to prometheus-configmap-reload.
Use 'kubectl describe pod/prometheus-0 -n istio-system' to see all of the containers in this pod.
Connecting to 10.206.7.196:9090 (10.206.7.196:9090)
wget: error getting response: Connection reset by peer

The pod we're trying to talk to here (10.206.7.196) has the following PodSpec:

    ports:                                                                                                                                                                                                         
    - containerPort: 8080
      name: http-web
      protocol: TCP 

Notice how we do not expose 9090 here, only 8080

And the following Sidecar information:

  spec:
    ingress:
    - defaultEndpoint: 127.0.0.1:8080
      port:
        name: http-app
        number: 8080
        protocol: HTTP
    workloadSelector:
      labels:
        app: istio-test-app-1
        group: delivery-platform

The only way we could get this to work was to add this to the deployment annotations:

traffic.sidecar.istio.io/includeInboundPorts: 8080

[x] Docs
[ ] Installation
[ ] Networking
[ ] Performance and Scalability
[ ] Extensions and Telemetry
[ ] Security
[x] Test and Release
[x] User Experience
[ ] Developer Infrastructure

Expected behavior
portLevelMtls to be honoured in the default PeerAuthenticationPolicy

Steps to reproduce the bug
As above

Version (include the output of istioctl version --remote and kubectl version --short and helm version if you used Helm)
1.6.12

How was Istio installed?
Helm

Environment where bug was observed (cloud vendor, OS, etc)
GKE

Activity

  1. changed the title [-]portLevelMtls does not work on the default PeerAuthenticationPolicy[/-] [+]portLevelMtls does not work on PeerAuthenticationPolicy[/+] on Oct 19, 2020
  2. Stono commented on Oct 19, 2020

    @Stono
    ContributorAuthor

    I've updated this issue to reflect the fact that it doesn't work on a local namespace peerAuthenticationPolicy either (discussing with @howardjohn)

  3. howardjohn commented on Oct 19, 2020

    @howardjohn
    Member

    The first issue faced here is invalid PA cause by not having validating webhook. However, even with that fixed, we see a poor interaction between Sidecar.ingress field and presence of the port in Service:

    Goal - all ports except 9090 are strict mtls. Port 9090 is for prometheus, so its not exposed in Service. Config:

    apiVersion: security.istio.io/v1beta1
    kind: PeerAuthentication
    metadata:
      name: default
    spec:
      selector:
        matchLabels:
          app: foo
      mtls:
        mode: STRICT
      portLevelMtls:
        9090:
          mode: DISABLE
    ---
    apiVersion: networking.istio.io/v1beta1
    kind: Sidecar
    metadata:
      labels:
        app: foo
      name: sidecar
    spec:
      ingress:
      - defaultEndpoint: 127.0.0.1:8080
        port:
          name: http-app
          number: 8080
          protocol: HTTP
      - defaultEndpoint: 127.0.0.1:9090
        port:
          name: tcp-test
          number: 9090
          protocol: TCP
      workloadSelector:
        labels:
          app: foo

    Results:

    PA+sidecar.ingress 8080 = no port 9090 config (seems like a bug to me)
    PA+sidecar.ingress 8080 and 9090 = port 9090 strict (clearly a bug)
    PA+no sidecar.ingress = no port 9090 config

    Add 9090 to Service:
    PA+sidecar.ingress 8080 = no port 9090 config
    PA+sidecar.ingress 8080 and 9090 = working
    PA+no sidecar.ingress = working

  4. howardjohn commented on Oct 19, 2020

    @howardjohn
    Member

    Seems same behavior is in master as well

  5. yangminzhu commented on Oct 19, 2020

    @yangminzhu
    Contributor

    @Stono Does this only happen when using the Sidecar.ingress to control the port on sidecar directly? Also note the port in PeerAuthentication should be workload port (not service port)

    @howardjohn , the documentation of the sidecar.ingress says that If specified, inbound ports are configured if and only if the workload instance is associated with a service., Are the bugs you see happening when there is no service?

  6. howardjohn commented on Oct 19, 2020

    @howardjohn
    Member

    @yangminzhu there are two bugs:

    • If sidecar.ingress is configured for the port, portLevelMtls is not set. This is because ServiceInstance.Endpoint.EndpointPort is not set when calling the plugin.
    • If a port in portLevelMtls is not included in an associated Service, there is no config for that port. This is because pilot does not generate a filter chain for this port, and therefor the plugin cannot apply the mTLS config on that port. Instead it goes through passthrough which gets the non-portLevelMtls settings.
  7. jacob-delgado commented on Oct 27, 2020

    @jacob-delgado
    Contributor

    cc @howardjohn @yangminzhu Would this affect a relatively small set of users? I'm not sure how many people have disabled the validating webhook.

    With release 1.6 closing mid-November is this something that can be fixed before then? This only affects in-cluster communication to, right?

  8. howardjohn commented on Oct 27, 2020

    @howardjohn
    Member

    @jacob-delgado the validation part is not very relevant, the bug occurs even with valid PA, and impacts versions 1.6+, including master

  9. yangminzhu commented on Oct 29, 2020

    @yangminzhu
    Contributor

    If sidecar.ingress is configured for the port, portLevelMtls is not set. This is because ServiceInstance.Endpoint.EndpointPort is not set when calling the plugin.
    If a port in portLevelMtls is not included in an associated Service, there is no config for that port. This is because pilot does not generate a filter chain for this port, and therefor the plugin cannot apply the mTLS config on that port. Instead it goes through passthrough which gets the non-portLevelMtls settings.

    When port is specified in service:
    Case 1: no sidecar resource applied -> good
    Case 2: port specified in the sidecar.ingress -> good
    Case 3: port NOT specified in the sidecar.ingress -> filter chain NOT created for the port, portLevelSetting NOT applied

    When port is NOT specified in service:
    Case 4: no sidecar resource applied -> filter chain NOT created for the port, portLevelSetting NOT applied
    Case 5: port specified in the sidecar.ingress -> filter chain created for the port, portLevelSetting NOT applied
    Case 6: port NOT specified in the sidecar.ingress -> filter chain NOT created for the port, portLevelSetting NOT applied

    I think case 3, 4 and 6 are actually the same thing that we don't generate the filter chain for the port if it is only specified in the portLevelSetting, in all these cases the traffic is to be handled by the passthrough filter chain which is still controlled by the top-level setting in PeerAuthN. We probably should add some clarifications to the API and documentation about this behavior. The other way is to probably to create the filter chain also depending on portLevelSetting, which I don't feel it's a good idea as it introduces the 3rd factor that affects the filter chain creation out of networking API. I guess this is also kind of the reason why we decided not to mess up with the passthrough filter chain with portLevelSetting in the first place? cc @incfly @myidpt do you have more context on this? (Diem probably know more)

    Case 5 seems like a bug, @howardjohn , is this the case when you say If sidecar.ingress is configured for the port, portLevelMtls is not set. This is because ServiceInstance.Endpoint.EndpointPort is not set when calling the plugin.? If so we should fix this.

  10. howardjohn commented on Oct 29, 2020

    @howardjohn
    Member

    I think from an implementation perspective it makes sense how it works. From an API/user perspective, I think it's pretty clear that if you specify the port level setting you expect it to apply. IMO we should optimize for the API not the implementation.

    and yes that's what I meant by case 5

  11. yangminzhu commented on Oct 29, 2020

    @yangminzhu
    Contributor

    From an API/user perspective, I think it's pretty clear that if you specify the port level setting you expect it to apply. IMO we should optimize for the API not the implementation.

    yeah, I agree. From the API perspective the user would expect it just work since the creation of filter chain is an implementation detail and should not affect the API. Regarding implementation, it seems the only feasible solution is to duplicate all the passthrough filter chains for the ports that are ONLY specified in portLevelSettings, do you have any suggestions? (Not sure how complex to do this)

    also cc @lambdai, not sure how will the BTS affect the passthrough filter chain and the issue here.

  12. yangminzhu commented on Oct 29, 2020

    @yangminzhu
    Contributor

    Actually thinking more of case 3 and 6 and looking at the sidecar.ingress API, it seems the semantic is that the sidecar should only process inbound traffic to the attached workload instance for ports specified in sidecar.ingress (if any)?
    If so, shouldn't we restrict the passthrough filter chain to only accept the explicitly specified ports in the first place? And this should be done regardless of PeerAuthN.portLevelSetting.

  13. incfly commented on Nov 9, 2020

    @incfly

    @yangminzhu the case 4) is not intention if I remembered correctly. We just lack the bandwidth to do that properly: if the port is not defined in the service, by API semantics, generating additional configuration would be more intended behavior.

  14. yangminzhu commented on Nov 10, 2020

    @yangminzhu
    Contributor

    @yangminzhu the case 4) is not intention if I remembered correctly. We just lack the bandwidth to do that properly: if the port is not defined in the service, by API semantics, generating additional configuration would be more intended behavior.

    correct, it is actually NOT supported from the beginning but we didn't document this very clearly though.

  15. ltdeoliveira commented on Dec 1, 2020

    @ltdeoliveira

    I'm currently migrating to 1.6.8 and having many connection problems. Also, not looking for moving to 1.8 right now.

    I'm interested to know if there would be any other way to disable mTLS for a port directly in the proxy, perhaps using an EvoyFilter or something like that.

  16. infa-sanaik commented on Dec 15, 2020

    @infa-sanaik

    I'm currently migrating to 1.6.8 and having many connection problems. Also, not looking for moving to 1.8 right now.

    I'm interested to know if there would be any other way to disable mTLS for a port directly in the proxy, perhaps using an EvoyFilter or something like that.

    Please try portLevelMtls, it worked for us

    apiVersion: security.istio.io/v1beta1
    kind: PeerAuthentication
    metadata:
      name: your-service-peer-auth
      namespace: {{ .Release.Namespace }}
    spec:
      selector:
        matchLabels:
          app: your-app-name
          release: your-app-release
      portLevelMtls:
        8443:
          mode: DISABLE
    
  17. added
    lifecycle/staleIndicates a PR or issue hasn't been manipulated by an Istio team member for a while
    on Feb 8, 2021
  18. istio-policy-bot commented on Feb 23, 2021

    @istio-policy-bot

    🚧 This issue or pull request has been closed due to not having had activity from an Istio team member since 2020-11-10. If you feel this issue or pull request deserves attention, please reopen the issue. Please see this wiki page for more information. Thank you for your contributions.

    Created by the issue and PR lifecycle manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions