-
Notifications
You must be signed in to change notification settings - Fork 6
/
org-admin-setup.sh
executable file
·123 lines (102 loc) · 3.68 KB
/
org-admin-setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright 2023 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.
# New project setup - Run as org admin
PROJECT_ID=cymbal-eats-$RANDOM-$RANDOM
ORGANIZATION_ID=your org id
BILLING_ACCOUNT=your billing account id
gcloud projects create $PROJECT_ID --organization=$ORGANIZATION_ID
gcloud beta billing projects link ${PROJECT_ID} --billing-account=$BILLING_ACCOUNT
gcloud config set project ${PROJECT_ID}
gcloud services enable \
orgpolicy.googleapis.com \
compute.googleapis.com
gcloud compute networks create default --subnet-mode=auto
sleep 1m
# vmExternalIpAccess
cat > vmExternalIpAccess.yaml << ENDOFFILE
name: projects/$PROJECT_ID/policies/compute.vmExternalIpAccess
spec:
rules:
- allowAll: true
ENDOFFILE
gcloud org-policies set-policy vmExternalIpAccess.yaml --project=$PROJECT_ID
# vpc-access connectors creation.
cat > vmCanIpForward.yaml << ENDOFFILE
name: projects/$PROJECT_ID/policies/compute.vmCanIpForward
spec:
rules:
- allowAll: true
ENDOFFILE
gcloud org-policies set-policy vmCanIpForward.yaml --project=$PROJECT_ID
# requireOsLogin
# cat > requireOsLogin.yaml << ENDOFFILE
# name: projects/$PROJECT_ID/policies/compute.requireOsLogin
# spec:
# rules:
# - allowAll: true
# ENDOFFILE
# gcloud org-policies set-policy requireOsLogin.yaml --project=$PROJECT_ID
# requireShieldedVm
# cat > requireShieldedVm.yaml << ENDOFFILE
# name: projects/$PROJECT_ID/policies/compute.requireShieldedVm
# spec:
# rules:
# - allowAll: true
# ENDOFFILE
# gcloud org-policies set-policy requireShieldedVm.yaml --project=$PROJECT_ID
# Domain restricted sharing. To allow allUsers access on resource, ex. GCS.
# Allow Cloud Run public access
cat > allowedPolicyMemberDomains.yaml << ENDOFFILE
name: projects/$PROJECT_ID/policies/iam.allowedPolicyMemberDomains
spec:
rules:
- allowAll: true
ENDOFFILE
gcloud org-policies set-policy allowedPolicyMemberDomains.yaml --project=$PROJECT_ID
# Define trusted image projects. serverless-vpc-access-images.
cat > trusted-images-policy.yaml << ENDOFFILE
constraint: constraints/compute.trustedImageProjects
listPolicy:
allowedValues:
- projects/suse-sap-cloud
- projects/opensuse-cloud
- projects/rhel-sap-cloud
- projects/windows-sql-cloud
- projects/suse-cloud
- projects/cos-cloud
- projects/debian-cloud
- projects/fedora-coreos-cloud
- projects/rocky-linux-cloud
- projects/fedora-cloud
- projects/centos-cloud
- projects/rhel-cloud
- projects/ubuntu-os-cloud
- projects/confidential-vm-images
- projects/windows-cloud
- projects/ubuntu-os-pro-cloud
- projects/serverless-vpc-access-images
ENDOFFILE
gcloud resource-manager org-policies set-policy trusted-images-policy.yaml --project=$PROJECT_ID
# Allowed ingress settings (Cloud Functions)
cat > allowedIngressSettings.yaml << ENDOFFILE
name: projects/$PROJECT_ID/policies/cloudfunctions.allowedIngressSettings
spec:
rules:
- allowAll: true
ENDOFFILE
gcloud org-policies set-policy allowedIngressSettings.yaml --project=$PROJECT_ID
# Grant your GCP account owner role on the new project
gcloud projects add-iam-policy-binding $PROJECT_ID --member=user:$GCP_USER_ACCOUNT --role=roles/owner
# Login with your GCP account, clone the repo and run ```./setup.sh```