### Running One-Command Autocert Installation Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md This command executes a one-time Kubernetes job to install `autocert` automatically. It uses the `smallstep/autocert-init` image to perform the necessary setup within the cluster. ```bash kubectl run autocert-init -it --rm --image smallstep/autocert-init --restart Never ``` -------------------------------- ### Installing Smallstep Autocert via Helm (Bash) Source: https://github.com/smallstep/autocert/blob/master/README.md These commands install autocert using the Helm package manager. First, the Smallstep Helm chart repository is added, then the local Helm repositories are updated, and finally, autocert is installed from the smallstep chart. ```Bash helm repo add smallstep https://smallstep.github.io/helm-charts/ helm repo update helm install smallstep/autocert ``` -------------------------------- ### Installing Smallstep Autocert via Kubectl (Bash) Source: https://github.com/smallstep/autocert/blob/master/README.md This command installs autocert using kubectl by running a one-off initialization container. It pulls the autocert-init image and executes it to set up the necessary components in the Kubernetes cluster. ```Bash kubectl run autocert-init -it --rm --image cr.smallstep.com/smallstep/autocert-init --restart Never ``` -------------------------------- ### Verifying Autocert Installation in Kubernetes (Shell) Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md These commands verify the successful installation of `autocert`. The first command checks if the `ca` and `controller` pods are running in the `step` namespace, while the second confirms that the `autocert-webhook-config` mutation webhook has been registered. ```Shell kubectl -n step get pods NAME READY STATUS RESTARTS AGE ca-7577d7d667-vtfq5 1/1 Running 0 1m controller-86bd99bd96-s9zlc 1/1 Running 0 28s kubectl get mutatingwebhookconfiguration NAME CREATED AT autocert-webhook-config 2019-01-17T22:57:57Z ``` -------------------------------- ### Creating Kubernetes Namespace for Autocert Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md This command creates a new Kubernetes namespace named `step`. This namespace will house the `step` CA and the `autocert` controller, providing a dedicated environment for their deployment. ```bash kubectl create namespace step ``` -------------------------------- ### Verifying Kubernetes Prerequisites Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md This snippet verifies that `kubectl` is installed and the Kubernetes cluster meets the minimum version requirement (1.9+) with admission webhooks enabled, which are necessary for `autocert` to function correctly. ```bash kubectl version --short Client Version: v1.13.1 Server Version: v1.10.11 kubectl api-versions | grep "admissionregistration.k8s.io/v1beta1" admissionregistration.k8s.io/v1beta1 ``` -------------------------------- ### Deploying mTLS Client and Server with Kubernetes Source: https://github.com/smallstep/autocert/blob/master/examples/hello-mtls/README.md This command deploys the built mTLS server and client applications to a Kubernetes cluster. It applies the respective YAML configuration files, which define the necessary Kubernetes resources to run these services. This enables the deployment and orchestration of the mTLS examples within a Kubernetes environment. ```Shell kubectl apply -f hello-mtls.server.yaml kubectl apply -f hello-mtls.client.yaml ``` -------------------------------- ### Installing Autocert Controller in Kubernetes (Shell) Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md This command installs the core `autocert` controller components into the Kubernetes cluster by applying the provided YAML manifest from the official GitHub repository. It sets up the necessary deployments and services for `autocert` to function. ```Shell kubectl apply -f https://raw.githubusercontent.com/smallstep/autocert/master/install/02-autocert.yaml ``` -------------------------------- ### Verifying Step CLI Version Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md This command checks the installed version of the `step` CLI tool. A minimum version of `0.18.2` is required for manual `autocert` installation. ```bash step version Smallstep CLI/0.18.2 (darwin/amd64) Release Date: 2022-03-30 06:08 UTC ``` -------------------------------- ### Initializing Step CA for Autocert Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md This command initializes a new `step` Certificate Authority with specific configurations for `autocert`. It sets the CA name, DNS names for the CA service, listening address, and defines an 'admin' provisioner. It also prompts for a password to encrypt key material. ```bash step ca init \ --name Autocert \ --dns "ca.step.svc.cluster.local,127.0.0.1" \ --address ":4443" \ --provisioner admin \ --with-ca-url "ca.step.svc.cluster.local" ``` -------------------------------- ### Verifying Kubernetes and Admission Webhook Prerequisites (Bash) Source: https://github.com/smallstep/autocert/blob/master/README.md This snippet demonstrates how to verify the kubectl client and server versions, and confirm that Kubernetes admission webhooks are enabled. It ensures the environment meets the basic requirements for autocert installation. ```Bash $ kubectl version Client Version: v1.26.1 Kustomize Version: v4.5.7 Server Version: v1.25.3 $ kubectl api-versions | grep "admissionregistration.k8s.io/v1" admissionregistration.k8s.io/v1 ``` -------------------------------- ### Creating Kubernetes ConfigMaps for CA Artifacts Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md These commands create three Kubernetes ConfigMaps in the `step` namespace. They store the CA's configuration, certificates, and encrypted secrets (key material), making them accessible to the `step` CA pod. ```bash kubectl -n step create configmap config --from-file $(step path)/config kubectl -n step create configmap certs --from-file $(step path)/certs kubectl -n step create configmap secrets --from-file $(step path)/secrets ``` -------------------------------- ### Applying Step CA Kubernetes Manifest Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md This command applies the main Kubernetes manifest for the `step` CA from a remote URL. This manifest defines the necessary deployments, services, and other Kubernetes resources to run the `step` CA within the cluster. ```bash kubectl apply -f https://raw.githubusercontent.com/smallstep/autocert/master/install/01-step-ca.yaml ``` -------------------------------- ### Adding Autocert Provisioner to Step CA Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md This command adds a new provisioner named 'autocert' to the `step` CA. This provisioner will be used by the `autocert` controller to issue certificates. The command will prompt for a password for the 'autocert' provisioner. ```bash step ca provisioner add autocert --create ``` -------------------------------- ### Building Docker Images for mTLS Client and Server Source: https://github.com/smallstep/autocert/blob/master/examples/hello-mtls/README.md This command builds Docker images for both the mTLS server and client components. It leverages multi-stage Docker builds, allowing the creation of self-contained images without requiring local dependencies beyond Docker itself. The `-f` flag specifies the Dockerfile, and `-t` tags the resulting image for easy identification. ```Shell docker build -f Dockerfile.server -t hello-mtls-server- . docker build -f Dockerfile.client -t hello-mtls-client- . ``` -------------------------------- ### Building Autocert Container Images - Shell Source: https://github.com/smallstep/autocert/blob/master/README.md These commands build the four core Docker container images for the Autocert project: `autocert-controller`, `autocert-bootstrapper`, `autocert-renewer`, and `autocert-init`. They utilize multi-stage builds and require Docker to be installed. Each command specifies the target image name, tag, and the path to its respective Dockerfile. ```Shell docker build -t smallstep/autocert-controller:latest -f controller/Dockerfile . docker build -t smallstep/autocert-bootstrapper:latest -f bootstrapper/Dockerfile . docker build -t smallstep/autocert-renewer:latest -f renewer/Dockerfile . docker build -t smallstep/autocert-init:latest -f init/Dockerfile . ``` -------------------------------- ### Setting Temporary STEPPATH for CA Artifacts Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md These commands set the `STEPPATH` environment variable to a temporary directory, which will be used to stage CA artifacts generated by `step`. This directory can be safely deleted after the installation is complete. ```bash export STEPPATH=$(mktemp -d /tmp/step.XXX) step path /tmp/step.0kE ``` -------------------------------- ### Creating Kubernetes Secrets for CA Passwords Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md These commands create two generic Kubernetes secrets in the `step` namespace. These secrets store the passwords required to decrypt the CA's key material and the `autocert` provisioner's key, ensuring secure access. ```bash kubectl -n step create secret generic ca-password --from-literal password= kubectl -n step create secret generic autocert-password --from-literal password= ``` -------------------------------- ### Registering Autocert Mutation Webhook in Kubernetes (Shell/YAML) Source: https://github.com/smallstep/autocert/blob/master/INSTALL.md This command registers the `autocert` mutation webhook with Kubernetes. It defines a `MutatingWebhookConfiguration` that intercepts pod creation requests, allowing `autocert` to inject bootstrap tokens. The `caBundle` is dynamically populated using `step path` to ensure secure communication. ```Shell cat < autocert.step.sm=enabled ``` -------------------------------- ### Exposing Deployment as Service (Kubectl) Source: https://github.com/smallstep/autocert/blob/master/README.md This command exposes the `hello-mtls` deployment as a Kubernetes Service, making it discoverable and accessible to other workloads within the cluster on port 443. This is a prerequisite for inter-service communication. ```bash kubectl expose deployment hello-mtls --port 443 ``` -------------------------------- ### Deploying mTLS Client with Autocert Annotation (Bash/YAML) Source: https://github.com/smallstep/autocert/blob/master/README.md This bash command uses a heredoc to apply a Kubernetes Deployment manifest for the `hello-mtls-client`. The manifest includes the `autocert.step.sm/name` annotation, which instructs Smallstep Autocert to provision a certificate for this pod. The `HELLO_MTLS_URL` environment variable specifies the target server's internal cluster URL for the mTLS connection. ```bash cat < step ca certificate mike mike.crt mike.key --ca-url https://127.0.0.1:4443 --root root.crt ``` -------------------------------- ### Verifying Custom Autocert Certificate Properties (Bash) Source: https://github.com/smallstep/autocert/blob/master/README.md These bash commands first retrieve the pod name and then use `ls -ln` to verify the custom owner (999:999) and permissions (0600) of the certificate files. Subsequently, `step certificate inspect` is used to confirm the certificate's subject and its 1-hour validity duration, demonstrating the effect of the `autocert` annotations. ```bash $ export HELLO_MTLS_1H=$(kubectl get pods -l app=hello-mtls-1h -o jsonpath='{$.items[0].metadata.name}') $ kubectl exec -it $HELLO_MTLS_1H -c hello-mtls -- ls -ln /var/run/autocert.step.sm -rw------- 1 999 999 623 Jun 6 21:17 root.crt -rw------- 1 999 999 1470 Jun 6 21:37 site.crt -rw------- 1 999 999 227 Jun 6 21:17 site.key $ kubectl exec -it $HELLO_MTLS_1H -c hello-mtls -- cat /var/run/autocert.step.sm/site.crt | step certificate inspect --short - X.509v3 TLS Certificate (ECDSA P-256) [Serial: 3182...1140] Subject: hello-mtls-1h.default.svc.cluster.local Issuer: Autocert Intermediate CA Provisioner: autocert [ID: A1lX...ty1Q] Valid from: 2020-04-30T01:58:17Z to: 2020-04-30T02:58:17Z ``` -------------------------------- ### Cleaning Up Deployments and Services (Kubernetes) Source: https://github.com/smallstep/autocert/blob/master/README.md These commands are used to clean up the resources created during the tutorial. They delete the 'hello-mtls' and 'hello-mtls-client' deployments, along with their associated services, 'hello-mtls' and 'hello-mtls-lb', from the Kubernetes cluster. ```shell kubectl delete deployment hello-mtls kubectl delete deployment hello-mtls-client kubectl delete service hello-mtls kubectl delete service hello-mtls-lb ``` -------------------------------- ### Deploying mTLS Server with Custom Autocert Duration, Owner, and Mode (YAML) Source: https://github.com/smallstep/autocert/blob/master/README.md This YAML defines a Kubernetes Deployment that leverages `autocert` annotations for advanced certificate control. It sets a specific `duration` for the certificate (1 hour), defines the `owner` (UID:GID 999:999), and specifies file `mode` (0600) for the generated certificate, key, and root files. ```yaml cat < -c autocert-renewer -- step certificate inspect /var/run/autocert.step.sm/site.crt ``` -------------------------------- ### Uninstalling Smallstep Autocert from Kubernetes Source: https://github.com/smallstep/autocert/blob/master/RUNBOOK.md These commands provide a comprehensive uninstallation procedure for `autocert`. The first block deletes core Kubernetes resources like the webhook configuration, namespace, and RBAC roles. The second block iterates through enabled namespaces to remove `autocert` labels and clean up remaining one-time token secrets. ```bash kubectl delete mutatingwebhookconfiguration autocert-webhook-config kubectl delete namespace step kubectl delete clusterrolebinding autocert-controller kubectl delete clusterrole autocert-controller ``` ```bash for ns in $(kubectl get namespace --selector autocert.step.sm=enabled -o jsonpath='{$.items[*].metadata.name}'); do kubectl label namespace "$ns" autocert.step.sm- kubectl -n "$ns" delete secrets --selector="autocert.step.sm/token=true" done ``` -------------------------------- ### Recovering Admin and CA Password in Kubernetes Source: https://github.com/smallstep/autocert/blob/master/RUNBOOK.md This command retrieves the `admin` and CA password from the `ca-password` Kubernetes secret within the `step` namespace. It uses `jsonpath` to extract the password data and then decodes it from base64. ```bash kubectl -n step get secret ca-password -o jsonpath='{$.data.password}' | base64 -D ``` -------------------------------- ### Recovering Autocert Password in Kubernetes Source: https://github.com/smallstep/autocert/blob/master/RUNBOOK.md This command retrieves the `autocert` password from the `autocert-password` Kubernetes secret within the `step` namespace. It uses `jsonpath` to extract the password data and then decodes it from base64. ```bash kubectl -n step get secret autocert-password -o jsonpath='{$.data.password}' | base64 -D ``` -------------------------------- ### Disabling Autocert for a Kubernetes Namespace Source: https://github.com/smallstep/autocert/blob/master/RUNBOOK.md This command removes the `autocert.step.sm` label from a specified Kubernetes namespace, effectively disabling `autocert`'s certificate management for that namespace. ```bash kubectl label namespace autocert.step.sm- ``` -------------------------------- ### Cleaning Up Autocert One-Time Token Secrets Source: https://github.com/smallstep/autocert/blob/master/RUNBOOK.md This script iterates through all namespaces where `autocert` is enabled and deletes one-time token secrets. These secrets are identified by the selector `autocert.step.sm/token=true`. ```bash for ns in $(kubectl get namespace --selector autocert.step.sm=enabled -o jsonpath='{$.items[*].metadata.name}'); do kubectl -n "$ns" delete secrets --selector="autocert.step.sm/token=true" done ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.