Repository navigation
Description
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
[-]portLevelMtls does not work on the default PeerAuthenticationPolicy[/-][+]portLevelMtls does not work on PeerAuthenticationPolicy[/+]Stono commentedon Oct 19, 2020
I've updated this issue to reflect the fact that it doesn't work on a local namespace peerAuthenticationPolicy either (discussing with @howardjohn)
howardjohn commentedon Oct 19, 2020
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:
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
howardjohn commentedon Oct 19, 2020
Seems same behavior is in master as well
yangminzhu commentedon Oct 19, 2020
@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?howardjohn commentedon Oct 19, 2020
@yangminzhu there are two bugs:
jacob-delgado commentedon Oct 27, 2020
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?
howardjohn commentedon Oct 27, 2020
@jacob-delgado the validation part is not very relevant, the bug occurs even with valid PA, and impacts versions 1.6+, including master
yangminzhu commentedon Oct 29, 2020
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.howardjohn commentedon Oct 29, 2020
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
yangminzhu commentedon Oct 29, 2020
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.
yangminzhu commentedon Oct 29, 2020
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.
incfly commentedon Nov 9, 2020
@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.
yangminzhu commentedon Nov 10, 2020
correct, it is actually NOT supported from the beginning but we didn't document this very clearly though.
ltdeoliveira commentedon Dec 1, 2020
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.
infa-sanaik commentedon Dec 15, 2020
Please try portLevelMtls, it worked for us
istio-policy-bot commentedon Feb 23, 2021
🚧 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.