From 1680c13b4f5a763927485af4341e0b7aecaf80b1 Mon Sep 17 00:00:00 2001 From: rksharma95 Date: Wed, 15 Jan 2025 21:46:23 +0530 Subject: [PATCH] remove deprecated package vm Signed-off-by: rksharma95 --- CONTRIBUTING.md | 2 +- README.md | 2 +- cmd/policy.go | 22 ++- cmd/vm.go | 51 +------ cmd/vmlabel.go | 86 ------------ cmd/vmonboarding.go | 76 ----------- vm/getscript.go | 139 ------------------- vm/label.go | 100 -------------- vm/onboarding.go | 115 ---------------- vm/policy.go | 52 +------ vm/protobuf/vm.pb.go | 317 ------------------------------------------- vm/protobuf/vm.proto | 20 --- vm/vm.go | 5 - 13 files changed, 18 insertions(+), 969 deletions(-) delete mode 100644 cmd/vmlabel.go delete mode 100644 cmd/vmonboarding.go delete mode 100644 vm/getscript.go delete mode 100644 vm/label.go delete mode 100644 vm/onboarding.go delete mode 100644 vm/protobuf/vm.pb.go delete mode 100644 vm/protobuf/vm.proto delete mode 100644 vm/vm.go diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9f6bd076..53b87ef7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,7 +18,7 @@ Contributions are not necessarily in the form of code changes. KubeArmor communi 2. Blogs - a. Explain The use of KubeArmor-Client's features (KVMService, Event Auditor, Visibility, etc) + a. Explain The use of KubeArmor-Client's features (Event Auditor, Visibility, etc) b. Describe How to use KubeArmor-Client to protect your workload with specific use-cases you may have. Please do not shy away from getting as technical as you can. diff --git a/README.md b/README.md index 028f5076..b7d28a3d 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Available Commands: sysdump Collect system dump information for troubleshooting and error report uninstall Uninstall KubeArmor from a Kubernetes Cluster version Display version information - vm VM commands for kvmservice + vm VM commands for non kubernetes/bare metal KubeArmor Flags: --context string Name of the kubeconfig context to use diff --git a/cmd/policy.go b/cmd/policy.go index bbc88884..38acd740 100644 --- a/cmd/policy.go +++ b/cmd/policy.go @@ -6,7 +6,6 @@ package cmd import ( "errors" - "net" "github.com/kubearmor/kubearmor-client/vm" "github.com/spf13/cobra" @@ -17,15 +16,15 @@ var policyOptions vm.PolicyOptions // vmPolicyCmd represents the vm command for policy enforcement var vmPolicyCmd = &cobra.Command{ Use: "policy", - Short: "policy handling for bare-metal vm/kvms control plane vm", - Long: `policy handling for bare-metal vm/kvms control plane vm`, + Short: "policy handling for non kubernetes/bare metal KubeArmor", + Long: `policy handling for non kubernetes/bare metal KubeArmor`, } // vmPolicyAddCmd represents the vm add policy command for policy enforcement var vmPolicyAddCmd = &cobra.Command{ Use: "add", - Short: "add policy for bare-metal vm/kvms control plane vm", - Long: `add policy for bare-metal vm/kvms control plane vm`, + Short: "add policy for non kubernetes/bare metal KubeArmor", + Long: `add policy for non kubernetes/bare metal KubeArmor`, Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { return errors.New("requires a path to valid policy YAML as argument") @@ -33,10 +32,7 @@ var vmPolicyAddCmd = &cobra.Command{ return nil }, RunE: func(cmd *cobra.Command, args []string) error { - // Create http address - httpAddress := "http://" + net.JoinHostPort(HTTPIP, HTTPPort) - - if err := vm.PolicyHandling("ADDED", args[0], policyOptions, httpAddress, IsKvmsEnv); err != nil { + if err := vm.PolicyHandling("ADDED", args[0], policyOptions); err != nil { return err } return nil @@ -46,8 +42,8 @@ var vmPolicyAddCmd = &cobra.Command{ // vmPolicyDeleteCmd represents the vm delete policy command for policy enforcement var vmPolicyDeleteCmd = &cobra.Command{ Use: "delete", - Short: "delete policy for bare-metal vm/kvms control plane vm", - Long: `delete policy for bare-metal vm/kvms control plane vm`, + Short: "delete policy for non kubernetes/bare metal KubeArmor", + Long: `delete policy for non kubernetes/bare metal KubeArmor`, Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { return errors.New("requires a path to valid policy YAML as argument") @@ -55,9 +51,7 @@ var vmPolicyDeleteCmd = &cobra.Command{ return nil }, RunE: func(cmd *cobra.Command, args []string) error { - httpAddress := "http://" + net.JoinHostPort(HTTPIP, HTTPPort) - - if err := vm.PolicyHandling("DELETED", args[0], policyOptions, httpAddress, IsKvmsEnv); err != nil { + if err := vm.PolicyHandling("DELETED", args[0], policyOptions); err != nil { return err } return nil diff --git a/cmd/vm.go b/cmd/vm.go index 50e217de..e8406be7 100644 --- a/cmd/vm.go +++ b/cmd/vm.go @@ -4,42 +4,14 @@ package cmd import ( - "fmt" - - "github.com/kubearmor/kubearmor-client/vm" "github.com/spf13/cobra" ) -var ( - scriptOptions vm.ScriptOptions - // HTTPIP : IP of the http request - HTTPIP string - // HTTPPort : Port of the http request - HTTPPort string - //IsKvmsEnv : Is kubearmor virtual machine env? - IsKvmsEnv bool -) - // vmCmd represents the vm command var vmCmd = &cobra.Command{ Use: "vm", - Short: "VM commands for kvmservice", - Long: `VM commands for kvmservice`, -} - -// vmScriptCmd represents the vm command for script download -var vmScriptCmd = &cobra.Command{ - Use: "getscript", - Short: "download vm installation script for kvms control plane", - Long: `download vm installation script for kvms control plane`, - RunE: func(cmd *cobra.Command, args []string) error { - ip := HTTPIP - - if err := vm.GetScript(client, scriptOptions, ip, IsKvmsEnv); err != nil { - return err - } - return nil - }, + Short: "VM commands for non kubernetes/bare metal KubeArmor", + Long: `VM commands for non kubernetes/bare metal KubeArmor`, } // ========== // @@ -48,23 +20,6 @@ var vmScriptCmd = &cobra.Command{ func init() { rootCmd.AddCommand(vmCmd) - - // Options for vm script download - vmScriptCmd.Flags().StringVarP(&scriptOptions.Port, "port", "p", "32770", "Port of kvmservice") - vmScriptCmd.Flags().StringVarP(&scriptOptions.VMName, "kvm", "v", "", "Name of configured vm") - vmScriptCmd.Flags().StringVarP(&scriptOptions.File, "file", "f", "none", "Filename with path to store the configured vm installation script") - - // Marking this flag as markedFlag and mandatory - err := vmScriptCmd.MarkFlagRequired("kvm") - if err != nil { - _ = fmt.Errorf("kvm option not supplied") - } - - // options for vm generic commands related to HTTP Request - vmCmd.PersistentFlags().StringVar(&HTTPIP, "http-ip", "127.0.0.1", "IP of kvm-service") - vmCmd.PersistentFlags().StringVar(&HTTPPort, "http-port", "8000", "Port of kvm-service") - vmCmd.PersistentFlags().BoolVar(&IsKvmsEnv, "kvms", false, "Enable if kvms environment/control-plane") - // All subcommands - vmCmd.AddCommand(vmScriptCmd) + rootCmd.AddCommand(vmPolicyCmd) } diff --git a/cmd/vmlabel.go b/cmd/vmlabel.go deleted file mode 100644 index 90a16096..00000000 --- a/cmd/vmlabel.go +++ /dev/null @@ -1,86 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2021 Authors of KubeArmor - -package cmd - -import ( - "net" - - "github.com/kubearmor/kubearmor-client/vm" - "github.com/spf13/cobra" -) - -var ( - labelOptions vm.LabelOptions -) - -// vmLabelCmd represents the vm command for label management -var vmLabelCmd = &cobra.Command{ - Use: "label", - Short: "label handling for kvms control plane vm", - Long: `label handling for kvms control plane vm`, -} - -// vmLabelAddCmd represents the vm add label command for label management -var vmLabelAddCmd = &cobra.Command{ - Use: "add", - Short: "add label for kvms control plane vm", - Long: `add label for kvms control plane vm`, - RunE: func(cmd *cobra.Command, args []string) error { - // Create http address - httpAddress := "http://" + net.JoinHostPort(HTTPIP, HTTPPort) - - if err := vm.LabelHandling("ADD", labelOptions, httpAddress, IsKvmsEnv); err != nil { - return err - } - return nil - }, -} - -// vmLabelDeleteCmd represents the vm add label command for label management -var vmLabelDeleteCmd = &cobra.Command{ - Use: "delete", - Short: "delete label for kvms control plane vm", - Long: `delete label for kvms control plane vm`, - RunE: func(cmd *cobra.Command, args []string) error { - // Create http address - httpAddress := "http://" + net.JoinHostPort(HTTPIP, HTTPPort) - - if err := vm.LabelHandling("DELETE", labelOptions, httpAddress, IsKvmsEnv); err != nil { - return err - } - return nil - }, -} - -// vmLabelListCmd represents the vm list label command for label management -var vmLabelListCmd = &cobra.Command{ - Use: "list", - Short: "list labels for vm in k8s/nonk8s control plane", - Long: `list labels for vm in k8s/nonk8s control plane`, - RunE: func(cmd *cobra.Command, args []string) error { - // Create http address - httpAddress := "http://" + net.JoinHostPort(HTTPIP, HTTPPort) - - if err := vm.LabelHandling("LIST", labelOptions, httpAddress, IsKvmsEnv); err != nil { - return err - } - return nil - }, -} - -// ========== // -// == Init == // -// ========== // - -func init() { - vmCmd.AddCommand(vmLabelCmd) - - vmLabelCmd.PersistentFlags().StringVar(&labelOptions.VMName, "vm", "", "VM name") - vmLabelCmd.PersistentFlags().StringVar(&labelOptions.VMLabels, "label", "", "list of labels") - - // Subcommand for policy command - vmLabelCmd.AddCommand(vmLabelAddCmd) - vmLabelCmd.AddCommand(vmLabelDeleteCmd) - vmLabelCmd.AddCommand(vmLabelListCmd) -} diff --git a/cmd/vmonboarding.go b/cmd/vmonboarding.go deleted file mode 100644 index 7155ea5e..00000000 --- a/cmd/vmonboarding.go +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2021 Authors of KubeArmor - -package cmd - -import ( - "errors" - "net" - - "github.com/kubearmor/kubearmor-client/vm" - "github.com/spf13/cobra" -) - -// vmOnboardAddCmd represents the command for vm onboarding -var vmOnboardAddCmd = &cobra.Command{ - Use: "add", - Short: "onboard new VM onto kvms control plane vm", - Long: `onboard new VM onto kvms control plane vm`, - Args: func(cmd *cobra.Command, args []string) error { - if len(args) < 1 { - return errors.New("requires a path to valid vm YAML as argument") - } - return nil - }, - RunE: func(cmd *cobra.Command, args []string) error { - httpAddress := "http://" + net.JoinHostPort(HTTPIP, HTTPPort) - if err := vm.Onboarding("ADDED", args[0], httpAddress); err != nil { - return err - } - return nil - }, -} - -// vmOnboardDeleteCmd represents the command for vm offboarding -var vmOnboardDeleteCmd = &cobra.Command{ - Use: "delete", - Short: "offboard existing VM from kvms control plane vm", - Long: `offboard existing VM from kvms control plane vm`, - Args: func(cmd *cobra.Command, args []string) error { - if len(args) < 1 { - return errors.New("requires a path to valid vm YAML as argument") - } - return nil - }, - RunE: func(cmd *cobra.Command, args []string) error { - httpAddress := "http://" + net.JoinHostPort(HTTPIP, HTTPPort) - if err := vm.Onboarding("DELETED", args[0], httpAddress); err != nil { - return err - } - return nil - }, -} - -// vmListCmd represents the command for vm listing -var vmListCmd = &cobra.Command{ - Use: "list", - Short: "list configured VMs", - Long: `list configured VMs`, - RunE: func(cmd *cobra.Command, args []string) error { - httpAddress := "http://" + net.JoinHostPort(HTTPIP, HTTPPort) - if err := vm.List(httpAddress); err != nil { - return err - } - return nil - }, -} - -// ========== // -// == Init == // -// ========== // - -func init() { - vmCmd.AddCommand(vmOnboardAddCmd) - vmCmd.AddCommand(vmOnboardDeleteCmd) - vmCmd.AddCommand(vmListCmd) -} diff --git a/vm/getscript.go b/vm/getscript.go deleted file mode 100644 index c211c449..00000000 --- a/vm/getscript.go +++ /dev/null @@ -1,139 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2021 Authors of KubeArmor - -package vm - -import ( - "context" - "errors" - "fmt" - "net" - "os" - "path/filepath" - - "github.com/kubearmor/kubearmor-client/k8s" - pb "github.com/kubearmor/kubearmor-client/vm/protobuf" - "github.com/rs/zerolog/log" - "google.golang.org/grpc" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// ScriptOptions for karmor vm getscript -type ScriptOptions struct { - Port string - VMName string - File string -} - -var ( - serviceAccountName = "kvmservice" - pbClient pb.HandleCliClient - namespace string -) - -func initGRPCClient(ip string, port string) error { - grpcClientConn, err := grpc.DialContext(context.Background(), net.JoinHostPort(ip, port), grpc.WithInsecure()) - if err != nil { - return err - } - - pbClient = pb.NewHandleCliClient(grpcClientConn) - if pbClient == nil { - return errors.New("invalid grpc client handle") - } - - return nil -} - -func writeScriptDataToFile(options ScriptOptions, scriptData string) error { - filename := "" - - if options.File == "none" { - filename = options.VMName + ".sh" - } else { - filename = options.File - } - - file, err := os.Create(filepath.Clean(filename)) - if err != nil { - return err - } - - _, err = file.WriteString(scriptData) - if err != nil { - return err - } - - fmt.Printf("VM installation script copied to %s\n", filename) - - return nil -} - -func getClusterIP(c *k8s.Client) (string, error) { - externalIP := "" - - svcInfo, err := c.K8sClientset.CoreV1().Services(namespace).Get(context.Background(), serviceAccountName, metav1.GetOptions{}) - if err != nil { - return "", err - } - - for _, lbIngress := range svcInfo.Status.LoadBalancer.Ingress { - externalIP = lbIngress.IP - break - } - - return externalIP, err -} - -// GetScript - Function to handle script download for vm option -func GetScript(c *k8s.Client, options ScriptOptions, httpIP string, isNonK8sEnv bool) error { - - var ( - clusterIP string - err error - ) - - if isNonK8sEnv { - // Consider as kubectl is not configured - clusterIP = httpIP - } else { - // Get the list of namespaces in kubernetes context - namespaces, err := c.K8sClientset.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{}) - if err != nil { - return err - } - - for _, ns := range namespaces.Items { - // Fetch the namespace of kvmservice - if _, err := c.K8sClientset.CoreV1().ServiceAccounts(ns.Name).Get(context.Background(), serviceAccountName, metav1.GetOptions{}); err != nil { - continue - } - namespace = ns.Name - break - } - - clusterIP, err := getClusterIP(c) - if err != nil || clusterIP == "" { - return err - } - } - - err = initGRPCClient(clusterIP, options.Port) - if err != nil { - log.Error().Msgf("unable to connect to grpc server: %s", err.Error()) - return err - } - - response, err := pbClient.HandleCliRequest(context.Background(), &pb.CliRequest{KvmName: options.VMName}) - if err != nil { - return err - } - - if response.Status == 0 { - err = writeScriptDataToFile(options, response.ScriptData) - } else { - return errors.New(response.StatusMsg) - } - - return err -} diff --git a/vm/label.go b/vm/label.go deleted file mode 100644 index f6250efa..00000000 --- a/vm/label.go +++ /dev/null @@ -1,100 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2022 Authors of KubeArmor - -package vm - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "net/http" - "strings" - "time" - - kg "github.com/kubearmor/KubeArmor/KubeArmor/log" -) - -// LabelOptions are optional configuration for kArmor vm policy -type LabelOptions struct { - VMName string - VMLabels string -} - -// KubeArmorVirtualMachineLabel - Label struct for KVMS control plane -type KubeArmorVirtualMachineLabel struct { - Type string `json:"type"` - Name string `json:"name"` - Labels []map[string]string `json:"labels,omitempty"` -} - -// LabelHandling Function recives path to YAML file with the type of event and HTTP Server -func LabelHandling(t string, o LabelOptions, address string, isKvmsEnv bool) error { - - var respBody []byte - - if isKvmsEnv { - - labelEvent := KubeArmorVirtualMachineLabel{ - Type: t, - Name: o.VMName, - } - - if t == "LIST" { - // List all labels for mentioned VM - labelEvent.Labels = nil - } else { - labelArr := strings.Split(o.VMLabels, ",") - - for _, labelList := range labelArr { - label := make(map[string]string) - - labelVal := strings.Split(labelList, ":") - label[labelVal[0]] = labelVal[1] - labelEvent.Labels = append(labelEvent.Labels, label) - } - } - - labelEventData, err := json.Marshal(labelEvent) - if err != nil { - return err - } - - timeout := time.Duration(5 * time.Second) - client := http.Client{ - Timeout: timeout, - } - - request, err := http.NewRequest("POST", address+"/label", bytes.NewBuffer(labelEventData)) - request.Header.Set("Content-type", "application/json") - if err != nil { - return fmt.Errorf("failed to manage labels") - } - - resp, err := client.Do(request) - if err != nil { - return fmt.Errorf("failed to manage labels") - } - defer func() { - if err := resp.Body.Close(); err != nil { - kg.Warnf("Error closing http stream %s\n", err) - } - }() - - respBody, err = io.ReadAll(resp.Body) - if err != nil { - return fmt.Errorf("failed to send label") - } - } - - if t == "LIST" { - if string(respBody) == "" { - return fmt.Errorf("failed to get label list") - } - fmt.Printf("The label list for %s is %s\n", o.VMName, string(respBody)) - return nil - } - - fmt.Println("Success") - return nil -} diff --git a/vm/onboarding.go b/vm/onboarding.go deleted file mode 100644 index 23e1895e..00000000 --- a/vm/onboarding.go +++ /dev/null @@ -1,115 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2022 Authors of KubeArmor - -package vm - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "net/http" - "os" - "path/filepath" - "strconv" - "strings" - "time" - - tp "github.com/kubearmor/KVMService/src/types" - kg "github.com/kubearmor/KubeArmor/KubeArmor/log" - "sigs.k8s.io/yaml" -) - -func postHTTPRequest(eventData []byte, vmAction string, address string) (string, error) { - - timeout := time.Duration(5 * time.Second) - client := http.Client{ - Timeout: timeout, - } - - request, err := http.NewRequest("POST", address+"/"+vmAction, bytes.NewBuffer(eventData)) - request.Header.Set("Content-type", "application/json") - if err != nil { - return "", err - } - - resp, err := client.Do(request) - if err != nil { - return "", err - } - defer func() { - if err := resp.Body.Close(); err != nil { - kg.Warnf("Error closing http stream %s\n", err) - } - }() - - respBody, err := io.ReadAll(resp.Body) - if err != nil { - return "", err - } - - return string(respBody), err -} - -// List - Lists all configured VMs -func List(address string) error { - var endpoints []tp.KVMSEndpoint - - vmlist, err := postHTTPRequest(nil, "vmlist", address) - if err != nil { - fmt.Println("Failed to get vm list") - return err - } - - err = json.Unmarshal([]byte(vmlist), &endpoints) - if err != nil { - fmt.Println("Failed to parse vm list") - return err - } - - if len(endpoints) == 0 { - fmt.Println("No VMs configured") - } else { - fmt.Println("-------------------------------------------") - fmt.Printf(" %-3s| %-15s| %-10s| %s\n", "", "VM Name", "Identity", "Labels") - fmt.Println("-------------------------------------------") - for idx, vm := range endpoints { - fmt.Printf(" %-3s| %-15s| %-10s| %s\n", strconv.Itoa(idx+1), - vm.VMName, strconv.Itoa(int(vm.Identity)), strings.Join(vm.Labels, "; ")) - } - } - - return nil -} - -// Onboarding - onboards a vm -func Onboarding(eventType string, path string, address string) error { - var vm tp.KubeArmorVirtualMachinePolicy - - vmFile, err := os.ReadFile(filepath.Clean(path)) - if err != nil { - return err - } - - err = yaml.Unmarshal(vmFile, &vm) - if err != nil { - return err - } - - vmEvent := tp.KubeArmorVirtualMachinePolicyEvent{ - Type: eventType, - Object: vm, - } - - vmEventData, err := json.Marshal(vmEvent) - if err != nil { - return err - } - - if _, err = postHTTPRequest(vmEventData, "vm", address); err != nil { - return err - } - - fmt.Println("Success") - return nil -} diff --git a/vm/policy.go b/vm/policy.go index 741a8eeb..eb0bcab2 100644 --- a/vm/policy.go +++ b/vm/policy.go @@ -4,18 +4,14 @@ package vm import ( - "bytes" "context" "encoding/json" "fmt" - "net/http" "os" "path/filepath" "regexp" "strings" - "time" - kg "github.com/kubearmor/KubeArmor/KubeArmor/log" tp "github.com/kubearmor/KubeArmor/KubeArmor/types" pb "github.com/kubearmor/KubeArmor/protobuf" @@ -77,40 +73,8 @@ func sendPolicyOverGRPC(o PolicyOptions, policyEventData []byte, kind string) er } -func sendPolicyOverHTTP(address string, kind string, policyEventData []byte) error { - - timeout := time.Duration(5 * time.Second) - client := http.Client{ - Timeout: timeout, - } - - var url string - if kind == KubeArmorHostPolicy { - url = address + "/policy/kubearmor" - } - - request, err := http.NewRequest("POST", url, bytes.NewBuffer(policyEventData)) - request.Header.Set("Content-type", "application/json") - if err != nil { - return fmt.Errorf("failed to send policy") - } - - resp, err := client.Do(request) - if err != nil { - return fmt.Errorf("failed to send policy") - } - defer func() { - if err := resp.Body.Close(); err != nil { - kg.Warnf("Error closing http stream %s\n", err) - } - }() - - fmt.Println("Success") - return nil -} - // PolicyHandling Function recives path to YAML file with the type of event and emits an Host Policy Event to KubeArmor gRPC/HTTP Server -func PolicyHandling(t string, path string, o PolicyOptions, httpAddress string, isKvmsEnv bool) error { +func PolicyHandling(t string, path string, o PolicyOptions) error { var k struct { Kind string `json:"kind"` } @@ -170,18 +134,12 @@ func PolicyHandling(t string, path string, o PolicyOptions, httpAddress string, return err } - if isKvmsEnv { - // Non-K8s control plane with kvmservice, hence send policy over HTTP - if err = sendPolicyOverHTTP(httpAddress, k.Kind, policyEventData); err != nil { - return err - } - } else { - // Systemd mode, hence send policy over gRPC - if err = sendPolicyOverGRPC(o, policyEventData, k.Kind); err != nil { - return err + // Systemd mode, hence send policy over gRPC + if err = sendPolicyOverGRPC(o, policyEventData, k.Kind); err != nil { + return err - } } + } return nil diff --git a/vm/protobuf/vm.pb.go b/vm/protobuf/vm.pb.go deleted file mode 100644 index 2e2c229e..00000000 --- a/vm/protobuf/vm.pb.go +++ /dev/null @@ -1,317 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1 -// protoc v3.6.1 -// source: vm.proto - -package clihandler - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type CliRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - KvmName string `protobuf:"bytes,1,opt,name=KvmName,proto3" json:"KvmName,omitempty"` -} - -func (x *CliRequest) Reset() { - *x = CliRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_vm_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CliRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CliRequest) ProtoMessage() {} - -func (x *CliRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CliRequest.ProtoReflect.Descriptor instead. -func (*CliRequest) Descriptor() ([]byte, []int) { - return file_vm_proto_rawDescGZIP(), []int{0} -} - -func (x *CliRequest) GetKvmName() string { - if x != nil { - return x.KvmName - } - return "" -} - -type ResponseStatus struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ScriptData string `protobuf:"bytes,1,opt,name=ScriptData,proto3" json:"ScriptData,omitempty"` - StatusMsg string `protobuf:"bytes,2,opt,name=StatusMsg,proto3" json:"StatusMsg,omitempty"` - Status int32 `protobuf:"varint,3,opt,name=Status,proto3" json:"Status,omitempty"` -} - -func (x *ResponseStatus) Reset() { - *x = ResponseStatus{} - if protoimpl.UnsafeEnabled { - mi := &file_vm_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ResponseStatus) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ResponseStatus) ProtoMessage() {} - -func (x *ResponseStatus) ProtoReflect() protoreflect.Message { - mi := &file_vm_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ResponseStatus.ProtoReflect.Descriptor instead. -func (*ResponseStatus) Descriptor() ([]byte, []int) { - return file_vm_proto_rawDescGZIP(), []int{1} -} - -func (x *ResponseStatus) GetScriptData() string { - if x != nil { - return x.ScriptData - } - return "" -} - -func (x *ResponseStatus) GetStatusMsg() string { - if x != nil { - return x.StatusMsg - } - return "" -} - -func (x *ResponseStatus) GetStatus() int32 { - if x != nil { - return x.Status - } - return 0 -} - -var File_vm_proto protoreflect.FileDescriptor - -var file_vm_proto_rawDesc = []byte{ - 0x0a, 0x08, 0x76, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x63, 0x6c, 0x69, 0x68, - 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x22, 0x26, 0x0a, 0x0a, 0x43, 0x6c, 0x69, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x4b, 0x76, 0x6d, 0x4e, 0x61, 0x6d, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x4b, 0x76, 0x6d, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x66, - 0x0a, 0x0e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x12, 0x1e, 0x0a, 0x0a, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x44, 0x61, 0x74, 0x61, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x44, 0x61, 0x74, 0x61, - 0x12, 0x1c, 0x0a, 0x09, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x09, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x4d, 0x73, 0x67, 0x12, 0x16, - 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, - 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x32, 0x53, 0x0a, 0x09, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, - 0x43, 0x6c, 0x69, 0x12, 0x46, 0x0a, 0x10, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x43, 0x6c, 0x69, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x2e, 0x63, 0x6c, 0x69, 0x68, 0x61, 0x6e, - 0x64, 0x6c, 0x65, 0x72, 0x2e, 0x43, 0x6c, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1a, 0x2e, 0x63, 0x6c, 0x69, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x2b, 0x5a, 0x29, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6b, 0x75, 0x62, 0x65, 0x61, 0x72, - 0x6d, 0x6f, 0x72, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x76, 0x6d, 0x2f, 0x63, 0x6c, - 0x69, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_vm_proto_rawDescOnce sync.Once - file_vm_proto_rawDescData = file_vm_proto_rawDesc -) - -func file_vm_proto_rawDescGZIP() []byte { - file_vm_proto_rawDescOnce.Do(func() { - file_vm_proto_rawDescData = protoimpl.X.CompressGZIP(file_vm_proto_rawDescData) - }) - return file_vm_proto_rawDescData -} - -var file_vm_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_vm_proto_goTypes = []interface{}{ - (*CliRequest)(nil), // 0: clihandler.CliRequest - (*ResponseStatus)(nil), // 1: clihandler.ResponseStatus -} -var file_vm_proto_depIdxs = []int32{ - 0, // 0: clihandler.HandleCli.HandleCliRequest:input_type -> clihandler.CliRequest - 1, // 1: clihandler.HandleCli.HandleCliRequest:output_type -> clihandler.ResponseStatus - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_vm_proto_init() } -func file_vm_proto_init() { - if File_vm_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_vm_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CliRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_vm_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ResponseStatus); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_vm_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_vm_proto_goTypes, - DependencyIndexes: file_vm_proto_depIdxs, - MessageInfos: file_vm_proto_msgTypes, - }.Build() - File_vm_proto = out.File - file_vm_proto_rawDesc = nil - file_vm_proto_goTypes = nil - file_vm_proto_depIdxs = nil -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConnInterface - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion6 - -// HandleCliClient is the client API for HandleCli service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type HandleCliClient interface { - HandleCliRequest(ctx context.Context, in *CliRequest, opts ...grpc.CallOption) (*ResponseStatus, error) -} - -type handleCliClient struct { - cc grpc.ClientConnInterface -} - -func NewHandleCliClient(cc grpc.ClientConnInterface) HandleCliClient { - return &handleCliClient{cc} -} - -func (c *handleCliClient) HandleCliRequest(ctx context.Context, in *CliRequest, opts ...grpc.CallOption) (*ResponseStatus, error) { - out := new(ResponseStatus) - err := c.cc.Invoke(ctx, "/clihandler.HandleCli/HandleCliRequest", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// HandleCliServer is the server API for HandleCli service. -type HandleCliServer interface { - HandleCliRequest(context.Context, *CliRequest) (*ResponseStatus, error) -} - -// UnimplementedHandleCliServer can be embedded to have forward compatible implementations. -type UnimplementedHandleCliServer struct { -} - -func (*UnimplementedHandleCliServer) HandleCliRequest(context.Context, *CliRequest) (*ResponseStatus, error) { - return nil, status.Errorf(codes.Unimplemented, "method HandleCliRequest not implemented") -} - -func RegisterHandleCliServer(s *grpc.Server, srv HandleCliServer) { - s.RegisterService(&_HandleCli_serviceDesc, srv) -} - -func _HandleCli_HandleCliRequest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CliRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(HandleCliServer).HandleCliRequest(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/clihandler.HandleCli/HandleCliRequest", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(HandleCliServer).HandleCliRequest(ctx, req.(*CliRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _HandleCli_serviceDesc = grpc.ServiceDesc{ - ServiceName: "clihandler.HandleCli", - HandlerType: (*HandleCliServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "HandleCliRequest", - Handler: _HandleCli_HandleCliRequest_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "vm.proto", -} diff --git a/vm/protobuf/vm.proto b/vm/protobuf/vm.proto deleted file mode 100644 index 17ffbb3d..00000000 --- a/vm/protobuf/vm.proto +++ /dev/null @@ -1,20 +0,0 @@ - -syntax = "proto3"; - -package clihandler; - -option go_package="github.com/kubearmor-client/vm/clihandler"; - -message CliRequest { - string KvmName = 1; -} - -message ResponseStatus { - string ScriptData = 1; - string StatusMsg = 2; - int32 Status = 3; -} - -service HandleCli { - rpc HandleCliRequest (CliRequest) returns (ResponseStatus); -} diff --git a/vm/vm.go b/vm/vm.go deleted file mode 100644 index 2bf884b7..00000000 --- a/vm/vm.go +++ /dev/null @@ -1,5 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2022 Authors of KubeArmor - -// Package vm contains interfaces to setup or communicate with KubeArmor running in either systemd mode or with KVM Service -package vm