Skip to content

Conversation

@superdev947
Copy link

Description

Currently, all namespaces on a provider are isolated from each other, regardless of whether they belong to the same tenant (lease.id.owner). This makes it impossible for tenants to deploy modular applications that span multiple namespaces within the same cluster.

This PR introduces a new NetworkPolicy called allow-same-owner, which allows ingress and egress traffic between namespaces that share the same lease.id.owner label. This enables intra-tenant communication while maintaining isolation from other tenants.

My Solution

Modify provider/cluster/kube/builder/netpol.go:

  • Add logic in Create() to generate an additional NetworkPolicy named allow-same-owner.
  • The policy applies to all pods in the namespace (podSelector: {}).
  • Ingress from any namespace with the same lease.id.owner.
  • Egress to any namespace with the same lease.id.owner.
  • Leaves all existing policies (akash-deployment-restrictions, -np, -ip) untouched.

Benefits:

  • Enables tenants to build and run distributed, modular workloads within the same provider.
  • Traffic stays internal to the cluster — no public IPs.
  • No external scripts, no manual intervention.
  • Maintains strong multi-tenant isolation.

Future Updates

  • Expose a provider-level configuration to enable/disable this feature if needed.
  • Investigate supporting cross-provider (inter-cluster) secure communication (e.g., via mTLS or VPN).
  • Enhance observability — e.g., log whenever same-owner traffic is allowed.

@ Author: Jesse Rohner

@superdev947 superdev947 requested review from boz and troian as code owners July 23, 2025 17:35
@coderabbitai
Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

A new constant for an annotation key was added, and the Kubernetes network policy builder logic was updated to introduce a new NetworkPolicy. This policy allows cross-namespace network traffic between namespaces sharing the same owner, based on a label. No existing logic or interfaces were changed.

Changes

File(s) Change Summary
cluster/kube/builder/builder.go Added new constant string akashAllowSameOwner for annotation/label key.
cluster/kube/builder/netpol.go Added logic to generate a NetworkPolicy permitting intra-owner cross-namespace traffic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant netPol.Create()
    participant Kubernetes API

    User->>netPol.Create(): Request NetworkPolicies for deployment
    netPol.Create()->>netPol.Create(): Extract owner ID from LeaseID
    netPol.Create()->>netPol.Create(): Build allowSameOwner NetworkPolicy
    netPol.Create()->>Kubernetes API: Append allowSameOwner policy to policies list
    Kubernetes API-->>User: NetworkPolicies including allowSameOwner
Loading

Estimated code review effort

2 (~15 minutes)

Poem

In the cluster where owners roam,
A new rule lets their traffic roam home.
Namespaces now freely chat,
If their owner labels match.
With a string and a policy, neat and clever,
Akash’s network grows more together!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.2.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/product/migration-guide for migration instructions

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cluster/kube/builder/netpol.go (1)

144-186: Consider the security implications of broad cross-namespace access.

The new NetworkPolicy correctly implements cross-namespace communication for same-owner deployments. However, consider these security implications:

  1. Broad access scope: The empty PodSelector allows ALL pods in a namespace to communicate with ALL pods in other same-owner namespaces, which may be broader than necessary for modular applications.

  2. Potential for unintended communication: Different deployments from the same owner could inadvertently communicate, which might not align with the principle of least privilege.

Suggestions for enhanced security:

  • Consider adding deployment-specific labels to limit communication to related deployments only
  • Document the security model clearly for operators to understand the implications
  • Consider implementing this as an opt-in feature per deployment

The current implementation is functionally correct and serves the stated objective of enabling modular applications across namespaces.

Would you like me to suggest a more granular approach that limits cross-namespace communication to specific deployment groups?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17937d6 and d98da93.

📒 Files selected for processing (2)
  • cluster/kube/builder/builder.go (1 hunks)
  • cluster/kube/builder/netpol.go (2 hunks)
🔇 Additional comments (2)
cluster/kube/builder/builder.go (1)

32-32: LGTM: Well-named constant following established conventions.

The new constant follows the existing naming patterns and is appropriately placed among related constants. The value "akash-same-owner" clearly indicates its purpose for the new NetworkPolicy.

cluster/kube/builder/netpol.go (1)

40-41: LGTM: Clean owner ID extraction.

The owner ID extraction from the deployment's LeaseID is straightforward and correct.

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.

1 participant