§ ½@¾jz ãóÆ—dZddlZddlZddlZddlZddlmZmZmZddl m Z ddl m Z ddl mZddlmZdZd Zd Zd Zeje¦«Zd efd „Zded efd„Zded eefd„Ze fded eefd„Ze fdeeded efd„Zefded eefd„Zdeded dfd„Z deded eeeffd„Z!dZ"e efdeded efd„Z#e efdeded efd„Z$deed e%fd„Z&dS)aÑKeep kernel.lve_ipc_isolation in step with the lve-ipc-isolation feature flag. The decision point of this feature is inside kmod-lve: the module reads the sysctl when it sets up a per-user LVE, so it cannot ask clflags.is_enabled() itself. This module asks on its behalf and writes the answer where the module reads it: - persisted in /etc/sysctl.d/90-cloudlinux.conf, which lve.service re-applies right after it loads the module - so the value is in place before the first LVE of every boot is created; - live in /proc/sys/kernel/lve_ipc_isolation, while the module is loaded. The feature ships off, and "off" means the kernel default: the line is dropped from the config rather than pinned to 0, so a server that never opted in carries no setting for a key its kernel may not have. Only that one line and that one /proc key are ever written. clcommon's SysCtlConf is deliberately not used here: its set() and remove() run `sysctl --system`, which re-applies every sysctl file on the server, and this helper runs whenever the flag changes - at runtime, not only at install - so it must not undo settings an administrator changed by hand. Run by lve-ipc-isolation.service - at boot after lve.service, whenever lve-ipc-isolation.path sees one of the feature's own flag files change, and every five minutes from lve-ipc-isolation.timer as a safety net for a change the path unit missed - and by the lve-utils install scriptlets. Idempotent: nothing that already matches is touched. éN)ÚListÚOptionalÚTuple)ÚSYSCTL_CL_CONF_FILE)Úget_file_lines)Ú is_enabled)Úinit_lve_utils_sentry_clientúlve-ipc-isolationzkernel.lve_ipc_isolationz"/proc/sys/kernel/lve_ipc_isolationFÚreturncó8—ttt¬¦«S)zRWhether the flag switches the feature on for this server; asked afresh every time.)Údefault)rÚFEATUREÚSHIPS_ON©óúpy/lve_utils/ipc_isolation.pyÚwantedr;s€å •g¥xÐ 0Ñ 0Ô 0Ð0rÚlinecóÌ—| ¦«}| d¦«sd|vrdS| d¦«\}}}| ¦«tkS)zUWhether a sysctl config line sets SYSCTL_NAME (comments and other keys are not ours).ú#ú=F)ÚstripÚ startswithÚ partitionÚ SYSCTL_NAME)rÚstrippedÚkeyÚ_s rÚ _is_our_liner@s`€à�zŠz‰|Œ|€HØ×Ò˜3ÑÔð 3¨hÐ#6Ð#6؈uØ×"Ò" 3Ñ'Ô'�I€CˆˆAØ �9Š9‰;Œ;�+Ò %Ð%rÚ config_filecó|—tj |¦«sgStt |¦«¦«S)N)ÚosÚpathÚisfileÚlistr)r s rÚ _read_linesr&Is3€Ý Œ7�>Š>˜+Ñ &Ô &ðØˆ Ý •˜{Ñ+Ô+Ñ ,Ô ,Ð,rcóÊ—d}t|¦«D]P}t|¦«r?| ¦« d¦«d ¦«}ŒQ|S)z_The value the CloudLinux sysctl config carries for the key, or None when it has no line for it.Nré)r&rrr)r Úvaluers rÚpersisted_valuer*Os`€à€EݘKÑ(Ô(ð;ð;ˆÝ ˜Ñ Ô ð ;à—J’J‘L”L×*Ò*¨3Ñ/Ô/°Ô2×8Ò8Ñ:Ô:ˆEøØ €Lrr)có–—t|¦«}d„|D¦«}|r+|d d¦«s|dxxdz cc<|� | t›d|›d�¦«||krdStj |¦«pd}tj |¦«rt j|¦«j dznd }tj d |¬ ¦«\}} t j |d d ¬¦«5}|  |¦«| ¦«t j| ¦«¦«ddd¦«n #1swxYwYt j||¦«t j||¦«n5#t&$r( t j|¦«n#t*$rYnwxYw‚wxYwdS)a Set (value) or drop (None) the key's line in config_file, leaving every other line as it is. Written atomically (temp file in the same directory, then rename), so lve.service never sees a half-written file at boot. Returns whether the file changed. có0—g|]}t|¦«°|‘ŒSr)r)Ú.0rs rú zpersist..as%€Ð =Ð =Ð =�T­,°tÑ*<Ô*<Ð =ˆDÐ =Ð =Ð =réÿÿÿÿú Nz = Fú.iÿi¤z.90-cloudlinux.)ÚprefixÚdirÚwúutf-8©ÚencodingT)r&ÚendswithÚappendrr"r#Údirnamer$ÚstatÚst_modeÚtempfileÚmkstempÚfdopenÚ writelinesÚflushÚfsyncÚfilenoÚchmodÚreplaceÚ BaseExceptionÚunlinkÚOSError) r)r ÚlinesÚkeptÚ directoryÚmodeÚfdÚtmp_pathÚtmps rÚpersistrPYs€õ ˜ Ñ $Ô $€EØ =Ð =˜UÐ =Ñ =Ô =€DØ ð�D˜”H×%Ò% dÑ+Ô+ðØ ˆRˆˆŒ�Dшˆ‰Ø ÐØ � Š •{Ð0Ð0 uÐ0Ð0Ð0Ñ1Ô1Ð1Ø ˆu‚}€}؈uå”—’  Ñ,Ô,Ð3°€IÝ35´7·>²>À+Ñ3NÔ3NÐ Y�2Œ7�;Ñ Ô Ô '¨%Ñ /Ð /ÐTY€DÝÔ#Ð+<À)ÐLÑLÔL�L€Bˆð Ý ŒY�r˜3¨Ð 1Ñ 1Ô 1ð #°SØ �NŠN˜4Ñ Ô Ð Ø �IŠI‰KŒKˆKÝ ŒH�S—Z’Z‘\”\Ñ "Ô "Ð "ð #ð #ð #ñ #ô #ð #ð #ð #ð #ð #ð #øøøð #ð #ð #ð #õ Œ�˜4Ñ Ô Ð Ý Œ �8˜[Ñ)Ô)Ð)Ð)øÝ ðððð Ý ŒI�hÑ Ô Ð Ð øÝð ð ð Ø ˆDð øøøà ð øøøð ˆ4sUÃ+FÄAEÅ FÅE"Å"FÅ%E"Å&-FÆ GÆF4Æ3GÆ4 GÆ>GÇGÇGÚ proc_pathcóÈ— t|d¬¦«5}| ¦« ¦«cddd¦«S#1swxYwYdS#t$rYdSwxYw)zLThe value the loaded module runs with, or None while kmod-lve is not loaded.r5r6N)ÚopenÚreadrÚFileNotFoundError)rQÚ proc_files rÚ live_valuerW|s¶€ðÝ �) gÐ .Ñ .Ô .ð ,°)Ø—>’>Ñ#Ô#×)Ò)Ñ+Ô+ð ,ð ,ð ,ð ,ñ ,ô ,ð ,ð ,ð ,ð ,ð ,ð ,øøøð ,ð ,ð ,ð ,ð ,ð ,øå ððð؈tˆtðøøøs3‚A“&A¹ AÁA Á AÁ A ÁAÁ A!Á A!có†—t|dd¬¦«5}| |¦«ddd¦«dS#1swxYwYdS)Nr4r5r6)rSÚwrite)r)rQrVs rÚ _set_liverZ…sŠ€Ý ˆi˜ wÐ /Ñ /Ô /ð°9Ø�Š˜ÑÔÐðððñôðððððððøøøððððððs “6¶:½:cóô—t¦«}|rdnd}d}t|rdnd|¦«rS|r(t dtt |¦«n't dtt |¦«d}t |¦«}|€'t dtt ¦«n@||kr:t||¦«t d tt ||¦«d}||fS) zžOne pass: read the flag, bring both copies of the sysctl in line with it. Returns (the flag state that was applied, whether anything had to change). Ú1Ú0FNz %s is on: %s = 1 persisted in %sz%s is off: %s dropped from %sTz6%s: kmod-lve is not loaded, %s takes effect once it isz=%s: %s set to %s (was %s); LVEs created from now on follow it)rrPÚloggerÚinforrrWrZ)r rQÚonr)ÚchangedÚlives rÚ _apply_oncercŠsú€õ ‰Œ€BØÐ ˆCˆC˜3€EØ€Gå�bÐ"ˆsˆs˜d KÑ0Ô0ðØ ð \Ý �KŠKÐ:½GÅ[ÐR]Ñ ^Ô ^Ð ^Ð ^å �KŠKÐ7½Å+È{Ñ [Ô [Ð [؈å �iÑ Ô €DØ €|Ý� Š ÐLÍgÕWbÑcÔcÐcÐcØ �ŠˆÝ�%˜Ñ#Ô#Ð#Ý� Š Ø KÍWÕVaÐchÐjnñ ô ð ðˆà ˆwˆ;ÐrécóŽ—d}tt¦«D]-}t||¦«\}}|p|}t¦«|krnŒ.|S)aGBring the persisted and the live sysctl in line with the flag. The flag can change while a pass runs - the path unit does not start the service again for an event that arrives during a run - so the pass is repeated until the flag reads the same before and after it. Returns whether anything had to change. F)ÚrangeÚ SETTLE_PASSESrcr)r rQrarÚappliedÚ pass_changeds rÚapplyrj«s\€ð€GÝ •=Ñ !Ô !ððˆÝ +¨K¸Ñ CÔ Cш�ØÐ)˜\ˆÝ ‰8Œ8�wÒ Ð Ø ˆEð à €NrcóÚ—t|¦«}t|¦«}d t›dt ¦«rdnd›�t ›d|�|nd›�t ›d|�|nd ›�f¦«S) zIA short report of the flag and of both copies of the sysctl, for support.r0z: r`Úoffz persisted: Nz(not set, kernel default 0)z live: z(kmod-lve not loaded))r*rWÚjoinrrr)r rQÚ persistedrbs rÚstatusro¼s‹€å  Ñ,Ô,€IÝ �iÑ Ô €DØ �9Š9åÐ 7Ð 7¥&¡(¤(Ð5˜$˜$°Ð 7Ð 7ÝÐ oÐ o°YÐ5J¨ ¨ ÐPmÐ oÐ oÝÐ ZÐ Z¨4Ð+; 4 4ÐAXÐ ZÐ Zð ñ ô ðrÚargvcóò—tjddt›dt›d�¬¦«}| ddd¬ ¦«| |¦«}t jt jd ¬ ¦«|j rtt¦«¦«d Std¦« t¦«n?#t$r2}t d tt|¦«Yd}~dSd}~wwxYwd S)Nr z Apply the z feature flag to r1)ÚprogÚ descriptionz--statusÚ store_truez8report the flag and the sysctl without changing anything)ÚactionÚhelpz %(message)s)ÚlevelÚformatrz%s: could not apply %s: %sé)ÚargparseÚArgumentParserrrÚ add_argumentÚ parse_argsÚloggingÚ basicConfigÚINFOroÚprintr rjrHr^Úerror)rpÚparserÚargsÚerrs rÚmainr†És€Ý Ô $Ø ØI¥ÐIÐI½;ÐIÐIÐIðñô€Fð ×ÒØØØ Gðñôðð × Ò ˜TÑ "Ô "€Då Ô�gœl°=ÐAÑAÔAÐAØ „{ðÝ �f‰hŒh‰ŒˆØˆqå Ð!4Ñ5Ô5Ð5ðÝ ‰ŒˆˆøÝ ðððõ � Š Ð1µ7½KÈÑMÔMÐM؈qˆqˆqˆqˆqøøøøð øøøð ˆ1sÂ)B8Â8 C4Ã'C/Ã/C4)'Ú__doc__rzr~r"r=ÚtypingrrrÚclcommon.sysctlrÚclcommon.utilsrÚclflagsrÚlve_utils.sentryr rrÚ PROC_PATHrÚ getLoggerÚ__name__r^ÚboolrÚstrrr&r*rPrWrZrcrgrjroÚintr†rrrúr“s½ðððð:€€€Ø€€€Ø € € € Ø€€€Ø(Ð(Ð(Ð(Ð(Ð(Ð(Ð(Ð(Ð(à/Ð/Ð/Ð/Ð/Ð/Ø)Ð)Ð)Ð)Ð)Ð)ØÐÐÐÐÐà9Ð9Ð9Ð9Ð9Ð9à €Ø(€ Ø 0€ ð €à ˆÔ ˜8Ñ $Ô $€ð1�ð1ð1ð1ð1ð &�sð&˜tð&ð&ð&ð&ð-˜Sð- T¨#¤Yð-ð-ð-ð-ð (;ðð ð¸xȼ}ððððð6Ið ð �8˜C”=ð ¨sð ÈTð ð ð ð ðF!*ðð˜#ð¨h°s¬mððððð�Sð Sð¨Tððððð ˜Sð¨Sð°U¸4À¸:Ô5Fððððð<€ ð1À9ðð�sð¸SðÐQUððððð"2ÀIð ð ˜ð ¸cð ÐRUð ð ð ð ð ˆt�CŒyð ˜Sð ð ð ð ð ð r