Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
feat: Configurable task capabilities
Browse files Browse the repository at this point in the history
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
  • Loading branch information
gnosek committed Oct 30, 2023
1 parent 7ad0244 commit d124f22
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
5 changes: 5 additions & 0 deletions pkg/hocon/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func extractBuild(config *configuration.Config) (*kilt.Build, error) {
b.Command = make([]string, 0)
}

b.Capabilities = config.GetStringList("build.capabilities")
if b.Capabilities == nil {
b.Capabilities = make([]string, 0)
}

b.EnvironmentVariables = extractToStringMap(config, "build.environment_variables")

if config.IsArray("build.mount") {
Expand Down
1 change: 1 addition & 0 deletions pkg/kilt/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Build struct {
EntryPoint []string
Command []string
EnvironmentVariables map[string]string
Capabilities []string

Resources []BuildResource
}
Expand Down
3 changes: 3 additions & 0 deletions runtimes/cloudformation/cfnpatcher/cfn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ build {
entry_point: ["/kilt/wait"]
}
]
capabilities: ["SYS_PTRACE"]
}
`

Expand All @@ -88,6 +89,7 @@ build {
entry_point: ["/kilt/wait"]
}
]
capabilities: ["SYS_PTRACE"]
}
`

Expand All @@ -106,6 +108,7 @@ build {
}
}
]
capabilities: ["SYS_PTRACE"]
}
`

Expand Down
47 changes: 30 additions & 17 deletions runtimes/cloudformation/cfnpatcher/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,40 @@ func applyContainerDefinitionPatch(ctx context.Context, container *gabs.Containe

}

// We need to add SYS_PTRACE capability to the container
if !container.Exists("LinuxParameters") {
emptyMap := make(map[string]interface{})
_, err = container.Set(emptyMap, "LinuxParameters")
if err != nil {
return fmt.Errorf("could not add LinuxParameters: %w", err)
if len(patch.Capabilities) > 0 {
capabilities := make([]interface{}, len(patch.Capabilities))
for i, v := range patch.Capabilities {
capabilities[i] = v
}
// We need to add capabilities to the container
if !container.Exists("LinuxParameters") {
emptyMap := make(map[string]interface{})
_, err = container.Set(emptyMap, "LinuxParameters")
if err != nil {
return fmt.Errorf("could not add LinuxParameters: %w", err)
}
}
}

if !container.Exists("LinuxParameters", "Capabilities") {
emptyMap := make(map[string]interface{})
_, err = container.Set(emptyMap, "LinuxParameters", "Capabilities")
if err != nil {
return fmt.Errorf("could not add LinuxParameters.Capabilities: %w", err)
if !container.Exists("LinuxParameters", "Capabilities") {
emptyMap := make(map[string]interface{})
_, err = container.Set(emptyMap, "LinuxParameters", "Capabilities")
if err != nil {
return fmt.Errorf("could not add LinuxParameters.Capabilities: %w", err)
}
}
}

// fargate only supports SYS_PTRACE
_, err = container.Set([]string{"SYS_PTRACE"}, "LinuxParameters", "Capabilities", "Add")
if err != nil {
return fmt.Errorf("could not add LinuxParamaters.Capabilities.Add: %w", err)
if !container.Exists("LinuxParameters", "Capabilities", "Add") {
emptyList := make([]interface{}, 0)
_, err = container.Set(emptyList, "LinuxParameters", "Capabilities", "Add")
if err != nil {
return fmt.Errorf("could not add LinuxParameters.Capabilities.Add: %w", err)
}
}

err := container.ArrayConcat(capabilities, "LinuxParameters", "Capabilities", "Add")
if err != nil {
return fmt.Errorf("could not append to LinuxParameters.Capabilities.Add: %w", err)
}
}

return nil
Expand Down

0 comments on commit d124f22

Please sign in to comment.