# Copyright 2021 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.
#########
# Grant GCP role Service Account Admin to GCP networking-sa
# AC-3(7)
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata:
  name: networking-sa-serviceaccountadmin-permissions
  namespace: config-control # kpt-set: ${management-namespace}
  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: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/hub-project-id # kpt-set: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/${hub-project-id}
spec:
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: hub-project-id # kpt-set: ${hub-project-id}
  role: roles/iam.serviceAccountAdmin
  member: "serviceAccount:networking-sa@management-project-id.iam.gserviceaccount.com" # kpt-set: serviceAccount:networking-sa@${management-project-id}.iam.gserviceaccount.com
---
# Grant GCP role Service Account User to GCP networking-sa
# AC-3(7)
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata:
  name: networking-sa-serviceaccountuser-permissions
  namespace: config-control # kpt-set: ${management-namespace}
  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: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/hub-project-id # kpt-set: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/${hub-project-id}
spec:
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: hub-project-id # kpt-set: ${hub-project-id}
  role: roles/iam.serviceAccountUser
  member: "serviceAccount:networking-sa@management-project-id.iam.gserviceaccount.com" # kpt-set: serviceAccount:networking-sa@${management-project-id}.iam.gserviceaccount.com
---
# Grant GCP role Compute Instance Admin v1 to GCP networking-sa
# AC-3(7)
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata:
  name: networking-sa-computeinstanceadmin-permissions
  namespace: config-control # kpt-set: ${management-namespace}
  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: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/hub-project-id # kpt-set: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/${hub-project-id}
spec:
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: hub-project-id # kpt-set: ${hub-project-id}
  role: roles/compute.instanceAdmin.v1
  member: "serviceAccount:networking-sa@management-project-id.iam.gserviceaccount.com" # kpt-set: serviceAccount:networking-sa@${management-project-id}.iam.gserviceaccount.com
---
# Grant GCP role IAP-Secured Tunnel 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-iaptunnelresourceaccessor-permissions
  namespace: config-control # kpt-set: ${management-namespace}
  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: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/hub-project-id # kpt-set: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/${hub-project-id}
spec:
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: hub-project-id # kpt-set: ${hub-project-id}
  role: roles/iap.tunnelResourceAccessor
  member: "group:group@domain.com" # kpt-set: ${hub-admin}
---
# Grant GCP role Compute Instance Admin v1 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-computeinstanceadmin-permissions
  namespace: config-control # kpt-set: ${management-namespace}
  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: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/hub-project-id # kpt-set: resourcemanager.cnrm.cloud.google.com/namespaces/projects/Project/${hub-project-id}
spec:
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: hub-project-id # kpt-set: ${hub-project-id}
  role: roles/compute.instanceAdmin.v1
  member: "group:group@domain.com" # kpt-set: ${hub-admin}
