作者投稿和查稿 主编审稿 专家审稿 编委审稿 远程编辑

计算机工程 ›› 2025, Vol. 51 ›› Issue (3): 189-196. doi: 10.19678/j.issn.1000-3428.0068330

• 体系结构与软件技术 • 上一篇    下一篇

基于规则验证的Dockerfile临时文件静态检测方法

苏珲1,*(), 张建辉1,2, 曾俊杰1, 楚小茜1   

  1. 1. 郑州大学网络空间安全学院, 河南 郑州 450000
    2. 嵩山实验室, 河南 郑州 450000
  • 收稿日期:2023-09-05 出版日期:2025-03-15 发布日期:2024-04-09
  • 通讯作者: 苏珲
  • 基金资助:
    国家重点研发计划(2022YFB2901403); 河南省重大科技专项(221100210900-01)

Static Detection Method for Dockerfile Temporary Files Based on Rule Validation

SU Hui1,*(), ZHANG Jianhui1,2, ZENG Junjie1, CHU Xiaoxi1   

  1. 1. School of Cyber Science and Engineering, Zhengzhou University, Zhengzhou 450000, Henan, China
    2. Songshan Laboratory, Zhengzhou 450000, Henan, China
  • Received:2023-09-05 Online:2025-03-15 Published:2024-04-09
  • Contact: SU Hui

摘要:

Dockerfile中存在的临时文件问题使Docker镜像打包了超过其功能所需的不必要的文件资源, 导致镜像尺寸增大, 影响了镜像传输和部署的效率。现有的动态分析法在运行时会产生大量日志, 造成较大的系统开销, 而静态分析法无法检测出临时文件的多种变化形式, 限制了其在日常检测中的有效应用。提出一种Dockerfile临时文件静态检测方法, 通过规则验证收集21种临时文件形式, 使用节点关联算法改进抽象语法树(AST)结构, 提高检测效率, 并在节点关联的AST(NA-AST)结构基础上使用着色机制对节点进行处理, 保证检测完整性。实验结果表明, 相较于现有方法, 所提方法能够以较小的时间开销检测出文件中存在的各种临时文件形式。此外, 提供一种对临时文件形式分类的依据, 其可用于对后续临时文件新增形式的分析和检测, 具有较高的普适性。

关键词: Docker技术, 容器, Dockerfile临时文件, 抽象语法树, 镜像

Abstract:

The temporary file issue in the Dockerfile causes the Docker image to pack unnecessary file resources beyond its functional requirements, resulting in an increase in image size and affecting the efficiency of image transmission and deployment. Existing dynamic analysis methods generate many logs during runtime, resulting in significant system overhead. However, static analysis methods cannot detect various changes in temporary files, which limits their effective application for daily detection. A static detection method for Dockerfile temporary files is proposed, which collects 21 temporary file forms through rule validation using a node association algorithm to improve the Abstract Syntax Tree(AST) structure and enhance detection efficiency. Based on Node Association-AST (NA-AST), a coloring mechanism is used to process nodes, ensuring detection integrity. The experimental results show that compared to existing schemes, the proposed method can detect various temporary file forms in files with less time overhead. In addition, a basis for classifying the forms of temporary files is provided, which can be used for analyzing and detecting new forms of subsequent temporary files and has higher universality.

Key words: Docker technology, container, Dockerfile temporary file, Abstract Syntax Tree (AST), image