noderings.cloud.firewall_ruleset module – Manage NodeRings firewall rulesets and their rules

Note

This module is part of the noderings.cloud collection (version 0.2.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install noderings.cloud. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: noderings.cloud.firewall_ruleset.

New in noderings.cloud 0.1.0

Synopsis

  • A ruleset is an ordered list of firewall rules that can be attached to virtual machines (see firewall_ruleset).

  • When rules is given, the ruleset is made to hold exactly those rules, in that order. Rules that already match are kept, so their IDs stay the same.

  • The firewall runs in the guest, so the VM’s hosting provider must support guest_firewall.

Requirements

The below requirements are needed on the host that executes this module.

  • python >= 3.9

Parameters

Parameter

Comments

api_retries

integer

How many times a request is retried after rate limiting (HTTP 429) or a gateway error (HTTP 502, 503 or 504).

Orders (virtual machines, game servers, snapshots) are never retried blindly.

Default: 5

api_timeout

integer

Timeout in seconds for a single HTTP request.

Default: 60

api_token

aliases: token

string

A NodeRings service-account token.

Create one in the NodeRings console under Organization > Service accounts.

If not set, the value of the NODERINGS_TOKEN, NODERINGS_API_TOKEN or NR_API_TOKEN environment variable is used.

api_url

string

Base URL of the NodeRings API.

If not set, the value of the NODERINGS_API_URL environment variable is used.

Default: "https://api.noderings.com"

force

boolean

With state=absent, delete the ruleset even while it is attached to virtual machines. They are left without a firewall.

Choices:

  • false ← (default)

  • true

name

string / required

Name of the ruleset. Unique within the organization.

organization_id

string

Organization to act in, sent as the X-Organization-ID header.

Defaults to the organization the token belongs to.

If not set, the value of the NODERINGS_ORGANIZATION_ID or NR_ORGANIZATION_ID environment variable is used.

rules

list / elements=dictionary

The rules, first evaluated first. At most 50.

Leave unset to not manage the rules. An empty list removes all rules.

action

string / required

What to do with matching traffic.

Choices:

  • "accept"

  • "drop"

destination

dictionary

Where the traffic goes.

address_group_ids

list / elements=string

IDs of address groups.

Default: []

address_groups

list / elements=string

Names of address groups (see noderings.cloud.firewall_address_group).

Default: []

cidrs

list / elements=string

Addresses or prefixes. 0.0.0.0/0 or ::/0 match everything and must be alone.

Default: []

vm_tags

list / elements=string

Match the addresses of your virtual machines that have any of these tags.

Each tag must be on at least one existing virtual machine when the rule is written, so create the VMs first. If no VM has the tag any more, the platform skips the rule.

Default: []

destination_ports

string

One port such as 443 or one range such as 8000-8100. Only for TCP, UDP, SCTP, DCCP and UDP-Lite.

direction

string / required

ingress (traffic to the VM) or egress (traffic from it).

Choices:

  • "ingress"

  • "egress"

protocol

string

IP protocol in lower case, for example tcp, udp, icmp, ipv6_icmp (ICMPv6) or any.

Any IANA protocol name the platform knows is accepted, such as gre, esp or sctp.

Default: "tcp"

source

dictionary

Where the traffic comes from. A rule needs a rules[].source or a rules[].destination.

address_group_ids

list / elements=string

IDs of address groups.

Default: []

address_groups

list / elements=string

Names of address groups (see noderings.cloud.firewall_address_group).

Default: []

cidrs

list / elements=string

Addresses or prefixes. 0.0.0.0/0 or ::/0 match everything and must be alone.

Default: []

vm_tags

list / elements=string

Match the addresses of your virtual machines that have any of these tags.

Each tag must be on at least one existing virtual machine when the rule is written, so create the VMs first. If no VM has the tag any more, the platform skips the rule.

Default: []

source_ports

string

One port such as 443 or one range such as 8000-8100. Only for TCP, UDP, SCTP, DCCP and UDP-Lite.

state

string

Whether the ruleset should exist.

Choices:

  • "present" ← (default)

  • "absent"

validate_certs

boolean

Whether to validate the API’s TLS certificate.

Choices:

  • false

  • true ← (default)

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying the target.

diff_mode

Support: full

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Notes

Note

  • All modules in this collection belong to the noderings.cloud.noderings action group, so connection options can be set once with module_defaults.

Examples

- name: Web server firewall
  noderings.cloud.firewall_ruleset:
    name: web
    rules:
      - {direction: ingress, action: accept, protocol: tcp, destination_ports: "22", source: {address_groups: [office]}}
      - {direction: ingress, action: accept, protocol: tcp, destination_ports: "80", source: {cidrs: [0.0.0.0/0]}}
      - {direction: ingress, action: accept, protocol: tcp, destination_ports: "443", source: {cidrs: [0.0.0.0/0]}}
      - {direction: ingress, action: accept, protocol: tcp, destination_ports: "443", source: {cidrs: ["::/0"]}}
      - {direction: ingress, action: accept, protocol: icmp, source: {cidrs: [0.0.0.0/0]}}
      - {direction: ingress, action: drop, protocol: any, source: {cidrs: [0.0.0.0/0]}}
  register: fw

- name: Remove a ruleset
  noderings.cloud.firewall_ruleset:
    name: old
    state: absent
    force: true

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

ruleset

dictionary

The ruleset with its rules. Empty after state=absent.

Returned: always

Sample: {"attached_vm_count": 1, "attached_vm_hostnames": ["web-1"], "id": "7a6b5c4d-1111-2222-3333-444455556666", "name": "web", "rules": [{"action": "accept", "destination": null, "destination_ports": "443", "direction": "ingress", "id": "1a2b3c4d-0000-0000-0000-000000000001", "position": 0, "protocol": "tcp", "source": {"cidrs": ["0.0.0.0/0"]}, "source_ports": null}]}

Authors

  • Shaygun (@shaygun)