Skip to content
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

Network policies and policy communities. #572

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft

Conversation

terjekv
Copy link
Collaborator

@terjekv terjekv commented Jan 22, 2025

Add support for networks to have policies and communities.

This PR allows for networks to have policies applied to them. Network policies consists of two things:

  1. attributes that say something useful to the end user about the network, and
  2. communities which contain lists of hosts within the community.

Legal attributes are defined by adding or removing entries to networkattributes.

Purpose

Say you want to create an isolated network, but within this network you want a set of communities that can talk together. You can do this creating a network attribute (isolated), and then create a network policy that includes that attribute. You then apply that policy to the network in question. Listing the network will now (hopefully) show the attribute.

Now, within this policy, you may create two communities, foo and bar. You can then add hosts to these communities. Note that to add a host to a community, at least one of the IPs of the host has to be in the network that the policy the community belongs to.

Changes

When creating a host, one may add a network_community attribute to the JSON, which takes the parameter of a network community ID that the host is to be assigned to. Note that this requires the host to be created with a network or an IP as a host cannot be a member of a network community that belongs to a network policy that again belongs to a network to which the host has no IPs.

Removing / changing policies

Since hosts may belong to communities that belong to policies, trying to change IPs on a host now requires a check to see if the new IP can belong to the community of the host. If that isn't the case, we return a 409.

(This description is currently incomplete.)

  - Still needs community and policy assigment endpoints.
  - Hard to fix in host create view and serializer due to the same issues we've seen before.
  - Will make specialized endpoints.
@terjekv terjekv self-assigned this Jan 22, 2025
@terjekv terjekv marked this pull request as draft January 22, 2025 13:55
@coveralls
Copy link
Collaborator

coveralls commented Jan 22, 2025

Coverage Status

coverage: 98.044% (-1.0%) from 99.021%
when pulling 9505c37 on network_policy
into 914fe86 on master.

docs/network_policies.md Outdated Show resolved Hide resolved
terjekv and others added 6 commits January 27, 2025 12:56
Co-authored-by: Peder Hovdan Andresen <107681714+pederhan@users.noreply.github.com>
- Fix it so policy-ID isn't required in POST for creating communities (it comes from THE URL).
- ruff format on the files created for this PR only.
- Update `pyproject.toml` to use the `tool.ruff.lint` namespace for selected rules.
- Duplcated names now gives 409 instead of 400. Sadly, the default returned from Django on duplicated entries in the database is 400, and we want 409.
- The NetworkPolicyAttribute 'isolated' is now persistent,  created during migration, and may not be renamed, deleted, or otherwise removed. One can however change its description.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants