You can easily protect access to all your Kubernetes clusters as Octelium Services and provide your client-less WORKLOAD
Users such as your Golang-based microservices and applications with secret-less access without having to expose, manage and share Kubeconfigs, mTLS client private keys or access tokens required to access such Kubernetes clusters. In this short guide, we're going to use the Golang SDK (read more here) to access a generic HTTP SaaS API that requires a bearer access token.
We first create a Secret that contains the kubeconfig file required to access the Kubernetes cluster (read more here) as follows:
octeliumctl create secret kubeconfig-k8s1 --file /PATH/TO/KUBECONFIG
Note that Octelium also supports secret-less access to Kubernetes clusters via access tokens and mTLS client certificates. You can read more here.
Now we create the KUBERNETES
Service representing our Kubernetes cluster that needs to be protected as follows:
1kind: Service2metadata:3name: k8s14spec:5mode: KUBERNETES6config:7upstream:8url: https://k8s-cluster.example.com:64439kubernetes:10kubeconfig:11fromSecret: kubeconfig-k8s1
You can now apply the Service k8s1
as follows:
octeliumctl apply /PATH/TO/SERVICE.YAML
We can now easily use the octelium-go
library and automatically feed its HTTP client into the NewForConfigAndClient()
function to create a kubernetes client as follows:
1package main23import (4"context"5"fmt"6"os"78"github.com/octelium/octelium/octelium-go"9v1 "k8s.io/apimachinery/pkg/apis/meta/v1"10"k8s.io/client-go/kubernetes"11"k8s.io/client-go/rest"12)1314func main() {15if err := doMain(context.Background()); err != nil {16panic(err)17}18}1920func doMain(ctx context.Context) error {21octeliumC, err := octelium.NewClient(ctx, &octelium.ClientConfig{22Domain: "example.com",23AuthenticationToken: os.Getenv("AUTH_TOKEN"),24})25if err != nil {26return err27}2829defer octeliumC.Close()3031k8sC, err := kubernetes.NewForConfigAndClient(&rest.Config{32Host: "k8s-cluster-01.example.com",33}, octeliumC.HTTP().Client())34if err != nil {35return err36}3738podList, err := k8sC.CoreV1().Pods("").List(ctx, v1.ListOptions{})39if err != nil {40return err41}42fmt.Printf("podList = %+v\n", podList)4344return nil45}
It's important to note that the Go-SDK is not the only way to access publicly exposed BeyondCorp Services. You can also use the OAuth2 client credentials flow to access any such Service (read more here). This enables your applications and microservices written in any language to access the Cluster's Services via standard OAuth2 libraries that are supported in most major programming languages without having to use any clients or use specific SDKs. You can also generate an access token Credential and use it directly as a standard bearer token (read more here).