Skip to content

Powerhsell 7.x Linux not honoring opt-out env variables #16112

Closed

Description

@Zimeon-

Prerequisites

Steps to reproduce

I have a Rocky Linux 8 installation with powershell 7.1.4. I use powershell for monitoring and run pwsh to get a set of results. I've added opt-out environment variables as following to the systemd.

systemctl edit zabbix-server

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_telemetry?view=powershell-7.1
https://docs.microsoft.com/en-us/dotnet/core/tools/telemetry

[Service]
Environment=POWERSHELL_TELEMETRY_OPTOUT=1
Environment=DOTNET_TELEMETRY_OPTOUT=1
Environment=POWERSHELL_CLI_TELEMETRY_OPTOUT=1
Environment=DOTNET_CLI_TELEMETRY_OPTOUT=1

printenv gives me the optout parameters as expected when verifying.

printenv
LANG=en_US.UTF-8
INVOCATION_ID=69a4bad5f0c14cf4b291504873445d19
PWD=/
JOURNAL_STREAM=9:66980
CONFFILE=/etc/zabbix/zabbix_server.conf
POWERSHELL_CLI_TELEMETRY_OPTOUT=1
DOTNET_TELEMETRY_OPTOUT=1
DOTNET_CLI_TELEMETRY_OPTOUT=1
SHLVL=1
POWERSHELL_TELEMETRY_OPTOUT=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
_=/usr/bin/printenv

Related issues would be running ps1 script create temp file in everytime #11599 and PowerShell ignoring telemetry opt-out options, tries to call home regularly #10005

Expected behavior

Expecting powershell to run without telemetry, not trying to gather data that selinux denies for the user.

Actual behavior

Each run of powershell generates a folder in /tmp/ as following;

04ad7c7a-7fd1-4465-9b31-38b83f70fcc1/
.cache/powershell/StartupProfileData-NonInteractive
15661dc5-9fdc-42ed-bf20-12d902193070/
30544f3e-6e5b-47d2-be8d-e2518802caa3/
.....

Each time a powershell script is run with the service user, selinux gives loads of denied events like the following;
#tail -f /var/log/audit/audit.log | grep denied
.......
type=AVC msg=audit(1631798453.792:11014): avc:  denied  { getattr } for  pid=5141 comm=506970656C696E6520457865637574 path="/usr/sbin/lvm" dev="dm-0" ino=492056 scontext=system_u:system_r:zabbix_t:s0 tcontext=system_u:object_r:lvm_exec_t:s0 tclass=file permissive=0
type=AVC msg=audit(1631798453.792:11016): avc:  denied  { getattr } for  pid=5141 comm=506970656C696E6520457865637574 path="/usr/bin/rpm" dev="dm-0" ino=50624503 scontext=system_u:system_r:zabbix_t:s0 tcontext=system_u:object_r:rpm_exec_t:s0 tclass=file permissive=0
type=AVC msg=audit(1631798453.792:11017): avc:  denied  { getattr } for  pid=5141 comm=506970656C696E6520457865637574 path="/usr/bin/gpg" dev="dm-0" ino=50706017 scontext=system_u:system_r:zabbix_t:s0 tcontext=system_u:object_r:gpg_exec_t:s0 tclass=file permissive=0
type=AVC msg=audit(1631798453.792:11018): avc:  denied  { getattr } for  pid=5141 comm=506970656C696E6520457865637574 path="/usr/bin/dnf-3" dev="dm-0" ino=50725090 scontext=system_u:system_r:zabbix_t:s0 tcontext=system_u:object_r:rpm_exec_t:s0 tclass=file permissive=0
type=AVC msg=audit(1631798453.792:11020): avc:  denied  { getattr } for  pid=5141 comm=506970656C696E6520457865637574 path="/usr/bin/sudo" dev="dm-0" ino=50755282 scontext=system_u:system_r:zabbix_t:s0 tcontext=system_u:object_r:sudo_exec_t:s0 tclass=file permissive=0
type=AVC msg=audit(1631798453.792:11021): avc:  denied  { getattr } for  pid=5141 comm=506970656C696E6520457865637574 path="/usr/bin/hostname" dev="dm-0" ino=50800802 scontext=system_u:system_r:zabbix_t:s0 tcontext=system_u:object_r:hostname_exec_t:s0 tclass=file permissive=0
.......

Error details

No response

Environment data

> uname -a
Linux 4.18.0-305.17.1.el8_4.x86_64 #1 SMP Wed Sep 8 16:42:05 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

> dnf list installed | grep powershell
powershell.x86_64                    7.1.4-1.rhel.7                            @packages-microsoft-com-prod

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Sep 16, 2021
  2. added
    WG-Security
    on Sep 16, 2021
  3. 237dmitry commented on Sep 17, 2021

    @237dmitry

    I think this is distribution related issue. Nothing like this do reproduce in my linux environment.

  4. Zimeon- commented on Sep 17, 2021

    @Zimeon-
    Author

    I think this is distribution related issue. Nothing like this do reproduce in my linux environment.

    What OS and do you have selinux enabled?

  5. added
    WG-Engine
    and removed
    WG-Security
    on Sep 21, 2021
  6. PaulHigin commented on Sep 21, 2021

    @PaulHigin
    Contributor

    WG-Security
    This is an engine telemetry issue.

  7. added
    WG-Security
    and removed
    WG-Engine
    on Sep 29, 2021
  8. PaulHigin commented on Oct 4, 2021

    @PaulHigin
    Contributor

    WG-Security
    Keith Hill (@rkeithhill) Travis Plunk (@TravisEz13) and I looked at this and it appears to be a telemetry issue and not a security issue. Why are you adding the security working group?

  9. rkeithhill commented on Oct 4, 2021

    @rkeithhill
    Collaborator

    Misunderstanding on my part. Sorry.

  10. added
    WG-Engine
    and removed
    WG-Security
    on Oct 4, 2021
  11. daxian-dbw commented on Oct 15, 2021

    @daxian-dbw
    Member

    The reported issue is not related to telemetry.

    Each run of powershell generates a folder in /tmp/ as following;

    04ad7c7a-7fd1-4465-9b31-38b83f70fcc1/
    .cache/powershell/StartupProfileData-NonInteractive
    15661dc5-9fdc-42ed-bf20-12d902193070/
    30544f3e-6e5b-47d2-be8d-e2518802caa3/
    .....

    This is because the environment variable Home is not defined. PowerShell needs to create a few cache folders (e.g. .cache, .local) under $Home, and when the environment variable Home is not defined or has an empty value, PowerShell will create a temporary folder and consider that as the user home directory. This is why you see those folders with GUID names.

    This should be fixed. We partially fixed the issue before (see #13239), where we make sure only 1 temporary folder is used within a pwsh session, but that didn't solve the problem when many pwsh sessions start and end quickly. We should fix that too.


    Each time a powershell script is run with the service user, selinux gives loads of denied events like the following;
    #tail -f /var/log/audit/audit.log | grep denied
    .......
    type=AVC msg=audit(1631798453.792:11014): avc:  denied  { getattr } for  pid=5141 comm=506970656C696E6520457865637574 path="/usr/sbin/lvm" dev="dm-0" ino=492056 scontext=system_u:system_r:zabbix_t:s0 tcontext=system_u:object_r:lvm_exec_t:s0 tclass=file permissive=0
    type=AVC msg=audit(1631798453.792:11016): avc:  denied  { getattr } for  pid=5141 comm=506970656C696E6520457865637574 path="/usr/bin/rpm" dev="dm-0" ino=50624503 scontext=system_u:system_r:zabbix_t:s0 tcontext=system_u:object_r:rpm_exec_t:s0 tclass=file permissive=0
    

    This is likely due to the policy of SELinux.
    According to this article, the "{ getattr }" means that someone tried to stat() the file. In this case, the file's attributes were looked up first (or at least, the operation tried to look them up), couldn't get those attributes and gave up. And the "path=/usr/sbin/lvm" is the path to the object you tried to perform an operation on -- it could be a command resolution (searching executables in PATH) triggered by a command invocation.

  12. added
    Issue-Bug
    and removed
    Needs-Triage
    on Oct 15, 2021
  13. daxian-dbw commented on Oct 15, 2021

    @daxian-dbw
    Member

    Actually, this is a duplicate of #15299 😄

  14. ghost closed this as completedon Nov 3, 2021
  15. yusufozturk commented on May 4, 2022

    @yusufozturk

    Dongbo Wang (@daxian-dbw) thanks for the resolution.

    I feel like telemetry shouldn't be enabled by default. For example related to this issue, our customer added values but didn't work out in PowerShell 7.2.2. It generates thousands of telemetry files and it fills up the disk and generates IO on the server.

    image

    image

    I kindly ask opinions of James Truher (@JamesWTruher) and Aditya Patwardhan (@adityapatwardhan) about the telemetry behaviour. I don't think majority of the people will ever use these files and it already caused some issues for now, so that makes me think "if someone needs telemetry in the future, they should enable the telemetry".

  16. daxian-dbw commented on May 4, 2022

    @daxian-dbw
    Member

    Yusuf Ozturk (@yusufozturk) As explained in #16112 (comment), the folders created in /tmp are not because of telemetry. When POWERSHELL_TELEMETRY_OPTOUT=1 is set, no telemetry will be sent out.

    The tons-of-temp-folder issue was resolved by #16263

  17. inoperable commented on Sep 28, 2022

    @inoperable

    pwsh.exe is calling, for example, a23-79-157-152.deploy.static.akamaitechnologies.com despite all of flags. Its just ridiculous how ms is handling it. I asked already before about that - and was answered some other component of .net is doing that... so which one? 5 years ago I asked about the installer flag being set by default to opt in - they fucking still didn't managed to build a installer in which this is opted out by default :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-DuplicateWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions