mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-27 05:08:11 +08:00

* add additional mutex lock on node acls func * increase verbosity * disable acls on cloud emqx * add emqx creds creation to go routine * add debug log of mq client id * comment port check * uncomment port check * check for connection mq connection open * use username for client id * add write mutex on acl is allowed * add mq connection lost handler on server * spin off zombie init as go routine * get whole api path from config * Revert "get whole api path from config" This reverts commit392f5f4c5f
. * update extclient acls async * add additional mutex lock on node acls func (cherry picked from commit5325f0e7d7
) * increase verbosity (cherry picked from commit705b3cf0bf
) * add emqx creds creation to go routine (cherry picked from commitc8e65f4820
) * add debug log of mq client id (cherry picked from commit29c5d6ceca
) * comment port check (cherry picked from commitdb8d6d95ea
) * check for connection mq connection open (cherry picked from commit13b11033b0
) * use username for client id (cherry picked from commite90c7386de
) * add write mutex on acl is allowed (cherry picked from commit4cae1b0bb4
) * add mq connection lost handler on server (cherry picked from commitc82918ad35
) * spin off zombie init as go routine (cherry picked from commit6d65c44c43
) * update extclient acls async (cherry picked from commit6557ef1ebe
) * additionl logs for oauth user flow (cherry picked from commit61703038ae
) * add more debug logs (cherry picked from commit5980beacd1
) * add more debug logs (cherry picked from commit4d001f0d27
) * add set auth secret (cherry picked from commitf41cef5da5
) * fix fetch pass (cherry picked from commit825caf4b60
) * make sure auth secret is set only once (cherry picked from commitba33ed02aa
) * make sure auth secret is set only once (cherry picked from commit920ac4c507
) * comment usage of emqx acls * replace read lock with write lock on acls * replace read lock with write lock on acls (cherry picked from commit808d2135c8
) * use deadlock pkg for visibility * add additional mutex locks * remove race flag * on mq re-connecting donot exit if failed * on mq re-connecting donot exit if failed * revert mutex package change * set mq clean session * remove debug log * go mod tidy * revert on prem emqx acls del
72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
package nodeacls
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"sync"
|
|
|
|
"github.com/gravitl/netmaker/logic/acls"
|
|
)
|
|
|
|
var NodesAllowedACLMutex = &sync.Mutex{}
|
|
|
|
// AreNodesAllowed - checks if nodes are allowed to communicate in their network ACL
|
|
func AreNodesAllowed(networkID NetworkID, node1, node2 NodeID) bool {
|
|
NodesAllowedACLMutex.Lock()
|
|
defer NodesAllowedACLMutex.Unlock()
|
|
var currentNetworkACL, err = FetchAllACLs(networkID)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
var allowed bool
|
|
acls.AclMutex.Lock()
|
|
currNetworkACLNode1 := currentNetworkACL[acls.AclID(node1)]
|
|
currNetworkACLNode2 := currentNetworkACL[acls.AclID(node2)]
|
|
acls.AclMutex.Unlock()
|
|
allowed = currNetworkACLNode1.IsAllowed(acls.AclID(node2)) && currNetworkACLNode2.IsAllowed(acls.AclID(node1))
|
|
return allowed
|
|
}
|
|
|
|
// FetchNodeACL - fetches a specific node's ACL in a given network
|
|
func FetchNodeACL(networkID NetworkID, nodeID NodeID) (acls.ACL, error) {
|
|
var currentNetworkACL, err = FetchAllACLs(networkID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var acl acls.ACL
|
|
acls.AclMutex.RLock()
|
|
if currentNetworkACL[acls.AclID(nodeID)] == nil {
|
|
acls.AclMutex.RUnlock()
|
|
return nil, fmt.Errorf("no node ACL present for node %s", nodeID)
|
|
}
|
|
acl = currentNetworkACL[acls.AclID(nodeID)]
|
|
acls.AclMutex.RUnlock()
|
|
return acl, nil
|
|
}
|
|
|
|
// FetchNodeACLJson - fetches a node's acl in given network except returns the json string
|
|
func FetchNodeACLJson(networkID NetworkID, nodeID NodeID) (acls.ACLJson, error) {
|
|
currentNodeACL, err := FetchNodeACL(networkID, nodeID)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
acls.AclMutex.RLock()
|
|
defer acls.AclMutex.RUnlock()
|
|
jsonData, err := json.Marshal(¤tNodeACL)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return acls.ACLJson(jsonData), nil
|
|
}
|
|
|
|
// FetchAllACLs - fetchs all node
|
|
func FetchAllACLs(networkID NetworkID) (acls.ACLContainer, error) {
|
|
var err error
|
|
var currentNetworkACL acls.ACLContainer
|
|
currentNetworkACL, err = currentNetworkACL.Get(acls.ContainerID(networkID))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return currentNetworkACL, nil
|
|
}
|