Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove deprecated package vm
Browse files Browse the repository at this point in the history
Signed-off-by: rksharma95 <ramakant@accuknox.com>
rksharma95 authored and Manik2708 committed Jan 17, 2025
1 parent e20ce1f commit 1680c13
Showing 13 changed files with 18 additions and 969 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
22 changes: 8 additions & 14 deletions cmd/policy.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ package cmd

import (
"errors"
"net"

"github.com/kubearmor/kubearmor-client/vm"
"github.com/spf13/cobra"
@@ -17,26 +16,23 @@ 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")
}
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,18 +42,16 @@ 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")
}
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
51 changes: 3 additions & 48 deletions cmd/vm.go
Original file line number Diff line number Diff line change
@@ -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)
}
86 changes: 0 additions & 86 deletions cmd/vmlabel.go

This file was deleted.

76 changes: 0 additions & 76 deletions cmd/vmonboarding.go

This file was deleted.

139 changes: 0 additions & 139 deletions vm/getscript.go

This file was deleted.

100 changes: 0 additions & 100 deletions vm/label.go

This file was deleted.

115 changes: 0 additions & 115 deletions vm/onboarding.go

This file was deleted.

52 changes: 5 additions & 47 deletions vm/policy.go
Original file line number Diff line number Diff line change
@@ -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
317 changes: 0 additions & 317 deletions vm/protobuf/vm.pb.go

This file was deleted.

20 changes: 0 additions & 20 deletions vm/protobuf/vm.proto

This file was deleted.

5 changes: 0 additions & 5 deletions vm/vm.go

This file was deleted.

0 comments on commit 1680c13

Please sign in to comment.