From 0aefa074763e8e4cde0c5cd5af1bf0037ecdbab9 Mon Sep 17 00:00:00 2001 From: attiasas Date: Wed, 7 Oct 2026 10:27:24 +0300 Subject: [PATCH 1/3] Pass project key to indexer app --- commands/scan/scan.go | 1 + sca/bom/indexer/indexerbom.go | 15 ++++++++++++- sca/bom/indexer/indexerbom_test.go | 35 +++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/commands/scan/scan.go b/commands/scan/scan.go index a7ac6289a..04899e1f9 100644 --- a/commands/scan/scan.go +++ b/commands/scan/scan.go @@ -393,6 +393,7 @@ func (scanCmd *ScanCommand) prepareForScan(cmdResults *results.SecurityCommandRe indexer.WithXray(xrayManager, scanCmd.xrayVersion), indexer.WithBypassArchiveLimits(scanCmd.bypassArchiveLimits), indexer.WithServerDetails(scanCmd.serverDetails), + indexer.WithProjectKey(scanCmd.resultsContext.ProjectKey), ).PrepareGenerator() }) } else { diff --git a/sca/bom/indexer/indexerbom.go b/sca/bom/indexer/indexerbom.go index 3d1871302..4ea1090a1 100644 --- a/sca/bom/indexer/indexerbom.go +++ b/sca/bom/indexer/indexerbom.go @@ -32,7 +32,8 @@ const ( // #nosec G101 -- Not credentials. XrayPasswordEnvVariable = "JFROG_XRAY_PASSWORD" // #nosec G101 -- Not credentials. - XrayTokenEnvVariable = "JFROG_XRAY_TOKEN" + XrayTokenEnvVariable = "JFROG_XRAY_TOKEN" + XrayProjectKeyEnvVariable = "JFROG_XRAY_PROJECT" ) // IndexerBomGenerator is a BomGenerator that uses the Xray Indexer to generate a CycloneDX SBOM. @@ -40,6 +41,7 @@ const ( type IndexerBomGenerator struct { bypassArchiveLimits bool serverDetails *config.ServerDetails + projectKey string xrayManager *xray.XrayServicesManager xrayVersion string @@ -77,6 +79,14 @@ func WithServerDetails(serverDetails *config.ServerDetails) bom.SbomGeneratorOpt } } +func WithProjectKey(projectKey string) bom.SbomGeneratorOption { + return func(sg bom.SbomGenerator) { + if ibg, ok := sg.(*IndexerBomGenerator); ok { + ibg.projectKey = projectKey + } + } +} + func (ibg *IndexerBomGenerator) WithOptions(options ...bom.SbomGeneratorOption) bom.SbomGenerator { for _, option := range options { option(ibg) @@ -145,6 +155,9 @@ func (ibg *IndexerBomGenerator) getIndexerEnvVars() utils.EnvironmentVariables { platformEnv[XrayPasswordEnvVariable] = ibg.serverDetails.Password } } + if ibg.projectKey != "" { + platformEnv[XrayProjectKeyEnvVariable] = ibg.projectKey + } if len(platformEnv) == 0 { return nil } diff --git a/sca/bom/indexer/indexerbom_test.go b/sca/bom/indexer/indexerbom_test.go index 0f5f068d3..d728ad51e 100644 --- a/sca/bom/indexer/indexerbom_test.go +++ b/sca/bom/indexer/indexerbom_test.go @@ -12,13 +12,14 @@ func TestGetIndexerEnvVars(t *testing.T) { tests := []struct { name string serverDetails *config.ServerDetails + projectKey string wantKeys map[string]string wantAbsent []string }{ { name: "nil server details", serverDetails: nil, - wantAbsent: []string{XrayUrlEnvVariable, XrayUserEnvVariable, XrayPasswordEnvVariable, XrayTokenEnvVariable}, + wantAbsent: []string{XrayUrlEnvVariable, XrayUserEnvVariable, XrayPasswordEnvVariable, XrayTokenEnvVariable, XrayProjectKeyEnvVariable}, }, { name: "access token preferred", @@ -32,7 +33,7 @@ func TestGetIndexerEnvVars(t *testing.T) { XrayUrlEnvVariable: "https://xray.example/", XrayTokenEnvVariable: "tok", }, - wantAbsent: []string{XrayUserEnvVariable, XrayPasswordEnvVariable}, + wantAbsent: []string{XrayUserEnvVariable, XrayPasswordEnvVariable, XrayProjectKeyEnvVariable}, }, { name: "user and password", @@ -46,13 +47,35 @@ func TestGetIndexerEnvVars(t *testing.T) { XrayUserEnvVariable: "u", XrayPasswordEnvVariable: "p", }, - wantAbsent: []string{XrayTokenEnvVariable}, + wantAbsent: []string{XrayTokenEnvVariable, XrayProjectKeyEnvVariable}, + }, + { + name: "project key with access token", + serverDetails: &config.ServerDetails{ + XrayUrl: "https://xray.example/", + AccessToken: "tok", + }, + projectKey: "my-project", + wantKeys: map[string]string{ + XrayUrlEnvVariable: "https://xray.example/", + XrayTokenEnvVariable: "tok", + XrayProjectKeyEnvVariable: "my-project", + }, + wantAbsent: []string{XrayUserEnvVariable, XrayPasswordEnvVariable}, + }, + { + name: "project key without server details", + projectKey: "my-project", + wantKeys: map[string]string{ + XrayProjectKeyEnvVariable: "my-project", + }, + wantAbsent: []string{XrayUrlEnvVariable, XrayUserEnvVariable, XrayPasswordEnvVariable, XrayTokenEnvVariable}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ibg := &IndexerBomGenerator{serverDetails: tt.serverDetails} + ibg := &IndexerBomGenerator{serverDetails: tt.serverDetails, projectKey: tt.projectKey} env := ibg.getIndexerEnvVars() for k, v := range tt.wantKeys { assert.Equal(t, v, env[k], "key %s", k) @@ -61,8 +84,8 @@ func TestGetIndexerEnvVars(t *testing.T) { _, ok := env[k] assert.False(t, ok, "key %s should be absent", k) } - // When server details are set, env must include process env (PATH at minimum). - if tt.serverDetails != nil { + // When platform env is set, env must include process env (PATH at minimum). + if tt.serverDetails != nil || tt.projectKey != "" { require.NotEmpty(t, env["PATH"]) } }) From ab10c20c77e6a8722e03542e848bd6d98c5827fe Mon Sep 17 00:00:00 2001 From: attiasas Date: Wed, 7 Oct 2026 10:30:33 +0300 Subject: [PATCH 2/3] update to JFROG_XRAY_PROJECT_KEY --- sca/bom/indexer/indexerbom.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sca/bom/indexer/indexerbom.go b/sca/bom/indexer/indexerbom.go index 4ea1090a1..0789a84a0 100644 --- a/sca/bom/indexer/indexerbom.go +++ b/sca/bom/indexer/indexerbom.go @@ -33,7 +33,7 @@ const ( XrayPasswordEnvVariable = "JFROG_XRAY_PASSWORD" // #nosec G101 -- Not credentials. XrayTokenEnvVariable = "JFROG_XRAY_TOKEN" - XrayProjectKeyEnvVariable = "JFROG_XRAY_PROJECT" + XrayProjectKeyEnvVariable = "JFROG_XRAY_PROJECT_KEY" ) // IndexerBomGenerator is a BomGenerator that uses the Xray Indexer to generate a CycloneDX SBOM. From b25ceb350dce39842d6816d5a30965195fcbdc60 Mon Sep 17 00:00:00 2001 From: attiasas Date: Wed, 7 Oct 2026 12:11:58 +0300 Subject: [PATCH 3/3] fix unrelated test fail and format --- commands/curation/curationaudit_test.go | 16 ++++++++-------- scans_test.go | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/commands/curation/curationaudit_test.go b/commands/curation/curationaudit_test.go index fe4882cc1..fc35db1d9 100644 --- a/commands/curation/curationaudit_test.go +++ b/commands/curation/curationaudit_test.go @@ -679,14 +679,14 @@ func getTestCasesForDoCurationAudit() []testCase { pathToProject: filepath.Join("projects", "package-managers", "go", "curation-project"), createServerWithoutCreds: true, serveResources: map[string]string{ - "v1.5.2.mod": filepath.Join("resources", "quote-v1.5.2.mod"), - "v1.5.2.zip": filepath.Join("resources", "quote-v1.5.2.zip"), - "v1.5.2.info": filepath.Join("resources", "quote-v1.5.2.info"), - "v1.3.0.mod": filepath.Join("resources", "sampler-v1.3.0.mod"), - "v1.3.0.zip": filepath.Join("resources", "sampler-v1.3.0.zip"), - "v1.3.0.info": filepath.Join("resources", "sampler-v1.3.0.info"), - "v0.0.0-20170915032832-14c0d48ead0c.mod": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.mod"), - "v0.0.0-20170915032832-14c0d48ead0c.zip": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.zip"), + "v1.5.2.mod": filepath.Join("resources", "quote-v1.5.2.mod"), + "v1.5.2.zip": filepath.Join("resources", "quote-v1.5.2.zip"), + "v1.5.2.info": filepath.Join("resources", "quote-v1.5.2.info"), + "v1.3.0.mod": filepath.Join("resources", "sampler-v1.3.0.mod"), + "v1.3.0.zip": filepath.Join("resources", "sampler-v1.3.0.zip"), + "v1.3.0.info": filepath.Join("resources", "sampler-v1.3.0.info"), + "v0.0.0-20170915032832-14c0d48ead0c.mod": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.mod"), + "v0.0.0-20170915032832-14c0d48ead0c.zip": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.zip"), "v0.0.0-20170915032832-14c0d48ead0c.info": filepath.Join("resources", "text-v0.0.0-20170915032832-14c0d48ead0c.info"), }, // example.com/localmod is a tripwire, not an expected call: it's local-replaced and must never diff --git a/scans_test.go b/scans_test.go index b83817a45..dffd1b079 100644 --- a/scans_test.go +++ b/scans_test.go @@ -223,7 +223,7 @@ func TestXrayBinaryScanSelectiveScan(t *testing.T) { validate: func(t *testing.T, issueCount validations.ValidationCountActualValues) { // Expect SCA vulnerabilities and contextual analysis statuses assert.GreaterOrEqual(t, issueCount.ScaVulnerabilities, 17, "SCA vulnerabilities count mismatch - should be 17 or more") - assert.Equal(t, 3, issueCount.ApplicableVulnerabilities, "Applicable vulnerabilities count mismatch - should be 3") + assert.Equal(t, 4, issueCount.ApplicableVulnerabilities, "Applicable vulnerabilities count mismatch - should be 4") assert.Equal(t, 4, issueCount.UndeterminedVulnerabilities, "Undetermined vulnerabilities count mismatch - should be 4") // All other vulnerability types should be 0 assert.Equal(t, 0, issueCount.SecretsVulnerabilities, "Secrets vulnerabilities count mismatch - should be 0")