Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: tests fixes for sru validation #15093

Merged

Conversation

sergiocazzolato
Copy link
Collaborator

These fixes are needed to fix sru validation where the snap snap is not used and we use the snapd deb from proposed instead.

The change include fixes for tests:

  • tests/main/apparmor-batch-reload/task.yaml
  • tests/main/apparmor-prompting-flag-restart/task.yaml
  • tests/main/apparmor-prompting-integration-tests/task.yaml
  • tests/main/apparmor-prompting-snapd-startup/task.yaml
  • tests/main/interfaces-requests-activates-handlers/task.yaml
  • tests/main/interfaces-snap-interfaces-requests-control/task.yaml
  • tests/main/remote-home/task.yaml
  • tests/main/store-state/task.yaml

@sergiocazzolato sergiocazzolato force-pushed the tests-fixes-sru-validation branch from 7f4b7c3 to d9c9940 Compare February 17, 2025 21:37
Copy link

github-actions bot commented Feb 17, 2025

Tue Feb 18 20:32:44 UTC 2025
The following results are from: https://github.com/canonical/snapd/actions/runs/13398332102

Failures:

Preparing:

  • openstack:opensuse-tumbleweed-64
  • openstack:opensuse-tumbleweed-64

Restoring:

  • openstack:opensuse-tumbleweed-64
  • openstack:opensuse-tumbleweed-64

@sergiocazzolato sergiocazzolato changed the title updates needed to be applied on master for sru tests: tests fixes for sru validation Feb 17, 2025
@@ -14,12 +14,18 @@ systems:
- ubuntu-core-*

prepare: |
if not tests.info is-reexec-in-use && os.query is-ubuntu 22.04; then
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this highlights the problem we discussed during one of the standups, the kernel supports prompting, but the userspace does not, unless reexec is enabled in which case we're using the apparmor userspace vendored in snapd snap. This should likely be considered a bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a bug that can be solved on the snapd side, unless snapd were somehow able to probe whether the system apparmor parser supports prompting.

One solution JJ suggested would be to simply backport a newer apparmor parser to 22.04, which would keep AA support for prompting in alignment between the kernel and parser.

The problem is that in general we can't/don't want to assume that kind of alignment. We can guarantee it on Ubuntu versions, but not other distributions. At the moment, AA kernel patches to support prompting are only in ubuntu kernels, so this would be a successful temporary fix, but I think the only way to know for sure if we can use prompting would be to check the system AA parser for support.

Even then, support could theoretically change after a .deb/.rpm update of the AA parser or kernel (likely due to a bug, but still), so I'm not sure we can have any real guarantees.

# We are testing on Ubuntu where we know that reexec is active and we
# use an internal apparmor userspace stack.
tests.cleanup defer test ! -e /var/lib/snapd/apparmor/snap-confine.internal/nfs-support
if tests.info is-reexec-in-use; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Member

@olivercalder olivercalder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with 22.04 without re-exec is that the system parser doesn't support prompting, not the kernel; the kernel does support it.

There are existing checks for expected prompting support in the execute sections of the prompting-related tests, and these validate that if we don't expect support, prompting is indeed not supported, so I'd rather integrate this new check into those existing cases, so it's more consistent and we know if/when that support changes (e.g. because of AppArmor parser being backported).

@@ -14,12 +14,18 @@ systems:
- ubuntu-core-*

prepare: |
if not tests.info is-reexec-in-use && os.query is-ubuntu 22.04; then
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a bug that can be solved on the snapd side, unless snapd were somehow able to probe whether the system apparmor parser supports prompting.

One solution JJ suggested would be to simply backport a newer apparmor parser to 22.04, which would keep AA support for prompting in alignment between the kernel and parser.

The problem is that in general we can't/don't want to assume that kind of alignment. We can guarantee it on Ubuntu versions, but not other distributions. At the moment, AA kernel patches to support prompting are only in ubuntu kernels, so this would be a successful temporary fix, but I think the only way to know for sure if we can use prompting would be to check the system AA parser for support.

Even then, support could theoretically change after a .deb/.rpm update of the AA parser or kernel (likely due to a bug, but still), so I'm not sure we can have any real guarantees.

Comment on lines 45 to 48
if not tests.info is-reexec-in-use && os.query is-ubuntu 22.04; then
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
fi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather integrate this into the check in execute: so we can verify that it is unsupported when we expect it to be, and supported otherwise.

TEST_UID="$(id -u test)"
echo "outstanding prompts:"
snap debug api "/v2/interfaces/requests/prompts?user-id=$TEST_UID" || true
echo "rules:"
snap debug api "/v2/interfaces/requests/rules?user-id=$TEST_UID" || true

execute: |
tests.exec is-skipped && exit 0

echo "Precondition check that snapd is active"
systemctl is-active snapd.service snapd.socket

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below,

if ! os.query is-ubuntu || os.query is-core || [ ! -f /sys/kernel/security/apparmor/features/policy/permstable32 ] || NOMATCH 'prompt' < /sys/kernel/security/apparmor/features/policy/permstable32 ; then

becomes

if ! os.query is-ubuntu || os.query is-core || [ ! -f /sys/kernel/security/apparmor/features/policy/permstable32 ] || NOMATCH 'prompt' < /sys/kernel/security/apparmor/features/policy/permstable32 || tests.info is-reexec-in-use && os.query is-ubuntu 22.04 ; then

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, all the checks to validate that apparmor prompting works in the supported systems and it doesn't in the unsupported will me moved to a new test with just one variant to avoid rechecks.
I'll push a following pr once this is merged.

@@ -14,12 +14,18 @@ systems:
- ubuntu-core-*

prepare: |
if not tests.info is-reexec-in-use && os.query is-ubuntu 22.04; then
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
tests.exec skip-test "Ubuntu 22.04 AppArmor parser doesn't support prompting" && exit 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like the check to occur on line 114 though so we can verify that prompting is not supported as expected.

@@ -11,12 +11,18 @@ systems:
- ubuntu-2*

prepare: |
if not tests.info is-reexec-in-use && os.query is-ubuntu 22.04; then
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
tests.exec skip-test "Ubuntu 22.04 AppArmor parser doesn't support prompting" && exit 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'd also prefer to add this to existing check on line 113 rather than skip the test for this edge case.

@@ -8,16 +8,24 @@ systems:
- ubuntu-2*

prepare: |
if not tests.info is-reexec-in-use && os.query is-ubuntu 22.04; then
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
tests.exec skip-test "Ubuntu 22.04 AppArmor parser doesn't support prompting" && exit 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here though, I'd rather this check be part of the existing one on line 36.

@@ -18,10 +18,16 @@ environment:
PYTHONIOENCODING: utf-8

prepare: |
if not tests.info is-reexec-in-use && os.query is-ubuntu 22.04; then
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
tests.exec skip-test "Ubuntu 22.04 AppArmor parser doesn't support prompting" && exit 0

But I would rather do this on line 67 instead

Copy link
Member

@olivercalder olivercalder Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only other remaining blocker: #15093 (comment)

Copy link
Member

@olivercalder olivercalder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, pending the final comment fix s/kernel/AppArmor parser/

And good idea to consolidate all the prompting support checks into a dedicated spread test, so all of the prompting behavior checks can just run on the systems for which support is expected and not deal with duplicate checks in each one.

@@ -74,7 +85,7 @@ execute: |

exit 0
fi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -18,10 +18,16 @@ environment:
PYTHONIOENCODING: utf-8

prepare: |
if not tests.info is-reexec-in-use && os.query is-ubuntu 22.04; then
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
Copy link
Member

@olivercalder olivercalder Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only other remaining blocker: #15093 (comment)

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.11%. Comparing base (a272aac) to head (39a3d52).
Report is 24 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15093      +/-   ##
==========================================
+ Coverage   78.07%   78.11%   +0.04%     
==========================================
  Files        1182     1174       -8     
  Lines      157743   157682      -61     
==========================================
+ Hits       123154   123179      +25     
+ Misses      26943    26859      -84     
+ Partials     7646     7644       -2     
Flag Coverage Δ
unittests 78.11% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@ernestl ernestl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, approving conditionally to blocker comment about kernel not supporting being corrected.

@@ -18,10 +18,16 @@ environment:
PYTHONIOENCODING: utf-8

prepare: |
if not tests.info is-reexec-in-use && os.query is-ubuntu 22.04; then
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tests.exec skip-test "Ubuntu 22.04 kernel doesn't support prompting" && exit 0
tests.exec skip-test "Ubuntu 22.04 AppArmor parser doesn't support prompting" && exit 0

@@ -74,7 +85,7 @@ execute: |

exit 0
fi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@sergiocazzolato sergiocazzolato merged commit d5ee313 into canonical:master Feb 19, 2025
76 of 77 checks passed
@sergiocazzolato sergiocazzolato deleted the tests-fixes-sru-validation branch February 19, 2025 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants