diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-09-17 08:43:48 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-09-17 08:43:48 +0000 |
commit | 5a8908bf587a0723b07e510dd6118a686d49af98 (patch) | |
tree | a19af868a1b0a7c676b56a43372811a662754b6f /lib | |
parent | ba40c7f1c32f62ad5370621f049500aa904149cd (diff) | |
parent | 528b060b89c2d6a6be611e88ceed28cfe86e167c (diff) | |
download | gitlab-ce-5a8908bf587a0723b07e510dd6118a686d49af98.tar.gz |
Merge branch '29398-support-rbac-for-gitlab-provisioned-clusters' into 'master'
Support Kubernetes RBAC for GitLab Managed Apps for creating new clusters
Closes #29398
See merge request gitlab-org/gitlab-ce!21401
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/kubernetes/kube_client.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/kubernetes/service_account_token.rb | 36 | ||||
-rw-r--r-- | lib/google_api/cloud_platform/client.rb | 4 |
3 files changed, 40 insertions, 2 deletions
diff --git a/lib/gitlab/kubernetes/kube_client.rb b/lib/gitlab/kubernetes/kube_client.rb index 8312b901524..588238de608 100644 --- a/lib/gitlab/kubernetes/kube_client.rb +++ b/lib/gitlab/kubernetes/kube_client.rb @@ -25,12 +25,14 @@ module Gitlab :get_config_map, :get_namespace, :get_pod, + :get_secret, :get_service, :get_service_account, :delete_pod, :create_config_map, :create_namespace, :create_pod, + :create_secret, :create_service_account, :update_config_map, :update_service_account, diff --git a/lib/gitlab/kubernetes/service_account_token.rb b/lib/gitlab/kubernetes/service_account_token.rb new file mode 100644 index 00000000000..2e912b26c09 --- /dev/null +++ b/lib/gitlab/kubernetes/service_account_token.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Gitlab + module Kubernetes + class ServiceAccountToken + attr_reader :name, :service_account_name, :namespace_name + + def initialize(name, service_account_name, namespace_name) + @name = name + @service_account_name = service_account_name + @namespace_name = namespace_name + end + + def generate + ::Kubeclient::Resource.new(metadata: metadata, type: service_acount_token_type) + end + + private + + # as per https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/#to-create-additional-api-tokens + def service_acount_token_type + 'kubernetes.io/service-account-token' + end + + def metadata + { + name: name, + namespace: namespace_name, + annotations: { + "kubernetes.io/service-account.name": service_account_name + } + } + end + end + end +end diff --git a/lib/google_api/cloud_platform/client.rb b/lib/google_api/cloud_platform/client.rb index 36859b4d025..77b6610286f 100644 --- a/lib/google_api/cloud_platform/client.rb +++ b/lib/google_api/cloud_platform/client.rb @@ -50,7 +50,7 @@ module GoogleApi service.get_zone_cluster(project_id, zone, cluster_id, options: user_agent_header) end - def projects_zones_clusters_create(project_id, zone, cluster_name, cluster_size, machine_type:) + def projects_zones_clusters_create(project_id, zone, cluster_name, cluster_size, machine_type:, legacy_abac:) service = Google::Apis::ContainerV1::ContainerService.new service.authorization = access_token @@ -63,7 +63,7 @@ module GoogleApi "machine_type": machine_type }, "legacy_abac": { - "enabled": true + "enabled": legacy_abac } } } |