From 1e02e0aea2638994d2de859ef0c9b4fd840b5e52 Mon Sep 17 00:00:00 2001 From: winstonsmith1897 Date: Fri, 25 Aug 2023 15:28:23 +0200 Subject: [PATCH] Implement UCS Communication --- Dockerfile | 1 + .../__pycache__/app_dht.cpython-310.pyc | Bin 5257 -> 5903 bytes .../__pycache__/app_dht.cpython-311.pyc | Bin 0 -> 9923 bytes .../__pycache__/catch_topic.cpython-310.pyc | Bin 2966 -> 5582 bytes .../security_by_contract.cpython-310.pyc | Bin 0 -> 4687 bytes application_manager/app_dht.py | 80 ++- application_manager/catch_topic.py | 135 ++++- application_manager/security_by_contract.py | 132 ++++- application_manager/test-ucs.py | 532 ++++++++++++++++++ trials/list_applications.py | 2 +- trials/pull_image.py | 4 +- trials/remove_image.py | 4 +- 12 files changed, 831 insertions(+), 59 deletions(-) create mode 100644 application_manager/__pycache__/app_dht.cpython-311.pyc create mode 100644 application_manager/__pycache__/security_by_contract.cpython-310.pyc create mode 100644 application_manager/test-ucs.py diff --git a/Dockerfile b/Dockerfile index b74bdf2..01b5686 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ COPY requirements.txt / RUN pip install --no-cache-dir -r /requirements.txt ADD application_manager/*.py / +ADD application_manager/get-labels.sh / ADD run_application_manager/run_manager.sh / #ADD services/leader_file.txt / uncomment this to test the run_manager diff --git a/application_manager/__pycache__/app_dht.cpython-310.pyc b/application_manager/__pycache__/app_dht.cpython-310.pyc index 2819f754fa989fcd47da26e6cb0775a799157e56..4d4b41a7b541beba16a05c1bff60ffef27b29876 100644 GIT binary patch literal 5903 zcma)ATaVku8RbyCiPCDXzU0z`N$fbvW!GtvUbabLHqTza}Xhn5M z?PeLu2v;EQytzmGz zVe%3;KGhl)H@St}<~DbbJG{(Y;_SMvy@eZsvU}Ez%w_0lg~xns9wt4 zn7V5ATHF5Uc`!f=bEnlE_{k~v=a2ltdwJBm_a=Jxwpx+*f$#UcL7%r`pVy7di2NSU zj7}8xGLsLs`%z~0Mb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^9js3vF=&qOVn?%ErnOXt%n+k5}jNlsJmoMx6>XBh9Nl4_4=c5J9;DK z*cUKOYc%flTGC4*ht6Gjo)m*|rvoQi$573fxka-?lRTb^B!%I~6Ozsn6E+_ALh%Z8 zy;rKIPDM;yf6OFO_RMsL(NQ;D!<~D^_NnOXPlOl>cWcw{d2)t7*hqKdekwO5-FUL< ze(Fu4lLt@UQ&-(5{|25PtI@01{2-upPR~|2?T*?4S_(b!2fhHN<&p>S$p8@6b6BTcU~aAW?lT-lC!J(NI}BLSqSY43e_WKzX zR(X2g$;hoZXV87*1}KoEv%Qf^mLwF)nPlZ4NkCx zLo4&dmy~j)BL@|4;nBy_Af;DT!8S2C-3?Qk+J4x0Ol($RLnuDReAAz=@Sh*OSFVmRhtjgTO2kXNZ z;!|pIrq$m-IJkr+XdPng+WT*164@kp~vJHLo>s;TVEsDFfLKzUwj)Do-Y ztdpDT1Ki%nI7EecAo&L_VkOY26piY6Faf_v{?Mr`k&J`Xi(6nEBhXdKTxxRGNS3H7pJ5=FgVH6MDPx$Gru+-(y(EwF^wBN< zAnwRsKFxamghc~lHOlf;wfd!u2bm2spH=il@QDV5_Cb%TL#i`mCGa<#Af)MY1s4E? zfCq@h#$3UL$~P~#Q2XMpxx-Kyza8qkxCaRzG)j znwE5FFhcU82r5hkK0IX=Hu;~R6kryrqVx3eC&1UA?Trn8cs}sg{oovZ!#MAa)9*m2 zzRuxuhSwPjuYRSbrWKzFCh^y|qv|JDude;v{V1#LR^3Q-93aW1$4~%D15REliq~oE zFf|fl5?!)(w8@24KeXgEqlOawJaY_iw73cOT6G8bA!oJua@^R05 fhwLnqKUAdvRkntjNw+DrC1w6EHg(#ih=9Oke* diff --git a/application_manager/__pycache__/app_dht.cpython-311.pyc b/application_manager/__pycache__/app_dht.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a04e7fbe95083961a382be032f7df47b4fe0c9bc GIT binary patch literal 9923 zcmdT~U2NP|b|!~2B!|QK(Tp_uu`E-v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*iVq-?KsS+3s<3>3ZG$OCue@BbF0{P(|SjXS()gtK9He{4j zX7ElduvF-T7Cf#J)*6kC9-zKF&^&gMS$BEInwWJTjpe3R#D4D>c#?-m%?S_G%)+;D z5;6l}t=${&G5SP?d8GpxMv35w&rD3_p}<+CuB?h<7sdWqi?^wL@xhO9ell=3~e z`~ZGx835OZpp*hCCHH+w`B?0HBz6{$f=ZUeeqHR>#C}+H{lC+gAsF;WBQH_^+&t!I zzKnQBdzddfX)O1&BEH}q<3WwEW}Wu{e!r1dUAX)CV^v0W-D93Hv2NUQB1RknX)*^! z+*2C@uP&*wj&TGdZiUaR#Sq!X$y33Xv@+IrSAK{6jv2=PZ4dRDgX@#k5h zkX7T%UT29y!Vwg5d#Aw}3sFecS%g`#s*A8XSrvtZuo!Xw-&B4IpEb8{=jD>E1!R$u zgRL9XCTl72tgU|)WbJ6{l?!ikiSKWem`DhQjM{jj-fwCpk3 z`;6#bSW2|RmM%cS560Qsbi=V9PL;%Iqp1tLb+7P*0{9jI zTz0SU9Zz}N)`a5u`vVW=OZ=qHPip+65gb_)wBU%H`4I@uH{Cd;`}SdnU#Nl+Jc136 zK)z4g$BSC5AEdrK*gSTcS$BKKBFws<#&V<;alkwF0<(UE)V$z_>I`ql#&EaCV9_}p# zp3?)*t(-FgEx$^CoL-wP9w`O-^gtg}ae=?uyL#o5{WoD(xeM|}>#m!*Vqd9sKyMwu zjkKQP2|YSk@EI*qu~Tn306T2HmbKY-5Lrwo4>7%0jD14UV2peVaCUFJCt z56c0uY2`fG=Z*!fcTapT{4yqwfvB0p;#JE{>xVk)KM?j{X+OdQ0*U{$Li9-pf>&UlpT@n+8kC0UV`a*LpV9qz?!ZszUG#}E b<-kcFo;uLkN+V^~;L%PRwiKQPGTi?K$zAZ0 literal 0 HcmV?d00001 diff --git a/application_manager/__pycache__/catch_topic.cpython-310.pyc b/application_manager/__pycache__/catch_topic.cpython-310.pyc index 4acbbbe3f5131bed8bbc7b647b2ea800dd238e54..55c1c75b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O{L7Dw5SYR@*=x-8M7xT49s979~>`(9^=5YTFCTww<5zCCNhoRAlL; zOh}NQVJ+UpWZEh+9!pJO087ns6`F!hq{&a`U{`f(|& z;*xT<(h!=bsngLj3$B&3Zb9()3_6o>gx69=*#dhBI#n>pzdHH9!C;X`1e887R1DQA z!yu~^;f4Z6;g+I=q411_t@ll^Zi8>9wy1zsKpjv=xT%eEo?-4{?xrYo`0i_%(n#%; zKSyRFLxJy6AxkXHHRs$KxIZN*IAq*nXC1ts6WoRG7dso^K1y(NX=f9>UlRuf%R#9s z?#dlQ#c0vmEtI3XQpIqM43kATPuKVEe0OK>MyV2H_CYWh%SC8p)o3J@t_rFGGpY^h z$P4N{>Mm1v1szHhe;h|)W)Gr3#5%_-ifBctPX~$yrrM&-RYeZUoS}?kRG_R*pZdjY zAz@a_E8dDwYMYK+Ny*;gfFH0N-$dsz*F+7Xw(_oF-bAaHsL3kKeal~Sn={UNUA1w< z5~?WwQPZfR2u+NX&3vLh0OKXokZ+s0f;LJ^q*g_BA*x>JPzEX5YMiZWE&%4JyBd>^GM8OO+sLhe^{)-Znb zF46Sj5GSas)a{^K%5hY=XM(9~n2<0ZtO$euo!|i?xL1~lX^B?vbYKpkEPP70=_^0O zD06-MbM!;spKeUz8=cM|>IQ>e6el;X@9gY!CNYu@ZPaek=F_6K*VTu_)pfo)kq_di z`$Q%=AT<^>Dk*a>0J(C8K9>Zb|2N;y>i6V>J$(%Rl5(ro)Hw7XMoJ#QlM5*7k^V(+ pzZynjJdiiZTrru+H8c_}x8YXNsQ26}E~l3>bN*KTt-Ji6{{W2NU8ev5 diff --git a/application_manager/__pycache__/security_by_contract.cpython-310.pyc b/application_manager/__pycache__/security_by_contract.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e8868949404561e407640ae03e3511e8f3d558fb GIT binary patch literal 4687 zcmai1TW=f372eq!my|@^Y}sb zvqMW-P(}f@k49gLzQhHjN24$OJ@eX!*1w>r8aVyVEU8G2i|k_0Tz6*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HUW(t-d>#Oy^2vq(Ed*}+HT`H3Zp;g|Z zosFt}%*A?o;byzn6Z~#5!7Qw4jMnkwk7+)szyv7mOOXwGN`6Q^6j@He<2*QS8Riid zOtN59cLlRt2JE*9^=;k1_|3KIFfqle)tM;MKsRl%SP&i*{@5)%y6%|0w?1AMMt_O{t(Jb(H z@fSC4-ubvT4j;8)CirUZ4b^7jy?R*^Jn1q#j<-l>W4U(PnYeyUmpj+5i9wWbBnq89 zB{J=EVVdQ&-AJUAHpz=vq3(q#|zs7PI zWfC@^IsjN#m~U4ZLM*x1rx-XRR674jQc0Tr`lJ#e*WxZxNnji~9cpDHl@%nFKt%xe z)Vg%Ak|fj&osD~+A_fz>nsh`yKu!B;f}~&Bykh4*kAFQ5P4EWPB4bIimJ^h#;8?%O_cY!K-}!6v{OXpvfAVy-M7ti$W2PiVckm>1lJ$Rw~72ysJx(gv@Y+Q>hP~-2fZ1K?Jw3x|zs+TOn)~ zSrNI!E1j)E8E$d<$C#7R>0Fxr?nd2_A7dN&QzExP@{4OlvL|@$&N$txeRThm^;JoTEw6$A;*8iS zXyER8`|et?2<3l866W=iHXr8>9wlTMB2SBke@moIgwQ&iM@UF}f@C}iMc<~u29b!! zS)Y{zWq-z(5k!(ui)i70?gxQWaRP@jZ!_zRmy%E^b1;HkM}@qUat7oG$P18-B1MA; z9e5;?vVB+KF0l>qQa14fBM=K5UkP7;JFy4v^~{~Pyq=#w?FT15l2@A(B)Yl+ zIR8?Lue{oM28|8M7=t$AlwBOS?iT{QfqGb`4AlgMuv$R8xpE;H4yzMTJ8iWu3Gp{r z<8Sz~Du`=hLIBG&S1uZ>Uy%1u6d-$*naMqfZAv>?eHK6YtZ7DkEbHtN>0` fycF2rYH+*22`&aDyk1ZaE(O!U`Cuuy;0FH#kb`dp literal 0 HcmV?d00001 diff --git a/application_manager/app_dht.py b/application_manager/app_dht.py index a0eb022..9455463 100644 --- a/application_manager/app_dht.py +++ b/application_manager/app_dht.py @@ -5,7 +5,7 @@ client = docker.from_env() -api_url = "http://localhost:3000/" +api_url = "http://sifis-device4.iit.cnr.it:3000/" def publish(ws, topic_uuid, requestor_id, request_id, containers): @@ -36,18 +36,27 @@ def request_list(ws, message, image_name): requestor_id = topic_value["requestor_id"] request_id = topic_value["request_id"] containers = topic_value["containers"] - containers.append(image_name) - publish(ws, topic_uuid, requestor_id, request_id, containers) - print("\n[!] Active Containers: " + str(containers) + "\n") + if image_name not in containers: + containers.append(image_name) + publish(ws, topic_uuid, requestor_id, request_id, containers) + print("\n[!] Active Containers: " + str(containers) + "\n") + result = "OK" + return result + else: + print("The App has been already installed") + print("\n[!] Active Containers: " + str(containers) + "\n") + result = "Already Installed" + return result def update_dht_list(ws, image_name): topic_name = "SIFIS:container_list" try: response = requests.get(api_url + "topic_name/" + topic_name) - message = str(response.json()[0]) + message = str(response.json()[-1]) message = message.replace("'", '"') - request_list(ws, message, image_name) + result = request_list(ws, message, image_name) + return result except IndexError: print("\n[!] Update List, the list is empty") topic_uuid = "Pippo" @@ -58,32 +67,39 @@ def update_dht_list(ws, image_name): def pull_image(ws, image_name, topic_uuid, requestor_id, request_id): + prefix = "ghcr.io/sifis-home/" if image_name == "": raise ValueError("Image name cannot be empty") + if prefix not in image_name: + image_name = prefix + image_name if image_name: try: - client.images.pull(image_name) - update_dht_list(ws, image_name) topic_name = "SIFIS:application_manager_pull_image" - pulling_data = { - "requestor_id": requestor_id, - "request_id": request_id, - "pulled_image": image_name, - "operation": "pull image", - "result": "successfull", - } - requests.post( - api_url - + "topic_name/" - + topic_name - + "/topic_uuid/" - + topic_uuid, - json=pulling_data, - ) + result = update_dht_list(ws, image_name) + if result != "Already Installed": + client.images.pull(image_name) + # update_dht_list(ws, image_name) + pulling_data = { + "requestor_id": requestor_id, + "request_id": request_id, + "pulled_image": image_name, + "operation": "pull image", + "result": "successfull", + } + requests.post( + api_url + + "topic_name/" + + topic_name + + "/topic_uuid/" + + topic_uuid, + json=pulling_data, + ) - print(f"[!] Image {image_name} pulled successfully!") - start_container(image_name, topic_uuid, requestor_id, request_id) - return "\n Pulling and Starting operation completed ..." + print(f"[!] Image {image_name} pulled successfully!") + start_container( + image_name, topic_uuid, requestor_id, request_id + ) + return "\n Pulling and Starting operation completed ..." except docker.errors.APIError as e: pulling_data = { "requestor_id": requestor_id, @@ -114,8 +130,8 @@ def start_container(image_name, topic_uuid, requestor_id, request_id): image_name, detach=True, volumes={ - "/var/run/docker.sock": { - "bind": "/var/run/docker.sock", + "/var/run/sifis.sock": { + "bind": "/var/run/sifis.sock", "mode": "rw", } }, # volume @@ -197,8 +213,9 @@ def remove_image(image_name, topic_uuid, request_id, requestor_id): return "Missing 'image_name' parameter", 400 try: - client.images.remove(image_name, force=True) + print("[!] Removing Image : " + image_name) topic_name = "SIFIS:application_manager_remove_image" + list_containers(topic_uuid, requestor_id, request_id, image_name) removing_info = { "requestor_id": requestor_id, "request_id": request_id, @@ -211,6 +228,7 @@ def remove_image(image_name, topic_uuid, request_id, requestor_id): json=removing_info, ) list_containers(topic_uuid, requestor_id, request_id, image_name) + client.images.remove(image_name, force=True) return f"Image {image_name} removed successfully!" except docker.errors.ImageNotFound as e: return f"Image {image_name} not found: {e}", 404 @@ -221,13 +239,13 @@ def remove_image(image_name, topic_uuid, request_id, requestor_id): def list_containers(topic_uuid, requestor_id, request_id, image_name): topic_name = "SIFIS:container_list" response = requests.get(api_url + "topic_name/" + topic_name) - message = str(response.json()[0]) + message = str(response.json()[-1]) message = message.replace("'", '"') if "value" in str(message): json_message = json.loads(message) topic_value = json_message["value"] containers = topic_value["containers"] - if image_name != None: + if image_name in containers: containers.remove(image_name) _list = { "requestor_id": requestor_id, diff --git a/application_manager/catch_topic.py b/application_manager/catch_topic.py index 34e2a09..3688c77 100644 --- a/application_manager/catch_topic.py +++ b/application_manager/catch_topic.py @@ -4,12 +4,32 @@ import security_by_contract import websocket +REGISTERED = False +registration_id = 1 +session_id = "None" +permit_installation = False -def handle_pull_image(ws, topic_name, topic_uuid): + +def UCS_request(ws, topic_name, topic_uuid): + global REGISTERED, session_id try: image_name = topic_name["image_name"] - security_by_contract.get_labels(image_name) + print("[!] Recovering App LABELS\n") + _, app_id = security_by_contract.get_labels(image_name) + session_id = app_id + print("[!] APP_ID: " + str(session_id)) + return + except Exception as e: + print(e) + +""" +def handle_pull_image(ws, topic_name, topic_uuid): + global REGISTERED, session_id + print("Permit Installation") + print(permit_installation) + try: + image_name = topic_name["image_name"] requestor_id = topic_name["requestor_id"] request_id = topic_name["request_id"] result = app_dht.pull_image( @@ -18,6 +38,33 @@ def handle_pull_image(ws, topic_name, topic_uuid): print(result) except Exception as e: print(e) +""" + + +def handle_pull_image(): + global REGISTERED, session_id, global_pull_image_params + + # Accedi ai parametri globali + params = global_pull_image_params + if params is not None: + ws = params["ws"] + topic_value = params["topic_value"] + topic_uuid = params["topic_uuid"] + try: + image_name = topic_value["image_name"] + requestor_id = topic_value["requestor_id"] + request_id = topic_value["request_id"] + result = app_dht.pull_image( + ws, image_name, topic_uuid, requestor_id, request_id + ) + print(result) + print( + "\n----------------- PULLING OPERATION COMPLETED ---------------------------------\n" + ) + except Exception as e: + print(e) + else: + print("No pull image parameters available.") def handle_start_container(topic_name): @@ -38,6 +85,9 @@ def handle_remove_image(topic_name, topic_uuid): image_name, topic_uuid, request_id, requestor_id ) print(result) + print( + "\n----------------- REMOVING OPERATION COMPLETED ---------------------------------\n" + ) except Exception as e: print(e) @@ -70,13 +120,67 @@ def handle_list_containers(topic_uuid, requestor_id, request_id): topic_uuid, requestor_id, request_id, None ) print(result) + print( + "\n----------------- LISTING OPERATION COMPLETED ---------------------------------\n" + ) + except Exception as e: + print(e) + + +def wait_for_access(json_value): + global registration_id + print("[!] Wait for access") + _id = json_value["command"]["value"]["id"] + try: + if _id == "pep-application_manager": + purpose = json_value["command"]["value"]["message"]["purpose"] + code = json_value["command"]["value"]["message"]["code"] + response_id = json_value["command"]["value"]["message"][ + "message_id" + ] + if ( + purpose == "REGISTER_RESPONSE" + and code == "OK" + and response_id == registration_id + ): + return "OK" + else: + return "REGISTRATION DENIED" except Exception as e: print(e) def on_message(ws, message): + global REGISTERED + global session_id + global permit_installation json_message = json.loads(message) + try: + if "Volatile" in json_message: + json_message = json_message["Volatile"] + json_value = json_message["value"] + purpose = json_value["command"]["value"]["message"]["purpose"] + if purpose == "TRY_RESPONSE": + print("[!] Permit Installation") + handle_pull_image() + + if ( + json_value["command"]["value"]["topic_name"] + == "application_manager_registration" + and REGISTERED == False + ): + access = wait_for_access(json_value) + if access == "OK": + REGISTERED = True + print( + "[!] REGISTRATION OK: Application Manager is registered to UC\n\n" + ) + else: + print("[!] Application Manager is not registered to UC") + except Exception as e: + pass + if "Persistent" in json_message: json_message = json_message["Persistent"] # Handle messages @@ -92,11 +196,29 @@ def on_message(ws, message): ) +global_pull_image_params = None + + +# Funzione per salvare i parametri di handle_pull_image +def save_pull_image_params(params): + global global_pull_image_params + global_pull_image_params = params + + def handle_message(ws, topic_uuid, topic_value, request_id, requestor_id): + global permit_installation if "operation" in topic_value: operation = topic_value["operation"] if operation == "pull_image": - handle_pull_image(ws, topic_value, topic_uuid) + print("[!] Forwarding UCS Request") + UCS_request(ws, topic_value, topic_uuid) + print("[!] Pulling Image Request") + params = { + "ws": ws, + "topic_value": topic_value, + "topic_uuid": topic_uuid, + } + save_pull_image_params(params) elif operation == "remove_image": handle_remove_image(topic_value, topic_uuid) elif operation == "start_container": @@ -118,12 +240,17 @@ def on_close(ws, close_status_code, close_msg): def on_open(ws): + global REGISTERED + global registration_id print("### Connection established ###") + if REGISTERED == False: + registration_id = security_by_contract.register() + print("[!] The registration ID is : " + str(registration_id)) if __name__ == "__main__": ws = websocket.WebSocketApp( - "ws://localhost:3000/ws", + "ws://sifis-device4.iit.cnr.it:3000/ws", on_open=on_open, on_message=on_message, on_error=on_error, diff --git a/application_manager/security_by_contract.py b/application_manager/security_by_contract.py index f1cd1ce..17d8ef3 100644 --- a/application_manager/security_by_contract.py +++ b/application_manager/security_by_contract.py @@ -1,6 +1,45 @@ +import base64 +import datetime import json import os import subprocess +import uuid +from pathlib import Path + +import requests + +REGISTERED = False +websocket_uri = "http://sifis-device4.iit.cnr.it:3000/" + + +def get_json_register(): + ws_req = { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pep-command", + "value": { + "message": { + "purpose": "REGISTER", + "message_id": str(uuid.uuid1()), + "sub_topic_name": "application_manager_registration", + "sub_topic_uuid": "application_manager_registration_uuid", + }, + "id": "pep-application_manager", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + print("\n---------- REGISTRATION ATTEMPT ------------\n") + message_id = ws_req["command"]["value"]["message"]["message_id"] + return ws_req, message_id + + +def register(): + req, id = get_json_register() + requests.post(websocket_uri + "pub", json=req) + REGISTERED = True + return id def extract_manifest_json(output): @@ -50,6 +89,39 @@ def run_cargo_command(json_filename): print("Command output (stderr):", e.stderr) +def xml_to_base64(xml_file_path): + try: + request = Path(xml_file_path).read_text() + print("XACML request used:") + b = base64.b64encode(bytes(request, "utf-8")) # bytes + request64 = b.decode("utf-8") + + return request64 + except Exception as e: + return str(e) + + +def organize_json(request_base64): + ws_req = { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pep-command", + "value": { + "message": { + "purpose": "TRY", + "message_id": str(uuid.uuid1()), + "request": request_base64, + "policy": None, + }, + "id": "pep-application_manager", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + return ws_req + + def get_labels(image_name): # Name of the file to execute script_file = "application_manager/get-labels.sh" @@ -58,32 +130,54 @@ def get_labels(image_name): try: # Execute the shell command with the given image name as an argument - completed_process = subprocess.run( - ["bash", script_file, sifis_prefix + image_name, version], - stdout=subprocess.PIPE, - text=True, - check=True, + manifest_data = _extract_labels( + image_name, script_file, sifis_prefix, version ) - - # Get the output of the execution - output = completed_process.stdout - - # Extract the JSON under the "manifest" label - manifest_json = extract_manifest_json(output) - - # Parse the extracted JSON - manifest_data = json.loads(manifest_json) - - # Print or process the extracted JSON data - print("Extracted Manifest JSON:") - print(json.dumps(manifest_data, indent=2)) json_filename = "manifest_" + image_name + ".json" path = "sifis-xacml/data/" save_manifest_to_file(manifest_data, path + json_filename) run_cargo_command(json_filename) - return manifest_data + formatted_json, message_id = handle_xcml_request(image_name) + requests.post(websocket_uri + "pub", json=formatted_json) + return json_filename, message_id except subprocess.CalledProcessError as e: print("Error during script execution:", e) +def _extract_labels(image_name, script_file, sifis_prefix, version): + completed_process = subprocess.run( + ["bash", script_file, sifis_prefix + image_name, version], + stdout=subprocess.PIPE, + text=True, + check=True, + ) + + # Get the output of the execution + output = completed_process.stdout + + # Extract the JSON under the "manifest" label + manifest_json = extract_manifest_json(output) + + # Parse the extracted JSON + manifest_data = json.loads(manifest_json) + + # Print or process the extracted JSON data + print("Extracted Manifest JSON:") + print(json.dumps(manifest_data, indent=2)) + return manifest_data + + +def handle_xcml_request(image_name): + source_path = "sifis-xacml/manifest_" + file_path = source_path + image_name + "/request_1.xml" + base64_content = xml_to_base64(file_path) + organized_json = organize_json(base64_content) + print(json.dumps(organized_json, indent=2)) + message_id = organized_json["command"]["value"]["message"]["message_id"] + return organized_json, message_id + + +""" +register() get_labels("3pa-lamp-amd64") +""" diff --git a/application_manager/test-ucs.py b/application_manager/test-ucs.py new file mode 100644 index 0000000..9e455ed --- /dev/null +++ b/application_manager/test-ucs.py @@ -0,0 +1,532 @@ +import base64 +import datetime +import json +import uuid +from pathlib import Path + +import websocket + +websocket_uri = "ws://sifis-device4.iit.cnr.it:3000/ws" +session_id = "None" + + +def on_message(ws, message): + if "ucs-command" in message: + print("\nReceived message from the ucs:") + parsed = json.loads(message) + print(json.dumps(parsed, indent=2)) + print("\n--------------------------------\n") + + if ( + parsed["Volatile"]["value"]["command"]["value"]["message"][ + "purpose" + ] + == "TRY_RESPONSE" + ): + global session_id + session_id = parsed["Volatile"]["value"]["command"]["value"][ + "message" + ]["session_id"] + + enter_command() + + +def on_error(ws, error): + print(error) + + +def on_close(ws, close_status_code, close_msg): + print("### Connection closed ###") + + +def on_open(ws): + print("### Connection established ###") + print("[ " + websocket_uri + " ]") + enter_command() + + +def enter_command(): + print("") + print("LIST OF COMMANDS:") + print("") + print( + " PEP commands: PAP commands: PIP commands:" + ) + print( + " 1 : register 5 : add policy 9: add pip time" + ) + print( + " 2 : try access 6 : list policies 10: add pip reader" + ) + print( + " 3 : start access 7 : get policy 11: add pip websocket lamps" + ) + print(" 4 : end access 8 : delete policy") + print("") + + command = input("Enter command number> ") + print("") + send_command(command) + + +def send_command(command): + if command == "1": + register() + elif command == "2": + try_access() + elif command == "3": + start_access() + elif command == "4": + end_access() + elif command == "5": + add_policy() + elif command == "6": + list_policies() + elif command == "7": + get_policy() + elif command == "8": + delete_policy() + elif command == "9": + add_pip_time() + elif command == "10": + add_pip_reader() + elif command == "11": + add_pip_websocket() + elif command == "12": + unrecognized_command() + elif command == "q": + exit("") + else: + print("command not found") + enter_command() + + +def print_and_send(json_out): + print("Message sent:") + print(json.dumps(json_out, indent=2)) + ws.send(json.dumps(json_out)) + + +## REGISTER +def register(): + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pep-command", + "value": { + "message": { + "purpose": "REGISTER", + "message_id": str(uuid.uuid1()), + "sub_topic_name": "topic-name-the-pep-is-subscribed-to", + "sub_topic_uuid": "topic-uuid-the-pep-is-subscribed-to", + }, + "id": "pep-websocket_client", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n---------- REGISTER ------------\n") + print_and_send(ws_req) + + +## TRY ACCESS +def try_access(): + request = Path( + "sifis-xacml/manifest_3pa-lamp-amd64/request_1.xml" + ).read_text() + print("XACML request used:") + print(request) + b = base64.b64encode(bytes(request, "utf-8")) # bytes + request64 = b.decode("utf-8") + + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pep-command", + "value": { + "message": { + "purpose": "TRY", + "message_id": str(uuid.uuid1()), + "request": "Pippo", + "policy": None, + }, + "id": "pep-websocket_client", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n--------- TRY ACCESS -----------\n") + print_and_send(ws_req) + + +## START ACCESS +def start_access(): + global session_id + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pep-command", + "value": { + "message": { + "purpose": "START", + "message_id": str(uuid.uuid1()), + "session_id": session_id, + }, + "id": "pep-websocket_client", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n-------- START ACCESS ----------\n") + check_session_before_sending(ws_req) + + +## END ACCESS +def end_access(): + global session_id + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pep-command", + "value": { + "message": { + "purpose": "END", + "message_id": str(uuid.uuid1()), + "session_id": session_id, + }, + "id": "pep-websocket_client", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n--------- END ACCESS -----------\n") + check_session_before_sending(ws_req) + session_id = "None" + + +def check_session_before_sending(ws_req): + global session_id + + if session_id == "None": + print("WARNING: No active session yet") + answer = "?" + while answer != "y" and answer != "n": + answer = input("Do you want to proceed anyway? (y/n)> ") + if answer == "y": + print_and_send(ws_req) + elif answer == "n": + print("\n--------------------------------\n") + enter_command() + else: + print_and_send(ws_req) + + +## ADD POLICY +def add_policy(): + policy = Path("../../../src/main/resources/example-policy.xml").read_text() + print("XACML policy used:") + print(policy) + b = base64.b64encode(bytes(policy, "utf-8")) # bytes + policy64 = b.decode("utf-8") + + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pap-command", + "value": { + "message": { + "purpose": "ADD_POLICY", + "message_id": str(uuid.uuid1()), + "policy": policy64, + "policy_id": "example-policy", + }, + "id": "pap-web_socket", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n--------- ADD POLICY -----------\n") + print_and_send(ws_req) + + +## LIST POLICIES +def list_policies(): + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pap-command", + "value": { + "message": { + "purpose": "LIST_POLICIES", + "message_id": str(uuid.uuid1()), + }, + "id": "pap-web_socket", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n-------- LIST POLICIES ---------\n") + print_and_send(ws_req) + + +## GET POLICY +def get_policy(): + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pap-command", + "value": { + "message": { + "purpose": "GET_POLICY", + "message_id": str(uuid.uuid1()), + "policy_id": "example-policy", + }, + "id": "pap-web_socket", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n--------- GET POLICY -----------\n") + print_and_send(ws_req) + + +## DELETE POLICY +def delete_policy(): + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pap-command", + "value": { + "message": { + "purpose": "DELETE_POLICY", + "message_id": str(uuid.uuid1()), + "policy": None, + "policy_id": "example-policy", + }, + "id": "pap-web_socket", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n-------- DELETE POLICY ---------\n") + print_and_send(ws_req) + + +def add_pip_time(): + attribute_id = "urn:oasis:names:tc:xacml:1.0:environment:current-time" + category = "urn:oasis:names:tc:xacml:3.0:attribute-category:environment" + data_type = "http://www.w3.org/2001/XMLSchema#time" + refresh_rate = 10000 + + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pip-command", + "value": { + "message": { + "purpose": "ADD_PIP", + "message_id": str(uuid.uuid1()), + "pip_type": "it.cnr.iit.ucs.piptime.PIPTime", + "attribute_id": attribute_id, + "category": category, + "data_type": data_type, + "refresh_rate": refresh_rate, + }, + "id": "pip-time", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n------- ADD PIP TIME --------\n") + print_and_send(ws_req) + + +def add_pip_reader(): + attribute_id = ( + "eu:sifis-home:1.0:environment:all-windows-in-bedroom-closed" + ) + category = "urn:oasis:names:tc:xacml:3.0:attribute-category:environment" + data_type = "http://www.w3.org/2001/XMLSchema#boolean" + attribute_value = "true" + file_name = "windows-in-bedroom.txt" + refresh_rate = 1000 + + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pip-command", + "value": { + "message": { + "purpose": "ADD_PIP", + "message_id": str(uuid.uuid1()), + "pip_type": "it.cnr.iit.ucs.pipreader.PIPReader", + "attribute_id": attribute_id, + "category": category, + "data_type": data_type, + "refresh_rate": refresh_rate, + "additional_properties": { + attribute_id: file_name, + file_name: attribute_value, + }, + }, + "id": "pip-reader-windows", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n------ ADD PIP READER -------\n") + print_and_send(ws_req) + + +def add_pip_websocket(): + attribute_id = "eu:sifis-home:1.0:environment:lamps-status" + category = "urn:oasis:names:tc:xacml:3.0:attribute-category:environment" + data_type = "http://www.w3.org/2001/XMLSchema#boolean" + dhtUri = "ws://sifis-device4.iit.cnr.it:3000/ws" + topicName = "domo_light" + topicUuid = "bd59a9b8-fb3d-452d-b4ca-f3d13cf2d504" + refresh_rate = 10000 + + ws_req = { + "RequestPubMessage": { + "value": { + "timestamp": int(datetime.datetime.now().timestamp() * 1000), + "command": { + "command_type": "pip-command", + "value": { + "message": { + "purpose": "ADD_PIP", + "message_id": str(uuid.uuid1()), + "pip_type": "it.cnr.iit.ucs.pipwebsocket.PIPWebSocketLamps", + "attribute_id": attribute_id, + "category": category, + "data_type": data_type, + "refresh_rate": refresh_rate, + "additional_properties": { + "dhtUri": dhtUri, + "topicName": topicName, + "topicUuid": topicUuid, + }, + }, + "id": "pip-websocket-lamps", + "topic_name": "topic-name", + "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to", + }, + }, + } + } + } + print("\n--- ADD PIP WEBSOCKETLAMPS --\n") + print_and_send(ws_req) + + +## UNRECOGNIZED COMMAND +def unrecognized_command(): + ws_req = { + "RequestPostTopicUUID": { + "value": { + "log": { + "type": "info", + "priority": "low", + "category": "status", + "message": "ACE Group Manager", + } + }, + "topic_name": "SIFIS:Log", + "topic_uuid": "Log", + "deleted": "false", + } + } + print("\n----- UNRECOGNIZED COMMAND -----\n") + print_and_send(ws_req) + + print( + "\nMessage was sent. However, if the UCS does not recognize the command, " + "discards it without responding." + ) + print("\n--------------------------------\n") + enter_command() + + ### GET POLICY (policy_XXX) (not present) + # ws_req = { + # "RequestPubMessage": { + # "value": { + # "timestamp": int(datetime.datetime.now().timestamp()*1000), + # "command": { + # "command_type": "pap-command", + # "value": { + # "message": { + # "purpose": "GET_POLICY", + # "message_id": str(uuid.uuid1()), + # "policy_id": "policy_XXX" + # }, + # "id": "pap-0", + # "topic_name": "topic-name", + # "topic_uuid": "topic-uuid-the-ucs-is-subscribed-to" + # } + # } + # } + # } + # } + + +if __name__ == "__main__": + ws = websocket.WebSocketApp( + websocket_uri, + on_open=on_open, + on_message=on_message, + on_error=on_error, + on_close=on_close, + ) + + ws.run_forever() diff --git a/trials/list_applications.py b/trials/list_applications.py index a4b4e1f..56f1421 100644 --- a/trials/list_applications.py +++ b/trials/list_applications.py @@ -18,7 +18,7 @@ def on_open(ws): def publish(): ws = websocket.WebSocketApp( - "ws://localhost:3000/ws", + "ws://sifis-device4.iit.cnr.it:3000/ws", on_open=on_open, on_error=on_error, on_close=on_close, diff --git a/trials/pull_image.py b/trials/pull_image.py index 4decd2c..a7d09ed 100644 --- a/trials/pull_image.py +++ b/trials/pull_image.py @@ -18,7 +18,7 @@ def on_open(ws): def publish(): ws = websocket.WebSocketApp( - "ws://localhost:3000/ws", + "ws://sifis-device4.iit.cnr.it:3000/ws", on_open=on_open, on_error=on_error, on_close=on_close, @@ -35,7 +35,7 @@ def publish(): "operation": "pull_image", "requestor_id": "1", "request_id": "1", - "image_name": "ghcr.io/sifis-home/application-manager:latest", + "image_name": "3pa-lamp-amd64", # ghcr.io/sifis-home/ }, } } diff --git a/trials/remove_image.py b/trials/remove_image.py index 627affa..7ce2b29 100644 --- a/trials/remove_image.py +++ b/trials/remove_image.py @@ -18,7 +18,7 @@ def on_open(ws): def publish(): ws = websocket.WebSocketApp( - "ws://localhost:3000/ws", + "ws://sifis-device4.iit.cnr.it:3000/ws", on_open=on_open, on_error=on_error, on_close=on_close, @@ -35,7 +35,7 @@ def publish(): "operation": "remove_image", "requestor_id": "1", "request_id": "1", - "image_name": "ghcr.io/sifis-home/application-manager:latest", + "image_name": "ghcr.io/sifis-home/3pa-lamp-amd64", }, } }