Skip to content

fix: tedge write remove hardcoded path#3099

Merged
Bravo555 merged 2 commits intothin-edge:mainfrom
Bravo555:fix/tedge-write-remove-hardcoded-path
Sep 4, 2024
Merged

fix: tedge write remove hardcoded path#3099
Bravo555 merged 2 commits intothin-edge:mainfrom
Bravo555:fix/tedge-write-remove-hardcoded-path

Conversation

@Bravo555
Copy link
Copy Markdown
Member

@Bravo555 Bravo555 commented Sep 3, 2024

Proposed changes

API for spawning a tedge-write process no longer uses a hardcoded /usr/bin/tedge-write path.

The path was hardcoded because of the wrong assumption of how sudo works: when provided with a command without the full path, e.g. sudo tedge-write /etc/config1, sudo will internally look for tedge-write in $PATH and then compare path with its sudoers entry, so it's not necessary to use full path for binaries used with sudo.

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

@reubenmiller reubenmiller added the theme:configuration Theme: Configuration management label Sep 3, 2024
match which::which(self.sudo_program.as_ref()) {
Ok(sudo) => {
let mut c = Command::new(sudo);
c.arg("--non-interactive");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd recommend using the short form option -n here (even though it is less readable) because -n is more cross compatible, e.g. freebsd only has the -n option and not the long form.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Additional details and impacted files

📢 Thoughts on this report? Let us know!

@Bravo555 Bravo555 force-pushed the fix/tedge-write-remove-hardcoded-path branch from 29e3b55 to 99bb5e7 Compare September 3, 2024 13:28
When thin-edge spawns processes using sudo without `--non-inteactive`
flag, sudo printed the following message:

```
sudo: a terminal is required to read the password; either use the -S
option to read from standard input or configure an askpass helper
```

The flag makes sudo not ask for a password and instead fail immediately
if a password is required.

Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 3, 2024

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
500 0 2 500 100 1h25m45.424937s

didier-wenzek
didier-wenzek previously approved these changes Sep 3, 2024
Copy link
Copy Markdown
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

@didier-wenzek didier-wenzek dismissed their stale review September 3, 2024 15:49

Oops I failed to notice the system tests are failing.

Copy link
Copy Markdown
Contributor

@gligorisaev gligorisaev left a comment

Choose a reason for hiding this comment

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

Have checked the added Test step and keyword, working as expected

API for spawning a tedge-write process no longer uses a hardcoded
`/usr/bin/tedge-write` path.

The path was hardcoded because of the wrong assumption of how `sudo`
works: when provided with a command without the full path, e.g. `sudo
tedge-write /etc/config1`, `sudo` will internally look for `tedge-write`
in $PATH and then compare path with its sudoers entry, so it's not
necessary to use full path for binaries used with `sudo`.

Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh left a comment

Choose a reason for hiding this comment

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

So, we're doing an explicit which lookup from the tedge-agent process to find tedge-write in its customized $PATH because sudo, by default, ignores the $PATH env of the parent process, right?

LGTM and I don't want to block this PR but I'm just wondering if running all sudo commands issued by tedge-agent with the --preserve-env option would be a better fix, as that'll make sure that not just tedge-write but any other process spawned by tedge-agent, like the software management plugins as well, would benefit from the same fix. I'm only concerned if it's some sort of "bad security practice" invoking sudo preserving the calling process's env.

@Bravo555 Bravo555 added this pull request to the merge queue Sep 4, 2024
Merged via the queue into thin-edge:main with commit b9467fe Sep 4, 2024
@Bravo555 Bravo555 deleted the fix/tedge-write-remove-hardcoded-path branch September 4, 2024 11:38
Comment on lines +62 to +66
// if tedge-write is in PATH of tedge process, use it, if not, defer PATH lookup to sudo
let tedge_write_binary =
which::which_global(TEDGE_WRITE_BINARY).unwrap_or(TEDGE_WRITE_BINARY.into());

let mut command = self.sudo.command(tedge_write_binary);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oops, I have not been fast enough to answer @albinsuresh question before this PR being merged by @Bravo555 !

I'm just wondering if running all sudo commands issued by tedge-agent with the --preserve-env option would be a better fix, as that'll make sure that not just tedge-write but any other process spawned by tedge-agent, like the software management plugins as well, would benefit from the same fix. I'm only concerned if it's some sort of "bad security practice" invoking sudo preserving the calling process's env.

One simple way, to have all the components benefiting from the same fix, is to move the call to which::which_global() inside the method sudo.command().

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.

5 participants