Skip to content

Commit

Permalink
import feeder apis
Browse files Browse the repository at this point in the history
  • Loading branch information
seungsoo-lee committed Oct 12, 2020
1 parent ce4880a commit a186cd7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/
knoxAutoPolicy

11 changes: 1 addition & 10 deletions autodiscovery/networkPolicyDiscovery.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package autodiscovery

import (
"fmt"
"math/rand"
"reflect"
"sort"
Expand Down Expand Up @@ -842,7 +841,7 @@ func groupingDst(perGroupedSrcMergedDst map[string][]DstMerged, conGroups []type
// ======================= //

// GenerateNetworkPolicies Function
func GenerateNetworkPolicies(networkLogs []types.NetworkLog, microName string, services []types.K8sService, conGroups []types.ContainerGroup) []types.NetworkPolicy {
func GenerateNetworkPolicies(microName string, networkLogs []types.NetworkLog, services []types.K8sService, conGroups []types.ContainerGroup) []types.NetworkPolicy {
networkLogs = filterLogs(networkLogs, microName)

// step 0: update exposed ports (k8s service, docker-compose portbinding)
Expand Down Expand Up @@ -871,11 +870,3 @@ func GenerateNetworkPolicies(networkLogs []types.NetworkLog, microName string, s

return policies
}

// ======================= //
// == Policy Generation == //
// ======================= //

func TestGenerateNetworkPolicies() {
fmt.Println("TestGenerateNetworkPolicies")
}
9 changes: 8 additions & 1 deletion dbase/dbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ func Conn() (db *sql.DB) {
dbUser := os.Getenv("NETWORKFLOW_DB_USER")
dbPass := os.Getenv("NETWORKFLOW_DB_PASS")
dbName := os.Getenv("NETWORKFLOW_DB_NAME")
db, err := sql.Open(dbDriver, dbUser+":"+dbPass+"@/"+dbName)

// for test
dbDriver = "mysql"
dbUser = "root"
dbPass = "password"
dbName = "flow_management"

db, err := sql.Open(dbDriver, dbUser+":"+dbPass+"@tcp(localhost:3306)/"+dbName)
if err != nil {
panic(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ require (
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 // indirect
google.golang.org/genproto v0.0.0-20201009135657-4d944d34d83c // indirect
google.golang.org/grpc v1.33.0
google.golang.org/protobuf v1.25.0 // indirect
google.golang.org/protobuf v1.25.0
)
26 changes: 18 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"strings"

autopol "github.com/seungsoo-lee/knoxAutoPolicy/autodiscovery"
"github.com/seungsoo-lee/knoxAutoPolicy/dbase"

pb "github.com/cilium/cilium/api/v1/flow"

"github.com/cilium/cilium/api/v1/observer"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/timestamppb"
)

//ConnectHubbleRelay function
func ConnectHubbleRelay() *grpc.ClientConn {
url := os.Getenv("HUBBLE_URL")
port := os.Getenv("HUBBLE_PORT")

// for test
url = "10.104.6.225"
port = "80"

addr := url + ":" + port
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
Expand Down Expand Up @@ -315,12 +321,18 @@ func StartFeederService(ctx context.Context) error {

client := observer.NewObserverClient(conn)

wl := []*pb.FlowFilter{
{
SourceIp: []string{"10.0.1.222"},
},
}

req := &observer.GetFlowsRequest{
Number: 20,
Follow: true,
Whitelist: nil,
Whitelist: wl,
Blacklist: nil,
Since: nil,
Since: timestamppb.Now(),
Until: nil,
}

Expand All @@ -333,6 +345,7 @@ func StartFeederService(ctx context.Context) error {
if err != nil {
return errors.New("can't receive network flow")
}

err = insertFlow(res)
if err != nil {
return err
Expand All @@ -344,8 +357,5 @@ func StartFeederService(ctx context.Context) error {
}

func main() {
autopol.TestGenerateNetworkPolicies()
url := os.Getenv("HUBBLE_URL")
port := os.Getenv("HUBBLE_PORT")
fmt.Println(url, port)
StartFeederService(context.Background())
}

0 comments on commit a186cd7

Please sign in to comment.