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

Error Running Scripts due to Read-Only File System - NixOS #39

Open
SoarinFerret opened this issue Nov 24, 2023 · 2 comments
Open

Error Running Scripts due to Read-Only File System - NixOS #39

SoarinFerret opened this issue Nov 24, 2023 · 2 comments

Comments

@SoarinFerret
Copy link
Contributor

https://github.com/amidaware/rmmagent/blob/db17e3e28ec0351597c02c7049255f90c85c9e7a/agent/utils.go#L342:L365

NixOS is a Linux distribution built on top of the Nix package manager. Its declarative configuration allows reliable system upgrades via several official channels. One of the features it has is the location where all the binaries are stored are a read-only filesystem.

I am able to successfully build and use the rmmagent on NixOS, except my scripts fail to run due to them trying to run in the same directory where the executable is located. Would the maintainers be open to a pull request adding a runtime feature flag allowing the tmp directory to be changed to a specific location (like --tmpdir /opt/trmm/scripts)? This would not change the default functionality, and could be easily specified in the systemd unit file that my nix package creates.

@SoarinFerret
Copy link
Contributor Author

SoarinFerret commented Nov 24, 2023

In the meantime, for anyone interested, the following patch file does allow scripts to run correctly on agent v2.5.0 in NixOS. This sends the scripts to /opt/tacticalrmm (only accessible by the user running the agent, which is by default root)

diff --git a/agent/utils.go b/agent/utils.go
index 6eacaca..e731088 100644
--- a/agent/utils.go
+++ b/agent/utils.go
@@ -351,12 +351,17 @@ func getCwd() (string, error) {
 
 func createNixTmpFile() (*os.File, error) {
 	var f *os.File
-	cwd, err := getCwd()
-	if err != nil {
-		return f, err
+
+	dirPath := "/opt/tacticalrmm"
+
+	if _, err := os.Stat(dirPath); os.IsNotExist(err) {
+		err := os.MkdirAll(dirPath, 0750)
+		if err != nil {
+			return f, err
+		}
 	}
 
-	f, err = os.CreateTemp(cwd, "trmm")
+	f, err := os.CreateTemp(dirPath, "trmm")
 	if err != nil {
 		return f, err
 	}

@truatpasteurdotfr
Copy link

+1, that would also allow diskless linux machines to be used with read-only rootfs.

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

No branches or pull requests

2 participants