Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Argocd/Vault] Integrate Vault inside Argocd by the plugin

Posted on July 1, 2022January 12, 2023 By nim No Comments on [Argocd/Vault] Integrate Vault inside Argocd by the plugin

Argocd là 1 công cụ vip pro để deploy bất cứ application nào lên k8s và quản lý manifest thông qua gitops.
Vault được khá nhiều người tin tưởng để lưu secret.

Việc đầu tiên chúng ta cần cài đặt thêm plugin vault cho argocd.
Mình dùng kustomize để merge config và manifest argocd.

Sau đây là config merge của mình

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - https://raw.githubusercontent.com/argoproj/argo-cd/v2.4.0-rc2/manifests/install.yaml

patchesStrategicMerge:
  - argocd-vault-plugin.yaml

Bạn sẽ thấy là pod argocd-repo-server như hình bên dưới.

Contents

Toggle
  • 1) Config Vault
  • 2) Config argocd to integrate vault
    • Config Management Plugins
      • Manifest Yaml.
  • ArgoCD + AWS Secrets Manager

1) Config Vault

Đầu tiên bạn cần có sẵn 1 hệ thông vault đã nhé
Nếu bạn chưa cài thì có thể thảm khảo bài viết sau:

[Vault/Consul] Install vault and consul through Helm in K8s

Và chúng ta thực hiện exec pod vault và thi triển 1 số command.

kubectl -n vault exec -it pod/vault-0 -- sh

export CLUSTER_NAME=kubernetes-argocd-vault

vault policy write ${CLUSTER_NAME}-kv-rw - <<EOH
path "avp/*" {
    capabilities = ["read", "list"]
}
EOH
Bạn tạo 1 policy sẽ cho người dùng action lên các secret nằm trong path “avp/*”
vault auth enable --path="${CLUSTER_NAME}" kubernetes

Giờ bạn tạo 1 path authen với kubernetes

và chúng ta sẽ có 1 Kuberentes Auth Mount PATH là auth/kubernetes-argocd-vault
bạn sẽ nhờ phần này vì tý chúng ta sẽ dùng

Trong argocd thì con argocd-repo-server sẽ có vài trò là tương tác với các repository.
Bạn có thể hiểu là argocd-repo-server sẽ clone code từ github về.
Và nếu có overwrite lại argocd-repo-server có quyền điều chỉnh file yaml trước khi apply.

Giờ đến phần bạn get infro của argocd-repo-server

# Set VAULT_SA_NAME to the service account you created earlier
$ export VAULT_SA_NAME=$(kubectl -n argocd get sa argocd-repo-server -o jsonpath="{.secrets[*]['name']}")

# Set SA_JWT_TOKEN value to the service account JWT used to access the TokenReview API
$ export SA_JWT_TOKEN=$(kubectl -n argocd get secret $VAULT_SA_NAME -o jsonpath="{.data.token}" | base64 --decode; echo)

# Set SA_CA_CRT to the PEM encoded CA cert used to talk to Kubernetes API
$ export SA_CA_CRT=$(kubectl -n argocd get secret $VAULT_SA_NAME -o jsonpath="{.data['ca\.crt']}" | base64 --decode; echo)

# Look in your cloud provider console for this value
$ export K8S_HOST=<https://your_API_server_endpoint>
==>export K8S_HOST=https://192.168.101.40:6443


vault write auth/${CLUSTER_NAME}/config \
token_reviewer_jwt="${SA_JWT_TOKEN}" \
kubernetes_host="${K8S_HOST}" \
kubernetes_ca_cert="${SA_CA_CRT}"

Như bạn thấy, chúng ta đang config auth/kubernetes-argocd-vault sẽ authen kubernetes.
– token SA của argocd-repo-server
– Host controller của cụm dev
– Import ca_cert.

Tiếp đến chúng authen vào với role
nghĩ là dựa vào Serice Account của workload (“service account -> argocd-repo-server” và namespace argocd ) được quyển read secret.

vault write auth/${CLUSTER_NAME}/role/${CLUSTER_NAME}-role \
  bound_service_account_names="argocd-repo-server" \
  bound_service_account_namespaces="argocd" \
  policies="default,${CLUSTER_NAME}-kv-rw" \
  ttl="1h"

Bạn login bằng 1 user khác (root)

vault secrets enable -path=avp -version=2 kv
vault kv put avp/test sample=secret

Bạn có thể test login thông qua serviec account lại bằng cách


>>>>>>>>>
# Set VAULT_SA_NAME to the service account you created earlier
$ export VAULT_SA_NAME=$(kubectl -n argocd get sa argocd-repo-server -o jsonpath="{.secrets[*]['name']}")

# Set SA_JWT_TOKEN value to the service account JWT used to access the TokenReview API
$ export SA_JWT_TOKEN=$(kubectl -n argocd get secret $VAULT_SA_NAME -o jsonpath="{.data.token}" | base64 --decode; echo)

vault write auth/kubernetes-argocd-vault/login role=kubernetes-argocd-vault-role jwt=$SA_JWT_TOKEN

vault login hvs.CAESIM5SBXGX7TUxxxxxxxxxxxxxxxxxxxxxx

vault kv get avp/test
>>>>>>>>
nếu thấy được secret là ok

2) Config argocd to integrate vault

Đây là command để encrypt base 64

echo -n 'my-string' | base64

file argocd-vault-plugin-credentials.yaml

kind: Secret
apiVersion: v1
metadata:
  name: argocd-vault-plugin-credentials
  namespace: argocd
type: Opaque
data:
  AVP_AUTH_TYPE: azhz
  AVP_K8S_MOUNT_PATH: YXV0aC9rdWJlcm5ldGVzLWFyZ29jZC12YXVsdA==
  AVP_K8S_ROLE: a3ViZXJuZXRlcy1hcmdvY2QtdmF1bHQtcm9sZQ==
  AVP_TYPE: dmF1bHQ=
  VAULT_ADDR: aHR0cDovL3ZhdWx0Lm5pbXRlY2hub2xvZ3kuY29t
   # AVP_K8S_TOKEN_PATH: Path to JWT (optional)
  #  TMPDIR: L2hvbWUvYXJnb2NkCg==

để hiểu hơn về AVP specific variables bạn đọc thêm:
https://argocd-vault-plugin.readthedocs.io/en/stable/config/
Mình cũng đã bị lỗi khi mà encrypt base 64 trong string của mình bị xuống hàn -> create app argocd ko được. các bạn cũng chú ý nhé

file argocd-vault-plugin.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/component: repo-server
    app.kubernetes.io/name: argocd-repo-server
    app.kubernetes.io/part-of: argocd
  name: argocd-repo-server
spec:
  template:
    spec:
      automountServiceAccountToken: true
      containers:
      - name: argocd-repo-server
        volumeMounts:
          - name: custom-tools
            mountPath: /usr/local/bin/argocd-vault-plugin
            subPath: argocd-vault-plugin
        envFrom:
          - secretRef:
              name: argocd-vault-plugin-credentials
      volumes:
      - name: custom-tools
        emptyDir: {}
      initContainers:
      - name: download-tools
        image: alpine:3.8
        command: [sh, -c]
        env:
          - name: AVP_VERSION
            value: "1.11.0"
        args:
          - >-
            wget -O argocd-vault-plugin
            https://github.com/argoproj-labs/argocd-vault-plugin/releases/download/v${AVP_VERSION}/argocd-vault-plugin_${AVP_VERSION}_linux_amd64 &&
            chmod +x argocd-vault-plugin &&
            mv argocd-vault-plugin /custom-tools/
        volumeMounts:
          - mountPath: /custom-tools
            name: custom-tools
tý nữa khi bạn install bạn sẽ thấy có thêm các container màu vàng như hình

Tiếp đến là chúng ta sẽ có 1 file kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - https://raw.githubusercontent.com/argoproj/argo-cd/v2.4.3/manifests/install.yaml
  - argocd-vault-plugin-credentials.yaml

patchesStrategicMerge:
  - argocd-vault-plugin.yaml
  - agocd-cm-plugin.yaml

Config Management Plugins

file agocd-cm-plugin.yaml
Và điểm mấu chột ở file này với mỗi style thì chúng ta cần tìm ra 1 config khách nhau

Ở phần này bạn sẽ cần hiểu các hoạt động của plugin argocd vault.
Bạn cần có file yaml –> bạn chạy câu lệnh argocd-vault-plugin -> trên file yaml bạn đã có cách chỗ đánh dấu để argocd-vault-plugin -> argocd-vault-plugin lấy thông tin trên vault và change lại các string sao cho đúng

Manifest Yaml.

Lab này đơn giản là bạn để 1 file yaml ở trên github.
https://github.com/werne2j/arogcd-vault-plugin-demo

agocd-cm-plugin.yaml

apiVersion: v1
data:
  configManagementPlugins: |
    - name: argocd-vault-plugin
      generate:
        command: ["argocd-vault-plugin"]
        args: ["generate", "./"]
kind: ConfigMap
metadata:
  name: argocd-cm

Bạn thực hiện create 1 application như bình thường

https://github.com/werne2j/arogcd-vault-plugin-demo

Ban cần chú ý đây là dấu chấm
Bạn cúng cần chọn plugin

Trên đó là các điểm mà mình lưu ý

Mình sẽ node 1 số config các bạn tự tiềm hiểu nhé!

...
    - name: argocd-vault-plugin-helm
      generate:
        command: ["sh", "-c"]
        args: ["helm template . | argocd-vault-plugin generate -"]
    # This lets you pass args to the Helm invocation as described here: https://argocd-vault-plugin.readthedocs.io/en/stable/usage/#with-helm
    - name: argocd-vault-plugin-helm-with-args
      generate:
        command: ["sh", "-c"]
        args: ["helm template ${helm_args} . | argocd-vault-plugin generate -"]
    - name: argocd-vault-plugin-kustomize
      generate:
        command: ["sh", "-c"]
        args: ["kustomize build . | argocd-vault-plugin generate -"]
#########

    - name: argocd-vault-plugin-kustomize-build-with-helm
      generate:
        command: [ "sh", "-c" ]
        args: [ "kustomize build --enable-helm . | argocd-vault-plugin generate -" ]

ArgoCD + AWS Secrets Manager

ArgoCD + AWS Secrets Manager. GitOps in trends these days, it has… | by Yevgeniy Ovsyannikov | AWS Tip

https://awstip.com/how-to-implement-argocd-vault-plugin-with-aws-secrets-manager-80c912f3a9ee

ArgoCD

Post navigation

Previous Post: [Vault] Using Service Acount of Kubernetes to login Vault system.
Next Post: [ArgoCD/KSOPS] Encrypting Resource on kustomize and Argocd.

More Related Articles

[ArgoCD] Cài đặt argocd cli và connect với ArgoCD ArgoCD
[ArgoCD/KSOPS] Encrypting Resource on kustomize and Argocd. ArgoCD
[AWS] Login Argocd via Cognito in AWS ArgoCD
[ArgoCD] Hướng dẫn tạo “local user” trên argocd ArgoCD
[ArgoCD] Failed to wait for service account secret: timed out waiting for the condition ArgoCD
[Argocd] Run “bash/sh” to execute pods on kubernetes via Argocd. ArgoCD

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Azure/Loadbalancer] Creating an internal load balancer on Azure Kubernetes Service (AKS). May 13, 2025
  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.