반응형
아래처럼 ServiceAccount에서 토큰을 추출하면 토큰만료기간이 정해져있어 보안에는 좋지만 관리가 쉽지 않다.
# 한시적인 Token 생성
kubectl create token <ServiceAccount명> -n <namespace명> --duration=24h
토큰을 영구적으로 사용하려면 kubernetes.io/service-account-token 타입의 Secret을 생성하여 ControlPlane이 etcd에 저장된 Token을 만료시간을 reconciliation 하도록 해야한다.
To create a non-expiring, persisted API token for a ServiceAccount, create a Secret of type kubernetes.io/service-account-token with an annotation referencing the ServiceAccount. The control plane then generates a long-lived token and updates that Secret with that generated token data. ( https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/ )
Secret 생성
apiVersion: v1
kind: Secret
metadata:
name: <SA이름>-token
namespace: <네임스페이스>
annotations:
kubernetes.io/service-account.name: "<SA이름>"
type: kubernetes.io/service-account-token
Token 추출
ARGO_TOKEN="Bearer $(kubectl get secret <ServiceAccount명>.service-account-token -o=jsonpath='{.data.token}' | base64 --decode)"
echo $ARGO_TOKEN반응형
'Ops > Kubernetes' 카테고리의 다른 글
| node-core-dns 란? (0) | 2025.12.31 |
|---|---|
| [이슈] Network Policy - failed to get status by proxying to the pod, you might lack permissions to get pods/proxy (0) | 2025.12.08 |
| Ingress에서 Gateway API로 전환해야 하는 이유 (0) | 2025.10.23 |
| [이슈] 파드가 반복해서 Evicted되는 현상 (0) | 2025.09.16 |
| K8S NFS 동적 프로비저닝 구현하기 (0) | 2025.09.16 |