-
Notifications
You must be signed in to change notification settings - Fork 56
Add network policy for build-workflows #1700
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
Open
AnoshanJ
wants to merge
8
commits into
wso2:main
Choose a base branch
from
AnoshanJ:netpol/build-workflows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c32e0b2
Label build-stage workflow pods so a NetworkPolicy can select them
AnoshanJ 6350774
Add build-workflow egress NetworkPolicy
AnoshanJ 7473ed7
Wire the build egress policy into the local and quick-start installers
AnoshanJ 061d2ba
Test the build egress policy renders
AnoshanJ 3b941c7
Document build-workflow egress restriction
AnoshanJ 6f86f8a
Render the build egress policy per workflow namespace
AnoshanJ 44d811c
Test the per-namespace and registry-podSelector rendering
AnoshanJ e1a7410
Correct the build egress docs on namespaces and API-server CIDRs
AnoshanJ 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
33 changes: 33 additions & 0 deletions
33
...helm-charts/wso2-amp-platform-resources-extension/templates/build-workflow-namespace.yaml
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,33 @@ | ||
| {{- if .Values.networkPolicy.buildWorkflows.enabled }} | ||
| {{- $bw := .Values.networkPolicy.buildWorkflows }} | ||
| {{- $namespaces := without ($bw.namespaces | default list) "" nil }} | ||
| {{- if not $namespaces }} | ||
| {{- $namespaces = list (printf "workflows-%s" (.Values.environment.name | default "default")) }} | ||
| {{- end }} | ||
| {{- range $namespace := $namespaces }} | ||
| {{- if ne $namespace $.Release.Namespace }} | ||
| {{- if not (lookup "v1" "Namespace" "" $namespace) }} | ||
| --- | ||
| # OpenChoreo does not create this namespace until a workflow first runs there, so rendering | ||
| # only the NetworkPolicy fails a fresh install with `namespaces "<name>" not found`. | ||
| # | ||
| # Only when it is absent: Helm refuses to adopt a resource lacking its ownership metadata, | ||
| # so rendering unconditionally fails with `invalid ownership metadata` wherever OpenChoreo, | ||
| # an installer, or the evaluation chart created it first. The lookup needs a live cluster; | ||
| # a path without one (helm template, GitOps dry-run) emits it, which is correct for a first | ||
| # install and the safe direction to be wrong in. | ||
| # | ||
| # resource-policy: keep — OpenChoreo owns this namespace's lifecycle and it holds running | ||
| # workflows, so uninstalling this chart must never delete it. | ||
| apiVersion: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| name: {{ $namespace }} | ||
| annotations: | ||
| helm.sh/resource-policy: keep | ||
| labels: | ||
| {{- include "amp-build-extension.labels" $ | nindent 4 }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} |
127 changes: 127 additions & 0 deletions
127
...-charts/wso2-amp-platform-resources-extension/templates/build-workflow-networkpolicy.yaml
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,127 @@ | ||
| {{- if .Values.networkPolicy.buildWorkflows.enabled }} | ||
| {{- $bw := .Values.networkPolicy.buildWorkflows }} | ||
| {{- $namespaces := without ($bw.namespaces | default list) "" nil }} | ||
| {{- if not $namespaces }} | ||
| {{- $namespaces = list (printf "workflows-%s" (.Values.environment.name | default "default")) }} | ||
| {{- end }} | ||
| {{- range $namespace := $namespaces }} | ||
| --- | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: amp-build-workflow-egress | ||
| namespace: {{ $namespace }} | ||
| labels: | ||
| {{- include "amp-build-extension.labels" $ | nindent 4 }} | ||
| spec: | ||
| # generate-workload-cr is unlabelled and so unselected: it calls the OpenChoreo API and | ||
| # Thunder, and runs no user content. | ||
| podSelector: | ||
| matchLabels: | ||
| {{- include "amp.buildWorkflowPodLabels" $ | nindent 6 }} | ||
| policyTypes: [Egress] | ||
| egress: | ||
| # Matched post-DNAT: every rule names the backing pod's address and containerPort, not the Service's. | ||
|
|
||
| # Scoped to the DNS workload, not left open — build pods run untrusted code. | ||
| - to: | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: {{ $bw.dns.namespace }} | ||
| podSelector: | ||
| matchLabels: | ||
| {{ $bw.dns.podLabel.key }}: {{ $bw.dns.podLabel.value }} | ||
| ports: | ||
| - port: 53 | ||
| protocol: UDP | ||
| - port: 53 | ||
| protocol: TCP | ||
|
|
||
| # The point of the policy: builds keep the internet, lose the private network. No | ||
| # `ports`, so a mirror or registry on a non-standard port cannot break. | ||
| - to: | ||
| - ipBlock: | ||
| cidr: 0.0.0.0/0 | ||
| {{- with without ($bw.internet.excludedCidrs | default list) "" nil }} | ||
| except: | ||
| {{- range . }} | ||
| - {{ . }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- if $bw.internet.ipv6 }} | ||
| # A policy with only an IPv4 block denies all IPv6 egress, so dual-stack builds fail. | ||
| - ipBlock: | ||
| cidr: ::/0 | ||
| {{- with without ($bw.internet.excludedCidrsV6 | default list) "" nil }} | ||
| except: | ||
| {{- range . }} | ||
| - {{ . }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- with $bw.apiServer }} | ||
| {{- $cidrs := without (.cidrs | default list) "" nil }} | ||
| {{- if and $cidrs .ports }} | ||
| # wait reports WorkflowTaskResults here; no pod backs the API server, so ipBlock. Pods | ||
| # are the unit of policy, so this reaches the build container too — workflow-sa can only | ||
| # create/patch workflowtaskresults. | ||
| - to: | ||
| {{- range $cidrs }} | ||
| - ipBlock: | ||
| cidr: {{ . }} | ||
| {{- end }} | ||
| ports: | ||
| {{- range .ports }} | ||
| - port: {{ . }} | ||
| protocol: TCP | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- with $bw.registry }} | ||
| {{- $cidrs := without (.cidrs | default list) "" nil }} | ||
| {{- if and $cidrs .ports }} | ||
| # publish-image pushes here and build-image pulls cached buildpacks; reached on the node | ||
| # network, which the internet rule's except withholds. registry.<baseDomain> needs no rule. | ||
| - to: | ||
| {{- range $cidrs }} | ||
| - ipBlock: | ||
| cidr: {{ . }} | ||
| {{- end }} | ||
| ports: | ||
| {{- range .ports }} | ||
| - port: {{ . }} | ||
| protocol: TCP | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- with .inCluster }} | ||
| {{- if and .namespace .ports }} | ||
| # A registry addressed by Service DNS is matched post-DNAT, so this names the registry | ||
| # pod's namespace and its containerPort — the Service's own port never matches. Without | ||
| # podLabels this reaches every pod in that namespace on those ports. | ||
| - to: | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: {{ .namespace }} | ||
| {{- with .podLabels }} | ||
| podSelector: | ||
| matchLabels: | ||
| {{- toYaml . | nindent 14 }} | ||
| {{- end }} | ||
| ports: | ||
| {{- range .ports }} | ||
| - port: {{ . }} | ||
| protocol: TCP | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- with $bw.extraEgress }} | ||
| # Private-network destinations a build needs: self-hosted git, internal registry, proxy. | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
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
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
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
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
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
Oops, something went wrong.
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.