Data Source revisions can import native extensions instead of reviewed Python source

Đang mở Phù hợp với người mới
#146 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu bằng cách đọc chính sách đường dẫn nguồn loại trừ .pyc, .pyo và __pycache__, sau đó theo dõi cách các bản sửa đổi Data Source tạo manifest và tải các mô-đun script. Kiểm tra các bài kiểm thử hiện có về việc nhập dữ liệu và xác thực bản sửa đổi. Công việc hoàn tất khi các tệp phần mở rộng gốc như .so và .pyd bị loại trừ, đồng thời bản sửa đổi có cả helper.so và helper.py sử dụng mã nguồn Python đã được xem xét.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

app: scripts severity: low status: backlog type: bug
Plugin Version

v0.0.1

NetBox Version

v4.7.1

Python Version

3.12

Steps to Reproduce
  1. On Linux with CPython 3.12, build a minimal native extension named helper.so from helper.c:
    #include <Python.h>
    
    static int initialize(PyObject *module) {
        return PyModule_AddStringConstant(module, "VALUE", "native extension");
    }
    
    static PyModuleDef_Slot slots[] = {{Py_mod_exec, initialize}, {0, NULL}};
    static struct PyModuleDef def = {PyModuleDef_HEAD_INIT, "helper", NULL, 0, NULL, slots};
    
    PyMODINIT_FUNC PyInit_helper(void) {
        return PyModuleDef_Init(&def);
    }
    
    gcc -shared -fPIC $(python3.12-config --includes) -o helper.so helper.c
    
  2. Create a Data Source containing these files under scripts/:
    • helper.so — the compiled extension.
    • helper.py — containing VALUE = "reviewed source".
    • deploy.py — containing:
    from netbox_scripts.scripts import Script
    
    from . import helper
    
    
    class Deploy(Script):
        class Meta:
            description = helper.VALUE
    
  3. Create a Script Project backed by that Data Source, using scripts as its data path, with Automatic if valid activation and deploy.py enabled as a Script File.
  4. Stage the source using netbox_scripts.ingestion.ingest_data_source() and run the revision's validation Job.
  5. Inspect the revision manifest, the published Script's description, and the loader used for helper.
Expected Behavior

Compiled Python extension modules should not be included in Project revisions, consistent with the existing policy for compiled Python files.

A native extension should not be imported instead of a reviewed .py file with the same module name.

Observed Behavior

The revision includes helper.so in its manifest, validates without errors, and activates successfully.

The published Deploy Script has the description "native extension" instead of "reviewed source".

Python imports helper.so using ExtensionFileLoader, giving it precedence over helper.py. The extension also imports successfully when helper.py is absent.

When only helper.py is present, the published description is "reviewed source".

The source path policy currently excludes .pyc, .pyo, and __pycache__, but does not exclude native extension modules such as .so or .pyd.

This affects Data Source Projects; uploads accept only .py files.

Someone with permission to modify the Data Source can already execute Python code, so this does not introduce a new execution capability. However, it allows a compiled module to run instead of the source a reviewer expects.

Related to #138, but a separate import mechanism.

Ngôn ngữ chính
Python
Star
8
Fork
0
Merge trung bình
12 giờ 34 phút
Pull request đã merge (30 ngày)
57

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của netbox-community/netbox-scripts

Tất cả issue của netbox-community/netbox-scripts

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.