Skip to content

Commit 36a7347

Browse files
authored
FAST stage docs cleanup (#1145)
* top-level and stage 0 * stage 1 * net peering * networking * networking * security * gke, dp * checks
1 parent e833485 commit 36a7347

File tree

13 files changed

+740
-527
lines changed

13 files changed

+740
-527
lines changed

fast/stage-links.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ case $STAGE_NAME in
7878
TFVARS="tfvars/0-bootstrap.auto.tfvars.json
7979
tfvars/1-resman.auto.tfvars.json"
8080
;;
81+
"2-security"*)
82+
PROVIDER="providers/2-security-providers.tf"
83+
TFVARS="tfvars/0-bootstrap.auto.tfvars.json
84+
tfvars/1-resman.auto.tfvars.json"
85+
;;
8186
*)
8287
# check for a "dev" stage 3
8388
echo "no stage found, trying for parent stage 3..."

fast/stages/0-bootstrap/README.md

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ Use the following diagram as a simple high level reference for the following sec
1414
<img src="diagram.svg" alt="Organization-level diagram">
1515
</p>
1616

17+
## Table of contents
18+
19+
- [Design overview and choices](#design-overview-and-choices)
20+
- [User groups](#user-groups)
21+
- [Organization-level IAM](#organization-level-iam)
22+
- [Automation project and resources](#automation-project-and-resources)
23+
- [Billing account](#billing-account)
24+
- [Organization-level logging](#organization-level-logging)
25+
- [Naming](#naming)
26+
- [Workload Identity Federation and CI/CD](#workload-identity-federation-and-cicd)
27+
- [How to run this stage](#how-to-run-this-stage)
28+
- [Prerequisites](#prerequisites)
29+
- [Output files and cross-stage variables](#output-files-and-cross-stage-variables)
30+
- [Running the stage](#running-the-stage)
31+
- [Customizations](#customizations)
32+
- [Group names](#group-names)
33+
- [IAM](#iam)
34+
- [Log sinks and log destinations](#log-sinks-and-log-destinations)
35+
- [Names and naming convention](#names-and-naming-convention)
36+
- [Workload Identity Federation](#workload-identity-federation)
37+
- [CI/CD repositories](#cicd-repositories)
38+
1739
## Design overview and choices
1840

1941
As mentioned above, this stage only does the bare minimum required to bootstrap automation, and ensure that base audit and billing exports are in place from the start to provide some measure of accountability, even before the security configurations are applied in a later stage.
@@ -80,7 +102,7 @@ The convention is used in its full form only for specific resources with globall
80102

81103
The [Customizations](#names-and-naming-convention) section on names below explains how to configure tokens, or implement a different naming convention.
82104

83-
## Workload Identity Federation and CI/CD
105+
### Workload Identity Federation and CI/CD
84106

85107
This stage also implements initial support for two interrelated features
86108

@@ -124,7 +146,7 @@ To quickly self-grant the above roles, run the following code snippet as the ini
124146
export FAST_BU=$(gcloud config list --format 'value(core.account)')
125147

126148
# find and set your org id
127-
gcloud organizations list --filter display_name:$partofyourdomain
149+
gcloud organizations list
128150
export FAST_ORG_ID=123456
129151

130152
# set needed roles
@@ -139,25 +161,6 @@ done
139161

140162
Then make sure the same user is also part of the `gcp-organization-admins` group so that impersonating the automation service account later on will be possible.
141163

142-
#### Billing account in a different organization
143-
144-
If you are using a billing account belonging to a different organization (e.g. in multiple organization setups), some initial configurations are needed to ensure the identities running this stage can assign billing-related roles.
145-
146-
If the billing organization is managed by another version of this stage, we leverage the `organizationIamAdmin` role created there, to allow restricted granting of billing roles at the organization level.
147-
148-
If that's not the case, an equivalent role needs to exist, or the predefined `resourcemanager.organizationAdmin` role can be used if not managed authoritatively. The role name then needs to be manually changed in the `billing.tf` file, in the `google_organization_iam_binding` resource.
149-
150-
The identity applying this stage for the first time also needs two roles in billing organization, they can be removed after the first `apply` completes successfully:
151-
152-
```bash
153-
export FAST_BILLING_ORG_ID=789012
154-
export FAST_ROLES=(roles/billing.admin roles/resourcemanager.organizationAdmin)
155-
for role in $FAST_ROLES; do
156-
gcloud organizations add-iam-policy-binding $FAST_BILLING_ORG_ID \
157-
--member user:$FAST_BU --role $role
158-
done
159-
```
160-
161164
#### Standalone billing account
162165

163166
If you are using a standalone billing account, the identity applying this stage for the first time needs to be a billing account administrator:
@@ -187,7 +190,7 @@ Please note that FAST also supports an additional group for users with permissio
187190
Then make sure you have configured the correct values for the following variables by providing a `terraform.tfvars` file:
188191

189192
- `billing_account`
190-
an object containing `id` as the id of your billing account, derived from the Cloud Console UI or by running `gcloud beta billing accounts list`, and `organization_id` as the id of the organization owning it, or `null` to use the billing account in isolation
193+
an object containing `id` as the id of your billing account, derived from the Cloud Console UI or by running `gcloud beta billing accounts list`, and the `is_org_level` flag that controls whether organization or account-level bindings are used, and a billing export project and dataset are created
191194
- `groups`
192195
the name mappings for your groups, if you're following the default convention you can leave this to the provided default
193196
- `organization.id`, `organization.domain`, `organization.customer_id`
@@ -202,7 +205,6 @@ You can also adapt the example that follows to your needs:
202205
# if you have too many accounts, check the Cloud Console :)
203206
billing_account = {
204207
id = "012345-67890A-BCDEF0"
205-
organization_id = 1234567890
206208
}
207209
208210
# use `gcloud organizations list`
@@ -237,18 +239,18 @@ Below is the outline of the output files generated by all stages, which is ident
237239
```bash
238240
[path specified in outputs_location]
239241
├── providers
240-
│   ├── 00-bootstrap-providers.tf
241-
│   ├── 01-resman-providers.tf
242-
│   ├── 02-networking-providers.tf
243-
│   ├── 02-security-providers.tf
244-
│   ├── 03-project-factory-dev-providers.tf
245-
│   ├── 03-project-factory-prod-providers.tf
246-
│   └── 99-sandbox-providers.tf
242+
│   ├── 0-bootstrap-providers.tf
243+
│   ├── 1-resman-providers.tf
244+
│   ├── 2-networking-providers.tf
245+
│   ├── 2-security-providers.tf
246+
│   ├── 3-project-factory-dev-providers.tf
247+
│   ├── 3-project-factory-prod-providers.tf
248+
│   └── 9-sandbox-providers.tf
247249
└── tfvars
248-
│ ├── 00-bootstrap.auto.tfvars.json
249-
│ ├── 01-resman.auto.tfvars.json
250-
│ ├── 02-networking.auto.tfvars.json
251-
│ └── 02-security.auto.tfvars.json
250+
│ ├── 0-bootstrap.auto.tfvars.json
251+
│ ├── 1-resman.auto.tfvars.json
252+
│ ├── 2-networking.auto.tfvars.json
253+
│ └── 2-security.auto.tfvars.json
252254
└── workflows
253255
└── [optional depending on the configured CI/CD repositories]
254256
```
@@ -267,17 +269,34 @@ terraform apply \
267269

268270
> If you see an error related to project name already exists, please make sure the project name is unique or the project was not deleted recently
269271
270-
Once the initial `apply` completes successfully, configure a remote backend using the new GCS bucket, and impersonation on the automation service account for this stage. To do this you can use the generated `providers.tf` file if you have configured output files as described above, or extract its contents from Terraform's output, then migrate state with `terraform init`:
272+
Once the initial `apply` completes successfully, configure a remote backend using the new GCS bucket, and impersonation on the automation service account for this stage. To do this you can use the generated `providers.tf` file from either
273+
274+
- the local filesystem if you have configured output files as described above
275+
- the GCS bucket where output files are always stored
276+
- Terraform outputs (not recommended as it's more complex)
277+
278+
The following two snippets show how to leverage the `stage-links.sh` script in the root FAST folder to fetch the commands required for output files linking or copying, using either the local output folder configured via Terraform variables, or the GCS bucket which can be derived from the `automation` output.
279+
280+
```bash
281+
../../stage-links.sh ~/fast-config
282+
283+
# copy and paste the following commands for '0-bootstrap'
284+
285+
ln -s ~/fast-config/providers/0-bootstrap-providers.tf ./
286+
```
287+
288+
```bash
289+
../../stage-links.sh gs://xxx-prod-iac-core-outputs-0
290+
291+
# copy and paste the following commands for '0-bootstrap'
292+
293+
gcloud alpha storage cp gs://xxx-prod-iac-core-outputs-0/providers/0-bootstrap-providers.tf ./
294+
```
295+
296+
Copy/paste the command returned by the script to link or copy the provider file, then migrate state with `terraform init` and run `terraform apply`:
271297

272298
```bash
273-
# if using output files via the outputs_location and set to `~/fast-config`
274-
ln -s ~/fast-config/providers/00-bootstrap* ./
275-
# or from outputs if not using output files
276-
terraform output -json providers | jq -r '.["00-bootstrap"]' \
277-
> providers.tf
278-
# migrate state to GCS bucket configured in providers file
279299
terraform init -migrate-state
280-
# run terraform apply to remove the bootstrap_user iam binding
281300
terraform apply
282301
```
283302

@@ -334,7 +353,7 @@ You can customize organization-level logs through the `log_sinks` variable in tw
334353
- creating additional log sinks to capture more logs
335354
- changing the destination of captured logs
336355

337-
By default, all logs are exported to Bigquery, but FAST can create sinks to Cloud Logging Buckets, GCS, or PubSub.
356+
By default, all logs are exported to a log bucket, but FAST can create sinks to BigQuery, GCS, or PubSub.
338357

339358
If you need to capture additional logs, please refer to GCP's documentation on [scenarios for exporting logging data](https://cloud.google.com/architecture/exporting-stackdriver-logging-for-security-and-access-analytics), where you can find ready-made filter expressions for different use cases.
340359

@@ -400,12 +419,6 @@ cicd_repositories = {
400419
name = "my-gh-org/fast-bootstrap"
401420
type = "github"
402421
}
403-
cicd = {
404-
branch = null
405-
identity_provider = "github-sample"
406-
name = "my-gh-org/fast-cicd"
407-
type = "github"
408-
}
409422
resman = {
410423
branch = "main"
411424
identity_provider = "github-sample"

fast/stages/1-resman/README.md

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ The following diagram is a high level reference of the resources created and man
1313
<img src="diagram.svg" alt="Resource-management diagram">
1414
</p>
1515

16+
## Table of contents
17+
18+
- [Design overview and choices](#design-overview-and-choices)
19+
- [Multitenancy](#multitenancy)
20+
- [Workload Identity Federation and CI/CD](#workload-identity-federation-and-cicd)
21+
- [How to run this stage](#how-to-run-this-stage)
22+
- [Provider and Terraform variables](#provider-and-terraform-variables)
23+
- [Impersonating the automation service account](#impersonating-the-automation-service-account)
24+
- [Variable configuration](#variable-configuration)
25+
- [Running the stage](#running-the-stage)
26+
- [Customizations](#customizations)
27+
- [Team folders](#team-folders)
28+
- [Organization Policies](#organization-policies)
29+
- [IAM](#iam)
30+
- [Additional folders](#additional-folders)
31+
1632
## Design overview and choices
1733

1834
Despite its simplicity, this stage implements the basics of a design that we've seen working well for a variety of customers, where the hierarchy is laid out following two conceptually different approaches:
@@ -54,51 +70,49 @@ It's of course possible to run this stage in isolation, but that's outside the s
5470

5571
Before running this stage, you need to make sure you have the correct credentials and permissions, and localize variables by assigning values that match your configuration.
5672

57-
### Providers configuration
58-
59-
The default way of making sure you have the right permissions, is to use the identity of the service account pre-created for this stage during bootstrap, and that you are a member of the group that can impersonate it via provider-level configuration (`gcp-devops` or `organization-admins`).
73+
### Provider and Terraform variables
6074

61-
To simplify setup, the previous stage pre-configures a valid providers file in its output, and optionally writes it to a local file if the `outputs_location` variable is set to a valid path.
75+
As all other FAST stages, the [mechanism used to pass variable values and pre-built provider files from one stage to the next](../0-bootstrap/README.md#output-files-and-cross-stage-variables) is also leveraged here.
6276

63-
If you have set a valid value for `outputs_location` in the bootstrap stage (see the [bootstrap stage README](../0-bootstrap/#output-files-and-cross-stage-variables) for more details), simply link the relevant `providers.tf` file from this stage's folder in the path you specified:
77+
The commands to link or copy the provider and terraform variable files can be easily derived from the `stage-links.sh` script in the FAST root folder, passing it a single argument with the local output files folder (if configured) or the GCS output bucket in the automation project (derived from stage 0 outputs). The following examples demonstrate both cases, and the resulting commands that then need to be copy/pasted and run.
6478

6579
```bash
66-
# `outputs_location` is set to `~/fast-config`
67-
ln -s ~/fast-config/providers/01-resman-providers.tf .
68-
```
80+
../../stage-links.sh ~/fast-config
6981

70-
If you have not configured `outputs_location` in bootstrap, you can derive the providers file from that stage's outputs:
82+
# copy and paste the following commands for '1-resman'
7183

72-
```bash
73-
cd ../0-bootstrap
74-
terraform output -json providers | jq -r '.["01-resman"]' \
75-
> ../1-resman/providers.tf
84+
ln -s ~/fast-config/providers/1-resman-providers.tf ./
85+
ln -s ~/fast-config/tfvars/globals.auto.tfvars.json ./
86+
ln -s ~/fast-config/tfvars/0-bootstrap.auto.tfvars.json ./
7687
```
7788

78-
If you want to continue to rely on `outputs_location` logic, create a `terraform.tfvars` file and configure it as described [here](../0-bootstrap/#output-files-and-cross-stage-variables).
89+
```bash
90+
../../stage-links.sh gs://xxx-prod-iac-core-outputs-0
7991

80-
### Variable configuration
92+
# copy and paste the following commands for '1-resman'
8193

82-
There are two broad sets of variables you will need to fill in:
94+
gcloud alpha storage cp gs://xxx-prod-iac-core-outputs-0/providers/1-resman-providers.tf ./
95+
gcloud alpha storage cp gs://xxx-prod-iac-core-outputs-0/tfvars/globals.auto.tfvars.json ./
96+
gcloud alpha storage cp gs://xxx-prod-iac-core-outputs-0/tfvars/0-bootstrap.auto.tfvars.json ./
97+
```
8398

84-
- variables shared by other stages (org id, billing account id, etc.), or derived from a resource managed by a different stage (folder id, automation project id, etc.)
85-
- variables specific to resources managed by this stage
99+
### Impersonating the automation service account
86100

87-
To avoid the tedious job of filling in the first group of variable with values derived from other stages' outputs, the same mechanism used above for the provider configuration can be used to leverage pre-configured `.tfvars` files.
101+
The preconfigured provider file uses impersonation to run with this stage's automation service account's credentials. The `gcp-devops` and `organization-admins` groups have the necessary IAM bindings in place to do that, so make sure the current user is a member of one of those groups.
88102

89-
If you configured a valid path for `outputs_location` in the bootstrap stage, simply link the relevant `*.auto.tfvars.json` files from the outputs folder. For this stage, you need the `globals.auto.tfvars.json` file containing global values compiled manually for the bootstrap stage, and `0-bootstrap.auto.tfvars.json` containing values derived from resources managed by the bootstrap stage:
103+
### Variable configuration
90104

91-
```bash
92-
# `outputs_location` is set to `~/fast-config`
93-
ln -s ~/fast-config/tfvars/globals.auto.tfvars.json .
94-
ln -s ~/fast-config/tfvars/0-bootstrap.auto.tfvars.json .
95-
```
105+
Variables in this stage -- like most other FAST stages -- are broadly divided into three separate sets:
106+
107+
- variables which refer to global values for the whole organization (org id, billing account id, prefix, etc.), which are pre-populated via the `globals.auto.tfvars.json` file linked or copied above
108+
- variables which refer to resources managed by previous stage, which are prepopulated here via the `0-bootstrap.auto.tfvars.json` file linked or copied above
109+
- and finally variables that optionally control this stage's behaviour and customizations, and can to be set in a custom `terraform.tfvars` file
96110

97-
A second set of variables is specific to this stage, they are all optional so if you need to customize them, create an extra `terraform.tfvars` file.
111+
The latter set is explained in the [Customization](#customizations) sections below, and the full list can be found in the [Variables](#variables) table at the bottom of this document.
98112

99-
Refer to the [Variables](#variables) table at the bottom of this document, for a full list of variables, their origin (e.g. a stage or specific to this one), and descriptions explaining their meaning. The sections below also describe some of the possible customizations. For billing configurations, refer to the [Bootstrap documentation on billing](../0-bootstrap/README.md#billing-account) as the `billing_account` variable is identical across all stages.
113+
### Running the stage
100114

101-
Once done, you can run this stage:
115+
Once provider and variable values are in place and the correct user is configured, the stage can be run:
102116

103117
```bash
104118
terraform init
@@ -139,9 +153,9 @@ This allows to centralize the minimum set of resources to delegate control of ea
139153

140154
### Organization policies
141155

142-
Organization policies are laid out in an explicit manner in the `organization.tf` file, so it's fairly easy to add or remove specific policies.
156+
Organization policies leverage -- with one exception -- the built-in factory implemented in the organization module, and configured via the yaml files in the `data` folder. To edit organization policies, check and edit the files there.
143157

144-
For policies where additional data is needed, a root-level `organization_policy_configs` variable allows passing in specific data. Its built-in use to add additional organizations to the [Domain Restricted Sharing](https://cloud.google.com/resource-manager/docs/organization-policy/restricting-domains) policy, can be taken as an example on how to leverage it for additional customizations.
158+
The one exception is [Domain Restricted Sharing](https://cloud.google.com/resource-manager/docs/organization-policy/restricting-domains), which is made dynamic and implemented in code so as to auto-add the current organization's customer id. The `organization_policy_configs` variable allow to easily add ids from third party organizations if needed.
145159

146160
### IAM
147161

0 commit comments

Comments
 (0)