Skip to content

Commit

Permalink
add a field for labels
Browse files Browse the repository at this point in the history
Signed-off-by: Jaehyun Nam <[email protected]>
  • Loading branch information
nam-jaehyun committed Apr 29, 2022
1 parent 93794fe commit 3d3ef11
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 169 deletions.
3 changes: 3 additions & 0 deletions KubeArmor/core/containerdHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ func (dm *KubeArmorDaemon) UpdateContainerdContainer(ctx context.Context, contai

container.NamespaceName = dm.Containers[container.ContainerID].NamespaceName
container.EndPointName = dm.Containers[container.ContainerID].EndPointName
container.Labels = dm.Containers[container.ContainerID].Labels

container.ContainerName = dm.Containers[container.ContainerID].ContainerName
container.ContainerImage = dm.Containers[container.ContainerID].ContainerImage

container.PolicyEnabled = dm.Containers[container.ContainerID].PolicyEnabled

Expand Down
6 changes: 6 additions & 0 deletions KubeArmor/core/dockerHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ func (dm *KubeArmorDaemon) GetAlreadyDeployedDockerContainers() {

container.NamespaceName = dm.Containers[container.ContainerID].NamespaceName
container.EndPointName = dm.Containers[container.ContainerID].EndPointName
container.Labels = dm.Containers[container.ContainerID].Labels

container.ContainerName = dm.Containers[container.ContainerID].ContainerName
container.ContainerImage = dm.Containers[container.ContainerID].ContainerImage

container.PolicyEnabled = dm.Containers[container.ContainerID].PolicyEnabled

Expand Down Expand Up @@ -280,7 +283,10 @@ func (dm *KubeArmorDaemon) UpdateDockerContainer(containerID, action string) {

container.NamespaceName = dm.Containers[containerID].NamespaceName
container.EndPointName = dm.Containers[containerID].EndPointName
container.Labels = dm.Containers[containerID].Labels

container.ContainerName = dm.Containers[containerID].ContainerName
container.ContainerImage = dm.Containers[containerID].ContainerImage

container.PolicyEnabled = dm.Containers[containerID].PolicyEnabled

Expand Down
14 changes: 14 additions & 0 deletions KubeArmor/core/kubeUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ func (dm *KubeArmorDaemon) UpdateEndPointWithPod(action string, pod tp.K8sPod) {

container.NamespaceName = newPoint.NamespaceName
container.EndPointName = newPoint.EndPointName

labels := []string{}
for k, v := range newPoint.Labels {
labels = append(labels, k+"="+v)
}
container.Labels = strings.Join(labels, ",")

container.ContainerName = pod.Containers[containerID]
container.ContainerImage = pod.ContainerImages[containerID]

Expand Down Expand Up @@ -330,6 +337,13 @@ func (dm *KubeArmorDaemon) UpdateEndPointWithPod(action string, pod tp.K8sPod) {

container.NamespaceName = newEndPoint.NamespaceName
container.EndPointName = newEndPoint.EndPointName

labels := []string{}
for k, v := range newEndPoint.Labels {
labels = append(labels, k+"="+v)
}
container.Labels = strings.Join(labels, ",")

container.ContainerName = pod.Containers[containerID]
container.ContainerImage = pod.ContainerImages[containerID]

Expand Down
4 changes: 4 additions & 0 deletions KubeArmor/feeder/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ func (fd *Feeder) PushLog(log tp.Log) {

pbAlert.NamespaceName = log.NamespaceName
pbAlert.PodName = log.PodName
pbAlert.Labels = log.Labels

pbAlert.ContainerID = log.ContainerID
pbAlert.ContainerName = log.ContainerName
pbAlert.ContainerImage = log.ContainerImage
Expand Down Expand Up @@ -645,6 +647,8 @@ func (fd *Feeder) PushLog(log tp.Log) {

pbLog.NamespaceName = log.NamespaceName
pbLog.PodName = log.PodName
pbLog.Labels = log.Labels

pbLog.ContainerID = log.ContainerID
pbLog.ContainerName = log.ContainerName
pbLog.ContainerImage = log.ContainerImage
Expand Down
2 changes: 1 addition & 1 deletion KubeArmor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/tools v0.1.10 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/grpc v1.45.0
google.golang.org/grpc v1.46.0
k8s.io/api v0.21.2
k8s.io/apimachinery v0.21.2
k8s.io/client-go v0.21.2
Expand Down
13 changes: 8 additions & 5 deletions KubeArmor/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
Expand Down Expand Up @@ -248,7 +248,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down Expand Up @@ -332,8 +332,9 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
Expand Down Expand Up @@ -804,6 +805,7 @@ golang.org/x/sys v0.0.0-20201117170446-d9b008d0a637/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201202213521-69691e467435/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -935,8 +937,8 @@ google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M=
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8=
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand All @@ -949,6 +951,7 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
Expand Down
5 changes: 4 additions & 1 deletion KubeArmor/monitor/logUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ func (mon *SystemMonitor) UpdateContainerInfoByContainerID(log tp.Log) tp.Log {
defer ContainersLock.RUnlock()

if val, ok := Containers[log.ContainerID]; ok {
// update container info
// update pod info
log.NamespaceName = val.NamespaceName
log.PodName = val.EndPointName
log.Labels = val.Labels

// update container info
log.ContainerName = val.ContainerName
log.ContainerImage = val.ContainerImage

Expand Down
2 changes: 2 additions & 0 deletions KubeArmor/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Container struct {

NamespaceName string `json:"namespaceName"`
EndPointName string `json:"endPointName"`
Labels string `json:"labels"`

AppArmorProfile string `json:"apparmorProfile"`

Expand Down Expand Up @@ -178,6 +179,7 @@ type Log struct {
// k8s
NamespaceName string `json:"namespaceName,omitempty"`
PodName string `json:"podName,omitempty"`
Labels string `json:"labels,omitempty"`

// container
ContainerID string `json:"containerID,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion protobuf/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ replace (
)

require (
google.golang.org/grpc v1.45.0
google.golang.org/grpc v1.46.0
google.golang.org/protobuf v1.28.0
)
Loading

0 comments on commit 3d3ef11

Please sign in to comment.