Skip to content

Commit b7052d5

Browse files
committed
cleanup
Signed-off-by: Kyle Quest <[email protected]>
1 parent 04d7514 commit b7052d5

File tree

10 files changed

+27
-140
lines changed

10 files changed

+27
-140
lines changed

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,17 @@ If you don't specify any command `mint` will start in the interactive prompt mod
273273

274274
### COMMANDS
275275

276+
- `slim` - Create a minimal container image for your selected image generating the supported security profiles. This is the most popular command. (aka `build`)
276277
- `debug` - Debug minimal or regular container images running in Docker, Podman, Kubernetes and ContainerD.
277278
- `xray` - Performs static analysis for the target container image (including 'reverse engineering' the Dockerfile for the image). Use this command if you want to know what's inside of your container image and what makes it fat.
278279
- `lint` - Analyzes container instructions in Dockerfiles (Docker image support is WIP)
279-
- `build` - Analyzes, profiles and optimizes your container image generating the supported security profiles. This is the most popular command.
280280
- `registry` - Execute registry operations (`pull`, `push`, `copy`, `server`).
281281
- `profile` - Performs basic container image analysis and dynamic container analysis, but it doesn't generate an optimized image.
282282
- `run` - Runs one or more containers (for now runs a single container similar to `docker run`)
283283
- `merge` - Merge two container images (optimized to merge minified images).
284284
- `images` - Get information about container images (example: `mint --quiet images`).
285285
- `vulnerability` - Execute vulnerability related tools and operations (`epss`).
286-
- `version` - Shows the version information.
287-
- `appbom` - Shows the application BOM (app composition/dependencies).
288-
- `update` - Updates Mint to the latest version.
286+
- `app` - Execute app management, maintenance, debugging and query operations (`bom`, `version`, `remove-sensor-volumes`, `update`, `install` operations).
289287
- `help` - Show the available commands and global flags
290288

291289
Example: `mint build my/sample-app`
@@ -300,18 +298,16 @@ If you run `mint` without any parameters you'll get an interactive prompt that w
300298

301299
Commands:
302300

301+
- `slim` - Create a minimal container image for your selected image generating the supported security profiles. (aka `build`)
303302
- `debug` - Debug minimal or regular container images running in Docker, Podman, Kubernetes and ContainerD.
304303
- `xray` - Show what's in the container image and reverse engineer its Dockerfile
305304
- `lint` - Lint the target Dockerfile (or image, in the future)
306-
- `build` - Analyze the target container image along with its application and build an optimized image from it
307305
- `registry` - Execute registry operations (`pull`, `push`, `copy`, `server`).
308306
- `profile` - Collect fat image information and generate a fat container report
309307
- `merge` - Merge two container images (optimized to merge minified images)
310308
- `images` - Get information about container images.
311309
- `vulnerability` - Execute vulnerability related tools and operations (`epss`).
312-
- `appbom` - Shows the application BOM (app composition/dependencies)
313-
- `version` - Show app and docker version information
314-
- `update` - Update the app
310+
- `app` - Execute app management, maintenance, debugging and query operations (`bom`, `version`, `remove-sensor-volumes`, `update`, `install` operations).
315311
- `help` - Show help info
316312

317313
Global options:
@@ -357,6 +353,7 @@ To disable the version checks set the global `--check-version` flag to `false` (
357353

358354
### `XRAY` COMMAND OPTIONS
359355

356+
- `--runtime` - Runtime environment type (values: `docker`, `podman` and a special meta runtime `auto`, which auto-selects the runtime based on the installed runtime; defaults to `auto`)
360357
- `--target` - Target container image (name or ID)
361358
- `--pull` - Try pulling target if it's not available locally (default: false).
362359
- `--docker-config-path` - Set the docker config path used to fetch registry credentials (used with the `--pull` flag).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
const (
1313
Name = "app"
14-
Usage = "Execute app management, maintanance, debugging and query operations"
14+
Usage = "Execute app management, maintenance, debugging and query operations"
1515
Alias = "a"
1616

1717
BomCmdName = "bom"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
const (
1818
Name = "slim"
19-
Usage = "Creates a slim version of your container image auto-generating Seccomp and AppArmor security profiles"
19+
Usage = "Shrinks your container image auto-generating Seccomp and AppArmor security profiles"
2020
AliasA = "build"
2121
AliasB = "b"
2222
)

pkg/app/master/inspectors/image/image_inspector.go

Lines changed: 10 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func NewInspector(apiClient crt.InspectorAPIClient, imageRef string /*, artifact
5656
// NoImage returns true if the target image doesn't exist
5757
func (i *Inspector) NoImage() (bool, error) {
5858
//first, do a simple exact match lookup
59-
ii, err := i.APIClient.HasImage(i.ImageRef) // := dockerutil.HasImage(i.APIClient, i.ImageRef)
59+
ii, err := i.APIClient.HasImage(i.ImageRef)
6060
if err == nil {
6161
log.Tracef("image.inspector.NoImage: ImageRef=%v ImageIdentity=%#v", i.ImageRef, ii)
6262
return false, nil
@@ -73,15 +73,17 @@ func (i *Inspector) NoImage() (bool, error) {
7373
//this will return/save the first available tag
7474
if err == crt.ErrNotFound &&
7575
!strings.Contains(i.ImageRef, ":") {
76+
log.Debugf("image.inspector.NoImage: no default 'latest' tag / i.ImageRef='%s'", i.ImageRef)
7677
//check if there are any tags for the target image
77-
matches, err := i.APIClient.ListImages(i.ImageRef) // dockerutil.ListImages(i.APIClient, i.ImageRef)
78+
matches, err := i.APIClient.ListImages(i.ImageRef)
7879
if err != nil {
7980
log.Errorf("image.inspector.NoImage: err=%v", err)
8081
return true, err
8182
}
8283

84+
log.Debugf("image.inspector.NoImage: matching image tag count - %d / i.ImageRef='%s'", len(matches), i.ImageRef)
8385
for ref, props := range matches {
84-
log.Debugf("image.inspector.NoImage: match.ref=%s match.props=%#v", ref, props)
86+
log.Debugf("image.inspector.NoImage: match.ref='%s' match.props=%#v", ref, props)
8587
i.ImageRef = ref
8688
return false, nil
8789
}
@@ -122,10 +124,6 @@ func (i *Inspector) Pull(showPullLog bool, dockerConfigPath, registryAccount, re
122124
//warn, attempt pull anyway, needs to work for public registries
123125
}
124126

125-
//if authConfig == nil {
126-
// authConfig = &docker.AuthConfiguration{}
127-
//}
128-
129127
err = i.APIClient.PullImage(input, authConfig)
130128
if err != nil {
131129
log.Debugf("image.inspector.Pull: client.PullImage err=%v", err)
@@ -141,120 +139,13 @@ func (i *Inspector) Pull(showPullLog bool, dockerConfigPath, registryAccount, re
141139
return nil
142140
}
143141

144-
/*
145-
func getRegistryCredential(registryAccount, registrySecret, dockerConfigPath, registry string) (cred *docker.AuthConfiguration, err error) {
146-
if registryAccount != "" && registrySecret != "" {
147-
cred = &docker.AuthConfiguration{
148-
Username: registryAccount,
149-
Password: registrySecret,
150-
}
151-
return
152-
}
153-
154-
missingAuthConfigErr := fmt.Errorf("could not find an auth config for registry - %s", registry)
155-
if dockerConfigPath != "" {
156-
dAuthConfigs, err := docker.NewAuthConfigurationsFromFile(dockerConfigPath)
157-
if err != nil {
158-
log.Warnf(
159-
"image.inspector.Pull: getDockerCredential - failed to acquire local docker config path=%s err=%s",
160-
dockerConfigPath,
161-
err.Error(),
162-
)
163-
return nil, err
164-
}
165-
r, found := dAuthConfigs.Configs[registry]
166-
if !found {
167-
return nil, missingAuthConfigErr
168-
}
169-
cred = &r
170-
return cred, nil
171-
}
172-
173-
cred, err = docker.NewAuthConfigurationsFromCredsHelpers(registry)
174-
if err != nil {
175-
log.Warnf(
176-
"image.inspector.Pull: failed to acquire local docker credential helpers for %s err=%s",
177-
registry,
178-
err.Error(),
179-
)
180-
return nil, err
181-
}
182-
183-
// could not find a credentials' helper, check auth configs
184-
if cred == nil {
185-
dConfigs, err := docker.NewAuthConfigurationsFromDockerCfg()
186-
if err != nil {
187-
log.Debugf("image.inspector.Pull: getDockerCredential err extracting docker auth configs - %s", err.Error())
188-
return nil, err
189-
}
190-
r, found := dConfigs.Configs[registry]
191-
if !found {
192-
return nil, missingAuthConfigErr
193-
}
194-
cred = &r
195-
}
196-
197-
log.Debugf("loaded registry auth config %+v", cred)
198-
return cred, nil
199-
}
200-
*/
201-
202-
/*
203-
func extractRegistry(repo string) string {
204-
var scheme string
205-
if strings.Contains(repo, https) {
206-
scheme = https
207-
repo = strings.TrimPrefix(repo, https)
208-
}
209-
if strings.Contains(repo, http) {
210-
scheme = http
211-
repo = strings.TrimPrefix(repo, http)
212-
}
213-
registry := strings.Split(repo, "/")[0]
214-
215-
domain := `((?:[a-z\d](?:[a-z\d-]{0,63}[a-z\d])?|\*)\.)+[a-z\d][a-z\d-]{0,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9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))`
220-
221-
if registry == "localhost" || strings.Contains(registry, "localhost:") {
222-
return scheme + registry
223-
}
224-
225-
validDomain := regexp.MustCompile(domain)
226-
validIpv4 := regexp.MustCompile(ipv4)
227-
validIpv6 := regexp.MustCompile(ipv6)
228-
validIpv4WithPort := regexp.MustCompile(ipv4Port)
229-
validIpv6WithPort := regexp.MustCompile(ipv6Port)
230-
231-
if validIpv6WithPort.MatchString(registry) {
232-
return scheme + registry
233-
}
234-
if validIpv4WithPort.MatchString(registry) {
235-
return scheme + registry
236-
}
237-
if validIpv6.MatchString(registry) {
238-
return scheme + registry
239-
}
240-
if validIpv4.MatchString(registry) {
241-
return scheme + registry
242-
}
243-
244-
if !validDomain.MatchString(registry) {
245-
return https + "index.docker.io"
246-
}
247-
return scheme + registry
248-
}
249-
*/
250-
251142
// Inspect starts the target image inspection
252143
func (i *Inspector) Inspect() error {
253144
var err error
254145
i.ImageInfo, err = i.APIClient.InspectImage(i.ImageRef)
255146
if err != nil {
256147
if err == crt.ErrNotFound { // docker.ErrNoSuchImage {
257-
log.Info("could not find target image")
148+
log.Infof("could not find target image - i.ImageRef='%s'", i.ImageRef)
258149
}
259150
return err
260151
}
@@ -269,15 +160,16 @@ func (i *Inspector) Inspect() error {
269160
log.Tracef("image.Inspector.Inspect: imageList.size=%v", len(imageList))
270161
for _, r := range imageList {
271162
log.Tracef("image.Inspector.Inspect: target=%v record=%#v", i.ImageInfo.ID, r)
272-
if r.ID == i.ImageInfo.ID {
163+
if strings.Contains(i.ImageInfo.ID, r.ID) {
273164
i.ImageRecordInfo = r
274165
break
275166
}
276167
}
277168

278169
if i.ImageRecordInfo.ID == "" {
279-
log.Info("could not find target image in the image list")
280-
return crt.ErrNotFound //docker.ErrNoSuchImage
170+
log.Infof("could not find target image in the image list - i.ImageRef='%s' / i.ImageInfo.ID='%s'",
171+
i.ImageRef, i.ImageInfo.ID)
172+
return crt.ErrNotFound
281173
}
282174

283175
return nil

pkg/app/master/version/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func PrintCheckVersion(
4141
printPrefix string,
4242
info *CheckVersionInfo) {
4343
if info != nil && info.Status == "success" && info.Outdated {
44-
msg := "Your version of SlimToolkit is out of date! Use `slim update` to get the latest version."
44+
msg := "Your version of MinToolkit is out of date! Use `mint update` to get the latest version."
4545
if xc == nil {
4646
fmt.Printf("%s info=version status=OUTDATED local=%s current=%s\n", printPrefix, v.Tag(), info.Current)
4747
fmt.Printf("%s info=message message='%s'\n", printPrefix, msg)
@@ -154,7 +154,7 @@ func Print(xc *app.ExecutionContext, cmdNameParam string, logger *log.Entry, cli
154154

155155
// Check checks the app version
156156
func Check(inContainer, isDSImage bool) *CheckVersionInfo {
157-
logger := log.WithFields(log.Fields{"app": "slim"})
157+
logger := log.WithFields(log.Fields{"app": "mint"})
158158

159159
client := http.Client{
160160
Timeout: 13 * time.Second,

pkg/crt/clients.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import (
66
"regexp"
77
"strings"
88
"time"
9-
//log "github.com/sirupsen/logrus"
109
)
1110

1211
var (
13-
ErrBadParam = errors.New("bad parameter")
14-
ErrNotFound = errors.New("not found")
12+
ErrBadParam = errors.New("crt - bad parameter")
13+
ErrNotFound = errors.New("crt - not found")
1514
)
1615

1716
type ImageIdentity struct {

pkg/crt/docker/dockercrtclient/dockercrtclient.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dockercrtclient
22

33
import (
44
"fmt"
5-
"strings"
65

76
docker "github.com/fsouza/go-dockerclient"
87
log "github.com/sirupsen/logrus"
@@ -50,7 +49,7 @@ func (ref *Instance) ListImagesAll() ([]crt.BasicImageInfo, error) {
5049
var imageList []crt.BasicImageInfo
5150
for _, r := range pimages {
5251
imageList = append(imageList, crt.BasicImageInfo{
53-
ID: strings.TrimPrefix(r.ID, "sha256:"),
52+
ID: r.ID,
5453
Size: r.Size,
5554
Created: r.Created,
5655
VirtualSize: r.VirtualSize,

pkg/crt/docker/dockerutil/dockerutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ func ListImages(dclient *dockerapi.Client, imageNameFilter string) (map[string]B
190190
for _, imageInfo := range imageList {
191191
for _, repo := range imageInfo.RepoTags {
192192
info := BasicImageProps{
193-
ID: strings.TrimPrefix(imageInfo.ID, "sha256:"),
193+
ID: imageInfo.ID,
194194
Size: imageInfo.Size,
195195
Created: imageInfo.Created,
196196
}
197197

198198
if repo == "<none>:<none>" {
199-
repo = strings.TrimPrefix(imageInfo.ID, "sha256:")
199+
repo = imageInfo.ID
200200
images[repo] = info
201201
break
202202
}

pkg/crt/podman/podmancrtclient/podmancrtclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (ref *Instance) ListImagesAll() ([]crt.BasicImageInfo, error) {
5555
var imageList []crt.BasicImageInfo
5656
for _, r := range pimages {
5757
imageList = append(imageList, crt.BasicImageInfo{
58-
ID: strings.TrimPrefix(r.ID, "sha256:"),
58+
ID: r.ID,
5959
Size: r.Size,
6060
Created: r.Created,
6161
VirtualSize: r.VirtualSize,

pkg/crt/podman/podmanutil/podmanutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ func ListImages(client context.Context, imageNameFilter string) (map[string]Basi
210210
for _, imageInfo := range imageList {
211211
for _, repo := range imageInfo.RepoTags {
212212
info := BasicImageProps{
213-
ID: strings.TrimPrefix(imageInfo.ID, "sha256:"),
213+
ID: imageInfo.ID,
214214
Size: imageInfo.Size,
215215
Created: imageInfo.Created,
216216
}
217217

218218
if repo == "<none>:<none>" {
219-
repo = strings.TrimPrefix(imageInfo.ID, "sha256:")
219+
repo = imageInfo.ID
220220
images[repo] = info
221221
break
222222
}

0 commit comments

Comments
 (0)