contents

         preface

         acknowledgments

         about this book

         about the authors

         about the cover illustration

Part 1. Overview

  1 Microservices security landscape

How security works in a monolithic application

Challenges of securing microservices

The broader the attack surface, the higher the risk of attack

Distributed security screening may result in poor performance

Deployment complexities make bootstrapping trust among microservices a nightmare

Requests spanning multiple microservices are harder to trace

Immutability of containers challenges how you maintain service credentials and access-control policies

The distributed nature of microservices makes sharing user context harder

Polyglot architecture demands more security expertise on each development team

Key security fundamentals

Authentication protects your system against spoofing

Integrity protects your system from data tampering

Nonrepudiation: Do it once, and you own it forever

Confidentiality protects your systems from unintended information disclosure

Availability: Keep the system running, no matter what

Authorization: Nothing more than you’re supposed to do

Edge security

The role of an API gateway in a microservices deployment

Authentication at the edge

Authorization at the edge

Passing client/end-user context to upstream microservices

Securing service-to-service communication

Service-to-service authentication

Service-level authorization

Propagating user context among microservices

Crossing trust boundaries

  2 First steps in securing microservices

Building your first microservice

Downloading and installing the required software

Clone samples repository

Compiling the Order Processing microservice

Accessing the Order Processing microservice

What is inside the source code directory?

Understanding the source code of the microservice

Setting up an OAuth 2.0 server

The interactions with an authorization server

Running the OAuth 2.0 authorization server

Getting an access token from the OAuth 2.0 authorization server

Understanding the access token response

Securing a microservice with OAuth 2.0

Security based on OAuth 2.0

Running the sample

Invoking a secured microservice from a client application

Performing service-level authorization with OAuth 2.0 scopes

Obtaining a scoped access token from the authorization server

Protecting access to a microservice with OAuth 2.0 scopes

Part 2. Edge security

  3 Securing north/south traffic with an API gateway

The need for an API gateway in a microservices deployment

Decoupling security from the microservice

The inherent complexities of microservice deployments make them harder to consume

The rawness of microservices does not make them ideal for external exposure

Security at the edge

Understanding the consumer landscape of your microservices

Delegating access

Why not basic authentication to secure APIs?

Why not mutual TLS to secure APIs?

Why OAuth 2.0?

Setting up an API gateway with Zuul

Compiling and running the Order Processing microservice

Compiling and running the Zuul proxy

Enforcing OAuth 2.0-based security at the Zuul gateway

Securing communication between Zuul and the microservice

Preventing access through the firewall

Securing the communication between the API gateway and microservices by using mutual TLS

  4 Accessing a secured microservice via a single-page application

Running a single-page application with Angular

Building and running an Angular application from the source code

Looking behind the scenes of a single-page application

Setting up cross-origin resource sharing

Using the same-origin policy

Using cross-origin resource sharing

Inspecting the source that allows cross-origin requests

Proxying the resource server with an API gateway

Securing a SPA with OpenID Connect

Understanding the OpenID Connect login flow

Inspecting the code of the applications

Using federated authentication

Multiple trust domains

Building trust between domains

  5 Engaging throttling, monitoring, and access control

Throttling at the API gateway with Zuul

Quota-based throttling for applications

Fair usage policy for users

Applying quota-based throttling to the Order Processing microservice

Maximum handling capacity of a microservice

Operation-level throttling

Throttling the OAuth 2.0 token and authorize endpoints

Privilege-based throttling

Monitoring and analytics with Prometheus and Grafana

Monitoring the Order Processing microservice

Behind the scenes of using Prometheus for monitoring

Enforcing access-control policies at the API gateway with Open Policy Agent

Running OPA as a Docker container

Feeding the OPA engine with data

Feeding the OPA engine with access-control policies

Evaluating OPA policies 132Next steps in using OPA

Part 3. Service-to-service communications

  6 Securing east/west traffic with certificates

Why use mTLS?

Building trust between a client and a server with a certificate authority

Mutual TLS helps the client and the server to identify each other

HTTPS is HTTP over TLS

Creating certificates to secure access to microservices

Creating a certificate authority

Generating keys for the Order Processing microservice

Generating keys for the Inventory microservice

Using a single script to generate all the keys

Securing microservices with TLS

Running the Order Processing microservice over TLS

Running the Inventory microservice over TLS

Securing communications between two microservices with TLS

Engaging mTLS

Challenges in key management

Key provisioning and bootstrapping trust

Certificate revocation

Key rotation

Monitoring key usage

  7 Securing east/west traffic with JWT

Use cases for securing microservices with JWT

Sharing user context between microservices with a shared JWT

Sharing user context with a new JWT for each service-to-service interaction

Sharing user context between microservices in different trust domains

Self-issued JWTs

Nested JWTs

Setting up an STS to issue a JWT

Securing microservices with JWT

Using JWT as a data source for access control

Securing service-to-service communications with JWT

Exchanging a JWT for a new one with a new audience

  8 Securing east/west traffic over gRPC

Service-to-service communications over gRPC

Securing gRPC service-to-service communications with mTLS

Securing gRPC service-to-service communications with JWT

  9 Securing reactive microservices

Why reactive microservices?

Setting up Kafka as a message broker

Developing a microservice to push events to a Kafka topic

Developing a microservice to read events from a Kafka topic

Using TLS to protect data in transit

Creating and signing the TLS keys and certificates for Kafka

Configuring TLS on the Kafka server

Configuring TLS on the microservices

Using mTLS for authentication

Controlling access to Kafka topics with ACLs

Enabling ACLs on Kafka and identifying the clients

Defining ACLs on Kafka

Setting up NATS as a message broker

Part 4. Secure deployment

10 Conquering container security with Docker

Running the security token service on Docker

Managing secrets in a Docker container

Externalizing secrets from Docker images

Passing secrets as environment variables

Managing secrets in a Docker production deployment

Using Docker Content Trust to sign and verify Docker images

The Update Framework

Docker Content Trust

Generating keys

Signing with DCT

Signature verification with DCT

Types of keys used in DCT

How DCT protects the client application from replay attacks

Running the Order Processing microservice on Docker

Running containers with limited privileges

Running a container with a nonroot user

Dropping capabilities from the root user

Running Docker Bench for security

Securing access to the Docker host

Enabling remote access to the Docker daemon

Enabling mTLS at the NGINX server to secure access to Docker APIs

Considering security beyond containers

11 Securing microservices on Kubernetes

Running an STS on Kubernetes

Defining a Kubernetes Deployment for the STS in YAML

Creating the STS Deployment in Kubernetes

Troubleshooting the Deployment

Exposing the STS outside the Kubernetes cluster

Managing secrets in a Kubernetes environment

Using ConfigMap to externalize configurations in Kubernetes

Defining a ConfigMap for application.properties file

Defining ConfigMaps for keystore.jks and jwt.jks files

Defining a ConfigMap for keystore credentials

Creating ConfigMaps by using the kubectl client

Consuming ConfigMaps from a Kubernetes Deployment

Loading keystores with an init container

Using Kubernetes Secrets

Exploring the default token secret in every container

Updating the STS to use Secrets

Understanding how Kubernetes stores Secrets

Running the Order Processing microservice in Kubernetes

Creating ConfigMaps/Secrets for the Order Processing microservice

Creating a Deployment for the Order Processing microservice

Creating a Service for the Order Processing microservice

Testing the end-to-end flow

Running the Inventory microservice in Kubernetes

Using Kubernetes service accounts

Creating a service account and associating it with a Pod

Benefits of running a Pod under a custom service account

Using role-based access control in Kubernetes

Talking to the Kubernetes API server from the STS

Associating a service account with a ClusterRole

12 Securing microservices with Istio service mesh

Setting up the Kubernetes deployment

Enabling Istio autoinjection

Clean up any previous work

Deploying microservices

Redeploying Order Processing and STS as NodePort Services

Testing end-to-end flow

Enabling TLS termination at the Istio Ingress gateway

Deploying TLS certificates to the Istio Ingress gateway

Deploying VirtualServices

Defining a permissive authentication policy

Testing end-to-end flow

Securing service-to-service communications with mTLS

Securing service-to-service communications with JWT

Enforcing JWT authentication

Testing end-to-end flow with JWT authentication

Peer authentication and request authentication

How to use JWT in service-to-service communications

A closer look at JSON Web Key

Enforcing authorization

A closer look at the JWT

Enforcing role-based access control

Testing end-to-end flow with RBAC

Improvements to role-based access control since Istio 1.4.0

Managing keys in Istio

Key provisioning and rotation via volume mounts

Limitations in key provisioning and rotation via volume mounts

Key provisioning and rotation with SDS

Part 5. Secure development

13 Secure coding practices and automation

OWASP API security top 10

Broken object-level authorization

Broken authentication

Excessive data exposure

Lack of resources and rate limiting

Broken function-level authorization

Mass assignment

Security misconfiguration

Injection

Improper asset management

Insufficient logging and monitoring

Running static code analysis

Integrating security testing with Jenkins

Setting up and running Jenkins

Setting up a build pipeline with Jenkins

Running dynamic analysis with OWASP ZAP

Passive scanning vs. active scanning

Performing penetration tests with ZAP

Appendixes

Appendix A. OAuth 2.0 and OpenID Connect

Appendix B. JSON Web Token

Appendix C. Single-page application architecture

Appendix D. Observability in a microservices deployment

Appendix E. Docker fundamentals

Appendix F. Open Policy Agent

Appendix G. Creating a certificate authority and related keys with OpenSSL

Appendix H. Secure Production Identity Framework for Everyone

Appendix I. gRPC fundamentals

Appendix J. Kubernetes fundamentals

Appendix K. Service mesh and Istio fundamentals

index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.218.147