-
Notifications
You must be signed in to change notification settings - Fork 441
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
Implemented chown file permissions and user/group creation #84
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
chown ${{user}}:${{group}} ${{path}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Adding ${{group}} as system group | ||
if ! getent group ${{group}} > /dev/null 2>&1 | ||
then | ||
echo "Creating system group: ${{group}}" | ||
addgroup --system ${{group}} | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Adding ${{user}} | ||
if ! id -u $1 >/dev/null 2>&1; then | ||
echo "Creating user ${{user}} in group ${{group}}" | ||
useradd --system --no-create-home --gid ${{group}} --shell /bin/false ${{user}} | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Deleting user: ${{user}} and group: ${{group}} | ||
case "$1" in | ||
remove|failed-upgrade|abort-upgrade|abort-install|disappear) | ||
;; | ||
purge) | ||
deluser --quiet --system ${{user}} > /dev/null || true | ||
delgroup --quiet --system ${{group}} > /dev/null || true | ||
;; | ||
upgrade) | ||
;; | ||
*) | ||
echo "postinst called with unknown argument \`\$1'" >&2 | ||
;; | ||
esac |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,8 +111,8 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin { | |
chmod(cfile, "0644") | ||
cfile | ||
}, | ||
debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, debianControlScriptsReplacements, linuxPackageSymlinks, target) | ||
map { (mappings, _, maintScripts, _, replacements, symlinks, t) => | ||
debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, debianControlScriptsReplacements, linuxPackageSymlinks, target, streams) | ||
map { (mappings, _, maintScripts, _, replacements, symlinks, t, streams) => | ||
|
||
// Create files and directories | ||
mappings foreach { | ||
|
@@ -142,6 +142,32 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin { | |
filterAndFixPerms(targetFile, replacements, LinuxFileMetaData()) | ||
} | ||
|
||
// Check for non root user/group and append to postinst / postrm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think maybe this entire bit of behavior belongs in its own task/method, and we should figure out how to explode the package, then run this. Right now, this code is getting to be a bit large to "grok" all at once, and a handy method name can help. I can do this after merging if you want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally agree. This was the first "it works" attempt :) |
||
// filter all root mappings, map to (user,group) key, group by, append everything | ||
mappings filter { | ||
case LinuxPackageMapping(_, LinuxFileMetaData("root", "root", _, _, _), _) => false | ||
case _ => true | ||
} map { | ||
case LinuxPackageMapping(paths, LinuxFileMetaData(user, group, _, _, _), _) => (user, group) -> paths | ||
} groupBy (_._1) foreach { | ||
case ((user, group), pathList) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting and slick. Nice work. |
||
streams.log info ("Altering postrm/postinst files to add user " + user + " and group " + group) | ||
val postinst = t / "DEBIAN" / "postinst" | ||
val postrm = t / "DEBIAN" / "postrm" | ||
|
||
val replacements = Seq("group" -> group, "user" -> user) | ||
IO.append(postinst, TemplateWriter.generateScript(DebianPlugin.postinstGroupaddTemplateSource, replacements)) | ||
IO.append(postinst, TemplateWriter.generateScript(DebianPlugin.postinstUseraddTemplateSource, replacements)) | ||
|
||
// remove key, flatten it and then go through each file | ||
pathList.map(_._2).flatten foreach { | ||
case (_, target) => | ||
val pathReplacements = replacements :+ ("path" -> target.toString) | ||
IO.append(postinst, TemplateWriter.generateScript(DebianPlugin.postinstChownTemplateSource, pathReplacements)) | ||
} | ||
|
||
IO.append(postrm, TemplateWriter.generateScript(DebianPlugin.postrmPurgeTemplateSource, replacements)) | ||
} | ||
t | ||
}, | ||
debianMD5sumsFile <<= (debianExplodedPackage, target) map { | ||
|
@@ -180,3 +206,10 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin { | |
})) | ||
|
||
} | ||
|
||
object DebianPlugin { | ||
private def postinstGroupaddTemplateSource: java.net.URL = getClass.getResource("postinst-groupadd") | ||
private def postinstUseraddTemplateSource: java.net.URL = getClass.getResource("postinst-useradd") | ||
private def postinstChownTemplateSource: java.net.URL = getClass.getResource("postinst-chown") | ||
private def postrmPurgeTemplateSource: java.net.URL = getClass.getResource("postrm-purge") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we can delete the group always?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. Actually we don't have any clue about the user/group.
I think we have two options
For 2. this would need a setting like
and question is: What are the default values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.... Well for now maybe we'll just document that it has to be a unique user for this service. That's generally a standard good practice. However, it does mean multiple services that are supposed to have the same user won't quite work. In that case, you want a DEB which adds the user/group, and then depend on that I think. In that case, you're probably directly implementing things.
SO, I'd say how it is now is fine for now.