• Stars
    star
    146
  • Rank 245,519 (Top 5 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Kubernetes mutating webhook for `secrets-init` injection

code Docker Pulls

Blog Post

Kubernetes and Secrets Management In The Cloud

kube-secrets-init

The kube-secrets-init is a Kubernetes mutating admission webhook, that mutates any K8s Pod that is using specially prefixed environment variables, directly or from Kubernetes as Secret or ConfigMap.

kube-secrets-init mutation

The kube-secrets-init injects a copy-secrets-init initContainer into a target Pod, mounts /helper/bin (default; can be changed with the volume-path flag) and copies the secrets-init tool into the mounted volume. It also modifies Pod entrypoint to secrets-init init system, following original command and arguments, extracted either from Pod specification or from Docker image.

skip injection

The kube-secrets-init can be configured to skip injection for all Pods in the specific Namespace by adding the admission.secrets-init/ignore label to the Namespace.

What secrets-init does

secrets-init runs as PID 1, acting like a simple init system. It launches a single process and then proxies all received signals to a session rooted at that child process.

secrets-init also passes almost all environment variables without modification, replacing secret variables with values from secret management services.

Integration with AWS Secrets Manager

User can put AWS secret ARN as environment variable value. The secrets-init will resolve any environment value, using specified ARN, to referenced secret value.

# environment variable passed to `secrets-init`
MY_DB_PASSWORD=arn:aws:secretsmanager:$AWS_REGION:$AWS_ACCOUNT_ID:secret:mydbpassword-cdma3

# environment variable passed to child process, resolved by `secrets-init`
MY_DB_PASSWORD=very-secret-password

Integration with AWS Systems Manager Parameter Store

It is possible to use AWS Systems Manager Parameter Store to store application parameters and secrets.

User can put AWS Parameter Store ARN as environment variable value. The secrets-init will resolve any environment value, using specified ARN, to referenced parameter value.

# environment variable passed to `secrets-init`
MY_API_KEY=arn:aws:ssm:$AWS_REGION:$AWS_ACCOUNT_ID:parameter/api/key

# environment variable passed to child process, resolved by `secrets-init`
MY_API_KEY=key-123456789

Integration with Google Secret Manager

User can put Google secret name (prefixed with gcp:secretmanager:) as environment variable value. The secrets-init will resolve any environment value, using specified name, to referenced secret value.

# environment variable passed to `secrets-init`
MY_DB_PASSWORD=gcp:secretmanager:projects/$PROJECT_ID/secrets/mydbpassword
# OR versioned secret (with version or 'latest')
MY_DB_PASSWORD=gcp:secretmanager:projects/$PROJECT_ID/secrets/mydbpassword/versions/2

# environment variable passed to child process, resolved by `secrets-init`
MY_DB_PASSWORD=very-secret-password

Requirement

AWS

In order to resolve AWS secrets from AWS Secrets Manager and Parameter Store, secrets-init should run under IAM role that has permission to access desired secrets.

This can be achieved by assigning IAM Role to Kubernetes Pod. It's possible to assign IAM Role to EC2 instance, where container is running, but this option is less secure.

Google Cloud

In order to resolve Google secrets from Google Secret Manager, secrets-init should run under IAM role that has permission to access desired secrets. For example, you can assign the following 2 predefined Google IAM roles to a Google Service Account: Secret Manager Viewer and Secret Manager Secret Accessor role.

This can be achieved by assigning IAM Role to Kubernetes Pod with Workload Identity. It's possible to assign IAM Role to GCE instance, where container is running, but this option is less secure.

Uncomment --provider=google flag in the deployment.yaml file.

The kube-secrets-init deployment

Deploy with Helm Chart

Consider using the kube-secrets-init Helm Chart, authored and managed by Márk Sági-Kazár.

helm repo add skm https://charts.sagikazarmark.dev
helm install --generate-name --wait skm/kube-secrets-init

Check chart GitHub repository

Manual Deployment

  1. To deploy the kube-secrets-init server, we need to create a webhook service and a deployment in our Kubernetes cluster. It’s pretty straightforward, except one thing, which is the server’s TLS configuration. If you’d care to examine the deployment.yaml file, you’ll find that the certificate and corresponding private key files are read from command line arguments, and that the path to these files comes from a volume mount that points to a Kubernetes secret:
[...]
      args:
      [...]
      - --tls-cert-file=/etc/webhook/certs/cert.pem
      - --tls-private-key-file=/etc/webhook/certs/key.pem
      volumeMounts:
      - name: webhook-certs
        mountPath: /etc/webhook/certs
        readOnly: true
[...]
   volumes:
   - name: webhook-certs
     secret:
       secretName: secrets-init-webhook-certs

The most important thing to remember is to set the corresponding CA certificate later in the webhook configuration, so the apiserver will know that it should be accepted. For now, we’ll reuse the script originally written by the Istio team to generate a certificate signing request. Then we’ll send the request to the Kubernetes API, fetch the certificate, and create the required secret from the result.

First, run webhook-create-signed-cert.sh script and check if the secret holding the certificate and key has been created:

./deployment/webhook-create-signed-cert.sh

creating certs in tmpdir /var/folders/vl/gxsw2kf13jsf7s8xrqzcybb00000gp/T/tmp.xsatrckI71
Generating RSA private key, 2048 bit long modulus
.........................+++
....................+++
e is 65537 (0x10001)
certificatesigningrequest.certificates.k8s.io/secrets-init-webhook-svc.default created
NAME                         AGE   REQUESTOR              CONDITION
secrets-init-webhook-svc.default   1s    [email protected]   Pending
certificatesigningrequest.certificates.k8s.io/secrets-init-webhook-svc.default approved
secret/secrets-init-webhook-certs configured

Note For the GKE Autopilot, run the webhook-create-self-signed-cert.sh script to generate a self-signed certificate.

Export the CA Bundle as a new environment variable CA_BUNDLE:

export CA_BUNDLE=[output value of the previous script "Encoded CA:"]

Once the secret is created, we can create deployment and service. These are standard Kubernetes deployment and service resources. Up until this point we’ve produced nothing but an HTTP server that’s accepting requests through a service on port 443:

kubectl create -f deployment/deployment.yaml

kubectl create -f deployment/service.yaml

configure mutating admission webhook

Now that our webhook server is running, it can accept requests from the apiserver. However, we should create some configuration resources in Kubernetes first. Let’s start with our validating webhook, then we’ll configure the mutating webhook later. If you take a look at the webhook configuration, you’ll notice that it contains a placeholder for CA_BUNDLE:

[...]
      service:
        name: secrets-init-webhook-svc
        namespace: default
        path: "/pods"
      caBundle: ${CA_BUNDLE}
[...]

There is a small script that substitutes the CA_BUNDLE placeholder in the configuration with this CA. Run this command before creating the validating webhook configuration:

cat ./deployment/mutatingwebhook.yaml | ./deployment/webhook-patch-ca-bundle.sh > ./deployment/mutatingwebhook-bundle.yaml

Create mutating webhook configuration:

kubectl create -f deployment/mutatingwebhook-bundle.yaml

configure RBAC for secrets-init-webhook

Create Kubernetes Service Account to be used with secrets-init-webhook:

kubectl create -f deployment/service-account.yaml

Define RBAC permission for webhook service account:

# create a cluster role
kubectl create -f deployment/clusterrole.yaml
# define a cluster role binding
kubectl create -f deployment/clusterrolebinding.yaml

More Repositories

1

kube-no-trouble

Easily check your clusters for use of deprecated APIs
Go
2,812
star
2

kubeip

Assign static public IPs to Kubernetes nodes (GKE, EKS)
Go
379
star
3

bigquery-grafana

Google BigQuery Datasource Plugin for Grafana. (NO LONGER MAINTAINED)
TypeScript
240
star
4

gcpinstances.info

GCPinstances.info source code
Python
170
star
5

secrets-init

minimalistic init system for containers with AWS/GCP secrets support
Go
156
star
6

zorya

Google Cloud Instance Scheduler helping to reduce costs by 60% on average for non-production environments.
JavaScript
141
star
7

secure-gcp-reference

Best practice example for secure and compliant Google Cloud Platform infrastructure
98
star
8

gSlack

Get Slack notifications from Google Cloud Platform
JavaScript
72
star
9

iris3

An upgraded and improved version of the Iris automatic GCP-labeling project
Python
68
star
10

gtoken

Securely access AWS services from GKE cluster
Go
67
star
11

SafeScrub

Safely delete unwanted resources in a GCP project, clearing clutter and saving money.
Shell
65
star
12

bigquery-optimization-queries

Queries to assist with BigQuery cost and performance.
Python
56
star
13

gpu-finder

Python
55
star
14

banias

Opinionated serverless event analytics pipeline
Go
43
star
15

janus

Janus is a simple way to assume AWS Role with Google Cloud Service Account
Python
38
star
16

ClusterCloner

Clone Kubernetes clusters (VM infrastructure, not K8s objects) to/from AWS EKS, GCP GKE, and Azure EKS.
Go
31
star
17

doit-composer-airflow-training

Getting started with Apache Airflow on Cloud Composer
Python
29
star
18

bq-snitch

Get visibility into expensive Google BigQuery queries on Slack
Python
27
star
19

gke-fundamentals-workshop

Shell
25
star
20

bqtop

Visualizing BigQuery query jobs with Cloud Functions, Firebase and Pub/Sub
JavaScript
25
star
21

CloudBlaster

Kotlin
22
star
22

AWSlack

Get Slack notifications on AWS CloudWatch events
JavaScript
19
star
23

Cloud-Tasks-In-Process-Emulator

Google doesn't offer an emulator for the Cloud Tasks API, as it does for Datastore or PubSub. This project answers that need with a single short Python module intended to be copied to your codebase.
Python
18
star
24

gcp-monitoring-metric-exporter

Python
17
star
25

workload-identity-analyzer

A tool to analyze a workload running in GKE and make sure that Workload Identity is configured properly
Python
16
star
26

dataflow-kafka-to-bq

Dataflow template which read data from Kafka (Support SSL), transform, and outputs the resulting records to BigQuery
Java
12
star
27

cloud-catalog

Extract categories and services (as unified JSON) for major public cloud services.
Python
11
star
28

doit-easily-marketplace

Python
10
star
29

AI-Platform-Notebook-Using-Custom-Container

Example for using AI platform notebook - custom container from scratch.
Shell
10
star
30

gcs-stats

Easily analyze the size of Google Cloud Storage buckets regardless of their size
JavaScript
10
star
31

aws-eks-sample-templates

The repository contains the sample templates to get started with AWS EKS quickly
9
star
32

secrets-consumer-webhook

Kubernetes mutation webhook for secrets-consumer-env - Automatically inject secrets to Pod
Go
9
star
33

gke-https-redirect

Demonstration how to use the newly introduced https redirect support in native GKE ingress resources.
9
star
34

terraform-iac-demo

GitOps demo of Terraform infrastructure as code (IaC)
HCL
8
star
35

gcp-discover-orphaned-firewall-rules

Find orphaned firewall rules that are not applied to any VM instances in a shared VPC
Go
8
star
36

esop

Employee Stock Option Plan
8
star
37

eks-spot-to-ondemand-fallback

7
star
38

terraform-bq-scheduled-queries

This is a demo project to use Terraform to manage BigQuery scheduled queries with Cloud Build CI/CD
HCL
6
star
39

long_john_silver

Long running background tasks on cloud run
Go
6
star
40

bi-engine-statistics

a opinionated bi engine statistics dashboard for dashboard
LookML
6
star
41

ignite-gke

Running Apache Ignite on GKE the "right" way
Java
6
star
42

bq-snitch-app

Get visibility into expensive Google BigQuery queries on Slack
Python
6
star
43

terraform-gcp-templates

Generic Terraform GCP templates
HCL
5
star
44

azure-instances.info

HTML
5
star
45

QuickQuickstarts

The simplest quickstart scripts for running multiple web backend infrastructures in AWS and GCP.
Shell
5
star
46

dataflow-bigquery-schema-migrator-insert

Dataflow Bigquery Schema Migrator Insert
Java
5
star
47

spotzero

Update EC2 Auto Scaling groups in AWS account to use Spot instances.
Go
4
star
48

validating-admission-policy-playground

4
star
49

galactus

A tool for detecting unused Service Accounts and Service Account Keys on GCP
Python
4
star
50

gcp-alerting-cis-benchmarks

Configuration instructions for Cloud Monitoring alerts on Google Cloud Platform for additional security based on CIS benchmarks
4
star
51

private_cloud_sql

4
star
52

intercloud-throughput

Python
4
star
53

secrets-consumer-env

Consume secrets securely from AWS, GCP and Hashicorp Vault secret managers
Go
3
star
54

ec2-auto-tag

Python
3
star
55

elasticsearch-gke

Blueprint for creating production-grade ElasticSearch deployments with Elastic K8s Operator
Makefile
3
star
56

ferent

Clojure
3
star
57

cre-playbooks

A collection of playbooks to help CREs solve problems more efficiently
3
star
58

docs-gitbook-cmp

ARCHIVED: GitBook repository for the DoiT Cloud Management Platform (CMP) User Documentation
Shell
3
star
59

docops

Common resources for doing DocOps at DoiT
Python
3
star
60

terraform-provider-doit-console

Terraform provider for DoiT API platform
Go
3
star
61

doit-eks-lens-helm-chart

Smarty
3
star
62

Security-Checklist-for-Workspace-Admins

A tool for Workspace administrators to review their security posture and inventory the admin SDK.
JavaScript
3
star
63

docops-devcontainer

DocOps devcontainer
2
star
64

next23-genai-demo

Jupyter Notebook
2
star
65

gke-ssh

HCL
2
star
66

platform-iac

DoiT platform infrastructure as a code templates
HCL
2
star
67

gcp-python-auth

Python
2
star
68

cloud-run-go-boilerplate

Go
2
star
69

GCP-Workshop

GCP Workshops
2
star
70

calculate-cloudfront-aos

Calculate CloudFront Average Object Size (AOS) using Cost Explorer API
Python
2
star
71

gceinstances

Inspired by ec2instances.info, this is a summary page for Google Compute Engine instances
HTML
2
star
72

docops-python

DoiT International DocOps Python library and CLI program
Shell
2
star
73

mysql-57-eol

Documents to help guide customers through MySQL 5.7 End of life
2
star
74

cf-google-cloud

Creating Google Cloud resources using AWS CloudFormation
Java
2
star
75

tf-fundamentals-workshop-101

Basic workshop on the topic of Terraform in the context of AWS
HCL
2
star
76

looker-cph-event

LookML
1
star
77

robust-multicloud

Kotlin
1
star
78

help

DoiT International Help Center and product documentation
JavaScript
1
star
79

secret-manager-nodejs-example

JavaScript
1
star
80

assembly-pipeline

Shell
1
star
81

cloudbuild-demo

JavaScript
1
star
82

demo-gke-pubsub-consumer

JavaScript
1
star
83

clojure-exercises

Clojure
1
star
84

poc-gcp-nextflow

Nextflow + GCP + LifeSciencesAPI + Compute Engine + NextflowTower + Workflows
1
star
85

app-engine-firebase-identity

BYO Identity through Firebase
Python
1
star
86

dynamodb-lens

Python
1
star
87

cloudrun-cloudsql-psc

Accessing CloudSQL with Private Service Connect enabled from Cloud Run
1
star
88

zen-dog

Tool to sync crucial zendesk configuration from code
1
star
89

gcp-auto-tag

Python
1
star
90

locust-demo

Python
1
star
91

GCP-Custom-metric-monitoring

Easy python script to publish custom metrics to stackdriver
Python
1
star
92

GCP-DR-Checklist

Disaster Recovery Plan - Checklist
1
star
93

gke-node-autoscheduler-poc

HCL
1
star
94

next24-genai-demo

Gen AI Demo for Google Next'24. This is a RAG system with Agents to retrieve project specific cost and combine it with DoiT blog posts to deliver a analysis on how to reduce cost.
Jupyter Notebook
1
star
95

eks-lens-agent

Go
1
star
96

aws-help

Help Docs for DoIT AWS Customers
1
star
97

gcp-qms

Quota Monitoring Solution support files for Google Cloud Platform
Shell
1
star
98

developer-envs

HCL
1
star
99

simple-cloud-run

Sometimes it's amazing how simple Google Cloud can be - this time Cloud Run
Go
1
star
100

terraform-provider-doit

Terraform provider for DoiT API platform
Go
1
star