Skip to content

fix: normalize CIDRs and keep SSH rules without an ip range - #18

Merged
tuunit merged 1 commit into
stackitcloud:mainfrom
corioliskraft:fix/cidr-normalization
Nov 27, 2026
Merged

tuunit merged 1 commit into
stackitcloud:mainfrom
corioliskraft:fix/cidr-normalization

Conversation

@corioliskraft

Copy link
Copy Markdown
Contributor

Summary

Compare the bastion SSH rules by normalized CIDR, and keep the SSH rules that
have no ip range.

Fixes #6

What was broken

  • ensureBastionSecurityGroupRules compared allowedCIDRs as raw strings
    against the ip range that the API returns. A prefix with host bits set, for
    example 203.0.113.5/24, never matched the stored 203.0.113.0/24, so the
    rule was deleted and created again on each reconcile. validateBastionSpec
    admits such a value, because netip.ParsePrefix permits host bits.
  • The revoke loop deleted each ingress TCP/22 rule whose ip range is not in
    allowedCIDRs. A rule with no ip range is never in that list, so the
    controller deleted a rule that it did not create.

Testing

  • make test
  • make lint
  • New: TestSDKClientEnsureBastionToleratesNonCanonicalCIDR and
    TestSDKClientEnsureBastionKeepsSSHRulesWithoutIPRange.

Both tests keep their own fake server, which repeats the setup of
TestSDKClientEnsureBastionRevokesRemovedCIDR. Each test then holds its
request setup next to the assertion it serves, so two //nolint:dupl
directives replace a shared helper. Is it fine or do you prefer a shared
helper instead?

Open question

The fix assumes that the API returns the ip range in canonical form. I did not
find this in the SDK or in the documentation, and the e2e suite does not assert
on the returned ipRange. Does the API guarantee it?

@tuunit
tuunit force-pushed the fix/cidr-normalization branch from 5902f67 to 3c074c6 Compare September 15, 2026 08:47
@corioliskraft

Copy link
Copy Markdown
Contributor Author

Hi @tuunit , please let me know if there is anything that blocks this PR from merging.

@tuunit
tuunit force-pushed the fix/cidr-normalization branch from 3c074c6 to 37ed42a Compare November 25, 2026 22:27
@tuunit
tuunit requested a review from a team November 25, 2026 22:27
tuunit
tuunit previously approved these changes Nov 25, 2026
The bastion reconcile compared allowed CIDRs as raw strings, so a prefix
with host bits set never matched the stored rule. The revoke loop also
deleted each SSH rule that has no ip range.

Signed-off-by: Jan Larwig <jan.larwig@digits.schwarz>

@tuunit tuunit 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 for the improvement. We had a major refactor of the whole code base and structure therefore I kept this open for so long.

@tuunit
tuunit merged commit 2256946 into stackitcloud:main Nov 27, 2026
2 checks passed
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.

Proper normalization / reconciliation of CIDRs

2 participants