-
Notifications
You must be signed in to change notification settings - Fork 6
Kubernetes: add deny all global network policy #1164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
YuryHrytsuk
merged 24 commits into
ITISFoundation:main
from
YuryHrytsuk:kubernetes-add-deny-all-global-network-policy
Aug 6, 2025
Merged
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a54b73c
Kubernetes: refactor local cluster deployment
YuryHrytsuk 3b2a5c9
Use newer version
YuryHrytsuk 2b99236
Update install calico link
YuryHrytsuk eadd4a7
Add default global network policy
YuryHrytsuk b950879
Merge branch 'main' into local-kubernetes-use-calico
YuryHrytsuk 79b333a
Global deny network policy
YuryHrytsuk 3bcac1e
Merge branch 'local-kubernetes-use-calico' into kubernetes-add-deny-a…
YuryHrytsuk f4f980d
Report progress on waiting for calico to start
YuryHrytsuk c1a5ec4
Merge branch 'local-kubernetes-use-calico' into kubernetes-add-deny-a…
YuryHrytsuk 943e9be
Merge remote-tracking branch 'upstream/main' into kubernetes-add-deny…
YuryHrytsuk cab6786
Update notes for calico configuration helm chart
YuryHrytsuk 0130ae3
Update calico configuration readme
YuryHrytsuk 28815f5
Fix typo
YuryHrytsuk dbd7fcc
Fix readme
YuryHrytsuk df6f591
Add missing longhorn ns
YuryHrytsuk 952b976
Fix portainer values
YuryHrytsuk ea116a7
Allow public dns requests and imrpove calico config readme
YuryHrytsuk 2c63548
Merge remote-tracking branch 'upstream/main' into kubernetes-add-deny…
YuryHrytsuk 574c5bb
Document how to view network policies
YuryHrytsuk 05adb57
Warn to restart pods to apply network policies
YuryHrytsuk b64c882
Automaticalla restart adminer pods on network policy change
YuryHrytsuk 15336ba
Remove comment. It renders in final chart
YuryHrytsuk 6c41bc4
Portainer: document lacking pod annotations and link PR
YuryHrytsuk 4839a75
Document pod annotation checksum trick
YuryHrytsuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,5 @@ values.yaml | |
| values.*.yaml | ||
| k8s_hosts.ini | ||
| helmfile.y?ml | ||
|
|
||
| *.tgz | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| apiVersion: projectcalico.org/v3 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: adminer-network-policy | ||
| labels: | ||
| {{- include "adminer.labels" . | nindent 4 }} | ||
| spec: | ||
| selector: app.kubernetes.io/instance == "{{ .Release.Name }}" | ||
| ingress: | ||
| - action: Allow | ||
| protocol: TCP | ||
| destination: | ||
| ports: | ||
| - {{ .Values.service.port }} | ||
| egress: | ||
| - action: Allow | ||
| protocol: TCP | ||
| destination: | ||
| ports: | ||
| - 5432 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Patterns to ignore when building packages. | ||
| # This supports shell glob matching, relative path matching, and | ||
| # negation (prefixed with !). Only one pattern per line. | ||
| .DS_Store | ||
| # Common VCS dirs | ||
| .git/ | ||
| .gitignore | ||
| .bzr/ | ||
| .bzrignore | ||
| .hg/ | ||
| .hgignore | ||
| .svn/ | ||
| # Common backup files | ||
| *.swp | ||
| *.bak | ||
| *.tmp | ||
| *.orig | ||
| *~ | ||
| # Various IDEs | ||
| .project | ||
| .idea/ | ||
| *.tmproj | ||
| .vscode/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| apiVersion: v2 | ||
| name: calico-configuration | ||
| description: A Helm chart for Kubernetes | ||
|
|
||
| # A chart can be either an 'application' or a 'library' chart. | ||
| # | ||
| # Application charts are a collection of templates that can be packaged into versioned archives | ||
| # to be deployed. | ||
| # | ||
| # Library charts provide useful utilities or functions for the chart developer. They're included as | ||
| # a dependency of application charts to inject those utilities and functions into the rendering | ||
| # pipeline. Library charts do not define any templates and therefore cannot be deployed. | ||
| type: application | ||
|
|
||
| # This is the chart version. This version number should be incremented each time you make changes | ||
| # to the chart and its templates, including the app version. | ||
| # Versions are expected to follow Semantic Versioning (https://semver.org/) | ||
| version: 0.0.1 | ||
|
|
||
| # This is the version number of the application being deployed. This version number should be | ||
| # incremented each time you make changes to the application. Versions are not expected to | ||
| # follow Semantic Versioning. They should reflect the version the application is using. | ||
| # It is recommended to use it with quotes. | ||
| appVersion: "3.26.4" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ## How to add network policy (local deployment) | ||
|
|
||
YuryHrytsuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| How to discover ports / networks that are used by application | ||
| * enable and observe traffic via | ||
| - https://docs.tigera.io/calico/3.30/observability/enable-whisker | ||
| - https://docs.tigera.io/calico/3.30/observability/view-flow-logs | ||
| * add staged policies to make sure all cases are included https://docs.tigera.io/calico/3.30/network-policy/staged-network-policies | ||
| * transform staged policies to "normal" policies | ||
|
|
||
| ## Debug network policies | ||
| * observe traffic and check `policies` field in whisker logs | ||
| - https://docs.tigera.io/calico/3.30/observability/enable-whisker | ||
| - https://docs.tigera.io/calico/3.30/observability/view-flow-logs | ||
|
|
||
| Warning: make sure that calico version being used support Whisker (first introduced in v3.30) | ||
|
|
||
| ## Known issues | ||
|
|
||
| If network policy is created after pod, pod **MUST** be restarted for policy to take effect. Read more https://github.com/projectcalico/calico/issues/10753#issuecomment-3140717418 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| This chart configures Calico but does not deploy Calico itself. Calico is deployed during the Kubernetes cluster creation. | ||
YuryHrytsuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Note: to make sure network policies are applied correctly, you may need to restart targeted application pods. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Source: https://docs.tigera.io/calico/3.30/network-policy/get-started/kubernetes-default-deny | ||
| apiVersion: projectcalico.org/v3 | ||
| kind: GlobalNetworkPolicy | ||
| metadata: | ||
| name: default-global-deny-network-policy | ||
| spec: | ||
| # "kube-public", "kube-system", "kube-node-lease" -- system namespaces | ||
| # "calico-system", "calico-apiserver", "tigera-operator" -- calico namespaces (when installed via scripts [local deployment]) | ||
| # TODO: other namespaces are to be removed from this list (once appropriate network policies are created) | ||
| namespaceSelector: | ||
| kubernetes.io/metadata.name not in {"kube-public", "kube-system", "kube-node-lease", "calico-system", "calico-apiserver", "tigera-operator", "simcore", "cert-manager", "reflector", "traefik", "victoria-logs", "csi-s3", "portainer", "topolvm", "local-path-storage"} | ||
YuryHrytsuk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| types: | ||
| - Ingress | ||
| - Egress | ||
| egress: | ||
YuryHrytsuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # allow all namespaces to communicate to DNS pods | ||
| # this will also apply to pods that have network policy defined | ||
| # so that we don't need to define DNS policy for each pod | ||
| - action: Allow | ||
| protocol: UDP | ||
| destination: | ||
| selector: 'k8s-app == "kube-dns"' | ||
| ports: | ||
| - 53 | ||
| - action: Allow | ||
| protocol: TCP | ||
| destination: | ||
| selector: 'k8s-app == "kube-dns"' | ||
| ports: | ||
| - 53 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| dependencies: | ||
| - name: portainer | ||
| repository: https://portainer.github.io/k8s/ | ||
| version: 1.0.54 | ||
| digest: sha256:bafe4182881aee8c6df3d3c6f8c523a1bd7577bed04942ad3d9b857a5437d96f | ||
| generated: "2025-07-29T11:07:15.39037387+02:00" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| apiVersion: v2 | ||
| name: portainer | ||
| description: A Helm chart for Kubernetes | ||
|
|
||
| # A chart can be either an 'application' or a 'library' chart. | ||
| # | ||
| # Application charts are a collection of templates that can be packaged into versioned archives | ||
| # to be deployed. | ||
| # | ||
| # Library charts provide useful utilities or functions for the chart developer. They're included as | ||
| # a dependency of application charts to inject those utilities and functions into the rendering | ||
| # pipeline. Library charts do not define any templates and therefore cannot be deployed. | ||
| type: application | ||
|
|
||
| # This is the chart version. This version number should be incremented each time you make changes | ||
| # to the chart and its templates, including the app version. | ||
| # Versions are expected to follow Semantic Versioning (https://semver.org/) | ||
| version: 1.0.54 | ||
|
|
||
| # This is the version number of the application being deployed. This version number should be | ||
| # incremented each time you make changes to the application. Versions are not expected to | ||
| # follow Semantic Versioning. They should reflect the version the application is using. | ||
| # It is recommended to use it with quotes. | ||
| appVersion: 2.21.2 | ||
|
|
||
| dependencies: | ||
| - name: portainer | ||
| version: 1.0.54 | ||
| repository: "https://portainer.github.io/k8s/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Wrapper around portainer helm chart https://github.com/portainer/k8s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| apiVersion: projectcalico.org/v3 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: portainer-network-policy | ||
| spec: | ||
| selector: app.kubernetes.io/instance == "portainer" | ||
| types: | ||
| - Ingress | ||
| - Egress | ||
| egress: | ||
| - action: Allow | ||
| protocol: TCP | ||
| # connect to the Kubernetes API server | ||
| destination: | ||
| ports: | ||
| - 6443 | ||
| nets: | ||
| - 10.0.0.0/8 | ||
YuryHrytsuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - 172.16.0.0/12 | ||
| - 192.168.0.0/16 | ||
| # coredns 53 allow from kube system | ||
| - action: Allow | ||
| protocol: UDP | ||
| destination: | ||
| # `selector: 'k8s-app == "kube-dns"'` does not work (so global policy default dns allow does not work) | ||
| # manually allow dns and use different selector that works. | ||
| selectorNamespace: kubernetes.io/metadata.name == "kube-system" | ||
| ports: | ||
| - 53 | ||
| ingress: | ||
| - action: Allow | ||
| # allow traffic to portainer GUI | ||
| protocol: TCP | ||
| destination: | ||
| ports: | ||
| - {{ .Values.servicePort }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,69 +1,68 @@ | ||
| # Default values for adminer. | ||
| # This is a YAML-formatted file. | ||
| # Declare variables to be passed into your templates. | ||
| servicePort: &servicePort 9000 | ||
|
|
||
| replicaCount: 1 | ||
| portainer: | ||
| replicaCount: 1 | ||
|
|
||
| image: | ||
| repository: portainer/portainer-ce | ||
| pullPolicy: IfNotPresent | ||
| image: | ||
| repository: portainer/portainer-ce | ||
| pullPolicy: IfNotPresent | ||
|
|
||
| imagePullSecrets: [] | ||
| nameOverride: "" | ||
| fullnameOverride: "" | ||
| imagePullSecrets: [] | ||
| nameOverride: "" | ||
| fullnameOverride: "" | ||
|
|
||
| serviceAccount: | ||
| # Annotations to add to the service account | ||
| annotations: {} | ||
| # The name of the service account to use. | ||
| # If not set and create is true, a name is generated using the fullname template | ||
| name: portainer-sa-clusteradmin | ||
| serviceAccount: | ||
| # Annotations to add to the service account | ||
| annotations: {} | ||
| # The name of the service account to use. | ||
| # If not set and create is true, a name is generated using the fullname template | ||
| name: portainer-sa-clusteradmin | ||
|
|
||
| persistence: {} | ||
| persistence: {} | ||
|
|
||
| podAnnotations: {} | ||
| podLabels: {} | ||
| podAnnotations: {} | ||
| podLabels: {} | ||
|
|
||
| podSecurityContext: | ||
| {} | ||
| podSecurityContext: | ||
| {} | ||
|
|
||
| securityContext: | ||
| {} | ||
| securityContext: | ||
| {} | ||
|
|
||
| service: | ||
| type: "ClusterIP" | ||
| port: 9000 | ||
| service: | ||
| type: "ClusterIP" | ||
| port: *servicePort | ||
YuryHrytsuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ingress: | ||
| enabled: true | ||
| className: "" | ||
| annotations: | ||
| namespace: {{ .Release.Namespace }} | ||
| cert-manager.io/cluster-issuer: "cert-issuer" | ||
| traefik.ingress.kubernetes.io/router.entrypoints: websecure | ||
| traefik.ingress.kubernetes.io/router.middlewares: traefik-traefik-basic-auth@kubernetescrd,traefik-portainer-strip-prefix@kubernetescrd # namespace + middleware name | ||
| tls: | ||
| - hosts: | ||
| - {{ requiredEnv "K8S_MONITORING_FQDN" }} | ||
| secretName: monitoring-tls | ||
| hosts: | ||
| - host: {{ requiredEnv "K8S_MONITORING_FQDN" }} | ||
| paths: | ||
| - path: /portainer | ||
| pathType: Prefix | ||
| backend: | ||
| service: | ||
| name: portainer | ||
| port: | ||
| number: 9000 | ||
| ingress: | ||
| enabled: true | ||
| className: "" | ||
| annotations: | ||
| namespace: {{ .Release.Namespace }} | ||
| cert-manager.io/cluster-issuer: "cert-issuer" | ||
| traefik.ingress.kubernetes.io/router.entrypoints: websecure | ||
| traefik.ingress.kubernetes.io/router.middlewares: traefik-traefik-basic-auth@kubernetescrd,traefik-portainer-strip-prefix@kubernetescrd # namespace + middleware name | ||
| tls: | ||
| - hosts: | ||
| - {{ requiredEnv "K8S_MONITORING_FQDN" }} | ||
| secretName: monitoring-tls | ||
| hosts: | ||
| - host: {{ requiredEnv "K8S_MONITORING_FQDN" }} | ||
| paths: | ||
| - path: /portainer | ||
| pathType: Prefix | ||
| backend: | ||
| service: | ||
| name: portainer | ||
| port: | ||
| number: *servicePort | ||
|
|
||
| resources: | ||
| limits: | ||
| cpu: 2 | ||
| memory: 1024Mi | ||
| requests: | ||
| cpu: 0.1 | ||
| memory: 128Mi | ||
| resources: | ||
| limits: | ||
| cpu: 2 | ||
| memory: 1024Mi | ||
| requests: | ||
| cpu: 0.1 | ||
| memory: 128Mi | ||
|
|
||
| nodeSelector: | ||
| ops: "true" | ||
| nodeSelector: | ||
| ops: "true" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.