From 93fcfbe78b512099e83a265a6bf909d42b7c131b Mon Sep 17 00:00:00 2001 From: Grant Orndorff Date: Wed, 16 Oct 2024 12:15:20 -0400 Subject: [PATCH] apt-hook: only run apt upgrade hook when run as root LP: #2084677 --- apt-hook/20apt-esm-hook.conf | 2 +- features/apt_messages.feature | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apt-hook/20apt-esm-hook.conf b/apt-hook/20apt-esm-hook.conf index 163853b115..8e6ddf46c4 100644 --- a/apt-hook/20apt-esm-hook.conf +++ b/apt-hook/20apt-esm-hook.conf @@ -3,5 +3,5 @@ APT::Update::Pre-Invoke { }; binary::apt::AptCli::Hooks::Upgrade { - "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook 2>> /var/log/ubuntu-advantage-apt-hook.log || true"; + "[ ! -f /usr/lib/ubuntu-advantage/apt-esm-json-hook ] || [ $(id -u) -ne 0 ] || /usr/lib/ubuntu-advantage/apt-esm-json-hook 2>> /var/log/ubuntu-advantage-apt-hook.log || true"; }; diff --git a/features/apt_messages.feature b/features/apt_messages.feature index a5aaa88274..7b10d522a0 100644 --- a/features/apt_messages.feature +++ b/features/apt_messages.feature @@ -1158,6 +1158,22 @@ Feature: APT Messages # | oracular | lxd-container | jammy | libcurl4t64 | 8.8.0-3ubuntu3 | | noble | lxd-container | jammy | libcurl4t64 | 8.5.0-2ubuntu10 | + Scenario Outline: APT Hook does not error when run as non-root + Given a `` `` machine with ubuntu-advantage-tools installed + When I run `apt upgrade --simulate` as non-root + Then I will see the following on stderr + """ + WARNING: apt does not have a stable CLI interface. Use with caution in scripts. + """ + + Examples: ubuntu release + | release | machine_type | + | xenial | lxd-container | + | bionic | lxd-container | + | focal | lxd-container | + | jammy | lxd-container | + | noble | lxd-container | + @uses.config.contract_token Scenario Outline: APT Hook do not advertises esm-apps on upgrade for interim releases Given a `` `` machine with ubuntu-advantage-tools installed