-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup user on docker image to run it as rootless
- Loading branch information
1 parent
b46a3c2
commit 5c913bf
Showing
4 changed files
with
95 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package v2 | ||
|
||
import ( | ||
"path/filepath" | ||
"sigs.k8s.io/kubebuilder/pkg/scaffold/input" | ||
) | ||
|
||
const EntrypointFile = "entrypoint" | ||
|
||
// Entrypoint - entrypoint script | ||
type Entrypoint struct { | ||
input.Input | ||
} | ||
|
||
func (e *Entrypoint) GetInput() (input.Input, error) { | ||
if e.Path == "" { | ||
e.Path = filepath.Join(BuildScriptDir, EntrypointFile) | ||
} | ||
e.TemplateBody = entrypointTmpl | ||
return e.Input, nil | ||
} | ||
|
||
const entrypointTmpl = `#!/bin/sh -e | ||
# This is documented here: | ||
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines | ||
if ! whoami &>/dev/null; then | ||
if [ -w /etc/passwd ]; then | ||
echo "${USER_NAME:-default}:x:$(id -u):$(id -g):${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd | ||
fi | ||
fi | ||
exec ${OPERATOR} $@ | ||
` |
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,33 @@ | ||
package v2 | ||
|
||
import ( | ||
"path/filepath" | ||
"sigs.k8s.io/kubebuilder/pkg/scaffold/input" | ||
) | ||
|
||
const UserSetupFile = "user_setup" | ||
|
||
// UserSetup - userSetup script | ||
type UserSetup struct { | ||
input.Input | ||
} | ||
|
||
func (u *UserSetup) GetInput() (input.Input, error) { | ||
if u.Path == "" { | ||
u.Path = filepath.Join(BuildScriptDir, UserSetupFile) | ||
} | ||
u.TemplateBody = userSetupTmpl | ||
return u.Input, nil | ||
} | ||
|
||
const userSetupTmpl = `#!/bin/sh | ||
set -x | ||
# ensure $HOME exists and is accessible by group 0 (we don't know what the runtime UID will be) | ||
mkdir -p ${HOME} | ||
chown ${USER_UID}:0 ${HOME} | ||
chmod ug+rwx ${HOME} | ||
# runtime user will need to be able to self-insert in /etc/passwd | ||
chmod g+rw /etc/passwd | ||
# no need for this script to remain in the image after running | ||
rm $0 | ||
` |