Skip to content

Commit f83aed1

Browse files
committed
fix(oss-index)!: Rework OSS Index authentication
As of September 22nd, 2025, authentication will be mandatory, see [1]. Reflect that by making respective properties non-nullable. While at it, also make the `username` a non-`Secret` and use a more fitting `token` property name. While at it also remove the unauthenticated endpoint from the OSS Index client implementation completely. BREAKING CHANGE: Users need to move their configured `username` property from the `secrets` to the `options` section, and rename the `password` property to `token` in the `secrets` section. [1]: https://ossindex.sonatype.org/doc/auth-required Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent cbb580d commit f83aed1

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

clients/oss-index/src/main/kotlin/OssIndexService.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@ interface OssIndexService {
137137
val versionRanges: List<String>? = null
138138
)
139139

140-
/**
141-
* Request vulnerability reports for [components] (does not require authentication; rate limits apply).
142-
*/
143-
@POST("api/v3/component-report")
144-
suspend fun getComponentReport(@Body components: ComponentReportRequest): List<ComponentReport>
145-
146140
/**
147141
* Request vulnerability reports for [components] (requires basic authentication; rate limits are relaxed).
148142
*/

plugins/advisors/oss-index/src/main/kotlin/OssIndex.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,12 @@ class OssIndex(
7272
private val service by lazy {
7373
OssIndexService.create(
7474
config.serverUrl,
75-
config.username?.value,
76-
config.password?.value,
75+
config.username,
76+
config.token.value,
7777
OkHttpClientHelper.buildClient()
7878
)
7979
}
8080

81-
private val getComponentReport by lazy {
82-
val hasCredentials = config.username != null && config.password != null
83-
if (hasCredentials) service::getAuthorizedComponentReport else service::getComponentReport
84-
}
85-
8681
override suspend fun retrievePackageFindings(packages: Set<Package>): Map<Package, AdvisorResult> {
8782
val startTime = Instant.now()
8883

@@ -96,7 +91,7 @@ class OssIndex(
9691
logger.debug { "Getting report for ${chunk.size} components (chunk ${index + 1} of ${chunks.size})." }
9792

9893
runCatching {
99-
val results = getComponentReport(ComponentReportRequest(chunk)).associateBy {
94+
val results = service.getAuthorizedComponentReport(ComponentReportRequest(chunk)).associateBy {
10095
it.coordinates
10196
}
10297

plugins/advisors/oss-index/src/main/kotlin/OssIndexConfiguration.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ data class OssIndexConfiguration(
3434
val serverUrl: String,
3535

3636
/**
37-
* The username to use for authentication. If not both [username] and [password] are provided, authentication is
38-
* disabled.
37+
* The username to use for authentication towards the API.
3938
*/
40-
val username: Secret?,
39+
val username: String,
4140

4241
/**
43-
* The password to use for authentication. If not both [username] and [password] are provided, authentication is
44-
* disabled.
42+
* The token to use for authentication towards the API.
4543
*/
46-
val password: Secret?
44+
val token: Secret
4745
)

plugins/advisors/oss-index/src/test/kotlin/OssIndexTest.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import org.ossreviewtoolkit.model.AdvisorDetails
4444
import org.ossreviewtoolkit.model.Severity
4545
import org.ossreviewtoolkit.model.vulnerabilities.Vulnerability
4646
import org.ossreviewtoolkit.model.vulnerabilities.VulnerabilityReference
47+
import org.ossreviewtoolkit.plugins.api.Secret
4748
import org.ossreviewtoolkit.utils.common.enumSetOf
4849
import org.ossreviewtoolkit.utils.test.identifierToPackage
4950

@@ -68,7 +69,9 @@ class OssIndexTest : WordSpec({
6869
"OssIndex" should {
6970
"return vulnerability information" {
7071
server.stubComponentsRequest("response_components.json")
71-
val ossIndex = OssIndex(config = OssIndexConfiguration("http://localhost:${server.port()}", null, null))
72+
val ossIndex = OssIndex(
73+
config = OssIndexConfiguration("http://localhost:${server.port()}", "username", Secret("token"))
74+
)
7275

7376
val result = ossIndex.retrievePackageFindings(PACKAGES).mapKeys { it.key.id }
7477

@@ -113,7 +116,9 @@ class OssIndexTest : WordSpec({
113116
aResponse().withStatus(500)
114117
)
115118
)
116-
val ossIndex = OssIndex(config = OssIndexConfiguration("http://localhost:${server.port()}", null, null))
119+
val ossIndex = OssIndex(
120+
config = OssIndexConfiguration("http://localhost:${server.port()}", "username", Secret("token"))
121+
)
117122

118123
val result = ossIndex.retrievePackageFindings(PACKAGES).mapKeys { it.key.id.toCoordinates() }
119124

@@ -128,7 +133,9 @@ class OssIndexTest : WordSpec({
128133
}
129134

130135
"provide correct details" {
131-
val ossIndex = OssIndex(config = OssIndexConfiguration("http://localhost:${server.port()}", null, null))
136+
val ossIndex = OssIndex(
137+
config = OssIndexConfiguration("http://localhost:${server.port()}", "username", Secret("token"))
138+
)
132139

133140
ossIndex.details shouldBe AdvisorDetails(ADVISOR_NAME, enumSetOf(AdvisorCapability.VULNERABILITIES))
134141
}
@@ -139,7 +146,7 @@ private const val ADVISOR_NAME = "OSSIndex"
139146

140147
private val PKG_HAMCREST = identifierToPackage("Maven:org.hamcrest:hamcrest-core:1.3")
141148
private val PKG_JUNIT = identifierToPackage("Maven:junit:junit:4.12")
142-
private const val COMPONENTS_REQUEST_URL = "/api/v3/component-report"
149+
private const val COMPONENTS_REQUEST_URL = "/api/v3/authorized/component-report"
143150
private val PACKAGES = setOf(PKG_HAMCREST, PKG_JUNIT)
144151

145152
private val COMPONENTS_REQUEST_JSON =

0 commit comments

Comments
 (0)