# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#########
# GCP SA Management VM
# AC-2(A) - One GCP service account is created and attached to the management VM.
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMServiceAccount
metadata:
  name: hub-managementvm-sa
  namespace: networking
  annotations:
    cnrm.cloud.google.com/project-id: hub-project-id # kpt-set: ${hub-project-id}
    config.kubernetes.io/depends-on: iam.cnrm.cloud.google.com/namespaces/config-control/IAMPolicyMember/networking-sa-serviceaccountadmin-permissions
spec:
  resourceID: managementvm-sa
  displayName: Management VM
---
# Grant GCP role Service Account User to hub admin
# Required for IAP
# AC-3(7)
# AC-17(1)
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata:
  name: hub-admin-serviceaccountuser-permissions
  namespace: networking
  annotations:
    cnrm.cloud.google.com/project-id: hub-project-id # kpt-set: ${hub-project-id}
    cnrm.cloud.google.com/ignore-clusterless: "true"
    config.kubernetes.io/depends-on: iam.cnrm.cloud.google.com/namespaces/networking/IAMServiceAccount/hub-managementvm-sa
spec:
  resourceRef:
    apiVersion: iam.cnrm.cloud.google.com/v1beta1
    kind: IAMServiceAccount
    name: hub-managementvm-sa
  role: roles/iam.serviceAccountUser
  member: "group:group@domain.com" # kpt-set: ${hub-admin}
