Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cluster/kube/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
AkashServiceCapabilityStorage = "akash.network/capabilities.storage"
AkashMetalLB = "metal-lb"
akashDeploymentPolicyName = "akash-deployment-restrictions"
akashAllowSameOwner = "akash-same-owner"
akashNetworkNamespace = "akash.network/namespace"
AkashLeaseOwnerLabelName = "akash.network/lease.id.owner"
AkashLeaseDSeqLabelName = "akash.network/lease.id.dseq"
Expand Down
48 changes: 47 additions & 1 deletion cluster/kube/builder/netpol.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ func (b *netPol) Create() ([]*netv1.NetworkPolicy, error) { // nolint:golint,unp
const ingressLabelName = "app.kubernetes.io/name"
const ingressLabelValue = "ingress-nginx"

//extract ownerID from LeaseID
ownerID := b.deployment.LeaseID().Owner

result := []*netv1.NetworkPolicy{
{

ObjectMeta: metav1.ObjectMeta{
Name: akashDeploymentPolicyName,
Labels: b.labels(),
Expand Down Expand Up @@ -139,6 +141,50 @@ func (b *netPol) Create() ([]*netv1.NetworkPolicy, error) { // nolint:golint,unp
},
}

//allow-same-owner: enable cross-namespace traffic between namespaces owned by same owner
allowSameOwner := &netv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: akashAllowSameOwner,
Labels: b.labels(),
Namespace: LidNS(b.deployment.LeaseID()),
},
Spec: netv1.NetworkPolicySpec{
PodSelector: metav1.LabelSelector{},
PolicyTypes: []netv1.PolicyType{
netv1.PolicyTypeIngress,
netv1.PolicyTypeEgress,
},
Ingress: []netv1.NetworkPolicyIngressRule{
{
From: []netv1.NetworkPolicyPeer{
{
NamespaceSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
AkashLeaseOwnerLabelName: ownerID,
},
},
},
},
},
},
Egress: []netv1.NetworkPolicyEgressRule{
{
To: []netv1.NetworkPolicyPeer{
{
NamespaceSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
AkashLeaseOwnerLabelName: ownerID,
},
},
},
},
},
},
},
}

result = append(result, allowSameOwner)

for _, service := range b.deployment.ManifestGroup().Services {
// find all the ports that are exposed directly
ports := make([]netv1.NetworkPolicyPort, 0)
Expand Down