-
Notifications
You must be signed in to change notification settings - Fork 81
/
policy.go
79 lines (66 loc) · 2.24 KB
/
policy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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"
)
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`,
}
// 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`,
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 {
return err
}
return nil
},
}
// 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`,
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 {
return err
}
return nil
},
}
// ========== //
// == Init == //
// ========== //
func init() {
vmCmd.AddCommand(vmPolicyCmd)
// Subcommand for policy command
vmPolicyCmd.AddCommand(vmPolicyAddCmd)
vmPolicyCmd.AddCommand(vmPolicyDeleteCmd)
// gRPC endpoint flag to communicate with KubeArmor. Available across subcommands.
vmPolicyCmd.PersistentFlags().StringVar(&policyOptions.GRPC, "gRPC", "", "gRPC server information")
}