Coder Social home page Coder Social logo

brightzheng100 / tls-example-apps Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emalm/tls-example-apps

0.0 2.0 0.0 39 KB

Example Cloud Foundry applications that communicate directly over mutual TLS

Makefile 3.64% Go 91.42% Shell 4.94%

tls-example-apps's Introduction

TLS Example Apps

This collection of example applications contains a pair of applications designed to communicate directly over HTTP and to verify each other using Cloud Foundry instance-identity credentials.

Dependencies

  • CF CLI, v6.30.0 or later
  • CF user with the network.write scope, to set network policies

Deploy to Cloud Foundry

Clone this repository and make the frontend and backend binaries:

git clone https://github.com/emalm/tls-example-apps.git
cd tls-example-apps
make all

Set up a base domain for apps:

apps_domain=bosh-lite.com # change for your environment

Push the backend app:

cf push backend -p bin/linux/backend -b binary_buildpack -c './backend' -m 32M -k 32M -i 2 --no-start

Push the 'green' copy of the frontend app and grant it access to the backend app:

cf push frontend-green -p bin/linux/frontend -b binary_buildpack -c './frontend' -m 32M -k 32M -i 2 --no-start
cf set-env frontend-green BACKEND_DISCOVERY_URL "http://backend.${apps_domain}"

cf add-network-policy frontend-green --destination-app backend --protocol tcp --port 9999

Push the 'blue' copy of the frontend app and grant it access to the backend app:

cf push frontend-blue -p bin/linux/frontend -b binary_buildpack -c './frontend' -m 32M -k 32M -i 2 --no-start
cf set-env frontend-blue BACKEND_DISCOVERY_URL "http://backend.${apps_domain}"

cf add-network-policy frontend-blue --destination-app backend --protocol tcp --port 9999

Configure the backend app to authorize the 'green' frontend app:

FRONTEND_GREEN_APP_GUID=$(cf app frontend-green --guid)
FRONTEND_BLUE_APP_GUID=$(cf app frontend-blue --guid)

cf set-env backend AUTHORIZED_APP_GUIDS "[\"$FRONTEND_GREEN_APP_GUID\"]"

Start the apps:

cf start backend
cf start frontend-green
cf start frontend-blue

Make requests to the frontend apps:

curl https://frontend-green.${apps_domain}
curl https://frontend-blue.${apps_domain}

The 'green' frontend app will report success, and the 'blue' one will report failure.

Reconfigure the backend to authorize the 'blue' frontend instead:

cf set-env backend AUTHORIZED_APP_GUIDS "[\"$FRONTEND_GREEN_APP_GUID\"]"
cf restart backend

Now requests to the 'blue' frontend will succeed, and those to the 'green' frontend will fail.

CF Deployment Configuration

The CF deployment must be configured to use container networking and to enable the Diego cells to generate instance-identity credentials. Version v0.31.0 of cf-deployment with the enable-instance-identity-credentials operations file will be configured this way.

Local Development

make all

CERT_RELOAD_INTERVAL=10s \
CF_INSTANCE_GUID=backend-1 \
CF_INSTANCE_INTERNAL_IP=127.0.0.1 \
CF_INSTANCE_CERT=creds/server.crt \
CF_INSTANCE_KEY=creds/server.key \
CA_CERT_FILE=creds/ca.crt \
./bin/darwin/backend/backend

PORT=8081 \
CERT_RELOAD_INTERVAL=10s \
CF_INSTANCE_CERT=creds/client.crt \
CF_INSTANCE_KEY=creds/client.key \
CA_CERT_FILE=creds/ca.crt \
./bin/darwin/frontend/frontend

curl http://127.0.0.1:8081

TODO

  • Once CF Container Networking provides polyglot service discovery natively, remove the public instance-discovery route on the backend app in favor of app-guid-based infrastructure DNS.

tls-example-apps's People

Contributors

emalm avatar takeyourhatoff avatar

Watchers

James Cloos avatar Bright Zheng avatar

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.