Skip to content

Commit 7e76d68

Browse files
authored
Merge pull request #34700 from abrennan89/SRVKS-562
SRVKS-562: Restrictive network policy docs for Knative services
2 parents 59f7d5c + 2784ed2 commit 7e76d68

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[id="serverless-services-network-policies_{context}"]
2+
= Enabling communication with Knative applications on a cluster with restrictive network policies
3+
4+
If you are using a cluster that multiple users have access to, your cluster might use network policies to control which pods, services, and namespaces can communicate with each other over the network.
5+
6+
If your cluster uses restrictive network policies, it is possible that Knative system pods are not able to access your Knative application. For example, if your namespace has the following network policy, which denies all requests, Knative system pods cannot access your Knative application:
7+
8+
.Example NetworkPolicy object that denies all requests to the namespace
9+
[source,yaml]
10+
----
11+
kind: NetworkPolicy
12+
apiVersion: networking.k8s.io/v1
13+
metadata:
14+
name: deny-by-default
15+
namespace: example-namespace
16+
spec:
17+
podSelector:
18+
ingress: []
19+
----
20+
21+
To allow access to your applications from Knative system pods, you must add a label to each of the Knative system namespaces, and then create a `NetworkPolicy` object in your application namespace that allows access to the namespace for other namespaces that have this label.
22+
23+
[IMPORTANT]
24+
====
25+
A network policy that denies requests to non-Knative services on your cluster still prevents access to these services. However, by allowing access from Knative system namespaces to your Knative application, you are allowing access to your Knative application from all namespaces in the cluster.
26+
27+
If you do not want to allow access to your Knative application from all namespaces on the cluster, you might want to use _JSON Web Token authentication for Knative services_ instead (see the _Knative Serving_ documentation). JSON Web Token authentication for Knative services requires Service Mesh.
28+
====
29+
// xrefs for modules would be nice here to link to the JWT docs
30+
31+
.Procedure
32+
33+
. Add the `knative.openshift.io/system-namespace=true` label to each Knative system namespace that requires access to your application:
34+
35+
.. Label the `knative-serving` namespace:
36+
+
37+
[source, terminal]
38+
----
39+
$ oc label namespace knative-serving knative.openshift.io/system-namespace=true
40+
----
41+
42+
.. Label the `knative-serving-ingress` namespace:
43+
+
44+
[source, terminal]
45+
----
46+
$ oc label namespace knative-serving-ingress knative.openshift.io/system-namespace=true
47+
----
48+
49+
.. Label the `knative-eventing` namespace:
50+
+
51+
[source, terminal]
52+
----
53+
$ oc label namespace knative-eventing knative.openshift.io/system-namespace=true
54+
----
55+
56+
.. Label the `knative-kafka` namespace:
57+
+
58+
[source, terminal]
59+
----
60+
$ oc label namespace knative-kafka knative.openshift.io/system-namespace=true
61+
----
62+
63+
. Create a `NetworkPolicy` object in your application namespace to allow access from namespaces with the `knative.openshift.io/system-namespace` label:
64+
+
65+
.Example `NetworkPolicy` object
66+
[source,yaml]
67+
----
68+
apiVersion: networking.k8s.io/v1
69+
kind: NetworkPolicy
70+
metadata:
71+
name: <network_policy_name> <1>
72+
namespace: <namespace> <2>
73+
spec:
74+
ingress:
75+
- from:
76+
- namespaceSelector:
77+
matchLabels:
78+
knative.openshift.io/system-namespace: "true"
79+
podSelector: {}
80+
policyTypes:
81+
- Ingress
82+
----
83+
<1> Provide a name for your network policy.
84+
<2> The namespace where your application (Knative service) exists.

serverless/knative_serving/serverless-applications.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ include::modules/kn-service-describe.adoc[leveloffset=+1]
3535
include::modules/verifying-serverless-app-deployment.adoc[leveloffset=+1]
3636
include::modules/interacting-serverless-apps-http2-gRPC.adoc[leveloffset=+1]
3737

38+
// Using Knative services w/ restrictive NetworkPolicies
39+
include::modules/serverless-services-network-policies.adoc[leveloffset=+1]
40+
3841
[id="serverless-applications-kn-offline-mode"]
3942
== Using kn CLI in offline mode
4043

0 commit comments

Comments
 (0)