栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

libveinmind - 容器安全SDK初探

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

libveinmind - 容器安全SDK初探

一、简介

libveinmind是由长亭科技研发开源的可扩展容器安全 SDK。

问脉 (TM) SDK 提供了容器安全领域所关心的容器、镜像和运行时等对象的信息获取、镜像内容器访问等相关操作。并进行合理的抽象以提高容器安全工具对 Docker、Containerd 和 Kubernetes 等不同容器产品的兼容性,简化容器安全工具的开发和维护。

二、软件包依赖安装

Ubuntu 和 Debian 平台:

echo 'deb [trusted=yes] https://download.veinmind.tech/libveinmind/apt/ ./' | sudo tee /etc/apt/sources.list.d/libveinmind.list
sudo apt-get update
sudo apt-get install libveinmind-dev

RedHat 和 CentOS 平台:

sudo cat > /etc/yum.repos.d/libveinmind.repo << ==EOF==
[libveinmind]
name=libVeinMind SDK yum repository
baseurl=https://download.veinmind.tech/libveinmind/yum/
enabled=1
gpgcheck=0
==EOF==
sudo yum install libveinmind-devel
三、示例代码

笔者以GO版本SDK为例,展示适用该SDK获取容器镜像、运行时的相关容器信息。

首先,引入SDK依赖包:

import (
	api "github.com/chaitin/libveinmind/go"
	"github.com/chaitin/libveinmind/go/cmd"
	"github.com/chaitin/libveinmind/go/plugin"
	"github.com/chaitin/libveinmind/go/plugin/log"
)

接下来,添加命令函数:

func init() {
	rootCmd.AddCommand(cmd.MapImageCommand(scanCmd, scan))  //容器镜像相关SDK函数
	rootCmd.AddCommand(cmd.MapRuntimeCommand(runCmd, runtime)) //运行时相关SDK函数
	rootCmd.AddCommand(cmd.NewInfoCommand(plugin.Manifest{
		Name:   "veinmind-example",
		Author: "veinmind-team",
	}))
}

我们添加了镜像以及运行时2个SDK的阶段函数。

以打印所有docker images id为例,scan函数应如下声明:

func scan(c *cmd.Command, image api.Image) error {
	log.Info(image.ID())
	return nil
}

以获取运行中的第一个CONTAINER的文件信息为例,runtime函数如下声明:

func runtime(c *cmd.Command, runtime api.Runtime) error {
	ids,_ := runtime.ListImageIDs()
	Aimage,_ := runtime.OpenImageByID(ids[0])
	fileHandle ,_:= Aimage.Stat("/etc/passwd")
	fmt.Println(fileHandle.Size(),fileHandle.Name())
	return nil
}

可以看到,程序打印出了所有images ID ,以及运行中的第一个CONTAINER里`/etc/passwd`的文件信息。

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/866010.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号