<?xml version="1.0" encoding="UTF-8" ?>

<bugzilla version="5.2"
          urlbase="https://bugzilla.altlinux.org/"
          
          maintainer="jenya@basealt.ru"
>

    <bug>
          <bug_id>53483</bug_id>
          
          <creation_ts>2025-03-17 09:00:25 +0300</creation_ts>
          <short_desc>При авторизации в tty обычным пользователем переменная окружения USER=root</short_desc>
          <delta_ts>2025-04-01 18:56:17 +0300</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Branch p11</product>
          <component>systemd</component>
          <version>unspecified</version>
          <rep_platform>all</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P5</priority>
          <bug_severity>critical</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>46625</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Антон Мидюков">antohami</reporter>
          <assigned_to name="Alexey Shabalin">shaba</assigned_to>
          <cc>aris</cc>
    
    <cc>arseny</cc>
    
    <cc>lav</cc>
    
    <cc>rider</cc>
    
    <cc>shaba</cc>
    
    <cc>zerg</cc>
          
          <qa_contact name="qa-p11@altlinux.org">qa-p11</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>261135</commentid>
    <comment_count>0</comment_count>
    <who name="Антон Мидюков">antohami</who>
    <bug_when>2025-03-17 09:00:25 +0300</bug_when>
    <thetext>При авторизации в tty обычным пользователем переменная окружения USER=root.
systemd environment показывает правильно при этом:

$ systemctl --user --show-environment |grep USER=
USER=antohami

А env показывает:

$ env |grep USER
USER=root

В /etc/profile есть такой код:

[ -n &quot;$USER&quot; ] || USER=&quot;/usr/bin/id -un&quot;

Если закомментировать строку, то ничего меняется.
Если убрать условие, т.е.:

USER=&quot;/usr/bin/id -un&quot;

то USER=antohami

Где-то переменная устанавливается, но непонятно где. Я ничего не нашёл.
Проблема началась 24 мая 2024 года после обновления systemd 254.10-alt2 -&gt; 255.6-alt1. Поэтому пока на systemd.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261162</commentid>
    <comment_count>1</comment_count>
    <who name="Антон Мидюков">antohami</who>
    <bug_when>2025-03-17 11:43:30 +0300</bug_when>
    <thetext>Я внёс такое исправление в /usr/lib/systemd/system/getty@.service:

 [Service]
 # the VT is cleared by TTYVTDisallocate
 # The &apos;-o&apos; option value tells agetty to replace &apos;login&apos; arguments with an
 # option to preserve environment (-p), followed by &apos;--&apos; for safety, and then
 # the entered username.
-ExecStart=-/sbin/agetty -o &apos;-p -- \\u&apos; --noclear - $TERM
+ExecStart=-/sbin/agetty -o &apos;-- \\u&apos; --noclear - $TERM

Т.е. убрал -p, и помогло.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261173</commentid>
    <comment_count>2</comment_count>
    <who name="Sergey V Turchin">zerg</who>
    <bug_when>2025-03-17 13:32:24 +0300</bug_when>
    <thetext>(Ответ для Антон Мидюков на комментарий #0)

[...]
&gt; В /etc/profile есть такой код:
&gt; [ -n &quot;$USER&quot; ] || USER=&quot;/usr/bin/id -un&quot;
&gt; Если закомментировать строку, то ничего меняется.
Значит, там уже заполнена неправильно.

[...]</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261174</commentid>
    <comment_count>3</comment_count>
    <who name="Антон Мидюков">antohami</who>
    <bug_when>2025-03-17 13:34:21 +0300</bug_when>
    <thetext>Можно также добавить в getty@.service:

UnsetEnvironment=USER</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261175</commentid>
    <comment_count>4</comment_count>
    <who name="Arseny Maslennikov">arseny</who>
    <bug_when>2025-03-17 13:39:16 +0300</bug_when>
    <thetext>(In reply to Антон Мидюков from comment #3)
&gt; Можно также добавить в getty@.service:
&gt; 
&gt; UnsetEnvironment=USER

Но это костыль.

Казалось бы, программа login(1), порождённая из-под getty, не должна переносить в сеанс значение USER из своего env block, потому что там PAM-стек задействуется.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261179</commentid>
    <comment_count>5</comment_count>
    <who name="Антон Мидюков">antohami</who>
    <bug_when>2025-03-17 14:07:25 +0300</bug_when>
    <thetext>(In reply to Антон Мидюков from comment #1)
&gt; Я внёс такое исправление в /usr/lib/systemd/system/getty@.service:
&gt; 
&gt;  [Service]
&gt;  # the VT is cleared by TTYVTDisallocate
&gt;  # The &apos;-o&apos; option value tells agetty to replace &apos;login&apos; arguments with an
&gt;  # option to preserve environment (-p), followed by &apos;--&apos; for safety, and then
&gt;  # the entered username.
&gt; -ExecStart=-/sbin/agetty -o &apos;-p -- \\u&apos; --noclear - $TERM
&gt; +ExecStart=-/sbin/agetty -o &apos;-- \\u&apos; --noclear - $TERM
&gt; 
&gt; Т.е. убрал -p, и помогло.

Информация от arseny@, что в Debian убрали:

commit 3d2157e7072b3e9691c469b992848fb249f8b605
Author: Ronan Pigott &lt;ronan@rjp.ie&gt;
Date:   Wed Aug 14 11:42:03 2024 -0700

    units: drop &quot;-p&quot; flag from agetty&apos;s login options

Так что предлагаю тоже это сделать.
Исправить в getty@.service и serial-getty@.service

Проблема актуальна для p11. Нужно исправить до выпуска дистрибутивов на p11.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261180</commentid>
    <comment_count>6</comment_count>
    <who name="Антон Мидюков">antohami</who>
    <bug_when>2025-03-17 14:46:57 +0300</bug_when>
    <thetext>Оказывается, уже есть апстримный патч (спасибо Арсению за ссылку), удаляющий опцию -p у agetty:
https://github.com/systemd/systemd/commit/3d2157e7072b3e9691c469b992848fb249f8b605</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261285</commentid>
    <comment_count>7</comment_count>
    <who name="Sergey V Turchin">zerg</who>
    <bug_when>2025-03-18 13:23:15 +0300</bug_when>
    <thetext>Ещё бы мантейнер пакета нашёлся...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261394</commentid>
    <comment_count>8</comment_count>
    <who name="Sergey V Turchin">zerg</who>
    <bug_when>2025-03-19 12:11:52 +0300</bug_when>
    <thetext>Похоже, что при багах все подобные пакеты баги репортеру флаг в руки. ;-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261401</commentid>
    <comment_count>9</comment_count>
    <who name="Arseny Maslennikov">arseny</who>
    <bug_when>2025-03-19 13:35:39 +0300</bug_when>
    <thetext>Пока что вокруг текущей баги остаётся один вопрос: стоит ли лишь сбекпортить патч, где убирают -p, или лучше просто обновиться до systemd-stable 257.x. Ответ на него, думаю, зависит от планируемого жизненного цикла systemd не только в сизифе, но и в p11. Скорее всего, у shaba@ были какие-то соображения на этот счёт.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261440</commentid>
    <comment_count>10</comment_count>
    <who name="Alexey Shabalin">shaba</who>
    <bug_when>2025-03-19 18:44:47 +0300</bug_when>
    <thetext>Я пока бэкпортирую. Обновлением на новую ветку займусь позже.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261534</commentid>
    <comment_count>11</comment_count>
    <who name="Repository Robot">repository-robot</who>
    <bug_when>2025-03-20 19:24:38 +0300</bug_when>
    <thetext>systemd-1:255.18-alt1 -&gt; sisyphus:

 Wed Mar 19 2025 Alexey Shabalin &lt;shaba@altlinux&gt; 1:255.18-alt1
 - 255.18
 - drop &quot;-p&quot; flag from agetty&apos;s login options (ALT#53483)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261543</commentid>
    <comment_count>12</comment_count>
    <who name="Антон Мидюков">antohami</who>
    <bug_when>2025-03-21 05:37:15 +0300</bug_when>
    <thetext>(In reply to Repository Robot from comment #11)
&gt; systemd-1:255.18-alt1 -&gt; sisyphus:
&gt; 
&gt;  Wed Mar 19 2025 Alexey Shabalin &lt;shaba@altlinux&gt; 1:255.18-alt1
&gt;  - 255.18
&gt;  - drop &quot;-p&quot; flag from agetty&apos;s login options (ALT#53483)

Спасибо. Теперь ждём исправление в p11.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261554</commentid>
    <comment_count>13</comment_count>
    <who name="Sergey V Turchin">zerg</who>
    <bug_when>2025-03-21 09:41:42 +0300</bug_when>
    <thetext>&gt; Спасибо. Теперь ждём исправление в p11.
Я отправил https://packages.altlinux.org/ru/tasks/378740/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261555</commentid>
    <comment_count>14</comment_count>
    <who name="Sergey V Turchin">zerg</who>
    <bug_when>2025-03-21 09:42:33 +0300</bug_when>
    <thetext>(Ответ для Sergey V Turchin на комментарий #13)
&gt; Я отправил https://packages.altlinux.org/ru/tasks/378740/
Ой, это другое. :-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>261698</commentid>
    <comment_count>15</comment_count>
    <who name="Антон Мидюков">antohami</who>
    <bug_when>2025-03-24 14:42:13 +0300</bug_when>
    <thetext>Ждём исправление в p11. Очень не хочется, чтобы дистрибутивы были из коробки с этим багом.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>262253</commentid>
    <comment_count>16</comment_count>
    <who name="Repository Robot">repository-robot</who>
    <bug_when>2025-04-01 18:56:17 +0300</bug_when>
    <thetext>systemd-1:255.18-alt1 -&gt; p11:

 Wed Mar 19 2025 Alexey Shabalin &lt;shaba@altlinux&gt; 1:255.18-alt1
 - 255.18
 - drop &quot;-p&quot; flag from agetty&apos;s login options (ALT#53483)
 Sun Jan 05 2025 Alexey Shabalin &lt;shaba@altlinux&gt; 1:255.16-alt1
 - 255.16
 Thu Oct 10 2024 Alexey Shabalin &lt;shaba@altlinux&gt; 1:255.13-alt1
 - 255.13
 Tue Sep 24 2024 Alexey Shabalin &lt;shaba@altlinux&gt; 1:255.12-alt1
 - 255.12</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>