-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: option to disable node viewer in enterprise deployments (#14879)
- Loading branch information
Showing
8 changed files
with
363 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
42 changes: 42 additions & 0 deletions
42
...ver/src/main/kotlin/io/airbyte/commons/server/helpers/KubernetesClientPermissionHelper.kt
This file contains 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,42 @@ | ||
package io.airbyte.commons.server.helpers | ||
|
||
import io.fabric8.kubernetes.api.model.Node | ||
import io.fabric8.kubernetes.api.model.NodeList | ||
import io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReview | ||
import io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReviewSpec | ||
import io.fabric8.kubernetes.client.KubernetesClient | ||
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation | ||
import io.fabric8.kubernetes.client.dsl.Resource | ||
import jakarta.inject.Inject | ||
import jakarta.inject.Singleton | ||
|
||
class PermissionDeniedException(message: String) : RuntimeException(message) | ||
|
||
@Singleton | ||
class KubernetesClientPermissionHelper | ||
@Inject | ||
constructor( | ||
private val kubernetesClient: KubernetesClient, | ||
) { | ||
fun listNodes(): NonNamespaceOperation<Node, NodeList, Resource<Node>>? { | ||
if (!allowedToListNodes()) { | ||
throw PermissionDeniedException("Permission denied: unable to list Kubernetes nodes.") | ||
} | ||
return kubernetesClient.nodes() | ||
} | ||
|
||
private fun allowedToListNodes(): Boolean { | ||
val review = SelfSubjectAccessReview() | ||
review.spec = | ||
SelfSubjectAccessReviewSpec().apply { | ||
resourceAttributes = | ||
io.fabric8.kubernetes.api.model.authorization.v1.ResourceAttributes().apply { | ||
verb = "list" | ||
resource = "nodes" | ||
} | ||
} | ||
|
||
val response = kubernetesClient.authorization().v1().selfSubjectAccessReview().create(review) | ||
return response.status?.allowed ?: false | ||
} | ||
} |
This file contains 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
Oops, something went wrong.