Commit ffc9a544 authored by Muhammad Umair Khan's avatar Muhammad Umair Khan
Browse files

fix(meepctl): safely set ownership only for platform-level workdirs

parent e0dc17e9
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -179,14 +179,24 @@ func deployEnsureStorage(cobraCmd *cobra.Command) {
		fmt.Println(err)
	}

	// Set ownership of the workdir to the configured uid and gid
	// Set ownership of specific platform-level directories to the configured uid and gid.
	// We intentionally exclude application-specific directories (e.g., grafana, couchdb)
	// as they manage their own ownership via Helm chart securityContext (fsGroup/runAsUser).
	uid := utils.RepoCfg.GetString("repo.deployment.permissions.uid")
	gid := utils.RepoCfg.GetString("repo.deployment.permissions.gid")
	if uid != "" && gid != "" {
		chownCmd := exec.Command("chown", "-R", uid+":"+gid, deployData.workdir)
		platformDirs := []string{
			deployData.workdir + "/user",
			deployData.workdir + "/tmp",
			deployData.workdir + "/certs",
			deployData.workdir + "/virt-engine",
		}
		for _, dir := range platformDirs {
			chownCmd := exec.Command("chown", "-R", uid+":"+gid, dir)
			_, err = utils.ExecuteCmd(chownCmd, cobraCmd)
			if err != nil {
			fmt.Println("Warning: Error setting ownership for path [" + deployData.workdir + "]. You may need to run this command with elevated privileges (e.g., sudo).")
				fmt.Println("Warning: Error setting ownership for path [" + dir + "]. You may need to run this command with elevated privileges (e.g., sudo).")
			}
		}
	}
}