Commit 6cd4497f authored by Kevin Di Lallo's avatar Kevin Di Lallo
Browse files

access control for mon-engine endpoints

parent a0931f82
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ require (
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-store v0.0.0
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions v0.0.0
	github.com/gogo/protobuf v1.2.1 // indirect
	github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
	github.com/google/btree v1.0.0 // indirect
@@ -40,4 +41,5 @@ replace (
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq => ../../go-packages/meep-mq
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis => ../../go-packages/meep-redis
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-store => ../../go-packages/meep-sandbox-store
	github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions => ../../go-packages/meep-sessions
)
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@ github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YAR
github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc h1:f8eY6cV/x1x+HLjOp4r72s/31/V2aTUtg5oKRRPf8/Q=
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
@@ -43,6 +47,8 @@ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
+6 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import (

	server "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-mon-engine/server"
	log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
	ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions"

	"github.com/gorilla/handlers"
)
@@ -66,7 +67,11 @@ func main() {
		}

		// Start Monitoring Engine REST API Server
		router := server.NewRouter()
		accessMap := map[string]string{
			"Index":     ss.AccessBlock,
			"GetStates": ss.AccessVerify,
		}
		router := server.NewRouter(accessMap)
		methods := handlers.AllowedMethods([]string{"OPTIONS", "DELETE", "GET", "HEAD", "POST", "PUT"})
		header := handlers.AllowedHeaders([]string{"content-type"})
		log.Fatal(http.ListenAndServe(":80", handlers.CORS(methods, header)(router)))
+13 −3
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ import (
	log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
	mq "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq"
	redis "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis"
	ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-store"
	sbs "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-store"
	ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions"
	v1 "k8s.io/api/core/v1"

	"k8s.io/apimachinery/pkg/fields"
@@ -83,7 +84,8 @@ var baseKey string = dkm.GetKeyRootGlobal() + monEngineKey
var stopChan = make(chan struct{})
var mqGlobal *mq.MsgQueue
var handlerId int
var sandboxStore *ss.SandboxStore
var sandboxStore *sbs.SandboxStore
var sessionStore *ss.SessionStore

var depPodsList []string
var corePodsList []string
@@ -156,13 +158,21 @@ func Init() (err error) {
	_ = rc.DBFlush(baseKey)

	// Connect to Sandbox Store
	sandboxStore, err = ss.NewSandboxStore(redisAddr)
	sandboxStore, err = sbs.NewSandboxStore(redisAddr)
	if err != nil {
		log.Error("Failed connection to Sandbox Store: ", err.Error())
		return err
	}
	log.Info("Connected to Sandbox Store")

	// Connect to Session Store
	sessionStore, err = ss.NewSessionStore(redisAddr)
	if err != nil {
		log.Error("Failed connection to Session Store: ", err.Error())
		return err
	}
	log.Info("Connected to Session Store")

	return nil
}

+18 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import (
	"strings"

	"github.com/gorilla/mux"

	ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions"
)

type Route struct {
@@ -37,16 +39,29 @@ type Route struct {
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
	AccessType  string
}

type Routes []Route

func NewRouter() *mux.Router {
func NewRouter(accessMap map[string]string) *mux.Router {
	router := mux.NewRouter().StrictSlash(true)
	for _, route := range routes {
		var handler http.Handler = route.HandlerFunc
		handler = Logger(handler, route.Name)

		// Authorization
		accessType, found := accessMap[route.Name]
		if !found {
			accessType = route.AccessType
		}

		if accessType == ss.AccessBlock {
			handler = sessionStore.AccessBlocker(handler)
		} else if accessType == ss.AccessVerify {
			handler = sessionStore.AccessVerifier(handler)
		}

		router.
			Methods(route.Method).
			Path(route.Pattern).
@@ -67,6 +82,7 @@ var routes = Routes{
		"GET",
		"/mon-engine/v1/",
		Index,
		ss.AccessGrant,
	},

	Route{
@@ -74,5 +90,6 @@ var routes = Routes{
		strings.ToUpper("Get"),
		"/mon-engine/v1/states",
		GetStates,
		ss.AccessGrant,
	},
}