| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 | package mqimport (	"errors"	"time"	mqtt "github.com/eclipse/paho.mqtt.golang"	"github.com/gravitl/netmaker/servercfg")const (	// constant for admin role	adminRole = "admin"	// constant for generic role	genericRole = "generic"	// const for dynamic security file	dynamicSecurityFile = "dynamic-security.json")var (	// default configuration of dynamic security	dynConfigInI = dynJSON{		Clients: []client{			{				Username:   mqAdminUserName,				TextName:   "netmaker admin user",				Password:   "",				Salt:       "",				Iterations: 0,				Roles: []clientRole{					{						Rolename: adminRole,					},				},			},			{				Username:   mqNetmakerServerUserName,				TextName:   "netmaker server user",				Password:   "",				Salt:       "",				Iterations: 0,				Roles: []clientRole{					{						Rolename: genericRole,					},				},			},			exporterMQClient,		},		Roles: []role{			{				Rolename: adminRole,				Acls:     fetchAdminAcls(),			},			{				Rolename: genericRole,				Acls:     fetchGenericAcls(),			},		},		DefaultAcl: defaultAccessAcl{			PublishClientSend:    false,			PublishClientReceive: true,			Subscribe:            false,			Unsubscribe:          true,		},	}	exporterMQClient = client{		Username:   mqExporterUserName,		TextName:   "netmaker metrics exporter",		Password:   "",		Salt:       "",		Iterations: 101,		Roles: []clientRole{			{				Rolename: genericRole,			},		},	})// GetAdminClient - fetches admin client of the MQfunc GetAdminClient() (mqtt.Client, error) {	opts := mqtt.NewClientOptions()	setMqOptions(mqAdminUserName, servercfg.GetMqAdminPassword(), opts)	mqclient := mqtt.NewClient(opts)	var connecterr error	if token := mqclient.Connect(); !token.WaitTimeout(MQ_TIMEOUT*time.Second) || token.Error() != nil {		if token.Error() == nil {			connecterr = errors.New("connect timeout")		} else {			connecterr = token.Error()		}	}	return mqclient, connecterr}// genericAcls - fetches generice role related aclsfunc fetchGenericAcls() []Acl {	return []Acl{		{			AclType:  "publishClientSend",			Topic:    "#",			Priority: -1,			Allow:    true,		},		{			AclType:  "publishClientReceive",			Topic:    "#",			Priority: -1,			Allow:    true,		},		{			AclType:  "subscribePattern",			Topic:    "#",			Priority: -1,			Allow:    true,		},		{			AclType:  "unsubscribePattern",			Topic:    "#",			Priority: -1,			Allow:    true,		},	}}// fetchAdminAcls - fetches admin role related aclsfunc fetchAdminAcls() []Acl {	return []Acl{		{			AclType:  "publishClientSend",			Topic:    "$CONTROL/dynamic-security/#",			Priority: -1,			Allow:    true,		},		{			AclType:  "publishClientReceive",			Topic:    "$CONTROL/dynamic-security/#",			Priority: -1,			Allow:    true,		},		{			AclType:  "subscribePattern",			Topic:    "$CONTROL/dynamic-security/#",			Priority: -1,			Allow:    true,		},		{			AclType:  "publishClientReceive",			Topic:    "$SYS/#",			Priority: -1,			Allow:    true,		},		{			AclType:  "subscribePattern",			Topic:    "$SYS/#",			Priority: -1,			Allow:    true,		},		{			AclType:  "publishClientReceive",			Topic:    "#",			Priority: -1,			Allow:    true,		},		{			AclType:  "subscribePattern",			Topic:    "#",			Priority: -1,			Allow:    true,		},		{			AclType:  "unsubscribePattern",			Topic:    "#",			Priority: -1,			Allow:    true,		},		{			AclType:  "publishClientSend",			Topic:    "#",			Priority: -1,			Allow:    true,		},	}}
 |