provider icon indicating copy to clipboard operation
provider copied to clipboard

feat: allow cross-namespace communication to namespaces

Open superdev947 opened this issue 5 months ago • 1 comments

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 avatar Jul 23 '25 17:07 superdev947

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

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.

coderabbitai[bot] avatar Jul 23 '25 17:07 coderabbitai[bot]