Skip to content

Add support for default security group rules - #3978

Open
pslestang wants to merge 1 commit into
gophercloud:mainfrom
pslestang:add-default-security-group-rules
Open

Add support for default security group rules#3978
pslestang wants to merge 1 commit into
gophercloud:mainfrom
pslestang:add-default-security-group-rules

Conversation

@pslestang

Copy link
Copy Markdown

Add a new openstack/networking/v2/extensions/security/defaultrules package supporting the List, Create, Get and Delete operations of the Neutron /v2.0/default-security-group-rules API, provided by the security-groups-default-rules extension (Neutron 2023.2). The API does not support update nor bulk create for this resource.

The package mirrors the existing security/rules package and reuses its RuleDirection, RuleProtocol and RuleEtherType constants. Unit tests and an acceptance test are included.

Fixes #3175

List security group default rules (GET /v2.0/default-security-group-rules):
https://docs.openstack.org/api-ref/network/v2/index.html#list-security-group-default-rules

Create security group default rule (POST /v2.0/default-security-group-rules):
https://docs.openstack.org/api-ref/network/v2/index.html#create-security-group-default-rule

Show security group default rule (GET /v2.0/default-security-group-rules/{id}):
https://docs.openstack.org/api-ref/network/v2/index.html#show-security-group-default-rule

Delete security group default rule (DELETE /v2.0/default-security-group-rules/{id}):
https://docs.openstack.org/api-ref/network/v2/index.html#delete-security-group-default-rule

Add a new openstack/networking/v2/extensions/security/defaultrules
package supporting the List, Create, Get and Delete operations of the
Neutron /v2.0/default-security-group-rules API, provided by the
security-groups-default-rules extension (Neutron 2023.2). The API does
not support update nor bulk create for this resource.

The package mirrors the existing security/rules package and reuses its
RuleDirection, RuleProtocol and RuleEtherType constants. Unit tests and
an acceptance test are included.

For gophercloud#3175

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Pierre-Samuel Le Stang <pierre-samuel.le-stang@ovhcloud.com>
@github-actions github-actions Bot added edit:networking This PR updates networking code semver:minor Backwards-compatible change backport-v2 This PR will be backported to v2 labels Aug 20, 2026
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 63.638% (+0.07%) from 63.573% — pslestang:add-default-security-group-rules into gophercloud:main

@winiciusallan winiciusallan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pslestang for working on this. Left a few comments, let me know what you think.

Comment on lines +34 to +35
UsedInDefaultSG *bool `q:"used_in_default_sg"`
UsedInNonDefaultSG *bool `q:"used_in_non_default_sg"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The api-ref says that these fields should go into the body request, but I believe this is a bug on the documentation. Pushed a patch to fix this

Comment on lines +18 to +19
// the API. Filtering is achieved by passing in struct field values that map to
// the default security group rule attributes you want to see returned. SortKey

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence about filtering confused me a little. Wouldn't be the idea of this something like: we pass field values for the attributes that we would like to use as filters.?

Comment on lines +51 to +59
th.AssertEquals(t, description, rule.Description)
th.AssertEquals(t, "ingress", rule.Direction)
th.AssertEquals(t, "IPv4", rule.EtherType)
th.AssertEquals(t, fromPort, rule.PortRangeMin)
th.AssertEquals(t, toPort, rule.PortRangeMax)
th.AssertEquals(t, string(rules.ProtocolTCP), rule.Protocol)
th.AssertEquals(t, "PARENT", rule.RemoteGroupID)
th.AssertEquals(t, true, rule.UsedInDefaultSG)
th.AssertEquals(t, false, rule.UsedInNonDefaultSG)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually do a GET for the created resource and then compare the returned value with the expected, instead of comparing with the result of a creation operation. Some APIs return different values for these operations and comparing with the GET result shows that in a N + 1 operation the resource state is as expected.

So IMO, you might want to move these checks after the defaultrules.Get and then compare with the getRule SG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v2 This PR will be backported to v2 edit:networking This PR updates networking code semver:minor Backwards-compatible change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support neutron security group default rules

3 participants