forked from torrust/torrust-index-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [torrust#295] update docker image
- Update bash scritps to follow conventions on Tracker and Index. - Update build base image to `node:21-bookworm` (latest). Fix security vunerabilities. - Use `entrypoint` to run container as non root user. - Use distroless image for production.
- Loading branch information
1 parent
b501746
commit 879f5c9
Showing
12 changed files
with
289 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,8 +1,8 @@ | ||
#!/bin/bash | ||
|
||
mkdir -p ./storage/index-gui/lib/ ./storage/index-gui/log/ ./storage/index-gui/etc/ | ||
mkdir -p ./storage/index-gui/log/ | ||
|
||
docker run -it \ | ||
--env USER_ID"$(id -u)" \ | ||
--env USER_ID="$(id -u)" \ | ||
--publish 3000:3000/tcp \ | ||
torrust/index-gui:latest |
This file contains 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,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 ncopa | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains 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,17 @@ | ||
|
||
CFLAGS ?= -Wall -Werror -g | ||
LDFLAGS ?= | ||
|
||
PROG := su-exec | ||
SRCS := $(PROG).c | ||
|
||
all: $(PROG) | ||
|
||
$(PROG): $(SRCS) | ||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) | ||
|
||
$(PROG)-static: $(SRCS) | ||
$(CC) $(CFLAGS) -o $@ $^ -static $(LDFLAGS) | ||
|
||
clean: | ||
rm -f $(PROG) $(PROG)-static |
This file contains 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,46 @@ | ||
# su-exec | ||
switch user and group id, setgroups and exec | ||
|
||
## Purpose | ||
|
||
This is a simple tool that will simply execute a program with different | ||
privileges. The program will be executed directly and not run as a child, | ||
like su and sudo does, which avoids TTY and signal issues (see below). | ||
|
||
Notice that su-exec depends on being run by the root user, non-root | ||
users do not have permission to change uid/gid. | ||
|
||
## Usage | ||
|
||
```shell | ||
su-exec user-spec command [ arguments... ] | ||
``` | ||
|
||
`user-spec` is either a user name (e.g. `nobody`) or user name and group | ||
name separated with colon (e.g. `nobody:ftp`). Numeric uid/gid values | ||
can be used instead of names. Example: | ||
|
||
```shell | ||
$ su-exec apache:1000 /usr/sbin/httpd -f /opt/www/httpd.conf | ||
``` | ||
|
||
## TTY & parent/child handling | ||
|
||
Notice how `su` will make `ps` be a child of a shell while `su-exec` | ||
just executes `ps` directly. | ||
|
||
```shell | ||
$ docker run -it --rm alpine:edge su postgres -c 'ps aux' | ||
PID USER TIME COMMAND | ||
1 postgres 0:00 ash -c ps aux | ||
12 postgres 0:00 ps aux | ||
$ docker run -it --rm -v $PWD/su-exec:/sbin/su-exec:ro alpine:edge su-exec postgres ps aux | ||
PID USER TIME COMMAND | ||
1 postgres 0:00 ps aux | ||
``` | ||
|
||
## Why reinvent gosu? | ||
|
||
This does more or less exactly the same thing as [gosu](https://github.com/tianon/gosu) | ||
but it is only 10kb instead of 1.8MB. | ||
|
This file contains 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,109 @@ | ||
/* set user and group id and exec */ | ||
|
||
#include <sys/types.h> | ||
|
||
#include <err.h> | ||
#include <errno.h> | ||
#include <grp.h> | ||
#include <pwd.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
static char *argv0; | ||
|
||
static void usage(int exitcode) | ||
{ | ||
printf("Usage: %s user-spec command [args]\n", argv0); | ||
exit(exitcode); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
char *user, *group, **cmdargv; | ||
char *end; | ||
|
||
uid_t uid = getuid(); | ||
gid_t gid = getgid(); | ||
|
||
argv0 = argv[0]; | ||
if (argc < 3) | ||
usage(0); | ||
|
||
user = argv[1]; | ||
group = strchr(user, ':'); | ||
if (group) | ||
*group++ = '\0'; | ||
|
||
cmdargv = &argv[2]; | ||
|
||
struct passwd *pw = NULL; | ||
if (user[0] != '\0') { | ||
uid_t nuid = strtol(user, &end, 10); | ||
if (*end == '\0') | ||
uid = nuid; | ||
else { | ||
pw = getpwnam(user); | ||
if (pw == NULL) | ||
err(1, "getpwnam(%s)", user); | ||
} | ||
} | ||
if (pw == NULL) { | ||
pw = getpwuid(uid); | ||
} | ||
if (pw != NULL) { | ||
uid = pw->pw_uid; | ||
gid = pw->pw_gid; | ||
} | ||
|
||
setenv("HOME", pw != NULL ? pw->pw_dir : "/", 1); | ||
|
||
if (group && group[0] != '\0') { | ||
/* group was specified, ignore grouplist for setgroups later */ | ||
pw = NULL; | ||
|
||
gid_t ngid = strtol(group, &end, 10); | ||
if (*end == '\0') | ||
gid = ngid; | ||
else { | ||
struct group *gr = getgrnam(group); | ||
if (gr == NULL) | ||
err(1, "getgrnam(%s)", group); | ||
gid = gr->gr_gid; | ||
} | ||
} | ||
|
||
if (pw == NULL) { | ||
if (setgroups(1, &gid) < 0) | ||
err(1, "setgroups(%i)", gid); | ||
} else { | ||
int ngroups = 0; | ||
gid_t *glist = NULL; | ||
|
||
while (1) { | ||
int r = getgrouplist(pw->pw_name, gid, glist, &ngroups); | ||
|
||
if (r >= 0) { | ||
if (setgroups(ngroups, glist) < 0) | ||
err(1, "setgroups"); | ||
break; | ||
} | ||
|
||
glist = realloc(glist, ngroups * sizeof(gid_t)); | ||
if (glist == NULL) | ||
err(1, "malloc"); | ||
} | ||
} | ||
|
||
if (setgid(gid) < 0) | ||
err(1, "setgid(%i)", gid); | ||
|
||
if (setuid(uid) < 0) | ||
err(1, "setuid(%i)", uid); | ||
|
||
execvp(cmdargv[0], cmdargv); | ||
err(1, "%s", cmdargv[0]); | ||
|
||
return 1; | ||
} |
Oops, something went wrong.