You can easily protect all your public SaaS APIs as Octelium Services and provide your client-less WORKLOAD
Users such as your Golang-based microservices and applications with secret-less access to all of your APIs without having to expose, manage and share the API keys, access tokens or OAuth2 client credentials required to access such APIs. 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 with the name apikey1
that stores the bearer access token required to access the protected SaaS API as follows:
octeliumctl create secret apikey1
You can read more about Secret management here. Note that Octelium supports more HTTP authentication types other than bearer authentication. You can read more here.
Now we actually create the Service representing our SaaS API as follows:
1kind: Service2metadata:3name: my-api4spec:5mode: HTTP6isPublic: true7config:8upstream:9url: https://api.example.com10http:11auth:12bearer:13fromSecret: apikey1
You can now apply the Service as follows (read more here):
octeliumctl apply /PATH/TO/SERVICE.YAML
Now, we can use the octelium-go
library in our Golang-based application to access the Service my-api
as follows:
1package main23import (4"context"5"fmt"6"io"7"os"89"github.com/octelium/octelium/octelium-go"10)1112func main() {13if err := doMain(context.Background()); err != nil {14panic(err)15}16}1718func doMain(ctx context.Context) error {19octeliumC, err := octelium.NewClient(ctx, &octelium.ClientConfig{20Domain: "example.com",21AuthenticationToken: os.Getenv("AUTH_TOKEN"),22})23if err != nil {24return err25}2627defer octeliumC.Close()2829httpC := octeliumC.HTTP().Client()3031resp, err := httpC.Get("https://my-api.example.com/v1/resources")32if err != nil {33return err34}3536defer resp.Body.Close()37body, err := io.ReadAll(resp.Body)38fmt.Printf("Body : %s", body)3940return nil41}
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.