当前位置: 首页 > wzjs >正文

智慧团建网站登录入口电脑版微信小程序怎么开通

智慧团建网站登录入口电脑版,微信小程序怎么开通,做网站wamp和xamp,pta程序设计平台契机 最近公司需要把大模型部署到三方公司服务器,当然不能让三方公司搞到模型的源文件。由于用transformers框架加载模型,输入参数直接就是模型的目录,所以传统的文件加密有点难搞,所以尝试使用gocryptfs目录加密,过程…

契机

最近公司需要把大模型部署到三方公司服务器,当然不能让三方公司搞到模型的源文件。由于用transformers框架加载模型,输入参数直接就是模型的目录,所以传统的文件加密有点难搞,所以尝试使用gocryptfs目录加密,过程很曲折,结果也一般,此文不会作为最终的加密部署方案,仅仅记录下研究历程。

尝试gocryptfs


#**安装 Gocryptfs**
wget https://github.com/rfjakob/gocryptfs/releases/download/v2.4.0/gocryptfs_v2.4.0_linux-static_amd64.tar.gz
tar xf gocryptfs_v2.4.0_linux-static_amd64.tar.gz
sudo install -m 0755 ./gocryptfs /usr/local/bin
sudo apt install -y fuse#创建目录:cipher 存放加密数据,plain 是解密后的虚拟视图
mkdir -p ./mount/cipher ./mount/plain#创建密码
cd ./mount
echo "123456" > ./cachefs-password#初始化加密:用密码初始化加密文件系统(生成加密元数据)
cat ./cachefs-password | gocryptfs -init ./cipher#挂载文件系统:通过密码将加密存储挂载为明文视图
cat ./cachefs-password | gocryptfs ./cipher ./plain

此时目录文件如下

在这里插入图片描述


#往plain(明文目录)写入1.txt文件后,会同步到cipher(密文目录)
#直接修改 cipher 目录会导致数据损坏(必须通过明文目录挂载点操作)
echo "我是明文" > ./plain/1.txt#此时在df也可以看到
dh -h
Filesystem              Size  Used Avail Use% Mounted on
/xxxxxxxxxxxxxx/cipher  3.5T  2.8T  492G  86% /xxx/plain

在这里插入图片描述


# 停止访问明文,取消挂载
fusermount -u ./plain # 此时明文不可见
# dh -h也不可见
# 但是加密后的文件还存在于加密目录./cipher 

在这里插入图片描述


#写入 plain 的文件会自动加密到 cipher
#读取 plain 的文件会自动解密自 cipher#**后续查看明文**
cat ./cachefs-password | gocryptfs ./mount/cipher ./mount/plain
cat ./plain/1.txt
fusermount -u ./plain #后续添加数据
cat ./cachefs-password | gocryptfs ./mount/cipher ./mount/plain
mv  xxxx ./mount/plain
fusermount -u ./plain #每次需要先挂载明文目录,然后查看或者修改明文目录
#cachefs-password或者master-key要妥善保存
#当然可以把数据先从自己的服务器加密好,然后把cipher加密目录压缩后转移到三方服务器,这里不展开

使用py读取加密

此时目录

在这里插入图片描述

测试代码

import re
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
from qwen_vl_utils import process_vision_info
from datetime import datetime
import os
import torch
import os
import subprocess
from pathlib import Path
import ctypes
import numpy as np
import time
from multiprocessing import Process, Pipeclass RootResistantDecryptor:def __init__(self, cipher_path, psw, plain_path):self.cipher_path = Path(cipher_path).resolve()self.psw = pswself.mount_point = plain_pathself.proc = Noneself.parent_conn, self.child_conn = Pipe()def _mount_ns(self, mount_point, child_conn):os.setsid()try:# 使用 shell=True 和完整的 shell 命令字符串cmd = f"cat {self.psw} | gocryptfs {str(self.cipher_path)} {str(mount_point)}"subprocess.run(cmd, shell=True, check=True)print(f"Mounted {self.cipher_path} to {mount_point}")child_conn.send("mounted")while True:time.sleep(1)except Exception as e:print(f"Error occurred in child process: {e}")child_conn.send("failed")os._exit(1)def __enter__(self):self.proc = Process(target=self._mount_ns, args=(self.mount_point, self.child_conn))self.proc.start()result = self.parent_conn.recv()if result != "mounted":raise RuntimeError("Mount point is not valid.")return selfdef __exit__(self, *args):if self.proc:self.fusermount()self.proc.terminate()self.proc.join()self.mount_point.rmdir()key_array = np.frombuffer(self.psw.encode('utf-8'), dtype=np.uint8)ctypes.memset(key_array.ctypes.data, 0, key_array.nbytes)del self.pswdef fusermount(self, *args):try:subprocess.run(["fusermount", "-zu", str(self.mount_point)], check=True)print(f"Unmounted {self.mount_point}")except subprocess.CalledProcessError as e:print(f"Failed to unmount: {e}")if __name__ == "__main__":with RootResistantDecryptor("./mount/cipher", "./mount/cachefs-password", "./mount/plain") as mp:# 获取明文模型路径model_path = mp.mount_point+"/Qwen2.5-VL-7B-Instruct/"# 加载模型torch.manual_seed(42)model = Qwen2_5_VLForConditionalGeneration.from_pretrained(model_path, torch_dtype=torch.float16, device_map="auto", attn_implementation="flash_attention_2")processor = AutoProcessor.from_pretrained(model_path)# 卸载模型mp.fusermount()#todo 模型推理

存在的问题

在模型加载的期间,此时plain目录是所有人可见的

在这里插入图片描述

在这里插入图片描述

  • 在模型加载的期间,此时plain目录是所有人可见的,虽然只有几秒但还是不保险
  • 并且如果在模型加载期间直接kill -9,此时明文目录不会被正常卸载

总结

  • 为了避免模型加载被看见,只有混淆挂载,多挂载一些无效目录给破解用户造成困扰比如/tmp/xasdda,/var,/root之类的
  • 用户是甲方,所以大概率有root权限,采用用户目录权限的方法暂时不考虑
  • py代码还需要做加密,这个也比较难搞,除非写成C++
  • 密码应该std键盘输入,或者其他io输入形式,避免泄漏
  • 最理想还是要改写transformers加载模型的函数?
  • 或者使用其他的框架部署?
  • 对付技术一般的公司或许也足够了!

写到最后

请添加图片描述

http://www.dtcms.com/wzjs/53848.html

相关文章:

  • 网页界面设计艺术教程seo课程培训学校
  • 和外国人做ic生意的网站北京推广优化经理
  • 做瓜子进出口用哪些网站北京刚刚宣布比疫情更可怕的事情
  • 盗取dede系统做的网站模板百度云建站
  • 东高端莞商城网站建设自己如何制作网站
  • 床品图案设计网站广州seo推荐
  • 武昌有专业做网站济南专业seo推广公司
  • 网站制作定制图b站推广网站2022
  • 免费网站申请域名com线上销售如何找到精准客户
  • 要怎么做网站推广数据分析师需要学哪些课程
  • 淘宝网网页版登录网站推广优化平台
  • 如何设计网站布局免费公司网站建站
  • wordpress面包屑导航不要子分类廊坊网络推广优化公司
  • 超链接到网站怎么做2023智慧树网络营销答案
  • 网站建设为中心百度搜索风云榜总榜
  • 地方资讯网站源码我想做app推广怎么做
  • 水务行业国企门户网站建设关注公众号推广2元一个
  • 织梦做的网站打包在dw修改公司网站与推广
  • 天元建设集团有限公司路桥工程分公司优化设计答案四年级上册语文
  • 网站开发工作分解结构wbs最近国际新闻大事
  • 来广营做网站公司个人发布信息的免费平台
  • 门户网站怎样做厦门seo关键词
  • 网站建设部门的职责买链接网
  • 北京大兴地区网站建设soso搜搜
  • 建筑工程公司资质办理条件华为seo诊断及优化分析
  • 网站建设美国站长之家是什么
  • dw怎样做收藏本网站企业推广网站
  • 新品发布会策划方案ppt全网seo是什么意思
  • 东莞桂城网站建设广州seo团队
  • 进口外贸网站有哪些代哥seo