0

我看到 spinnaker 使用system:anonymous用户来验证 K8s。但是我想要一个特定的用户(我已经在 K8s 中创建)来验证 K8s。我在下面kubeconfig使用用户veeru

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: RETRACTED
    server: https://xx.xx.xx.220:8443
  name: xx-xx-xx-220:8443
contexts:
- context:
    cluster: xx-xx-xx-220:8443
    namespace: default
    user: veeru/xx-xx-xx-220:8443
  name: area-51/xx-xx-xx-220:8443/veeru
current-context: area-51/xx-xx-xx-220:8443/veeru
kind: Config
preferences: {}
users:
- name: veeru/xx-xx-xx-220:8443
  user:
    client-certificate-data: RETRACTED
    client-key-data: RETRACTED

我在 config(~/.hal/config) 中指定(如这里) ,如下所示user

kubernetes:
      enabled: true
      accounts:
      - name: my-k8s-account
        requiredGroupMembership: []
        providerVersion: V1
        dockerRegistries:
        - accountName: my-docker-registry2
          namespaces: []
        configureImagePullSecrets: true
        namespaces: ["area-51"]
        user: veeru
        omitNamespaces: []
        kubeconfigFile: /home/ubuntu/.kube/config
        oauthScopes: []
        oAuthScopes: []
      primaryAccount: my-k8s-account

但大三角帆仍在使用system:anonymous

2018-01-22 08:35:13.929 ERROR 4639 --- [pool-4-thread-1] c.n.s.c.o.DefaultOrchestrationProcessor  : com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.exception.KubernetesOperationException: Get Service openshifttest-dev in area-51 for account my-k8s-account failed: User "system:anonymous" cannot get services in the namespace "area-51": User "system:anonymous" cannot get services in project "area-51"

有没有办法指定大三角帆应该使用配置用户以外的用户system:anonymous

更新-1

关注:https ://blog.spinnaker.io/spinnaker-kubernetes-rbac-c40f1f73c172

从下面获取secretkubectl describe secret spinnaker-service-account-token-9sl6q更新kubeconfig

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: REDACTED
    server: https://xx.xx.xx.xx:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    namespace: webapp
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
- context:
    cluster: kubernetes
    user: spinnaker-service-account
  name: spinnaker-context
current-context: spinnaker-context
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
- name: spinnaker-service-account
  user:
    token: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9....

比我跑sudo hal deploy

....
! ERROR Unable to communicate with your Kubernetes cluster: Failure
  executing: GET at: https://xx.xx.xx.xx:6443/api/v1/namespaces. Message:
  Forbidden! User spinnaker-service-account doesn't have permission. namespaces is
  forbidden: User "system:serviceaccount:default:spinnaker-service-account" cannot
  list namespaces at the cluster scope..
? Unable to authenticate with your Kubernetes cluster. Try using
  kubectl to verify your credentials.
....

我能跑

$ kubectl get namespace webapp
NAME      STATUS    AGE
webapp    Active    22m

我已经指定了webapp命名空间和用户,spinnaker-service-account~/.hal/config

4

1 回答 1

1

我正在使用禁用基本身份验证的GKE 。我让我的大三角帆使用我创建的专用 K8s 服务帐户。在我~/.kube/config的每个 K8s 集群中,我都有令牌。

users:
- name: gke_operation-covfefe-1_asia-east1_testing-asia-east1
  user:
    token: token1
- name: gke_operation-covfefe-1_europe-west1_testing-europe-west1
  user:
    token: token2
- name: gke_operation-covfefe-1_us-central1_testing-us-central1
  user:
    token: token3

我通过运行获得了这些令牌

kubectl get secret spinnaker-service-account -o json \
 | jq -r .data.token \
 | base64 -d

然后手动更新我的~/.kube/config文件。

确保您的服务帐户具有所需的 RBAC 权限。请参阅此处的博客文章

更新:

还要确保为服务帐户提供所需的 RBAC 权限。请参阅上面博客文章的“角色”部分或此处的指南。当您测试 RBAC 权限时,请kubectl确保您使用的服务帐户与 Spinnaker 使用的服务帐户相同。

更新 2

如果您希望 spinnaker 作用于所有命名空间,请在 RBAC 中使用 ClusterRole 和 ClusterRoleBinding。该博客文章仅使用 Role 和 RoleBinding ,它们将操作限制在特定的命名空间中。有关 Cluster* 方式的信息,请参阅本指南。请注意PR 以修复此处的错字

于 2018-01-23T17:21:53.740 回答