Browse Source

Support custom docker commands

Resolves #17
tags/v1.1.0
dump_stack() 5 months ago
parent
commit
5bad772125
Signed by: Mikhail Klementev <blame@dumpstack.io> GPG Key ID: BE44DA8C062D87DC
5 changed files with 49 additions and 14 deletions
  1. 3
    0
      CHANGELOG.md
  2. 9
    0
      config/out-of-tree.go
  3. 28
    9
      kernel.go
  4. 6
    3
      main.go
  5. 3
    2
      pack.go

+ 3
- 0
CHANGELOG.md View File

@@ -15,6 +15,9 @@

- Parameter for setting up docker registry server.

- Support for (distro-specific) custom docker commands that will be
executed before the base template.

### Fixed

- Spelling in output.

+ 9
- 0
config/out-of-tree.go View File

@@ -10,6 +10,11 @@ import (
"github.com/naoina/toml"
)

type DockerCommand struct {
DistroType DistroType
Command string
}

type OutOfTree struct {
Kernels string
UserKernels string
@@ -23,6 +28,10 @@ type OutOfTree struct {
Docker struct {
Timeout string
Registry string

// Commands that will be executed before
// the base layer of Dockerfile
Commands []DockerCommand
}
}


+ 28
- 9
kernel.go View File

@@ -109,7 +109,9 @@ func vsyscallAvailable() (available bool, err error) {
return
}

func generateBaseDockerImage(registry string, sk config.KernelMask) (err error) {
func generateBaseDockerImage(registry string, commands []config.DockerCommand,
sk config.KernelMask) (err error) {

imagePath, err := dockerImagePath(sk)
if err != nil {
return
@@ -143,6 +145,21 @@ func generateBaseDockerImage(registry string, sk config.KernelMask) (err error)
return
}

for _, c := range commands {
switch c.DistroType {
case config.Ubuntu:
d += "RUN " + c.Command + "\n"
case config.CentOS:
d += "RUN " + c.Command + "\n"
case config.Debian:
d += "RUN " + c.Command + "\n"
default:
err = fmt.Errorf("%s not yet supported",
sk.DistroType.String())
return
}
}

switch sk.DistroType {
case config.Ubuntu:
d += "ENV DEBIAN_FRONTEND=noninteractive\n"
@@ -578,7 +595,8 @@ func shuffle(a []string) []string {
return a
}

func generateKernels(km config.KernelMask, registry string, max int64,
func generateKernels(km config.KernelMask, registry string,
commands []config.DockerCommand, max int64,
download bool) (err error) {

log.Println("Generating for kernel mask", km)
@@ -589,7 +607,7 @@ func generateKernels(km config.KernelMask, registry string, max int64,
return
}

err = generateBaseDockerImage(registry, km)
err = generateBaseDockerImage(registry, commands, km)
if err != nil {
return
}
@@ -639,8 +657,9 @@ func generateKernels(km config.KernelMask, registry string, max int64,
return
}

func kernelAutogenHandler(workPath, registry string, max int64, host,
download bool) (err error) {
func kernelAutogenHandler(workPath, registry string,
commands []config.DockerCommand,
max int64, host, download bool) (err error) {

ka, err := config.ReadArtifactConfig(workPath + "/.out-of-tree.toml")
if err != nil {
@@ -653,7 +672,7 @@ func kernelAutogenHandler(workPath, registry string, max int64, host,
return
}

err = generateKernels(sk, registry, max, download)
err = generateKernels(sk, registry, commands, max, download)
if err != nil {
return
}
@@ -704,8 +723,8 @@ func kernelDockerRegenHandler(host, download bool) (err error) {
return updateKernelsCfg(host, download)
}

func kernelGenallHandler(distro, version, registry string, host,
download bool) (err error) {
func kernelGenallHandler(distro, version, registry string,
commands []config.DockerCommand, host, download bool) (err error) {

distroType, err := config.NewDistroType(distro)
if err != nil {
@@ -717,7 +736,7 @@ func kernelGenallHandler(distro, version, registry string, host,
DistroRelease: version,
ReleaseMask: ".*",
}
err = generateKernels(km, registry, kernelsAll, download)
err = generateKernels(km, registry, commands, kernelsAll, download)
if err != nil {
return
}

+ 6
- 3
main.go View File

@@ -293,11 +293,13 @@ func main() {
err = kernelListHandler(kcfg)
case kernelAutogenCommand.FullCommand():
err = kernelAutogenHandler(*path, *dockerRegistry,
*kernelAutogenMax, *kernelUseHost, !*kernelNoDownload)
conf.Docker.Commands, *kernelAutogenMax,
*kernelUseHost, !*kernelNoDownload)
case kernelDockerRegenCommand.FullCommand():
err = kernelDockerRegenHandler(*kernelUseHost, !*kernelNoDownload)
case kernelGenallCommand.FullCommand():
err = kernelGenallHandler(*distro, *version, *dockerRegistry,
err = kernelGenallHandler(*distro, *version,
*dockerRegistry, conf.Docker.Commands,
*kernelUseHost, !*kernelNoDownload)
case genModuleCommand.FullCommand():
err = genConfig(config.KernelModule)
@@ -321,7 +323,8 @@ func main() {
case logMarkdownCommand.FullCommand():
err = logMarkdownHandler(db, *path, *logMarkdownTag)
case packCommand.FullCommand():
err = packHandler(db, *path, *dockerRegistry, kcfg, *packAutogen,
err = packHandler(db, *path, *dockerRegistry,
conf.Docker.Commands, kcfg, *packAutogen,
!*packNoDownload, *packExploitRuns, *packKernelRuns)
}


+ 3
- 2
pack.go View File

@@ -15,7 +15,8 @@ import (
"code.dumpstack.io/tools/out-of-tree/config"
)

func packHandler(db *sql.DB, path, registry string, kcfg config.KernelConfig,
func packHandler(db *sql.DB, path, registry string,
commands []config.DockerCommand, kcfg config.KernelConfig,
autogen, download bool, exploitRuns, kernelRuns int64) (err error) {

dockerTimeout := time.Minute
@@ -40,7 +41,7 @@ func packHandler(db *sql.DB, path, registry string, kcfg config.KernelConfig,
if autogen {
var perRegex int64 = 1
err = kernelAutogenHandler(workPath, registry,
perRegex, false, download)
commands, perRegex, false, download)
if err != nil {
return
}

Loading…
Cancel
Save