-
Notifications
You must be signed in to change notification settings - Fork 8
fix: fall back to TLS trust when cluster CA path is missing #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4f62070
fix: add missing ApiClientUtils import in DevWorkspacePodsTest
adietish 3bfcede
fix: use CA field in TLS trust resolution and sequentially show TLS t…
adietish 3e3a88d
fix: preserve default trust roots for OpenShift TLS
f8523b9
fix: validate OpenShift auth with SelfSubjectAccessReview
5ff6bef
fix: complete connection when remote IDE is already present
d233bab
test: align Projects and TLS tests with OpenShift OAuth fixes
adietish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,6 @@ build | |
| .DS_Store | ||
| .intellijPlatform/ | ||
| .kotlin/ | ||
| .vscode/ | ||
| .opencode/ | ||
| .serena/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/kotlin/com/redhat/devtools/gateway/auth/code/HttpClientExtensions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright (c) 2026 Red Hat, Inc. | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Red Hat, Inc. - initial API and implementation | ||
| */ | ||
| package com.redhat.devtools.gateway.auth.code | ||
|
|
||
| import kotlinx.coroutines.future.await | ||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
| import kotlinx.serialization.json.Json | ||
| import java.net.URI | ||
| import java.net.http.HttpClient | ||
| import java.net.http.HttpRequest | ||
| import java.net.http.HttpResponse | ||
|
|
||
| private val json = Json { ignoreUnknownKeys = true } | ||
|
|
||
| @Serializable | ||
| data class AccessTokenResponseJson( | ||
| @SerialName("access_token") val accessToken: String, | ||
| @SerialName("expires_in") val expiresIn: Long = 0L, | ||
| @SerialName("id_token") val idToken: String = "" | ||
| ) | ||
|
|
||
| suspend fun HttpClient.sendGetRequest( | ||
| url: String, | ||
| errorPrefix: String = "Request to $url failed" | ||
| ): HttpResponse<String> { | ||
| val request = HttpRequest.newBuilder() | ||
| .uri(URI.create(url)) | ||
| .timeout(java.time.Duration.ofSeconds(30)) | ||
| .GET() | ||
| .build() | ||
| val response = sendAsync(request, HttpResponse.BodyHandlers.ofString()).await() | ||
| if (response.statusCode() !in 200..299) { | ||
| error("$errorPrefix: ${response.statusCode()}\n${response.body()}") | ||
| } | ||
| return response | ||
| } | ||
|
|
||
| suspend fun HttpClient.sendPostRequest( | ||
| url: String, | ||
| authHeader: String, | ||
| formBody: String, | ||
| errorPrefix: String = "Request to $url failed" | ||
| ): AccessTokenResponseJson { | ||
| val request = HttpRequest.newBuilder() | ||
| .uri(URI(url)) | ||
| .timeout(java.time.Duration.ofSeconds(30)) | ||
| .header("Authorization", authHeader) | ||
| .header("Content-Type", "application/x-www-form-urlencoded") | ||
| .header("Accept", "application/json") | ||
| .POST(HttpRequest.BodyPublishers.ofString(formBody)) | ||
| .build() | ||
| val response = sendAsync(request, HttpResponse.BodyHandlers.ofString()).await() | ||
| if (response.statusCode() !in 200..299) { | ||
| error("$errorPrefix: ${response.statusCode()}\n${response.body()}") | ||
| } | ||
| return json.decodeFromString(AccessTokenResponseJson.serializer(), response.body()) | ||
| } | ||
68 changes: 68 additions & 0 deletions
68
src/main/kotlin/com/redhat/devtools/gateway/auth/code/OAuthDiscovery.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Copyright (c) 2026 Red Hat, Inc. | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Red Hat, Inc. - initial API and implementation | ||
| */ | ||
| package com.redhat.devtools.gateway.auth.code | ||
|
|
||
| import com.intellij.openapi.diagnostic.thisLogger | ||
| import com.redhat.devtools.gateway.util.toServerBaseUrl | ||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
| import kotlinx.serialization.json.Json | ||
| import java.net.URI | ||
| import java.net.http.HttpClient | ||
| import javax.net.ssl.SSLContext | ||
|
|
||
| private val json = Json { ignoreUnknownKeys = true } | ||
|
|
||
| @Serializable | ||
| data class OAuthMetadata( | ||
| val issuer: String, | ||
| @SerialName("authorization_endpoint") | ||
| val authorizationEndpoint: String, | ||
| @SerialName("token_endpoint") | ||
| val tokenEndpoint: String | ||
| ) | ||
|
|
||
| class OAuthDiscovery( | ||
| apiServerUrl: String, | ||
| sslContext: SSLContext, | ||
| private val client: HttpClient = HttpClient.newBuilder() | ||
| .sslContext(sslContext) | ||
| .version(HttpClient.Version.HTTP_1_1) | ||
| .followRedirects(HttpClient.Redirect.NORMAL) | ||
| .build() | ||
| ) { | ||
|
|
||
| private val discoveryUrl = "$apiServerUrl/.well-known/oauth-authorization-server" | ||
|
|
||
| suspend fun discoverOAuthMetadata(): OAuthMetadata { | ||
| val response = client.sendGetRequest(discoveryUrl) | ||
| return json.decodeFromString(OAuthMetadata.serializer(), response.body()) | ||
| } | ||
|
|
||
| suspend fun endpointBaseUrls(): List<String> { | ||
| thisLogger().info("TLS trust: discovering OAuth endpoints from $discoveryUrl") | ||
| val md = try { | ||
| discoverOAuthMetadata() | ||
| } catch (e: Exception) { | ||
| thisLogger().error("TLS trust: OAuth discovery request to $discoveryUrl failed", e) | ||
| throw e | ||
| } | ||
| val urls = listOf(md.tokenEndpoint, md.authorizationEndpoint) | ||
| .map { URI(it).toServerBaseUrl() } | ||
| .distinct() | ||
| thisLogger().info( | ||
| "TLS trust: OAuth discovery succeeded (issuer=${md.issuer}, " + | ||
| "endpoints=${urls.joinToString()})" | ||
| ) | ||
| return urls | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.