Skip to content

HYPERFLEET-1570 - feat: add policy for OKE load balancer NSGs - #95

Merged
openshift-merge-bot[bot] merged 2 commits into
openshift-hyperfleet:mainfrom
ldornele:HYPERFLEET-1570
Sep 23, 2026
Merged

openshift-merge-bot[bot] merged 2 commits into
openshift-hyperfleet:mainfrom
ldornele:HYPERFLEET-1570

Conversation

@ldornele

Copy link
Copy Markdown
Contributor

Summary

  • Adds the policy (module oke-lb-nsg-policy) letting the OCI cloud controller manager create and manage a frontend NSG per LoadBalancer service, per architecture ADR 0024
  • Grants network-security-groups and virtual-network-family management to the cluster resource principal (request.principal.type = 'cluster')
  • Disabled by default (oke_lb_nsg_policy_enabled = false) — no OKE cluster/VCN exists in this stack yet

Test plan

  • terraform validate clean on the new module and the updated root stack
  • terraform fmt clean
  • Applied live against the nsg-testing OKE cluster in hyperfleet-sandbox (rhelcert tenancy): a LoadBalancer service annotated oci.oraclecloud.com/security-rule-management-mode: "NSG" provisioned successfully, the CCM created a frontend NSG with the correct ingress rule, and the shared security list stayed empty before and after
  • Deleting the LoadBalancer service removed the frontend NSG automatically (confirmed via 404 on oci network nsg get); the security list remained unchanged

@openshift-ci
openshift-ci Bot requested review from Ruclo and jsell-rh September 21, 2026 23:32
@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 0317ed6b-2ebe-4961-8d51-0b54f8ab112a

📥 Commits

Reviewing files that changed from the base of the PR and between 2cfe5cb and e0afaca.

📒 Files selected for processing (3)
  • terraform/oci/README.md
  • terraform/oci/outputs.tf
  • terraform/oci/variables.tf
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift-hyperfleet/architecture (manual)
  • openshift-hyperfleet/hyperfleet-api (manual)
  • openshift-hyperfleet/hyperfleet-sentinel (manual)
  • openshift-hyperfleet/hyperfleet-adapter (manual)
  • openshift-hyperfleet/hyperfleet-broker (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • terraform/oci/README.md

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Summary

Summary by CodeRabbit

  • New Features
    • Added an optional OKE load balancer network security group policy.
    • When enabled, OKE cluster principals can manage network security groups and virtual network resources in the configured compartment.
    • Added configuration for the OKE compartment, enablement flag, and resource tags.
    • Added an output exposing the created policy identifier.
  • Documentation
    • Documented configuration, required service annotations, enablement settings, and current stack integration status.
    • Added example configuration with the policy disabled by default.

Walkthrough

The change adds an optional OCI IAM policy for OKE load balancer NSG management. The module accepts a compartment ID and tags, creates compartment-scoped permissions, and exposes its policy ID. Root Terraform conditionally creates the module and validates the OKE compartment ID. Documentation and example variables describe enablement and the required NSG annotation.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant TerraformConfiguration
  participant OkeLbNsgPolicyModule
  participant OCIIdentityPolicy
  TerraformConfiguration->>OkeLbNsgPolicyModule: enable policy and pass compartment ID
  OkeLbNsgPolicyModule->>OCIIdentityPolicy: create NSG management policy
  OCIIdentityPolicy-->>OkeLbNsgPolicyModule: return policy ID
Loading

Suggested reviewers: rafabene

Merge Risk: ⚪ Minimal · up to e0afa

The policy is conditionally usable with validated inputs; only a minor documentation correction remains.

🚥 Pre-merge checks | ✅ 11
✅ Passed checks (11 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of an OKE load balancer NSG policy and matches the main changeset.
Description check ✅ Passed The description explains the new policy module, permissions, default-disabled behavior, validation, and testing. It is directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Sec-02: Secrets In Log Output ✅ Passed PASS. The PR changes only Terraform HCL and Markdown files. The authoritative diff contains no slog, log, logr, zap, or fmt.Print* statements. No added non-example line contains token, passw…
No Hardcoded Secrets ✅ Passed No hardcoded secret was introduced. The added Terraform and documentation lines contain policy text, provider names, tags, booleans, null defaults, interpolated variables, public URLs, and a `REPLACE_…
No Weak Cryptography ✅ Passed The authoritative PR diff adds only Terraform IAM policy wiring, variables, outputs, provider metadata, documentation, and an example tfvars block. The added policy contains OCI permission statements …
No Injection Vectors ✅ Passed No CWE-89, CWE-78, CWE-79, or CWE-502 pattern is introduced. The PR changes only Terraform HCL and documentation. The ${var.compartment_id} interpolation builds an OCI IAM policy statement; it is no…
No Privileged Containers ✅ Passed PASS — The pull request changes only Terraform files and documentation. The review-scoped diff contains no Kubernetes/OpenShift manifest, Helm template, or Dockerfile. It introduces no privileged, `…
No Pii Or Sensitive Data In Logs ✅ Passed PASS — The pull request changes only Terraform configuration, outputs, variables, provider declarations, and documentation. The authoritative diff contains no slog, logr, zap, log, or fmt.Print* loggi…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
✨ Simplify code
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

Comment on lines +317 to +328
variable "oke_compartment_id" {
description = <<-EOT
OCID of the compartment that will contain the OKE cluster and its VCN.
No default: required once oke_lb_nsg_policy_enabled is true.
EOT
type = string
default = null

validation {
condition = !var.oke_lb_nsg_policy_enabled || var.oke_compartment_id != null
error_message = "oke_compartment_id is required when oke_lb_nsg_policy_enabled is true."
}

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 validation only rejects null, so an empty or whitespace-only oke_compartment_id passes when the policy is enabled and fails later during the OCI operation. Consider validating that the value is non-empty after trimming whitespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — now validates with trimspace, matching the existing pattern.

@rafabene rafabene left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

will comment inline.

@rafabene rafabene left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

will comment inline.

Comment thread terraform/oci/README.md
Comment on lines +152 to +176
`oke_lb_nsg_policy_enabled` (default `false`) creates the IAM policy the OCI
cloud controller manager needs to create and manage a dedicated **frontend
NSG** per `LoadBalancer` service, instead of editing the security list
Terraform owns for node and control-plane traffic — the decision recorded in
the architecture repo's
[ADR 0024](https://github.com/openshift-hyperfleet/architecture/blob/main/hyperfleet/adrs/0024-oke-load-balancer-security-nsg.md).

The CCM authenticates for this specific action as the **cluster resource
principal** (`request.principal.type = 'cluster'`), not via a worker node's
instance principal — verified live end-to-end against a test OKE cluster on
2026-09-21: a `LoadBalancer` service annotated
`oci.oraclecloud.com/security-rule-management-mode: "NSG"` provisioned
successfully, the CCM created a frontend NSG with the correct ingress rule,
and the shared security list was never touched.

This is not yet wired into this stack: no OKE cluster or VCN exists here yet
([HYPERFLEET-1525](https://redhat.atlassian.net/browse/HYPERFLEET-1525) is
still in Backlog), though the IAM mechanism itself is now proven correct.
Once HYPERFLEET-1525 lands, set `oke_compartment_id` to the compartment
holding the OKE cluster's VCN and flip `oke_lb_nsg_policy_enabled` to `true`;
every `LoadBalancer` service manifest in that cluster must then carry the
`oci.oraclecloud.com/security-rule-management-mode: "NSG"` annotation to
actually use the frontend NSG this policy authorizes — the policy alone does
not annotate anything.

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 feels a bit too detailed for the README. I'd move the live verification details to the PR/ADR and keep this focused on configuration and usage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the README to focus on configuration and usage only — moved the verification narrative out (already in the ADR/PR)

@@ -0,0 +1,4 @@
output "policy_id" {

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 output doesnt bubble up in terraform output. We have an existing pattern for flag gated modules you can follow for this output

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — added oke_lb_nsg_policy_id to terraform/oci/outputs.tf, mirroring the postgresql_id pattern (try(module.X[0].field, null)).

@ciaranRoche ciaranRoche 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.

/lgtm

@openshift-ci

openshift-ci Bot commented Sep 23, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ciaranRoche

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot
openshift-merge-bot Bot merged commit 3ccca2e into openshift-hyperfleet:main Sep 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants