_ᅱ d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZ ddlm
Z
mZ ddlmZmZ ddlmZ d Zd
Z ej e Z G d de
ZdS )
a
Goal: Invoke
/usr/sbin/cagefsctl --update-etc
/usr/sbin/cagefsctl --force-update-etc
asynchronously. As far production scale `cagefsctl --force-update-etc`
tends last for too long, e.g. -
# time cagefsctl --force-update-etc
Updating users ...
Updating user user523 ...
Updating user user804 ...
...
Updating user user269 ...
Updating user user116 ...
Updating user user121 ...
Updating user user117 ...
real 2m44.454s
user 0m26.233s
sys 0m19.972s
N)Optional)
inactivity)MessageType)MessageSinkexpect)
load_state
save_state)timefunz/usr/sbin/cagefsctlz--wait-lockc e Zd Zdej fdZd Z eej d Z
d Z ee
j dee fd Zed Zd
S )CageFSloopc K || _ t j | _ t d dd | _ | j | | _ d S )Nr last_force_update_tsr )
_loopasyncioQueue_queuer get_last_force_update_tscreate_task _consumer_consumer_task)selfr
s S/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/plugins/cagefs.pycreate_sinkzCageFS.create_sink, si
moo%/%9%9%=%="A&
&
" #j44T^^5E5EFF c K | j | j d {V | j r2t d| j t
dd| j i d S )Nz%d item(s) were not consumedr r )r cancelr qsizeloggerwarningr r )r s r shutdownzCageFS.shutdown4 s ""$$$!!!!!!!!; PNN94;;L;L;N;NOOO-t/IJ
r c K |d }t |dd }|| | j r| j | d S d S )Nconfusername)getattrmodified_sincer r
put_nowait)r messageconfigr% s r put_to_queuezCageFS.put_to_queue? si 6:t44 6#8#8&$
$
K""8,,,,, r c N K | j d{V }t j t
sF|h} | | j -# t j $ r Y nw xY wt j d 5 |D ]}|
| d{V ddd n# 1 swxY w Y n<# t j $ r Y dS t $ r t d Y w xY w#)z
:raise never:
TNcagefszSomething went wrong)r r ospathexists_CAGEFSCTL_TOOLadd
get_nowaitr
QueueEmptyr tracktask
_commitconfigCancelledError Exceptionr exception)r commitconfig_usernameuniqr% s r r zCageFS._consumerM s
.2koo.?.?(?(?(?(?(?(?% w~~o66 ..;!7!7!9!9:::;) D %**844 ; ;$( ; ;"00::::::::::;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; )
!7888
/ s` AC) C)
.A; ;B
C) B
"C) /!CC) C!!C) $C!%C) )D";#D"!D")logr% c J K |rt t d|g}nt t dg} t j |t j t j t j dd d{V }| |t j |j
}| |t j |j }t j
|| d{V | d{V \ }}| d{V }|t d dS |r t d|||| dS t d|| |t' j | _ dS dS # t j $ r t d | w xY w)
zJ
:raise asyncio.CancelledError:
:raise Exception:
z--update-etcz--force-update-etcF)stdinstdoutstderrstart_new_sessionNz+logic error: process has not terminated yetz,%r failed with rc [%s], stdout=%s, stderr=%sz%r succeeded with rc [%s]z"%r is terminated by CancelledError)r1
_WAIT_LOCKr create_subprocess_exec
subprocessDEVNULLPIPE
_passthru_logloggingDEBUGr@ WARNrA gathercommunicatewaitr errorinfotimer r8 r! ) r r% cmdprocfuture1future2outerrrcs r r7 zCageFS._commitconfign s F"JICC"J0DEC" = 7 (!! #( D ((gmT[IIG((glDKHHG.'222222222!--////////HCyy{{""""""B
zJKKKKK
=B 7bAAA#15D... $#! % NN?EEE s CE6 6,F"c K | d {V }|sd S t |d| | <)NTz%r: %r)readliner r= )rR loglevelstreamreaderlines r rH zCageFS._passthru_log sX 6%..00000000D
JJx3555 6r N)__name__
__module____qualname__r AbstractEventLoopr r" r r ConfigUpdater+ r r
r rP r strr7 staticmethodrH r r r r + s Gg&? G G G G
VK$%%- - &%- B
W,=HSM ,= ,= ,= ,=\ 6 6 \6 6 6r r )__doc__r rI r. rE rQ typingr defence360agent.apir "defence360agent.contracts.messagesr !defence360agent.contracts.pluginsr r 'defence360agent.subsys.persistent_stater r defence360agent.utilsr
r1 rC getLoggerr^ r r re r r