Skip to content

Conversation

Bravo555
Copy link
Member

@Bravo555 Bravo555 commented Jul 3, 2024

Proposed changes

Fixed two closely related problems in tedge-write:

  • When destination file existed, its owner/group was reset because when creating a temporary file for atomic write we forgot to set the same permissions as the destination file. Now we copy destination file permissions to the temporary, ensuring that after the rename permissions stay the same.
  • Changed some permissions used in the tests from 644 to 666, so the tests don't fail when default umask is different.

Also added new functionality: tedge-write can now use plain uid/gid numbers to change owner instead of needing a name. This was done so we can more easily test file owner changes, but is probably a user improvement in its own right.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Copy link
Contributor

github-actions bot commented Jul 3, 2024

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
475 0 3 475 100 1h14m28.854258s

@Bravo555 Bravo555 force-pushed the fix/2972/tedge-write-resets-user-and-group branch from 493a953 to 82ad08d Compare July 3, 2024 14:27
@Bravo555 Bravo555 temporarily deployed to Test Pull Request July 3, 2024 14:27 — with GitHub Actions Inactive
Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Adding an option to use plain uid/gid numbers is a good idea. And the fix seems correct. But, you have to come with another way to test it without assuming chown privileges.

@Bravo555 Bravo555 requested review from gligorisaev and a team as code owners July 5, 2024 10:45
@Bravo555 Bravo555 had a problem deploying to Test Pull Request July 5, 2024 10:45 — with GitHub Actions Failure
Copy link

codecov bot commented Jul 5, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 34 lines in your changes missing coverage. Please review.

Project coverage is 78.0%. Comparing base (d55b5a2) to head (70f761f).
Report is 51 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
crates/core/tedge_write/src/api.rs 62.2% <100.0%> (+44.4%) ⬆️
crates/core/tedge_write/src/bin.rs 0.0% <0.0%> (-50.0%) ⬇️

... and 28 files with indirect coverage changes

@Bravo555 Bravo555 force-pushed the fix/2972/tedge-write-resets-user-and-group branch from 43f5705 to d4bc9ce Compare July 5, 2024 12:34
@Bravo555 Bravo555 had a problem deploying to Test Pull Request July 5, 2024 12:34 — with GitHub Actions Failure
@Bravo555 Bravo555 force-pushed the fix/2972/tedge-write-resets-user-and-group branch from d4bc9ce to e05e910 Compare July 8, 2024 09:02
@Bravo555 Bravo555 requested a review from reubenmiller as a code owner July 8, 2024 09:02
@Bravo555 Bravo555 temporarily deployed to Test Pull Request July 8, 2024 09:02 — with GitHub Actions Inactive
@Bravo555 Bravo555 self-assigned this Jul 8, 2024
@Bravo555 Bravo555 had a problem deploying to Test Pull Request July 8, 2024 12:38 — with GitHub Actions Failure
@Bravo555 Bravo555 force-pushed the fix/2972/tedge-write-resets-user-and-group branch from 61da3df to 5e0cb80 Compare July 8, 2024 12:44
@Bravo555 Bravo555 temporarily deployed to Test Pull Request July 8, 2024 12:44 — with GitHub Actions Inactive
@Bravo555 Bravo555 removed their assignment Jul 8, 2024
Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Indeed replacing system tests by integration tests is more appropriate. The code being correct, I will approve this PR once rebased with the system-tests fix.

Bravo555 added 2 commits July 8, 2024 18:21
fixes: thin-edge#2972

Fixed two closely related problems in tedge-write:

- When destination file existed, its owner/group was reset because when
  creating a temporary file for atomic write we forgot to set the same
  permissions as the destination file. Now we copy destination file
  permissions to the temporary, ensuring that after the rename
  permissions stay the same.
- Changed some permissions used in the tests from 644 to 666, so the
  tests don't fail when default umask is different.

Also added new functionality: tedge-write can now use plain uid/gid
numbers to change owner instead of needing a name. This was done so we
can more easily test file owner changes, but is probably a user
improvement in its own right.

Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
To properly test tedge-write, we need to be running in the environment
where

1. sudo is installed
2. we run as `tedge` user
3. there is a sudoers entry that allows tedge to `sudo tedge-write`
   without password

RobotFramework provides that environment, so tests of tedge-write
functionality were moved there.

Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
@Bravo555 Bravo555 force-pushed the fix/2972/tedge-write-resets-user-and-group branch from 5e0cb80 to 6dfdbc5 Compare July 8, 2024 18:22
@Bravo555 Bravo555 temporarily deployed to Test Pull Request July 8, 2024 18:22 — with GitHub Actions Inactive
@Bravo555 Bravo555 self-assigned this Jul 9, 2024
@Bravo555 Bravo555 temporarily deployed to Test Pull Request July 9, 2024 15:06 — with GitHub Actions Inactive
@Bravo555
Copy link
Member Author

Bravo555 commented Jul 9, 2024

69bdfe1 is expected to fix the failing Set Configuration when file exists test, but i'm not sure of what exactly is the desired behaviour that it should be checking. Will confirm with @reubenmiller tomorrow, and if my understanding is correct, there should be no longer be any blockers for the merge.

@Bravo555 Bravo555 force-pushed the fix/2972/tedge-write-resets-user-and-group branch from 69bdfe1 to 4176c35 Compare July 10, 2024 13:00
@Bravo555 Bravo555 temporarily deployed to Test Pull Request July 10, 2024 13:00 — with GitHub Actions Inactive
@Bravo555 Bravo555 removed their assignment Jul 10, 2024
@Bravo555
Copy link
Member Author

After verifying with @reubenmiller, we decided that the test was indeed checking the wrong thing, so the fix was to change the test itself. I decided not to bother with the umask in Cumulocity Configuration Operation suite, as it should be already handled in the Tedge Write suite. Should be good to merge now.

Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Approved

Bravo555 added 2 commits July 11, 2024 11:30
Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
Test `Set Configuration when file exists` is changed to be consistent
with its comment that suggests that permissions for existing files
should not change. The test now actually asserts that permissions of
`/etc/config1.json` and `/etc/binary-config1.tar.gz` stay unchanged.

Previously, the test seemed to actually assert if the permission did
change, despite the comment claiming otherwise. Changing of permission
was not desirable, and along with resetting the owner of the file, was
part of a bug that is now fixed, so either the test must've been wrong
to begin with, or tedge-write behaviour is specified incorrectly.

`/etc/config1.json` was created with permissions 664, but the test
verified that they were 644 after the operation, which isn't consistent
with what's in `tedge-configuration-plugin.toml`, but is the default
file permissions with default umask 002, so a new file being created
without any changes to default permissions fulfilled the requirements of
the test.

Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
@Bravo555 Bravo555 force-pushed the fix/2972/tedge-write-resets-user-and-group branch from b94ea1f to 70f761f Compare July 11, 2024 11:30
@Bravo555 Bravo555 temporarily deployed to Test Pull Request July 11, 2024 11:30 — with GitHub Actions Inactive
@Bravo555 Bravo555 added this pull request to the merge queue Jul 11, 2024
Merged via the queue into thin-edge:main with commit 80ea226 Jul 11, 2024
@reubenmiller reubenmiller added the theme:configuration Theme: Configuration management label Aug 1, 2024
@Bravo555 Bravo555 deleted the fix/2972/tedge-write-resets-user-and-group branch August 1, 2024 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:configuration Theme: Configuration management
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants