Skip to content

Commit c2f0f92

Browse files
NVSHAS-10213: [Scanner] Handling of passwords as command arguments (20)
1 parent 74ebd8e commit c2f0f92

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

monitor/monitor.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@
3232
#define ENV_SCANNER_REGISTRY "SCANNER_REGISTRY"
3333
#define ENV_SCANNER_REPOSITORY "SCANNER_REPOSITORY"
3434
#define ENV_SCANNER_TAG "SCANNER_TAG"
35-
#define ENV_SCANNER_REG_USER "SCANNER_REGISTRY_USERNAME"
36-
#define ENV_SCANNER_REG_PASS "SCANNER_REGISTRY_PASSWORD"
3735
#define ENV_SCANNER_SCAN_LAYERS "SCANNER_SCAN_LAYERS"
3836
#define ENV_SCANNER_BASE_IMAGE "SCANNER_BASE_IMAGE"
39-
#define ENV_SCANNER_CTRL_USER "SCANNER_CTRL_API_USERNAME"
40-
#define ENV_SCANNER_CTRL_PASS "SCANNER_CTRL_API_PASSWORD"
4137
#define ENV_SCANNER_TLS_VERIFICATION "SCANNER_STANDALONE_TLS_VERIFICATION"
4238
#define ENV_SCANNER_DEBUG_MODE "SCANNER_DEBUG_MODE"
4339
#define ENV_SCANNER_PROXY_URL "PROXY_URL"
@@ -135,7 +131,7 @@ static pid_t fork_exec(int i)
135131
pid_t pid;
136132
char *args[PROC_ARGS_MAX], *join, *adv, *url;
137133
char *join_port, *adv_port;
138-
char *license, *registry, *repository, *tag, *user, *pass, *base, *api_user, *api_pass, *enable, *proxy_url;
134+
char *license, *registry, *repository, *tag, *base, *enable, *proxy_url;
139135
char *on_demand, *cache_record_max;
140136
int a;
141137

@@ -224,14 +220,6 @@ static pid_t fork_exec(int i)
224220
}
225221

226222
// The following options apply to both standalone or non-standalone mode
227-
if ((user = getenv(ENV_SCANNER_REG_USER)) != NULL) {
228-
args[a ++] = "--registry_username";
229-
args[a ++] = user;
230-
}
231-
if ((pass = getenv(ENV_SCANNER_REG_PASS)) != NULL) {
232-
args[a ++] = "--registry_password";
233-
args[a ++] = pass;
234-
}
235223
if ((base = getenv(ENV_SCANNER_BASE_IMAGE)) != NULL) {
236224
args[a ++] = "--base_image";
237225
args[a ++] = base;
@@ -241,19 +229,11 @@ static pid_t fork_exec(int i)
241229
args[a ++] = "--scan_layers";
242230
}
243231
}
244-
if ((api_user = getenv(ENV_SCANNER_CTRL_USER)) != NULL) {
245-
args[a ++] = "--ctrl_username";
246-
args[a ++] = api_user;
247-
}
248-
if ((api_pass = getenv(ENV_SCANNER_CTRL_PASS)) != NULL) {
249-
args[a ++] = "--ctrl_password";
250-
args[a ++] = api_pass;
251-
}
252232
if ((cache_record_max = getenv(ENV_SCANNER_CACHE_MAX)) != NULL) {
253233
args[a ++] = "-maxrec";
254234
args[a ++] = cache_record_max;
255235
}
256-
if ((api_pass = getenv(ENV_SCANNER_TLS_VERIFICATION)) != NULL) {
236+
if ((enable = getenv(ENV_SCANNER_TLS_VERIFICATION)) != NULL) {
257237
args[a ++] = "--enable-tls-verification";
258238
}
259239
if ((proxy_url = getenv(ENV_SCANNER_PROXY_URL)) != NULL) {

scanner.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,8 @@ func main() {
205205
registry := flag.String("registry", "", "Scan image registry")
206206
repository := flag.String("repository", "", "Scan image repository")
207207
tag := flag.String("tag", "latest", "Scan image tag (or digest like sha256:...)")
208-
regUser := flag.String("registry_username", "", "Registry username")
209-
regPass := flag.String("registry_password", "", "Registry password")
210208
scanLayers := flag.Bool("scan_layers", false, "Scan image layers")
211209
baseImage := flag.String("base_image", "", "Base image")
212-
ctrlUser := flag.String("ctrl_username", "", "Controller REST API username")
213-
ctrlPass := flag.String("ctrl_password", "", "Controller REST API password")
214210
noWait := flag.Bool("no_wait", false, "No initial wait")
215211
noTask := flag.Bool("no_task", false, "Not using scanner task")
216212
verbose := flag.Bool("x", false, "more debug")
@@ -257,6 +253,11 @@ func main() {
257253
showTaskDebug = true
258254
}
259255

256+
regUser := os.Getenv("SCANNER_REGISTRY_USERNAME")
257+
regPass := os.Getenv("SCANNER_REGISTRY_PASSWORD")
258+
ctrlUser := os.Getenv("SCANNER_CTRL_API_USERNAME")
259+
ctrlPass := os.Getenv("SCANNER_CTRL_API_PASSWORD")
260+
260261
var grpcServer *cluster.GRPCServer
261262
var ctx context.Context
262263
var internalCertControllerCancel context.CancelFunc
@@ -404,8 +405,8 @@ func main() {
404405
Registry: reg,
405406
Repository: repo,
406407
Tag: tag,
407-
Username: *regUser,
408-
Password: *regPass,
408+
Username: regUser,
409+
Password: regPass,
409410
ScanLayers: *scanLayers,
410411
ScanSecrets: false,
411412
BaseImage: *baseImage,
@@ -415,8 +416,8 @@ func main() {
415416
Registry: *registry,
416417
Repository: *repository,
417418
Tag: *tag,
418-
Username: *regUser,
419-
Password: *regPass,
419+
Username: regUser,
420+
Password: regPass,
420421
ScanLayers: *scanLayers,
421422
ScanSecrets: true,
422423
BaseImage: *baseImage,
@@ -429,7 +430,7 @@ func main() {
429430

430431
// submit scan result if join address is given
431432
if result != nil && result.Error == share.ScanErrorCode_ScanErrNone &&
432-
*join != "" && *ctrlUser != "" && *ctrlPass != "" {
433+
*join != "" && ctrlUser != "" && ctrlPass != "" {
433434
if *adv == "" {
434435
_, addr, err := cluster.ResolveJoinAndBindAddr(*join, sys)
435436
if err != nil {
@@ -444,7 +445,7 @@ func main() {
444445
joinPort = &port
445446
}
446447

447-
err := scanSubmitResult(*join, (uint16)(*joinPort), *adv, *ctrlUser, *ctrlPass, result)
448+
err := scanSubmitResult(*join, (uint16)(*joinPort), *adv, ctrlUser, ctrlPass, result)
448449
if err != nil {
449450
log.WithFields(log.Fields{"error": err}).Error("Failed to sumit scan result")
450451
} else {

0 commit comments

Comments
 (0)