-
Notifications
You must be signed in to change notification settings - Fork 43
feat: runtime NetworkPolicies for EDA operator workloads #362
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
Changes from all commits
3bdbc75
d38d8cd
1c48894
e3745dd
c1f4b0c
b0299a7
e6aaeb4
4ce037f
0255902
8065a2c
b1002d6
302107e
f0ae75e
8f0ed3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| - name: Load postgres role vars for supported_pg_version | ||
| ansible.builtin.include_vars: | ||
| file: "{{ role_path }}/../postgres/vars/main.yml" | ||
|
|
||
| - name: Apply default deny NetworkPolicy for EDA operand pods | ||
| kubernetes.core.k8s: | ||
| state: present | ||
| apply: true | ||
| definition: "{{ lookup('template', 'default-deny.networkpolicy.yaml.j2') }}" | ||
|
|
||
| - name: Apply EDA API NetworkPolicy | ||
| kubernetes.core.k8s: | ||
| state: present | ||
| apply: true | ||
| definition: "{{ lookup('template', 'eda-api.networkpolicy.yaml.j2') }}" | ||
|
|
||
| - name: Apply EDA UI NetworkPolicy | ||
|
ttuffin marked this conversation as resolved.
|
||
| kubernetes.core.k8s: | ||
| state: "{{ 'present' if not ui_disabled else 'absent' }}" | ||
|
ttuffin marked this conversation as resolved.
|
||
| apply: true | ||
| definition: "{{ lookup('template', 'eda-ui.networkpolicy.yaml.j2') }}" | ||
|
|
||
| - name: Apply EDA default-worker NetworkPolicy | ||
| kubernetes.core.k8s: | ||
| state: present | ||
| apply: true | ||
| definition: "{{ lookup('template', 'eda-default-worker.networkpolicy.yaml.j2') }}" | ||
|
|
||
| - name: Apply EDA activation-worker NetworkPolicy | ||
| kubernetes.core.k8s: | ||
| state: present | ||
| apply: true | ||
| definition: "{{ lookup('template', 'eda-activation-worker.networkpolicy.yaml.j2') }}" | ||
|
|
||
| - name: Apply EDA event-stream NetworkPolicy | ||
| kubernetes.core.k8s: | ||
| state: present | ||
| apply: true | ||
| definition: "{{ lookup('template', 'eda-event-stream.networkpolicy.yaml.j2') }}" | ||
|
|
||
| - name: Apply db-management NetworkPolicy for backup and restore pods | ||
| kubernetes.core.k8s: | ||
| state: present | ||
| apply: true | ||
| definition: "{{ lookup('template', 'db-management.networkpolicy.yaml.j2') }}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --- | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: '{{ ansible_operator_meta.name }}-db-management' | ||
| namespace: '{{ ansible_operator_meta.namespace }}' | ||
| labels: | ||
| {{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(4) | trim }} | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| app.kubernetes.io/managed-by: '{{ deployment_type }}-operator' | ||
| app.kubernetes.io/component: '{{ deployment_type }}' | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added Ingress |
||
| egress: | ||
| # Allow DNS resolution via OpenShift DNS | ||
| - to: | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: openshift-dns | ||
| ports: | ||
| - protocol: TCP | ||
| port: 5353 | ||
| - protocol: UDP | ||
| port: 5353 | ||
| # Allow egress to managed PostgreSQL for pg_dump / pg_restore | ||
| {% if managed_database | bool %} | ||
| - to: | ||
| - podSelector: | ||
| matchLabels: | ||
| app.kubernetes.io/component: database | ||
| app.kubernetes.io/instance: 'postgres-{{ supported_pg_version }}-{{ ansible_operator_meta.name }}' | ||
| ports: | ||
| - protocol: TCP | ||
| port: {{ eda_postgres_port | default('5432') }} | ||
| {% else %} | ||
| # External database — destination is user-configured, allow on the port | ||
| - ports: | ||
| - protocol: TCP | ||
| port: {{ eda_postgres_port | default('5432') }} | ||
| {% endif %} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: '{{ ansible_operator_meta.name }}-default-deny' | ||
| namespace: '{{ ansible_operator_meta.namespace }}' | ||
| labels: | ||
| {{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(4) | trim }} | ||
| spec: | ||
| podSelector: | ||
| matchExpressions: | ||
| - key: app.kubernetes.io/managed-by | ||
| operator: In | ||
| values: | ||
| - '{{ deployment_type }}-operator' | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: '{{ ansible_operator_meta.name }}-activation-worker' | ||
| namespace: '{{ ansible_operator_meta.namespace }}' | ||
| labels: | ||
| {{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(4) | trim }} | ||
| app.kubernetes.io/component: '{{ deployment_type }}-activation-worker' | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| app.kubernetes.io/name: '{{ ansible_operator_meta.name }}' | ||
| app.kubernetes.io/managed-by: '{{ deployment_type }}-operator' | ||
| app.kubernetes.io/component: '{{ deployment_type }}-activation-worker' | ||
| policyTypes: | ||
| - Egress | ||
| egress: | ||
| # Allow DNS resolution via OpenShift DNS | ||
| - to: | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: openshift-dns | ||
| ports: | ||
| - protocol: TCP | ||
| port: 5353 | ||
| - protocol: UDP | ||
| port: 5353 | ||
| # Unrestricted egress required: activation workers create and manage Job | ||
| # pods via the Kubernetes API, connect to user-defined event source | ||
| # destinations, and may call external SMS. Destinations cannot be | ||
| # enumerated at policy creation time. | ||
| - {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| --- | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: '{{ ansible_operator_meta.name }}-api' | ||
| namespace: '{{ ansible_operator_meta.namespace }}' | ||
| labels: | ||
| {{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(4) | trim }} | ||
| app.kubernetes.io/component: '{{ deployment_type }}-api' | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| app.kubernetes.io/name: '{{ ansible_operator_meta.name }}' | ||
| app.kubernetes.io/managed-by: '{{ deployment_type }}-operator' | ||
| app.kubernetes.io/component: '{{ deployment_type }}-api' | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress | ||
| ingress: | ||
| # Allow traffic from the OpenShift router (Routes) and ingress controllers | ||
| - from: | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| policy-group.network.openshift.io/ingress: "" | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| network.openshift.io/policy-group: ingress | ||
| ports: | ||
| - protocol: TCP | ||
| port: {{ api_nginx_port }} | ||
| # Allow traffic from the gateway operator (reverse proxy) and other AAP | ||
| # component pods that call the EDA API | ||
| - from: | ||
| - podSelector: | ||
| matchExpressions: | ||
| - key: app.kubernetes.io/managed-by | ||
| operator: In | ||
| values: | ||
| - '{{ deployment_type }}-operator' | ||
| - 'aap-operator' | ||
| - podSelector: | ||
| matchLabels: | ||
| control-plane: controller-manager | ||
| ports: | ||
| - protocol: TCP | ||
| port: {{ api_nginx_port }} | ||
| - protocol: TCP | ||
| port: {{ websocket_port }} | ||
| # Allow traffic from activation Job pods (created at runtime by activation | ||
| # workers, not operator-managed — carry only app: eda). | ||
| # ansible_rulebook connects to daphne (websocket_port) for rulebook | ||
| # execution and to the API (api_nginx_port) for token refresh. | ||
| - from: | ||
| - podSelector: | ||
| matchLabels: | ||
| app: eda | ||
| ports: | ||
| - protocol: TCP | ||
| port: {{ websocket_port }} | ||
| - protocol: TCP | ||
| port: {{ api_nginx_port }} | ||
| egress: | ||
| # Allow DNS resolution via OpenShift DNS | ||
| - to: | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: openshift-dns | ||
| ports: | ||
| - protocol: TCP | ||
| port: 5353 | ||
| - protocol: UDP | ||
| port: 5353 | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| # Unrestricted egress required for user-configured external services | ||
| # (external SMS such as HashiCorp Vault, fetched by daphne during websocket | ||
| # handshake; gateway JWT key fetch; postgres). Destinations are | ||
| # user-defined and cannot be enumerated at policy creation time. | ||
| - {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: '{{ ansible_operator_meta.name }}-default-worker' | ||
| namespace: '{{ ansible_operator_meta.namespace }}' | ||
| labels: | ||
| {{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(4) | trim }} | ||
| app.kubernetes.io/component: '{{ deployment_type }}-default-worker' | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| app.kubernetes.io/name: '{{ ansible_operator_meta.name }}' | ||
| app.kubernetes.io/managed-by: '{{ deployment_type }}-operator' | ||
| app.kubernetes.io/component: '{{ deployment_type }}-default-worker' | ||
| policyTypes: | ||
| - Egress | ||
| egress: | ||
| # Allow DNS resolution via OpenShift DNS | ||
| - to: | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: openshift-dns | ||
| ports: | ||
| - protocol: TCP | ||
| port: 5353 | ||
| - protocol: UDP | ||
| port: 5353 | ||
| # Unrestricted egress required: default-worker executes user-defined tasks | ||
| # (git clones, SCM syncs, webhook calls) and may call external SMS. | ||
| # Destinations are user-configured and cannot be enumerated at policy | ||
| # creation time. | ||
| - {} |
Uh oh!
There was an error while loading. Please reload this page.