Skip to content

Commit 1d9f45a

Browse files
committed
additional ability to obfuscate application package names for node apps and using full image IDs when saving images in XRAY to make it more compatible with non-Docker container runtimes
Signed-off-by: Kyle Quest <[email protected]>
1 parent f42872a commit 1d9f45a

File tree

14 files changed

+279
-161
lines changed

14 files changed

+279
-161
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ In the interactive CLI prompt mode you must specify the target image using the `
547547
- `--image-build-engine` - Select image build engine: `internal` | `docker` | `none` (`internal` - build the output image without using Docker [default behavior], `docker` - build the output image with Docker, `none` - don't build the output image, allows you to do your own build with the tools you want to use, which you'll be able to do by pointing to the artifact directory where the `files.tar` and `Dockerfile` artifacts are located for the output image)
548548
- `--image-build-arch` - Select output image build architecture (use the standard container image names for the architectures without the OS part)
549549
- `--obfuscate-metadata` - Obfuscate the standard system and application metadata to make it more challenging to identify the image components (experimental flag, first version of obfuscation; inspired by the [`Malicious Compliance`](https://kccnceu2023.sched.com/event/1Hybu/malicious-compliance-reflections-on-trusting-container-scanners-ian-coldwater-independent-duffie-cooley-isovalent-brad-geesaman-ghost-security-rory-mccune-datadog) KubeCon EU 2023 talk)
550+
- `--obfuscate-app-package-names` - Select the obfuscation mode for the application package names. Available modes: `none` | `empty` | `prefix` | `random` (`none` - Do no app package name obfuscation; `empty` - Replace the app package names with empty values; `prefix` - Prefix app package names with a string; `random` - Replace app package names with random values).
550551
- `--enable-mondel` - Enable monitor data event log for sensor monitors to log/stream the events captured by those monitors (default: false)
551552
- `--command-params-file` - JSON file with all command parameters - the JSON file can use a snake case formatted commands example `--docker-config-path` would be `docker_config_path`
552553

pkg/app/master/command/build/cli.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ var BuildFlags = (append([]cli.Flag{
158158
cflag(FlagExcludeMounts),
159159
//"EXCLUDE" FLAGS - END
160160
cflag(FlagObfuscateMetadata),
161+
cflag(FlagObfuscateAppPackageNames),
161162
command.Cflag(command.FlagContinueAfter),
162163
command.Cflag(command.FlagUseLocalMounts),
163164
command.Cflag(command.FlagUseSensorVolume),
@@ -739,6 +740,7 @@ var CLI = &cli.Command{
739740
rtaSourcePT := ctx.Bool(command.FlagRTASourcePT)
740741

741742
doObfuscateMetadata := ctx.Bool(FlagObfuscateMetadata)
743+
obfuscateAppPackageNames := ctx.String(FlagObfuscateAppPackageNames)
742744

743745
imageBuildEngine, err := getImageBuildEngine(ctx)
744746
if err != nil {
@@ -842,6 +844,7 @@ var CLI = &cli.Command{
842844
rtaOnbuildBaseImage,
843845
rtaSourcePT,
844846
doObfuscateMetadata,
847+
obfuscateAppPackageNames,
845848
ctx.String(command.FlagSensorIPCEndpoint),
846849
ctx.String(command.FlagSensorIPCMode),
847850
kubeOpts,

pkg/app/master/command/build/flags.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ const (
152152
FlagCBOCacheFrom = "cbo-cache-from"
153153

154154
//Experimenal flags
155-
FlagObfuscateMetadata = "obfuscate-metadata"
155+
FlagObfuscateMetadata = "obfuscate-metadata"
156+
FlagObfuscateAppPackageNames = "obfuscate-app-package-names"
156157
)
157158

158159
// Build command flag usage info
@@ -231,7 +232,8 @@ const (
231232
FlagCBONetworkUsage = "Networking mode to use for the RUN instructions at build-time"
232233
FlagCBOCacheFromUsage = "Add an image to the build cache"
233234

234-
FlagObfuscateMetadataUsage = "Obfuscate the standard system and application metadata to make it more challenging to identify the image components"
235+
FlagObfuscateMetadataUsage = "Obfuscate the standard system and application metadata to make it more challenging to identify the image components"
236+
FlagObfuscateAppPackageNamesUsage = "Select app package name obfuscate mode: none | empty | prefix | random"
235237
)
236238

237239
var Flags = map[string]cli.Flag{
@@ -648,6 +650,12 @@ var Flags = map[string]cli.Flag{
648650
Usage: FlagObfuscateMetadataUsage,
649651
EnvVars: []string{"DSLIM_OBFUSCATE_METADATA"},
650652
},
653+
FlagObfuscateAppPackageNames: &cli.StringFlag{
654+
Name: FlagObfuscateAppPackageNames,
655+
Value: config.OAPNNone,
656+
Usage: FlagObfuscateAppPackageNamesUsage,
657+
EnvVars: []string{"DSLIM_OBFUSCATE_APN"},
658+
},
651659
}
652660

653661
func cflag(name string) cli.Flag {

pkg/app/master/command/build/handler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func OnCommand(
148148
rtaOnbuildBaseImage bool,
149149
rtaSourcePT bool,
150150
doObfuscateMetadata bool,
151+
obfuscateAppPackageNames string,
151152
sensorIPCEndpoint string,
152153
sensorIPCMode string,
153154
kubeOpts config.KubernetesOptions,
@@ -641,8 +642,9 @@ func OnCommand(
641642
includeLastImageLayers, appImageStartInstGroup, appImageStartInst, len(appImageDockerfileInsts))
642643

643644
includeLayerPaths := map[string]*fsutil.AccessInfo{}
644-
imageID := dockerutil.CleanImageID(imageInspector.ImageInfo.ID)
645-
iaName := fmt.Sprintf("%s.tar", imageID)
645+
//not using dockerutil.CleanImageID() because some container runtime APIs might expect the full image ID with the hash prefix
646+
imageID := imageInspector.ImageInfo.ID
647+
iaName := fmt.Sprintf("%s.tar", dockerutil.CleanImageID(imageID))
646648
iaPath := filepath.Join(localVolumePath, "image", iaName)
647649
iaPathReady := fmt.Sprintf("%s.ready", iaPath)
648650

@@ -1109,6 +1111,7 @@ func OnCommand(
11091111
gparams.InContainer,
11101112
rtaSourcePT,
11111113
doObfuscateMetadata,
1114+
obfuscateAppPackageNames,
11121115
sensorIPCEndpoint,
11131116
sensorIPCMode,
11141117
printState,

pkg/app/master/command/build/prompt.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package build
22

33
import (
4-
"github.com/mintoolkit/mint/pkg/app/master/command"
5-
64
"github.com/c-bata/go-prompt"
5+
6+
"github.com/mintoolkit/mint/pkg/app/master/command"
7+
"github.com/mintoolkit/mint/pkg/app/master/config"
78
)
89

910
var CommandSuggestion = prompt.Suggest{
@@ -163,6 +164,7 @@ var CommandFlagSuggestions = &command.FlagSuggestions{
163164
{Text: command.FullFlagName(FlagImageBuildEngine), Description: FlagImageBuildEngineUsage},
164165
{Text: command.FullFlagName(FlagImageBuildArch), Description: FlagImageBuildArchUsage},
165166
{Text: command.FullFlagName(FlagObfuscateMetadata), Description: FlagObfuscateMetadataUsage},
167+
{Text: command.FullFlagName(FlagObfuscateAppPackageNames), Description: FlagObfuscateAppPackageNamesUsage},
166168
},
167169
Values: map[string]command.CompleteValue{
168170
command.FullFlagName(command.FlagCommandParamsFile): command.CompleteFile,
@@ -239,9 +241,21 @@ var CommandFlagSuggestions = &command.FlagSuggestions{
239241
command.FullFlagName(FlagImageBuildArch): CompleteImageBuildArch,
240242
command.FullFlagName(FlagAppImageDockerfile): command.CompleteFile,
241243
command.FullFlagName(FlagObfuscateMetadata): command.CompleteBool,
244+
command.FullFlagName(FlagObfuscateAppPackageNames): CompleteObfuscateAPN,
242245
},
243246
}
244247

248+
var obfuscateAPNValues = []prompt.Suggest{
249+
{Text: config.OAPNNone, Description: "Do no app package name obfuscation"},
250+
{Text: config.OAPNEmpty, Description: "Replace the app package names with empty values"},
251+
{Text: config.OAPNPrefix, Description: "Prefix app package names with a string"},
252+
{Text: config.OAPNRandom, Description: "Replace app package names with random values"},
253+
}
254+
255+
func CompleteObfuscateAPN(ia *command.InteractiveApp, token string, params prompt.Document) []prompt.Suggest {
256+
return prompt.FilterHasPrefix(obfuscateAPNValues, token, true)
257+
}
258+
245259
var imageBuildEngineValues = []prompt.Suggest{
246260
{Text: IBENone, Description: "no image build engine (output image is not built)"},
247261
{Text: IBEInternal, Description: "internal image build engine"},

pkg/app/master/command/cliflags.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
log "github.com/sirupsen/logrus"
55
"github.com/urfave/cli/v2"
66
"k8s.io/client-go/tools/clientcmd"
7+
8+
"github.com/mintoolkit/mint/pkg/app/master/config"
79
)
810

911
/////////////////////////////////////////////////////////
@@ -789,7 +791,7 @@ var CommonFlags = map[string]cli.Flag{
789791
},
790792
FlagContinueAfter: &cli.StringFlag{
791793
Name: FlagContinueAfter,
792-
Value: "probe",
794+
Value: config.CAMProbe,
793795
Usage: FlagContinueAfterUsage,
794796
EnvVars: []string{"DSLIM_CONTINUE_AFTER"},
795797
},

pkg/app/master/command/profile/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ func OnCommand(
274274
gparams.InContainer,
275275
true, //rtaSourcePT
276276
false, //doObfuscateMetadata
277+
"", //doObfuscateAPN
277278
sensorIPCEndpoint,
278279
sensorIPCMode,
279280
printState,

pkg/app/master/command/xray/handler.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,9 @@ func OnCommand(
346346
xc.Out.State("image.api.inspection.done")
347347
xc.Out.State("image.data.inspection.start")
348348

349-
imageID := dockerutil.CleanImageID(imageInspector.ImageInfo.ID)
350-
iaName := fmt.Sprintf("%s.tar", imageID)
349+
//not using dockerutil.CleanImageID() because some container runtime APIs might expect the full image ID with the hash prefix
350+
imageID := imageInspector.ImageInfo.ID
351+
iaName := fmt.Sprintf("%s.tar", dockerutil.CleanImageID(imageID))
351352
iaPath := filepath.Join(localVolumePath, "image", iaName)
352353
iaPathReady := fmt.Sprintf("%s.ready", iaPath)
353354

@@ -1357,8 +1358,16 @@ func objectHistoryString(history *dockerimage.ObjectHistory) string {
13571358
return "H=[]"
13581359
}
13591360

1361+
return fmt.Sprintf("H=%s", objectHistoryValue(history))
1362+
}
1363+
1364+
func objectHistoryValue(history *dockerimage.ObjectHistory) string {
1365+
if history == nil {
1366+
return "[]"
1367+
}
1368+
13601369
var builder strings.Builder
1361-
builder.WriteString("H=[")
1370+
builder.WriteString("[")
13621371
if history.Add != nil {
13631372
builder.WriteString(fmt.Sprintf("A:%d", history.Add.Layer))
13641373
}
@@ -1386,7 +1395,7 @@ func printObject(xc *app.ExecutionContext, object *dockerimage.ObjectMetadata) {
13861395
var hashInfo string
13871396

13881397
if object.Hash != "" {
1389-
hashInfo = fmt.Sprintf(" hash=%s", object.Hash)
1398+
hashInfo = fmt.Sprintf("%s", object.Hash)
13901399
}
13911400
ov := ovars{
13921401
"mode": object.Mode,
@@ -1395,7 +1404,7 @@ func printObject(xc *app.ExecutionContext, object *dockerimage.ObjectMetadata) {
13951404
"uid": object.UID,
13961405
"gid": object.GID,
13971406
"mtime": object.ModTime.UTC().Format(time.RFC3339),
1398-
"H": objectHistoryString(object.History),
1407+
"H": objectHistoryValue(object.History),
13991408
"hash": hashInfo,
14001409
"object.name": object.Name,
14011410
}

pkg/app/master/config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ type DockerClient struct {
145145
Env map[string]string
146146
}
147147

148+
// ContinueAfter mode enums
148149
const (
149150
CAMContainerProbe = "container-probe"
150151
CAMProbe = "probe"
@@ -207,3 +208,11 @@ type KubernetesTargetOverride struct {
207208
func (ko KubernetesOptions) HasTargetSet() bool {
208209
return ko.Target.Workload != ""
209210
}
211+
212+
// ObfuscateAppPackageNames mode enums
213+
const (
214+
OAPNNone = "none"
215+
OAPNEmpty = "empty"
216+
OAPNPrefix = "prefix"
217+
OAPNRandom = "random"
218+
)

0 commit comments

Comments
 (0)