Skip to content

Commit 4bee370

Browse files
authored
CI: add super-linter (#4)
* Configure super-linter GHA and fix directory structure
1 parent 90ee3e8 commit 4bee370

File tree

13 files changed

+287
-14
lines changed

13 files changed

+287
-14
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FIX_ENV=true
2+
FIX_JSON=true
3+
FIX_JSON_PRETTIER=true
4+
FIX_MARKDOWN=true
5+
FIX_MARKDOWN_PRETTIER=true
6+
FIX_PYTHON_BLACK=true
7+
FIX_PYTHON_ISORT=true
8+
FIX_PYTHON_RUFF=true
9+
FIX_SHELL_SHFMT=true
10+
FIX_TERRAFORM_FMT=true
11+
FIX_YAML_PRETTIER=true

.github/linters/super-linter.env

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
CREATE_LOG_FILE=false
2+
DEFAULT_BRANCH=main
3+
GITLEAKS_LOG_LEVEL=warn
4+
IGNORE_GITIGNORED_FILES=true
5+
REMOVE_ANSI_COLOR_CODES_FROM_OUTPUT=true
6+
VALIDATE_BASH=true
7+
VALIDATE_BASH_EXEC=true
8+
VALIDATE_CHECKOV=true
9+
VALIDATE_DOCKERFILE_HADOLINT=true
10+
VALIDATE_EDITORCONFIG=true
11+
VALIDATE_ENV=true
12+
VALIDATE_GITHUB_ACTIONS=true
13+
VALIDATE_GITLEAKS=true
14+
VALIDATE_JSON=true
15+
VALIDATE_JSON_PRETTIER=true
16+
VALIDATE_MARKDOWN=true
17+
VALIDATE_MARKDOWN_PRETTIER=true
18+
VALIDATE_NATURAL_LANGUAGE=true
19+
VALIDATE_PYTHON_BLACK=true
20+
VALIDATE_PYTHON_FLAKE8=true
21+
VALIDATE_PYTHON_ISORT=true
22+
VALIDATE_PYTHON_MYPY=true
23+
VALIDATE_PYTHON_RUFF=true
24+
VALIDATE_RENOVATE=true
25+
VALIDATE_SHELL_SHFMT=true
26+
VALIDATE_TERRAFORM_FMT=true
27+
VALIDATE_TERRAFORM_TFLINT=true
28+
VALIDATE_YAML=true
29+
VALIDATE_YAML_PRETTIER=true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ jobs:
5151
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
5252
commit_message: "chore: add license headers"
5353
commit_user_name: addlicense
54-
commit_user_email: no-reply@addlicense.dev
54+
commit_user_email: no-reply@addlicense.dev

.github/workflows/lint.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
name: Lint
17+
18+
on: # yamllint disable-line rule:truthy
19+
push: null
20+
pull_request: null
21+
workflow_call: null
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
lint:
28+
concurrency:
29+
# Ref: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
30+
# github.head_ref: head_ref or source branch of the pull request
31+
# github.ref: ref of the branch that triggered the workflow
32+
group: ${{ github.workflow }}-lint-${{ github.head_ref || github.ref }}-${{ github.event_name }}
33+
cancel-in-progress: true
34+
permissions:
35+
contents: read
36+
packages: read
37+
statuses: write
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
with:
42+
fetch-depth: 0
43+
- name: Load super-linter configuration
44+
# Use grep inverse matching to exclude eventual comments in the .env file
45+
# because the GitHub Actions command to set environment variables doesn't
46+
# support comments.
47+
# Ref: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable
48+
run: grep -v '^#' .github/linters/super-linter.env >> "$GITHUB_ENV"
49+
- name: Super-Linter
50+
uses: super-linter/super-linter@v7.2.1
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
# Environment-specific variables
1010
*.tfvars
1111
*.tfvars.json
12+
13+
# Super Linter output files
14+
super-linter-output/*

CONTRIBUTING

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,27 @@ This project follows
3030
All submissions, including submissions by project members, require review. We
3131
use GitHub pull requests for this purpose. Consult
3232
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
33-
information on using pull requests.
33+
information on using pull requests.
34+
35+
### Linting and Formatting
36+
37+
Many of the files in the repository are checked against linting tools and static code analysis for secure coding practices. This workflow is triggered by [.github/workflows/lint.yaml](.github/workflows/lint.yaml), running multiple lint libraries in [Super-Linter](https://github.com/super-linter/super-linter) with the settings configured in [.github/linters/super-linter.env](.github/linters/super-linter.env)
38+
39+
1. To validate that your code passes these checks, use the following methods depending on your environment:
40+
41+
1. **GitHub Actions**: GitHub Actions will automatically run all configured checks when a PR is created or modified.
42+
43+
1. **Local**: You can manually trigger the tests in a docker container from your local environment with the following command:
44+
45+
```bash
46+
./run_linters.sh
47+
```
48+
49+
1. For issues that can be fixed automatically, you can automatically fix issues in your local environment with either of the following methods:
50+
51+
1. **Fix mode**: Run super-linter locally in fix mode by setting an environment variable to additionally run automatic fixes for the libraries configure
52+
53+
```bash
54+
export LINTER_CONTAINER_FIX_MODE=true
55+
./run_linters.sh
56+
```

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
# OCISO Solutions
1+
# OCISO Solutions
22

3-
3+
This repository contains solutions and sample code from the Google Cloud Office of the Chief Information Security Officer (OCISO) team.
4+
Each sub-directory is a standalone solution that addresses different use cases.
5+
6+
This is not an official Google product.

gcmvsp/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Google Cloud Minimum Viable Secure Platform (GCMVSP)
32

43
This repository contains sample code to implement the set of terraform policies recommended by GMVSP.
@@ -8,16 +7,17 @@ This repository assumes you're already familiar with the [Organisation Policy Se
87

98
We recommend that new organizations should apply the full set of policies before creating other resources on Google Cloud. This creates a guardrail that resources cannot be created in violation of the organization policies.
109

11-
For existing Google Cloud customers that have already created resources, implementing policies at the organization node can be risky, and might have existing resources in violation of the policy. In this scenario, we recommend that you use a combination of the following strategies:
12-
- [Test organization policy changes with Policy Simulator](https://docs.cloud.google.com/policy-intelligence/docs/test-organization-policies)
13-
- [Create an organization policy in dry-run mode](https://docs.cloud.google.com/resource-manager/docs/organization-policy/dry-run-policy)
14-
- For legacy policies that don't support Policy Simulator or dry-run mode, enforce policies gradually by apply to a non-critical project or folder first to assess potential violations.
10+
For existing Google Cloud customers that have already created resources, implementing policies at the organization node can be risky, and might have existing resources in violation of the policy. In this scenario, we recommend that you use a combination of the following strategies:
11+
12+
- [Test organization policy changes with Policy Simulator](https://docs.cloud.google.com/policy-intelligence/docs/test-organization-policies)
13+
- [Create an organization policy in dry-run mode](https://docs.cloud.google.com/resource-manager/docs/organization-policy/dry-run-policy)
14+
- For legacy policies that don't support Policy Simulator or dry-run mode, enforce policies gradually by apply to a non-critical project or folder first to assess potential violations.
1515

1616
## Quickstart
1717

1818
To deploy the Infrastructure-as-Code (IaC) resources using terraform, perform the follow steps:
1919

20-
1. Decide where in the [resource hierarchy](https://docs.cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy) (organization, folder, or project) you will apply organization policies.
20+
1. Decide where in the [resource hierarchy](https://docs.cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy) (organization, folder, or project) you will apply organization policies.
2121

2222
1. This example code is deployed through Terraform using your own user identity. Your user identity needs the following [IAM Roles](https://cloud.google.com/iam/docs/roles-overview) on your organization, folder, or project:
2323

@@ -46,9 +46,9 @@ To deploy the Infrastructure-as-Code (IaC) resources using terraform, perform th
4646

4747
1. Create a terraform.tfvars file with the following variables:
4848

49-
| Terraform variables | Description |
50-
| --------------------------- | ----------------------------------------------------------------------------------------------------- |
51-
| parent_id | The ID of your your Google Cloud organization, folder, or project in the format organizations/123456789, folders/123456789, or projects/project-id. |
49+
| Terraform variables | Description |
50+
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
51+
| parent_id | The ID of your your Google Cloud organization, folder, or project in the format organizations/123456789, folders/123456789, or projects/project-id. |
5252

5353
1. Initialize Terraform:
5454

@@ -60,4 +60,4 @@ To deploy the Infrastructure-as-Code (IaC) resources using terraform, perform th
6060

6161
```sh
6262
terraform apply
63-
```
63+
```

gcmvsp/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
resource "google_org_policy_policy" "require_os_login" {
216
name = "${var.parent_id}/policies/compute.managed.requireOsLogin"
317
parent = var.parent_id

gcmvsp/providers.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
terraform {
216
required_providers {
317
google = {

0 commit comments

Comments
 (0)