dashingsoft / pyarmor

A tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.

Home Page:http://pyarmor.dashingsoft.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] License not working in docker container or during docker image build

Benjamin-T opened this issue · comments

On the (windows) host machine everything is working fine:

(c:\gitlab\xxx\.conda) PS C:\gitlab\xxx> pyarmor -d reg pyarmor-device-regfile-6296.2.zip
INFO     Python 3.11.7
INFO     Pyarmor 8.5.9 (group), 006296, xxx
INFO     Platform windows.x86_64
DEBUG    native platform windows.amd64
DEBUG    home path: C:\Users\xxx\.pyarmor
INFO     register "pyarmor-device-regfile-6296.2.zip"
DEBUG    extracting license.lic
DEBUG    extracting .pyarmor_capsule.zip
INFO     machine id in group license: m7ad01780566c0eb96dc88e973754f249
INFO     got machine id: m7ad01780566c0eb96dc88e973754f249
INFO     this machine id matchs group license
DEBUG    extracting tokens/m7ad01780566c0eb96dc88e973754f249
INFO     This license registration information:

License Type    : pyarmor-group
License No.     : pyarmor-vax-006296
License To      : xxx
License Product : xxx

BCC Mode        : Yes
RFT Mode        : Yes

Notes
* Offline obfuscation

And:

(c:\gitlab\xxx\.conda) PS C:\gitlab\xxx> pyarmor -v 
Pyarmor 8.5.9 (group), 006296, xxx

License Type    : pyarmor-group
License No.     : pyarmor-vax-006296
License To      : xxx
License Product : xxx

BCC Mode        : Yes
RFT Mode        : Yes

Notes
* Offline obfuscation

And the obfuscation is also possible:

pyarmor -d gen --enable-rft foo.py
INFO     Python 3.11.7
INFO     Pyarmor 8.5.9 (group), 006296, xxx
INFO     Platform windows.x86_64
DEBUG    native platform windows.amd64
DEBUG    home path: C:\Users\xxx\.pyarmor
DEBUG    command options: {'no_runtime': False, 'enable_rft': True, 'inputs': ['foo.py']}
DEBUG    install plugin: CodesignPlugin
DEBUG    install plugin: DarwinUniversalPlugin
INFO     search inputs ...
INFO     find script foo.py
INFO     find 1 top resources
DEBUG    build package relations
INFO     start to generate runtime files
INFO     target platforms {'windows.amd64'}
DEBUG    got c:\gitlab\shrimp\.conda\Lib\site-packages\pyarmor\cli\core\pyarmor_runtime.pyd
INFO     write dist\pyarmor_runtime_006296\pyarmor_runtime.pyd
DEBUG    patching runtime data at 526368
DEBUG    patch runtime file OK
DEBUG    call post runtime plugin <class 'pyarmor.cli.plugin.CodesignPlugin'>
INFO     generate runtime files OK
INFO     start to obfuscate scripts
INFO     process resource "pipeline"
INFO     obfuscating file pipeline.py
DEBUG    process inline marker
DEBUG    parse script
INFO     start to generate bcc code ...
INFO     no bcc code generated
DEBUG    process co
DEBUG    patch co
INFO     write dist\foo.py
INFO     obfuscate scripts OK
DEBUG    call post build plugin <class 'pyarmor.cli.plugin.DarwinUniversalPlugin'>

The issue arise when I try to run in docker container

I'm running my py-armor auth on host like this:
pyarmor-auth -d --host 172.27.32.1 pyarmor-device-regfile-6296.2.zip

When I run:
``

# pyarmor reg pyarmor-device-regfile-6296.2.zip
INFO     Python 3.11.9
INFO     Pyarmor 8.5.9 (trial), 000000, non-profits
INFO     Platform linux.x86_64
INFO     register "pyarmor-device-regfile-6296.2.zip"
INFO     machine id in group license: m7ad01780566c0eb96dc88e973754f249
INFO     got machine id: m2dd566faf1e60c42813116595f22c2d9
INFO     got machine id: l2dd566faf1e60c42813116595f22c2d9
INFO     got machine id: i593b655fd9880ce8a3d9b58ea31cf5b9
INFO     got machine id: ke6d3f46e070ea740724afbdfd7084efc
INFO     got machine id: ge6d3f46e070ea740724afbdfd7084efc
INFO     got machine id: bdb4942fcd9ba3ed141bc845f40590d26
INFO     no machine id matchs this group license
INFO     take this machine as docker container, and connect to docker host for authentication...
INFO     got docker host machine id: m7ad01780566c0eb96dc88e973754f249
INFO     got docker host machine id: l7ad01780566c0eb96dc88e973754f249
INFO     got docker host machine id: i8e8aa6882564939a46ccd8d9beb76f65
INFO     got docker host machine id: ka791af25fc973c2faba4976b9486d7fa
INFO     got docker host machine id: ga791af25fc973c2faba4976b9486d7fa
INFO     got docker host machine id: b1b234b0f6b98b04680c52037fb467042
INFO     This license registration information:

License Type    : pyarmor-group
License No.     : pyarmor-vax-006296
License To      :  xxx
License Product : xxx

BCC Mode        : Yes
RFT Mode        : Yes

Notes
* Offline obfuscation

And the following response on my pyarmor-auth:

2024-06-14 17:03:06,375: receive request from ('172.27.32.1', 54413)
2024-06-14 17:03:06,378: request data (64): b'PADHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
2024-06-14 17:03:06,378: send auth result to ('172.27.32.1', 54413)
2024-06-14 17:03:06,379: response data (204): b'm7ad01780566c0eb96dc88e973754f249\nl7ad01780566c0eb96dc88e973754f249\ni8e8aa6882564939a46ccd8d9beb76f65\nka791af25fc973c2faba4976b9486d7fa\nga791af25fc973c2faba4976b9486d7fa\nb1b234b0f6b98b04680c52037fb467042\x00'

Thn when I type:

# pyarmor -v
Pyarmor 8.5.9 (group), 006296, xxx

License Type    : pyarmor-group
License No.     : pyarmor-vax-006296
License To      :  xxx
License Product : xxx

BCC Mode        : Yes
RFT Mode        : Yes

Notes
* Offline obfuscation

INFO     got docker host machine id: m7ad01780566c0eb96dc88e973754f249
INFO     got docker host machine id: l7ad01780566c0eb96dc88e973754f249
INFO     got docker host machine id: i8e8aa6882564939a46ccd8d9beb76f65
INFO     got docker host machine id: ka791af25fc973c2faba4976b9486d7fa
INFO     got docker host machine id: ga791af25fc973c2faba4976b9486d7fa
INFO     got docker host machine id: b1b234b0f6b98b04680c52037fb467042

The following in pyarmor-auth

2024-06-14 17:05:42,118: receive request from ('172.27.32.1', 54589)
2024-06-14 17:05:42,119: request data (64): b'PADHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
2024-06-14 17:05:42,119: send auth result to ('172.27.32.1', 54589)
2024-06-14 17:05:42,120: response data (204): b'm7ad01780566c0eb96dc88e973754f249\nl7ad01780566c0eb96dc88e973754f249\ni8e8aa6882564939a46ccd8d9beb76f65\nka791af25fc973c2faba4976b9486d7fa\nga791af25fc973c2faba4976b9486d7fa\nb1b234b0f6b98b04680c52037fb467042\x00'

I conclude from this, that everything should be working; but when I try the example:

# pyarmor gen --enable-rft foo.py
INFO     Python 3.11.9
INFO     Pyarmor 8.5.9 (group), 006296, xxxx
INFO     Platform linux.x86_64
INFO     search inputs ...
INFO     find script foo.py
INFO     find 1 top resources
ERROR    invalid license token, try to run `pyarmor reg` to register license again
ERROR    something is wrong
*=============================================================*
*  Please enable debug option `-d` to run it again            *
*    pyarmor -d gen options ...                               *
*                                                             *
*  Then check console log to find more information            *
*                                                             *
*  Please also check                                          *
*    https://pyarmor.readthedocs.io/en/latest/questions.html  *
*  or run `pyarmor man` to find solutions quickly             *
*=============================================================*

And with debug on I get:

# pyarmor -d gen --enable-rft foo.py
INFO     Python 3.11.9
INFO     Pyarmor 8.5.9 (trial), 000000, non-profits
INFO     Platform linux.x86_64
DEBUG    native platform linux.x86_64
DEBUG    home path: /root/.pyarmor
DEBUG    command options: {'no_runtime': False, 'enable_rft': True, 'inputs': ['foo.py']}
DEBUG    install plugin: CodesignPlugin
DEBUG    install plugin: DarwinUniversalPlugin
INFO     search inputs ...
INFO     find script foo.py
INFO     find 1 top resources
DEBUG    unknown error, please check pyarmor.error.log
ERROR    request license token failed (5): ER:wrong use group licensevdQAY1bsPr_A4O9OX2Tl64UHNNIRkqBsoK-feYqcfnAQJUnkWdojmR843mR4W5dYrCRzF4npTl-BKF6Yw1VM7khPWZ0uJo_DAvmOQfs1FEM8eacaz0eebGUH1qorI8bpGI4W4oYEQe5eEKSt_P9IDfVCsSYG3H1lY0OoVk6ouXnHHkk1jesKGjuQYhjlOstAPqkXxARu6fGuvOf4_jBPH50qod0yh8Tvs-xfF393kRbQ6Q2u62YEfdd5Pcich-LZWSNRBf-fwOiyP-ZGlzPy2C9ITYAIh7KZ3fletxwVw7OThGIZLsz_i3G9v4flms0hPSw6Bq2LXIYYQ&timestamp=1718638120&rev=1&token=0&machine=bdb4942fcd9ba3ed141bc845f40590d26
ERROR    something is wrong
*=============================================================*
*  Please check                                               *
*    https://pyarmor.readthedocs.io/en/latest/questions.html  *
*  or run `pyarmor man` to find solutions quickly             *
*                                                             *
*  It's recommand to report issue by `pyarmor man` in order   *
*  to provide necessary information, and avoid dupcliated     *
*  issues or unclear question.                                *
*=============================================================*

what am I missing.

commented

Which machine is docker host?

   pyarmor-auth -d --host 172.27.32.1 pyarmor-device-regfile-6296.2.zip   

By this command, the docker host ip is 172.27.32.1, but pyarmor-auth log says

    2024-06-14 17:05:42,118: receive request from ('172.27.32.1', 54589)      
    2024-06-14 17:05:42,119: request data (64):   

If means docker container ip is '172.27.32.1'

It's imposibble, docker container and docker host should have different ip but in same network.

If still issue, please report docker host information with uname -a, and ipconfig -a, docker container information with uname -a, and ipconfig -a.

Also report pyarmor-auth run which machine and the full log.

So what Ip should be put in the host argument and what in the gateway of the docker

Not sure why it got closed, as its not yet working;

as requested:

Logs of pyarmor-auth

This is running on the windows host

2024-06-15 15:56:03,360: register ".\pyarmor-device-regfile-6296.2.zip"
2024-06-15 15:56:03,393: machine id in group license: m7ad01780566c0eb96dc88e973754f249
2024-06-15 15:56:03,445: got machine id: m7ad01780566c0eb96dc88e973754f249
2024-06-15 15:56:03,446: this machine id matchs group license
2024-06-15 15:56:03,481: listen container auth request on 0.0.0.0:29092
2024-06-15 15:59:42,452: receive request from ('127.0.0.1', 52376)
2024-06-15 15:59:42,453: send auth result to ('127.0.0.1', 52376)
2024-06-15 15:59:50,386: receive request from ('127.0.0.1', 52381)
2024-06-15 15:59:50,386: unknown packet b''
2024-06-15 16:02:19,207: receive request from ('127.0.0.1', 52489)
2024-06-15 16:02:19,208: send auth result to ('127.0.0.1', 52489)
2024-06-15 16:02:33,038: receive request from ('127.0.0.1', 52497)
2024-06-15 16:02:33,039: send auth result to ('127.0.0.1', 52497)
2024-06-15 16:02:42,934: receive request from ('127.0.0.1', 52504)
2024-06-15 16:02:42,934: unknown packet b''

Logs of the docker container

# pyarmor reg pyarmor-device-regfile-6296.2.zip
INFO     Python 3.11.9
INFO     Pyarmor 8.5.9 (trial), 000000, non-profits
INFO     Platform linux.x86_64
INFO     register "pyarmor-device-regfile-6296.2.zip"
ERROR    [Errno 2] No such file or directory: 'pyarmor-device-regfile-6296.2.zip'
ERROR    something is wrong
*=============================================================*
*  Please enable debug option `-d` to run it again            *
*    pyarmor -d gen options ...                               *
*                                                             *
*  Then check console log to find more information            *
*                                                             *
*  Please also check                                          *
*    https://pyarmor.readthedocs.io/en/latest/questions.html  *
*  or run `pyarmor man` to find solutions quickly             *
*=============================================================*

# cd all_results
# pyarmor reg pyarmor-device-regfile-6296.2.zip
INFO     Python 3.11.9
INFO     Pyarmor 8.5.9 (trial), 000000, non-profits
INFO     Platform linux.x86_64
INFO     register "pyarmor-device-regfile-6296.2.zip"
INFO     machine id in group license: m7ad01780566c0eb96dc88e973754f249
INFO     got machine id: m3c4ec8727b4c20c4bfef5fc8f6bf09fc
INFO     got machine id: l3c4ec8727b4c20c4bfef5fc8f6bf09fc
INFO     got machine id: i7f9489cb30c2a191d3b37789fa3dad85
INFO     got machine id: k87bb2a9195ff93fb117c58f46339bdd1
INFO     got machine id: g87bb2a9195ff93fb117c58f46339bdd1
INFO     got machine id: b8660ca1e07cbbb6cdefe7b0a728e64d5
INFO     no machine id matchs this group license
INFO     take this machine as docker container, and connect to docker host for authentication...
INFO     got docker host machine id: m7ad01780566c0eb96dc88e973754f249
INFO     got docker host machine id: l7ad01780566c0eb96dc88e973754f249
INFO     got docker host machine id: i13265895117ff43d52e8f22cf50c02c2
INFO     got docker host machine id: kbc31d8894d7234dc54aa56da7923cdc3
INFO     got docker host machine id: gbc31d8894d7234dc54aa56da7923cdc3
INFO     got docker host machine id: b5fd78e94175495dda2e9f87a93f1b9f4
INFO     This license registration information:

License Type    : pyarmor-group
License No.     : pyarmor-vax-006296
License To      : xxx
License Product : xxx

BCC Mode        : Yes
RFT Mode        : Yes

Notes
* Offline obfuscation

# pyarmor -v
Pyarmor 8.5.9 (group), 006296, xxx

License Type    : pyarmor-group
License No.     : pyarmor-vax-006296
License To      : xxx
License Product : xxx

BCC Mode        : Yes
RFT Mode        : Yes

Notes
* Offline obfuscation

INFO     got docker host machine id: m7ad01780566c0eb96dc88e973754f249
INFO     got docker host machine id: l7ad01780566c0eb96dc88e973754f249
INFO     got docker host machine id: i13265895117ff43d52e8f22cf50c02c2
INFO     got docker host machine id: kbc31d8894d7234dc54aa56da7923cdc3
INFO     got docker host machine id: gbc31d8894d7234dc54aa56da7923cdc3
INFO     got docker host machine id: b5fd78e94175495dda2e9f87a93f1b9f4
# pyarmor gen --enable-rft foo.py
INFO     Python 3.11.9
INFO     Pyarmor 8.5.9 (group), 006296, xxx
INFO     Platform linux.x86_64
INFO     search inputs ...
INFO     find script foo.py
INFO     find 1 top resources
ERROR    invalid license token, try to run `pyarmor reg` to register license again
ERROR    something is wrong
*=============================================================*
*  Please enable debug option `-d` to run it again            *
*    pyarmor -d gen options ...                               *
*                                                             *
*  Then check console log to find more information            *
*                                                             *
*  Please also check                                          *
*    https://pyarmor.readthedocs.io/en/latest/questions.html  *
*  or run `pyarmor man` to find solutions quickly             *
*=============================================================*

extra info:

# uname -a
Linux abbf6499d958 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 GNU/Linux
(c:\gitlab\xxx\.conda) PS C:\gitlab\xxx> ipconfig

Windows IP Configuration


Unknown adapter Local Area Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : epwzyovle32epmb2dhqywkpr3f.ax.internal.cloudapp.net
   Link-local IPv6 Address . . . . . : fe80::80bd:3ad6:aa26:ebbe%12
   IPv4 Address. . . . . . . . . . . : 10.1.0.57
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 10.1.0.1

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::131b:a157:3f07:b8bd%10
   IPv4 Address. . . . . . . . . . . : 172.25.48.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (WSL (Hyper-V firewall)):

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::2e8e:1d9d:4a5:6284%31
   IPv4 Address. . . . . . . . . . . : 172.27.32.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

I tried to get them on the same network, but this throws a docker deamon error “address pool overlaps” when i setup the network:

version: '3.8'

services:
  app:
    image: your_image_name
    networks:
      - custom_network

networks:
  custom_network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.27.0.0/16
          gateway: 172.27.0.1

Any suggestions @jondy ?

commented

I don't know well about docker, especially windows as docker host

And I can't find network information of docker container in your report

Generally need not custom docker network, just run container

$ docker run --add-host=host.docker.internal:172.22.32.1 ...

BTW by this information

IPv4 Address. . . . . . . . . . . : 172.27.32.1                        
Subnet Mask . . . . . . . . . . . : 255.255.240.0    

The network should be 172.27.32.0/20 and gateway should be 172.27.32.1

Please search internet to find solutions about how to config docker network