Skip to content

refactor: rework acl fetching for kubernetes and docker#1028

Merged
steveiliop56 merged 6 commits into
mainfrom
refactor/docker-kube-acls
Jul 20, 2026
Merged

refactor: rework acl fetching for kubernetes and docker#1028
steveiliop56 merged 6 commits into
mainfrom
refactor/docker-kube-acls

Conversation

@steveiliop56

@steveiliop56 steveiliop56 commented Jul 19, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Improvements

    • Access control resolution now uses a lookup-driven provider flow to match apps by domain or application name.
    • Matching is more flexible across domain variants (ports, trailing dots, case differences, and internationalized domains), with shared ACL selection logic.
    • Docker and Kubernetes integrations now expose consistent Lookup behavior for discovering matching apps.
  • Bug Fixes

    • Provider lookup errors are handled more reliably; disconnected providers return no results without failing.
  • Tests

    • Updated and expanded service tests to cover domain formats, static configuration, provider failures, and new cache/lookup behavior.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR replaces domain-specific label retrieval with callback-based lookup. Access-control matching is centralized in getACLs, Docker and Kubernetes implement Lookup, and Kubernetes ingress caching is consolidated around matched entries.

Changes

Access-control lookup refactor

Layer / File(s) Summary
Shared ACL matching and contract
internal/service/access_controls_service.go, internal/service/access_controls_service_test.go
LabelProvider now accepts locator callbacks. getACLs handles domain and app-name matching, static and dynamic resolution, errors, and expanded matching tests.
Docker lookup provider
internal/service/docker_service.go
Docker scans decoded application labels through Lookup, stops on the first locator match, and handles listing, inspection, and decoding outcomes.
Kubernetes ingress cache and lookup
internal/service/kubernetes_service.go
Kubernetes replaces indexed caches with ingressEntries, updates ingress matching and deletion handling, and exposes callback-based Lookup.
Kubernetes cache test migration
internal/service/kubernetes_service_test.go
Tests now populate and query ingress entries through the revised cache helpers and lookup API.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AccessControlsService
  participant LabelProvider
  participant DockerService
  participant KubernetesService

  AccessControlsService->>AccessControlsService: Build domain and app-name locator
  AccessControlsService->>LabelProvider: Lookup(locator)
  LabelProvider->>DockerService: Scan decoded app labels
  LabelProvider->>KubernetesService: Scan cached ingress entries
  DockerService-->>AccessControlsService: Invoke locator for matching app
  KubernetesService-->>AccessControlsService: Invoke locator for matching app
  AccessControlsService-->>AccessControlsService: Return matched ACL app
Loading

Possibly related PRs

Suggested reviewers: scottmckendry, rycochet

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main refactor: ACL fetching was reworked for Kubernetes and Docker.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/docker-kube-acls

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@steveiliop56
steveiliop56 marked this pull request as ready for review July 20, 2026 12:34
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 20, 2026
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.19048% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/service/docker_service.go 0.00% 11 Missing ⚠️
internal/service/kubernetes_service.go 85.18% 8 Missing ⚠️
internal/service/access_controls_service.go 85.00% 3 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/service/kubernetes_service.go (1)

114-118: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefer an explicit local copy before taking the address of the loop value.

locator receives &entry.app, and the shared locator (getACLs) retains that pointer (nameMatch = app) while returning false, so the scan keeps iterating with a pointer to a loop-copy still held. This is safe under per-iteration loop variables, but the project prefers the explicit-copy pattern here.

♻️ Proposed change
 	for _, entries := range k.ingressEntries {
 		for _, entry := range entries {
-			if ok := locator(entry.name, &entry.app); ok {
+			app := entry.app
+			if ok := locator(entry.name, &app); ok {
 				return
 			}
 		}
 	}

Based on learnings: when storing/returning a pointer to a for range loop value, prefer the explicit local copy pattern rather than &<range-variable> directly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/service/kubernetes_service.go` around lines 114 - 118, In the nested
iteration over k.ingressEntries, create an explicit local copy of each entry
before passing its app address to locator. Update the locator call to use the
copied entry while preserving the existing early return behavior.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/service/docker_service.go`:
- Around line 70-100: Update DockerService.Lookup so inspectContainer and
DecodeLabels failures are handled per container: log or otherwise record each
error, then continue scanning remaining containers instead of returning
immediately. Keep getContainers errors and successful locator matching behavior
unchanged, and ensure malformed labels or unavailable containers do not prevent
ACL resolution for unrelated apps.

---

Nitpick comments:
In `@internal/service/kubernetes_service.go`:
- Around line 114-118: In the nested iteration over k.ingressEntries, create an
explicit local copy of each entry before passing its app address to locator.
Update the locator call to use the copied entry while preserving the existing
early return behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 07e29bcf-4390-41ff-9794-cba7b8ac5636

📥 Commits

Reviewing files that changed from the base of the PR and between 0e7bdf6 and d1b2df3.

📒 Files selected for processing (5)
  • internal/service/access_controls_service.go
  • internal/service/access_controls_service_test.go
  • internal/service/docker_service.go
  • internal/service/kubernetes_service.go
  • internal/service/kubernetes_service_test.go

Comment thread internal/service/docker_service.go

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/service/docker_service.go (1)

94-95: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Avoid passing pointers to range loop variables.

Passing &config directly to the locator callback takes the address of the loop variable. Because the downstream callback stores this pointer, older Go versions (<1.22) will incorrectly reference the final iteration's value for all matched apps.

Based on learnings, when you need to pass or store a pointer to a loop value, prefer creating an explicit local copy (e.g., cfg := config) rather than returning &<range-variable> directly, even if newer Go versions mitigate the address-taking risk.

💡 Proposed fix
 		for app, config := range labels.Apps {
-			if ok := locator(app, &config); ok {
+			cfg := config
+			if ok := locator(app, &cfg); ok {
 				return nil
 			}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/service/docker_service.go` around lines 94 - 95, Update the loop in
the app-label processing flow to copy each range value into a distinct local
variable before passing its address to locator. Replace the direct &config
argument in the locator call while preserving the existing matching and callback
behavior.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@internal/service/docker_service.go`:
- Around line 94-95: Update the loop in the app-label processing flow to copy
each range value into a distinct local variable before passing its address to
locator. Replace the direct &config argument in the locator call while
preserving the existing matching and callback behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 79a171c1-e519-486c-a661-4ecaa59a393e

📥 Commits

Reviewing files that changed from the base of the PR and between d1b2df3 and 6757695.

📒 Files selected for processing (1)
  • internal/service/docker_service.go

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 20, 2026
@steveiliop56
steveiliop56 merged commit 80bc871 into main Jul 20, 2026
5 checks passed
@steveiliop56
steveiliop56 deleted the refactor/docker-kube-acls branch July 20, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants