This repository was archived by the owner on Dec 21, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Run as user #102
Merged
siegfriedweber
merged 13 commits into
stackabletech:main
from
siegfriedweber:run_as_user
Mar 11, 2021
Merged
Run as user #102
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
521c24d
User name mapped from the PodSpec to the Systemd unit
siegfriedweber a526ce8
Unit test created
siegfriedweber a0b1284
Unit test extended
siegfriedweber bcff97f
User is not set in systemd unit on the session bus; Functions created…
siegfriedweber c1d2848
Test case for systemd session bus added
siegfriedweber f19ceed
Formatting fixed
siegfriedweber dd524c3
TODOs removed as discussed
siegfriedweber ffb253d
Comments added
siegfriedweber f8a1c77
An info is logged if the agent runs in session mode and therefore the…
siegfriedweber 2bedfad
strum_macros used to remove error-prone code
siegfriedweber b28432a
Use path changed to the idiomatic way
siegfriedweber 38a5542
TODO added to put every environment variable on a separate line in th…
siegfriedweber 01fc1b4
All clippy warnings fixed
siegfriedweber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| //! Filesystem manipulation operations. | ||
| //! | ||
| //! This module contains additional operations which are not present in | ||
| //! `std::fs` and `std::os::$platform`. | ||
|
|
||
| use anyhow::{anyhow, Result}; | ||
| use nix::unistd; | ||
| use std::path::Path; | ||
|
|
||
| /// User identifier | ||
| pub struct Uid(unistd::Uid); | ||
|
|
||
| impl Uid { | ||
| /// Gets a Uid by user name. | ||
| /// | ||
| /// If no user with the given `user_name` exists then `Ok(None)` is returned. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// If this function encounters any form of I/O or other error, an error | ||
| /// variant will be returned. | ||
| pub fn from_name(user_name: &str) -> Result<Option<Uid>> { | ||
|
siegfriedweber marked this conversation as resolved.
|
||
| match unistd::User::from_name(user_name) { | ||
| Ok(maybe_user) => Ok(maybe_user.map(|user| Uid(user.uid))), | ||
| Err(err) => Err(anyhow!("Could not retrieve user [{}]. {}", user_name, err)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Changes the ownership of the file or directory at `path` to be owned by the | ||
| /// given `uid`. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// If this function encounters any form of I/O or other error, an error | ||
| /// variant will be returned. | ||
| pub fn change_owner(path: &Path, uid: &Uid) -> Result<()> { | ||
|
siegfriedweber marked this conversation as resolved.
|
||
| Ok(unistd::chown(path, Some(uid.0), None)?) | ||
| } | ||
|
|
||
| /// Changes the ownership of the file or directory at `path` recursively to be | ||
| /// owned by the given `uid`. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// If this function encounters any form of I/O or other error, an error | ||
| /// variant will be returned. | ||
| pub fn change_owner_recursively(root_path: &Path, uid: &Uid) -> Result<()> { | ||
|
siegfriedweber marked this conversation as resolved.
|
||
| visit_recursively(root_path, &|path| change_owner(path, uid)) | ||
| } | ||
|
|
||
| /// Calls the function `cb` on the given `path` and its contents recursively. | ||
| fn visit_recursively<F>(path: &Path, cb: &F) -> Result<()> | ||
| where | ||
| F: Fn(&Path) -> Result<()>, | ||
| { | ||
| cb(path)?; | ||
| if path.is_dir() { | ||
| for entry in path.read_dir()? { | ||
| visit_recursively(entry?.path().as_path(), cb)?; | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| pub mod config; | ||
| pub mod fsext; | ||
| pub mod provider; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.