Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding documentation describing how to configure Vault for mTLS #1390

Merged
merged 2 commits into from
Feb 16, 2024

Conversation

@jetstack-bot jetstack-bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 15, 2024
Copy link

netlify bot commented Jan 15, 2024

Deploy Preview for cert-manager-website ready!

Name Link
🔨 Latest commit d285b0e
🔍 Latest deploy log https://app.netlify.com/sites/cert-manager-website/deploys/65cfa9e8061d07000879ce35
😎 Deploy Preview https://deploy-preview-1390--cert-manager-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rodrigorfk

I like these new docs, but as an inexperienced vault user I really struggled to get everything setup. I'd like even more detail if possible and more links to official Hashicorp documentation.

Here's what I did:

  • Create Vault serving certificate and CA
step certificate create "Example Server Root CA" server_ca.crt server_ca.key \
  --profile root-ca \
  --not-after=87600h \
  --no-password \
   --insecure
   

step certificate create vault.vault vault.crt vault.key \
  --profile leaf \
  --not-after=8760h \
  --ca ./server_ca.crt \
  --ca-key server_ca.key \
  --no-password \
  --insecure
  • Create Vault client certificate and CA
step certificate create "Example Client Root CA" client_ca.crt client_ca.key \
  --profile root-ca \
  --not-after=87600h \
  --no-password \
   --insecure 

step certificate create client.vault vault_client.crt vault_client.key \
  --profile leaf \
  --not-after=8760h \
  --ca ./client_ca.crt \
  --ca-key client_ca.key \
  --no-password \
  --insecure
  • Create Vault namespace
kubectl create ns vault
  • Create Secret containing Vault serving certificate, Vault client certificate (for use by the readiness probe) and Vault client CA cert (the certificate that Vault will use to verify client certificates.
kubectl create secret generic vault-tls \
  --namespace vault \
  --from-file=server.key=vault.key \
  --from-file=server.crt=vault.crt \
  --from-file=client-ca.crt=client_ca.crt \
  --from-file=client.crt=vault_client.crt \
  --from-file=client.key=vault_client.key
  • Deploy Vault
# vault-values.yaml
global:
   tlsDisable: false
injector:
  enabled: false
server:
  dataStorage:
    enabled: false
  standalone:
    enabled: true
    config: |
      listener "tcp" {
        address = "[::]:8200"
        cluster_address = "[::]:8201"
        tls_disable = false
        tls_client_ca_file = "/vault/tls/client-ca.crt"
        tls_cert_file = "/vault/tls/server.crt"
        tls_key_file = "/vault/tls/server.key"
        tls_require_and_verify_client_cert = true
      }
  extraArgs: "-dev-tls -dev-listen-address=[::]:8202"
  extraEnvironmentVars:
    VAULT_TLSCERT: /vault/tls/server.crt
    VAULT_TLSKEY: /vault/tls/server.key
    VAULT_CLIENT_CERT: /vault/tls/client.crt
    VAULT_CLIENT_KEY: /vault/tls/client.key
  volumes:
    - name: vault-tls
      secret:
        defaultMode: 420
        secretName: vault-tls
  volumeMounts:
    - mountPath: /vault/tls
      name: vault-tls
      readOnly: true
helm upgrade vault hashicorp/vault --install --namespace vault --create-namespace --values vault-values.yaml
  • Configure Vault server for Kubernetes auth
kubectl -n vault exec pods/vault-0  -- \
        vault auth enable --tls-skip-verify kubernetes

kubectl -n vault exec pods/vault-0  -- \
        vault write --tls-skip-verify \
        auth/kubernetes/role/vault-issuer \
        bound_service_account_names=vault-issuer \
        bound_service_account_namespaces=application-1 \
        audience="vault://application-1/vault-issuer" \
        policies=vault-issuer \
        ttl=1m

kubectl -n vault exec pods/vault-0 -- \
        vault write --tls-skip-verify \
        auth/kubernetes/config \
        kubernetes_host=https://kubernetes.default
  • Create application namespace
kubectl create ns application-1
  • Create Service account
kubectl create serviceaccount -n application-1 vault-issuer
  • Create Role and Binding
# rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: vault-issuer
  namespace: application-1
rules:
  - apiGroups: ['']
    resources: ['serviceaccounts/token']
    resourceNames: ['vault-issuer']
    verbs: ['create']
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: vault-issuer
  namespace: application-1
subjects:
  - kind: ServiceAccount
    name: cert-manager
    namespace: cert-manager
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: vault-issuer
kubectl apply -f rbac.yaml
  • Create Issuer
export CA_BUNDLE=$(base64 -w 0 server_ca.crt)
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: vault-issuer
  namespace: application-1
spec:
  vault:
    path: pki_int/sign/application-1
    server: https://vault.vault:8200
    caBundle: ${CA_BUNDLE}
    clientCertSecretRef:
      name: vault-client-tls
      key: vault_client.crt
    clientKeySecretRef:
      name: vault-client-tls
      key: vault_client.key
    auth:
      kubernetes:
        role: vault-issuer
        mountPath: /v1/auth/kubernetes
        serviceAccountRef:
          name: vault-issuer
envsubst < vault-issuer.yaml | kubectl -f -
  • Check Issuer status
kubectl describe issuer -n application-1

content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
@jetstack-bot jetstack-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 15, 2024
Signed-off-by: Rodrigo Fior Kuntzer <rodrigo@miro.com>
@rodrigorfk
Copy link
Author

@wallrj , thanks for providing such detailed steps, I have merged it into the documentation, could you please have another look?

Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

I simplified some of the file names and used caBundleSecretRef to avoid having to base64 encode the ca and use envsubst.

Tested your branch again and it worked.

content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
content/docs/configuration/vault.md Outdated Show resolved Hide resolved
Co-authored-by: Richard Wall <wallrj@users.noreply.github.com>
Signed-off-by: Rodrigo Fior Kuntzer <rodrigofkuntzer@gmail.com>
Copy link
Member

@wallrj wallrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

/lgtm

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 16, 2024
@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wallrj

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jetstack-bot jetstack-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 16, 2024
@jetstack-bot jetstack-bot merged commit 1f37059 into cert-manager:release-next Feb 16, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants