kbs-operator

command module
v0.0.0-...-e23cde5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

kbs-operator

The kbs-operator manages the lifecycle of trustee along with it's configuration when deployed in a Kubernetes cluster

Description

The operator manages a Kubernetes custom resource named: KbsConfig. Following are the key fields of the KbsConfig custom resource definition

type KbsConfigSpec struct {

  // KbsConfigMapName is the name of the configmap that contains the KBS configuration
  KbsConfigMapName string `json:"kbsConfigMapName,omitempty"`

  // KbsAsConfigMapName is the name of the configmap that contains the KBS AS configuration
  KbsAsConfigMapName string `json:"kbsAsConfigMapName,omitempty"`

  // KbsRvpsConfigMapName is the name of the configmap that contains the KBS RVPS configuration
  KbsRvpsConfigMapName string `json:"kbsRvpsConfigMapName,omitempty"`

  // kbsRvpsRefValuesConfigMapName is the name of the configmap that contains the RVPS reference values
  KbsRvpsRefValuesConfigMapName string `json:"kbsRvpsRefValuesConfigMapName,omitempty"`

  // KbsAuthSecretName is the name of the secret that contains the KBS auth secret
  KbsAuthSecretName string `json:"kbsAuthSecretName,omitempty"`

  // KbsServiceType is the type of service to create for KBS
  KbsServiceType corev1.ServiceType `json:"kbsServiceType,omitempty"`

  // KbsDeploymentType is the type of KBS deployment
  // It can assume one of the following values:
  //    AllInOneDeployment: all the KBS components will be deployed in the same container
  //    MicroservicesDeployment: all the KBS components will be deployed in separate containers (part of the same Kubernetes pod)
  KbsDeploymentType DeploymentType `json:"kbsDeploymentType,omitempty"`
 
  // KbsHttpsKeySecretName is the name of the secret that contains the KBS https private key
  KbsHttpsKeySecretName string `json:"kbsHttpsKeySecretName,omitempty"`

  // KbsHttpsCertSecretName is the name of the secret that contains the KBS https certificate
  KbsHttpsCertSecretName string `json:"kbsHttpsCertSecretName,omitempty"`

  // KbsHttpsKeySecretName is the name of the secret that contains the KBS https private key
  KbsHttpsKeySecretName string `json:"kbsHttpsKeySecretName,omitempty"`

  // KbsSecretResources is an array of secret names that contain the keys required by clients
  KbsSecretResources []string `json:"kbsSecretResources,omitempty"`
}

Note: the default deployment type is MicroservicesDeployment. The examples below apply to this mode.

An example configmap for the KBS configuration looks like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: kbs-config-grpc
  namespace: kbs-operator-system
data:
  kbs-config.json: |
    {
        "insecure_http" : false,
        "sockets": ["0.0.0.0:8080"],
        "auth_public_key": "/etc/auth-secret/kbs.pem",
        "private_key": "/etc/https-key/key.pem",
        "certificate": "/etc/https-cert/cert.pem",
        "attestation_token_config": {
          "attestation_token_type": "CoCo"
        },
        "grpc_config" : {
          "as_addr": "http://127.0.0.1:50004"
        }
    }

If HTTPS support is not needed, please set insecure_http=true and no need to specify the attributes private_key and certificate.

An example configmap for AS config looks like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: as-config-grpc
  namespace: kbs-operator-system
data:
  as-config.json: |
    {
        "work_dir": "/opt/confidential-containers/attestation-service",
        "policy_engine": "opa",
        "rvps_config": {
           "remote_addr":"http://127.0.0.1:50003"
        },
        "attestation_token_broker": "Simple",
        "attestation_token_config": {
          "duration_min": 5
        }
    }

Currently these configmaps needs to be created during deployment. In subsequent releases we'll look into having these configmaps created by the operator based on user inputs.

A sample KbsConfig custom resource

apiVersion: confidentialcontainers.org/v1alpha1
kind: KbsConfig
metadata:  
  name: kbsconfig-sample
  namespace: kbs-operator-system
spec:
  # KBS configuration
  kbsConfigMapName: kbs-config
  # AS configuration
  kbsAsConfigMapName: as-config  
  # RVPS configuration
  kbsRvpsConfigMapName: rvps-config-grpc
  # reference values config map
  kbsRvpsReferenceValuesMapName: rvps-reference-values
  # authentication secret
  kbsAuthSecretName: kbs-auth-public-key
  # service type
  kbsServiceType: ClusterIP
  # deployment type
  kbsDeploymentType: MicroservicesDeployment
  # HTTPS support
  kbsHttpsKeySecretName: kbs-https-key
  kbsHttpsCertSecretName: kbs-https-certificate
  # K8s Secrets to be made available to KBS clients
  kbsSecretResources: ["kbsres1"]

Getting Started

You’ll need a Kubernetes cluster to run against. You can use KIND to get a local cluster for testing, or run against a remote cluster. Note: Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster kubectl cluster-info shows).

Running on the cluster
  • Export env variables.

    Set REGISTRY environment variable to point to your container registry. For example:

    export REGISTRY=quay.io/user
    
  • Build and push your image to the location specified by IMG.

    make docker-build docker-push IMG=${REGISTRY}/kbs-operator:latest
    

    Change the tag from latest to any other based on your requirements. Also ensure that the image is public.

  • Deploy the controller to the cluster with the image specified by IMG.

    make deploy IMG=${REGISTRY}/kbs-operator:latest
    
  • Deployment of CRDs, ConfigMaps and Secrets

    This is an example. Change it to real values as per your requirements.

    cd config/samples/microservices
    # or config/samples/all-in-one for the integrated mode
    
    # create authentication keys
    openssl genpkey -algorithm ed25519 > privateKey
    openssl pkey -in privateKey -pubout -out kbs.pem
    
    # create all the needed resources
    kubectl apply -k .
    

    Among various things, the command above is also responsible for injecting reference values into the RVPS component. The default json file is an empty sequence, but you may want to inject real values by applying a ConfigMap like the one below:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: rvps-reference-values
      namespace: kbs-operator-system
    data:
      reference-values.json: |
        apiVersion: v1
        kind: ConfigMap
        metadata:
          name: rvps-reference-values
          namespace: kbs-operator-system
        data:
          reference-values.json: |
            [
              {
                "name": "sample.svn",
                "expired": "2025-01-01T00:00:00Z",
                "hash-value": [
                  {
                    "alg": "sha256",
                    "value": "1"
                  }
                ]
              }
            ]
    

    It is also possible to create the K8s secrets (a commented out example is provided in the kustomization.yaml). To enable the secrets you'd need to uncomment the relevant secret generator entry and patch.

Uninstall CRDs

To delete the CRDs from the cluster:

make uninstall
Undeploy controller

UnDeploy the controller from the cluster:

make undeploy

Contributing

Contributions are most welcome. Please take a look at the guide for more details.

How it works

This project aims to follow the Kubernetes Operator pattern.

It uses Controllers, which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.

Test It Out
  • Install the CRDs into the cluster.

    make install
    
  • Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):

    make run
    

NOTE: You can also run this in one step by running: make install run

Modifying the API definitions

If you are editing the API definitions, generate the manifests such as CRs or CRDs using:

make manifests

NOTE: Run make --help for more information on all potential make targets

More information can be found via the Kubebuilder Documentation

License

Copyright Confidential Containers Contributors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
v1alpha1
Package v1alpha1 contains API Schema definitions for the v1alpha1 API group +kubebuilder:object:generate=true +groupName=confidentialcontainers.org
Package v1alpha1 contains API Schema definitions for the v1alpha1 API group +kubebuilder:object:generate=true +groupName=confidentialcontainers.org

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL