GithubHelp home page GithubHelp logo

confidential-containers / trustee-operator Goto Github PK

View Code? Open in Web Editor NEW
2.0 15.0 7.0 131 KB

Operator to manage the lifecycle of Trustee (KBS)

License: Apache License 2.0

Dockerfile 3.74% Makefile 20.72% Go 75.53%

trustee-operator's Introduction

trustee-operator

The trustee-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"`

// kbsResourcePolicyConfigMapName is the name of the configmap that contains the Resource Policy
	KbsResourcePolicyConfigMapName string `json:"kbsResourcePolicyConfigMapName,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"]
  # Resource policy
  kbsResourcePolicyConfigMapName: resource-policy

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.

    It is recommended to uncomment the secret generation for the trustee authorization in the kustomization.yaml, for both public and private key (kbs-auth-public-key and kbs-client secrets)

    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.

trustee-operator's People

Contributors

bpradipt avatar lmilleri avatar davidhadas avatar dependabot[bot] avatar fidencio avatar

Stargazers

Jiale Zhang avatar  avatar

Watchers

Chris Aniszczyk avatar Peng Tao avatar  avatar Jens Freimann avatar Chris Porter avatar Samuel Ortiz avatar Mikko Ylinen avatar Wainer Moschetta avatar Jiang Liu avatar Tobin Feldman-Fitzthum avatar Haidong Xia avatar James Magowan avatar  avatar Jia Zhang (乾越) avatar Arron Wang avatar

trustee-operator's Issues

Q: Does the operator perform state management?

The upstream kbs deployment recipes lack explicit state management and store resources like secrets, policies on a local container instance. There are APIs that allow altering of that pod-local state, which leads to unpredictable results. If the operator would provide facilities and defaults for explicit state (StatefulSet with Volume?) that would be good additional value, and we could point users to the operator as a default means for deploying KBS.

Add tests for trustee-operator

At least the following initial tests will be needed

  • operator install and uninstall
  • Trustee CRD creation, deletion
  • secret release
  • policy check (deny secret release due to policy deny)
  • policy check (allow secret release due to policy allow)
  • Update config, secret or policy via modifying the related K8s resources and verifying the update is reflected in the Trustee components
  • scaling trustee pods and verifying secret release, policy checks, config updatesetc

Add option to use Secrets Store CSI driver to inject secrets into KBS file store

A secret store CSI driver can be used to inject the secrets into the KBS file store. See the following blog describing how Azure Key Vault Storage is used to inject secrets into the KBS file store - https://confidentialcontainers.org/docs/key-broker-service/kbs-backed-by-akv/
Similar approach can be followed with Hashicorp vault: https://developer.hashicorp.com/vault/docs/platform/k8s/csi

This issue is to track adding support in the operator for the same

Ref: https://secrets-store-csi-driver.sigs.k8s.io/getting-started/usage.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.