Code Monkey home page Code Monkey logo

spiffe-demo-app's Introduction

SPIFFE Demo App

SPIFFE Demo application is a simple demo app that uses SPIFFE Workload API. The app consists of two parts: frontend and backend. Frontend provides simple functionality to view the content of SPIFFE X509-SVID, JWT-SVID, and SPIFFE Trust Bundle through simple UI.

You can use it to troubleshoot things like SPIFFE federation (because you can see the trust bundle content):

SPIFFE trust bundle content

Or easily view X509-SVID or JWT-SVID details:

X509-SVID details

Prerequisites

You'll need kubectl and helm installed. Follow the official documentation for both projects on how to install them:

Usage

Add SPIFFE Demo Helm Chart

helm repo add spiffe-demo https://spirl.github.io/spiffe-demo-app

Install the chart

$ helm install spiffe-demo spiffe-demo/spiffe-demo-app

NAME: spiffe-demo
LAST DEPLOYED: Wed May 24 10:34:58 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

That will install the app in the default namespace. If you want to install to a different namespace, you need to add --create-namespace flag to the above command:

$ helm install spiffe-demo spiffe-demo/spiffe-demo-app --namespace foo --create-namespace

NAME: spiffe-demo
LAST DEPLOYED: Wed May 24 10:39:28 2024
NAMESPACE: foo
STATUS: deployed
REVISION: 1
TEST SUITE: None

Connect to the frontend

The easiest way to use kubernetes port forwarding:

$ kubectl port-forward  svc/spiffe-demo-service 8080:80

Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080

If you installed a specific namespace - don't forget about `--namespace flag.

Now you can point your browser to http://localhost:8080 to reach a frontend.

Uninstall

> helm delete spiffe-demo

Example of using with SPIRE Helm Chart

SPIFFE community support SPIRE Helm Chart which provides a way to install SPIRE in k8s cluster for a quick start. Check for the latest version of SPIRE Helm Chart installation instructions here.

I'll use kind as an example but you can use any other k8s distribution with a little bit of adjusment (e.g. don't use port-forwarding)

1. Create kind cluster

$ kind create cluster --name spire-demo
Creating cluster "spire-demo" ...
 โœ“ Ensuring node image (kindest/node:v1.26.3) ๐Ÿ–ผ
 โœ“ Preparing nodes ๐Ÿ“ฆ
 โœ“ Writing configuration ๐Ÿ“œ
 โœ“ Starting control-plane ๐Ÿ•น๏ธ
 โœ“ Installing CNI ๐Ÿ”Œ
 โœ“ Installing StorageClass ๐Ÿ’พ
Set kubectl context to "kind-spire-demo"
You can now use your cluster with:

kubectl cluster-info --context kind-spire-demo

2. Install SPIRE Helm Charts

Install SPIRE:

helm upgrade --install -n spire-server spire-crds spire-crds --repo https://spiffe.github.io/helm-charts-hardened/ --create-namespace
helm upgrade --install -n spire-server spire spire --repo https://spiffe.github.io/helm-charts-hardened/

3. Install spiffe-demo-app

SPIRE Helm Chart by default uses SPIFFE Workload API socket with a name spire-agent.sock. However, spiffe-demo-app by default expects the name for a socket agent.sock. Therefore we need to change it.

To install SPIFFE Demo App you can use the following command with a few parameters or you may choose to set them in your values.yaml for a helm chart.

helm upgrade --install spiffe-demo spiffe-demo-app --repo https://elinesterov.github.io/spiffe-demo-app -n spiffe-demo --create-namespace --set app.spiffeSocketName=spire-agent.sock --set app.spiffeCSIDriverInjectionEnabled=false --set app.spiffeCSIDriverVolume=true
  • app.spiffeSocketName - is a name of the SPIFFE Workload API socket that is exposed by SPIFFE Agent. By default, SPIRE Helm Chart uses spire-agent.sock name for the socket. However, spiffe-demo-app expects agent.sock name. Therefore we need to change it.

  • app.spiffeCSIDriverInjectionEnabled - is a flag that enables or disables the SPIRL COntroller Manager that injects SPIFFE CSIDriver Volume and env variable. Since SPIRE Helm Cart doesn't have such a feature we need to disable it.

  • app.spiffeCSIDriverVolume - flag that enables SPIFFE CSI Driver Volume mount and also set SPIFFE_ENDPOINT_SOCKET environment variable to the path of the SPIFFE Workload API socket. This is required for the spiffe-demo-app to connect to the SPIFFE Agent. Since we cannot use SPIRL Controller Manager with SPIRE we should manually set these values.

4. Connecting to the spiffe-demo-app

Since we use kind cluster in this example, the easiest way to connect to a frontend is by using kubectl port-frowarding feature. If you use minikube, eks or any other flavour of k8s you might be able to use node port or LoadBalancer.

With kind run the following command to enable port-frwarding to the spiffe-demo-app frontend:

$ kubectl -n spiffe-demo port-forward  svc/spiffe-demo-service 8080:80

Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080

Now you can point your browser to http://localhost:8080 to connect to the frontend. Clock buttons to see JWT-SVID, X509-SVID and expore SPIFFE Trust Bundle in a very simple way.

5. Using busybox for troubleshooting

Sometimes you need to run a few simple shell commands to list mounted agent socket content or for any other reason. We have busybox container withtin the spiffe-demo-app deployemnt that is disabled by default. In order to enable it you can add --set app.enableBusybox=true when installing spiffe-demo-app helm chart.

6. Cleaning up

Cleaning up is simple:

helm -n spiffe-demo delete spiffe-demo
helm -n spire delete spire
kubectl delete namespace spire
kubectl delete namespace spiffe-demo
kind delete cluster --name spire-dem

or you can just execute the lates command in case of kind.

Values

See charts/spiffe-demo-app/README.md

spiffe-demo-app's People

Contributors

elinesterov avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

spiffe-demo-app's Issues

Chart for the demo-app failed to add the environment variable for the socket or the volume

After adding the helm repository for the demo-app, installing the chart applies the following manifests:

helm template -n spiffe-demo spiffe-demo  spiffe-demo/spiffe-demo-app --set app.spiffeSocketName=spire-agent.sock        
---
# Source: spiffe-demo-app/templates/sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: spiffe-demo-app
  namespace: spiffe-demo
---
# Source: spiffe-demo-app/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: spiffe-demo-service
  namespace: spiffe-demo
spec:
  selector:
    app: spiffe-demo-app
  ports:
    - name: http
      port: 80
      targetPort: 8080
  
  type: LoadBalancer
---
# Source: spiffe-demo-app/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: spiffe-demo-app
  namespace: spiffe-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: spiffe-demo-app
  template:
    metadata:
      labels:
        app: spiffe-demo-app
        k8s.spirl.com/spiffe-csi: enabled
    spec:
      serviceAccountName: spiffe-demo-app
      containers:
      - name: spiffe-demo-app
        image: ghcr.io/elinesterov/spiffe-demo-app:v0.2.2
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080

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.