mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Update kyaml to specify user for function
This commit is contained in:
@@ -133,6 +133,9 @@ type Filter struct {
|
||||
// StorageMounts is a list of storage options that the container will have mounted.
|
||||
StorageMounts []runtimeutil.StorageMount `yaml:"mounts,omitempty"`
|
||||
|
||||
// User username used to run the application in container,
|
||||
User string
|
||||
|
||||
Exec runtimeexec.Filter
|
||||
}
|
||||
|
||||
@@ -174,14 +177,18 @@ func (c *Filter) getCommand() (string, []string) {
|
||||
if c.Network != "" {
|
||||
network = c.Network
|
||||
}
|
||||
|
||||
// run as nobody by default
|
||||
user := c.User
|
||||
if user == "" {
|
||||
user = "nobody"
|
||||
}
|
||||
args := []string{"run",
|
||||
"--rm", // delete the container afterward
|
||||
"-i", "-a", "STDIN", "-a", "STDOUT", "-a", "STDERR", // attach stdin, stdout, stderr
|
||||
"--network", network,
|
||||
|
||||
// added security options
|
||||
"--user", "nobody", // run as nobody
|
||||
"--user", user,
|
||||
"--security-opt=no-new-privileges", // don't allow the user to escalate privileges
|
||||
// note: don't make fs readonly because things like heredoc rely on writing tmp files
|
||||
}
|
||||
|
||||
@@ -88,6 +88,26 @@ metadata:
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "root user",
|
||||
functionConfig: `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: foo
|
||||
`,
|
||||
expectedArgs: []string{
|
||||
"run",
|
||||
"--rm",
|
||||
"-i", "-a", "STDIN", "-a", "STDOUT", "-a", "STDERR",
|
||||
"--network", "none",
|
||||
"--user", "root",
|
||||
"--security-opt=no-new-privileges",
|
||||
},
|
||||
instance: Filter{
|
||||
Image: "example.com:version",
|
||||
User: "root",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i := range tests {
|
||||
|
||||
@@ -52,6 +52,9 @@ type ContainerSpec struct {
|
||||
|
||||
// Mounts are the storage or directories to mount into the container
|
||||
StorageMounts []StorageMount `json:"mounts,omitempty" yaml:"mounts,omitempty"`
|
||||
|
||||
// User is the username/uid that application runs as in continer
|
||||
User string `json:"user,omitempty" yaml:"user,omitempty"`
|
||||
}
|
||||
|
||||
// ContainerNetwork
|
||||
|
||||
Reference in New Issue
Block a user