Nếu bạn cần call vào API của Argo Workflow. thì chúng ta cần tạo ra 1 token trên Argo workflow và sử dụng token này để call vào nó.
Refer to: https://argo-workflows.readthedocs.io/en/latest/access-token/
Chúng ta sẽ vẫn thực hiện cài đặt argo workflow bằng helm chart.
apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization helmCharts: - name: argo-workflows includeCRDs: false releaseName: argoworkflow-nim-staging version: 0.45.18 repo: https://argoproj.github.io/argo-helm valuesFile: values_helm.yaml namespace: argo-workflow
Tiếp theo trong helm value add authModes của server là client.
server:
authModes:
- client
Thông qua helm chart thì bạn tạo thêm:
– Role
– ServiceAccount
– RoleBinding
– Secret -> Bạn cần tạo secret này để giữ token của service account.
extraObjects:
# Create an access token for API calls
- apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: argoworkflow-access-token
namespace: argo-workflow
rules:
- apiGroups: ["argoproj.io"]
resources: ["workflows"]
verbs: ["get", "list", "watch", "update"]
- apiVersion: v1
kind: ServiceAccount
metadata:
name: argoworkflow-access-token
namespace: argo-workflow
- apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: argoworkflow-access-token
namespace: argo-workflow
subjects:
- kind: ServiceAccount
name: argoworkflow-access-token
namespace: argo-workflow
roleRef:
kind: Role
name: argoworkflow-access-token
apiGroup: rbac.authorization.k8s.io
- apiVersion: v1
kind: Secret
metadata:
name: argoworkflow-access-token
namespace: argo-workflow
annotations:
kubernetes.io/service-account.name: argoworkflow-access-token
type: kubernetes.io/service-account-token
Sau khi bạn cài đặt xong thì run lệnh sau:
ARGO_TOKEN="Bearer $(kubectl get secret argoworkflow-access-token -n argo-workflow -o=jsonpath='{.data.token}' | base64 --decode)"
echo $ARGO_TOKEN
Bearer ZXlKaGJHY2lPaUpTVXpJMU5pSXNJbXRwWkNJNkltS...
tiếp đến bạn có thể call 1 curl để kiểm tra token:
curl https://localhost:2746/api/v1/workflows/argo -H "Authorization: $ARGO_TOKEN"
# 200 OK
https://localhost:2746 | Địa chỉ Argo Server | localhost ám chỉ chạy ngay trên máy hiện tại; cổng 2746 là mặc định khi cài Argo Workflows bằng argocd hoặc manifest chuẩn. |
/api/v1/workflows/argo | Endpoint REST của Argo Workflows | – api/v1 – phiên bản API hiện tại.– workflows – tài nguyên muốn truy cập.– argo – namespace Kubernetes cần liệt kê/lấy chi tiết workflow. |
-H "Authorization: $ARGO_TOKEN" | Header HTTP | Gửi Bearer Token đã tạo ở bước trước (biến môi trường ARGO_TOKEN). Token này chứng thực cho ServiceAccount trong Kubernetes và phân quyền thông qua RBAC. |