Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pulumi): add support to Pulumi yaml parsing #5648

Merged
merged 6 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/scripts/metrics/get_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'grpc': os.path.join(queries_basepath, 'grpc', '*'),
'gdm': os.path.join(queries_basepath, 'googleDeploymentManager', '*'),
'dockerCompose': os.path.join(queries_basepath, 'dockerCompose', '*'),
'pulumi': os.path.join(queries_basepath, 'pulumi', '*'),
}
samples_ext = {
'azureresourcemanager': ['json'],
Expand All @@ -35,7 +36,7 @@
'grpc': ['proto'],
'gdm': ['yaml'],
'dockerCompose': ['dockerCompose'],

'pulumi': ['yaml'],
}
summary = {
'total': 0,
Expand Down
3 changes: 2 additions & 1 deletion .github/scripts/queries-validator/metadata-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
"Knative",
"Kubernetes",
"OpenAPI",
"Terraform"
"Terraform",
"Pulumi"
]
},
"descriptionID": {
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ Find security vulnerabilities, compliance issues, and infrastructure misconfigur
<img alt="Cloud Deployment Kit" src="docs/img/logo-cdk.png" width="150">&nbsp;&nbsp;&nbsp;
<img alt="SAM" src="docs/img/logo-sam.png" width="55">&nbsp;&nbsp;&nbsp;
<img alt="Docker Compose" src="docs/img/logo-dockercompose.png" width="80">&nbsp;&nbsp;&nbsp;
<img alt="Knative" src="docs/img/logo-knative.png" width="80">&nbsp;&nbsp;&nbsp;
<br>
<br>
<img alt="Crossplane" src="docs/img/logo-crossplane.png" width="150">&nbsp;&nbsp;&nbsp;
<img alt="Pulumi" src="docs/img/logo-pulumi.png" width="130">&nbsp;&nbsp;&nbsp;



Support of other solutions and additional cloud providers are on the [roadmap](docs/roadmap.md).

Expand Down
1 change: 1 addition & 0 deletions assets/libraries/pulumi.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package generic.pulumi
2 changes: 1 addition & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Flags:
-r, --secrets-regexes-path string path to secrets regex rules configuration file
--timeout int number of seconds the query has to execute before being canceled (default 60)
-t, --type strings case insensitive list of platform types to scan
(Ansible, AzureResourceManager, Buildah, CloudFormation, Crossplane, DockerCompose, Dockerfile, GRPC, GoogleDeploymentManager, Knative, Kubernetes, OpenAPI, Terraform)
(Ansible, AzureResourceManager, Buildah, CloudFormation, Crossplane, DockerCompose, Dockerfile, GRPC, GoogleDeploymentManager, Knative, Kubernetes, OpenAPI, Pulumi, Terraform)

Global Flags:
--ci display only log messages to CLI output (mutually exclusive with silent)
Expand Down
2 changes: 1 addition & 1 deletion docs/dockerhub.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Flags:
-r, --secrets-regexes-path string path to secrets regex rules configuration file
--timeout int number of seconds the query has to execute before being canceled (default 60)
-t, --type strings case insensitive list of platform types to scan
(Ansible, AzureResourceManager, Buildah, CloudFormation, Crossplane, DockerCompose, Dockerfile, GRPC, GoogleDeploymentManager, Knative, Kubernetes, OpenAPI, Terraform)
(Ansible, AzureResourceManager, Buildah, CloudFormation, Crossplane, DockerCompose, Dockerfile, GRPC, GoogleDeploymentManager, Knative, Kubernetes, OpenAPI, Pulumi, Terraform)

Global Flags:
--ci display only log messages to CLI output (mutually exclusive with silent)
Expand Down
Binary file added docs/img/logo-crossplane.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/logo-knative.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/logo-pulumi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ KICS supports scanning Kubernetes manifests with `.yaml` extension.

KICS supports scanning Swagger 2.0 and OpenAPI 3.0 specs with `.json` and `.yaml` extension.

## Pulumi

KICS supports scanning Pulumi manifests with `.yaml` extension.


## Google Deployment Manager

KICS supports scanning Google Deployment Manager files with `.yaml` extension.
Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/E2E_CLI_010
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ valid arguments:
Knative
Kubernetes
OpenAPI
Pulumi
Terraform
{{.ScanHelp}}
1 change: 1 addition & 0 deletions e2e/fixtures/E2E_CLI_013
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ GoogleDeploymentManager
Knative
Kubernetes
OpenAPI
Pulumi
Terraform
2 changes: 1 addition & 1 deletion e2e/fixtures/assets/scan_help
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Flags:
-r, --secrets-regexes-path string path to secrets regex rules configuration file
--timeout int number of seconds the query has to execute before being canceled (default 60)
-t, --type strings case insensitive list of platform types to scan
(Ansible, AzureResourceManager, Buildah, CloudFormation, Crossplane, DockerCompose, Dockerfile, GRPC, GoogleDeploymentManager, Knative, Kubernetes, OpenAPI, Terraform)
(Ansible, AzureResourceManager, Buildah, CloudFormation, Crossplane, DockerCompose, Dockerfile, GRPC, GoogleDeploymentManager, Knative, Kubernetes, OpenAPI, Pulumi, Terraform)

Global Flags:
--ci display only log messages to CLI output (mutually exclusive with silent)
Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/schemas/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"Knative",
"Kubernetes",
"OpenAPI",
"Pulumi",
"Terraform"
]
},
Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/schemas/resultBoM.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"Knative",
"Kubernetes",
"OpenAPI",
"Pulumi",
"Terraform"
]
},
Expand Down
1 change: 1 addition & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var (
"GoogleDeploymentManager": "googleDeploymentManager",
"GRPC": "grpc",
"Buildah": "buildah",
"Pulumi": "pulumi",
}

// AvailableSeverities - All severities available
Expand Down
11 changes: 11 additions & 0 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ var (
dockerComposeServicesRegex = regexp.MustCompile(`\s*services\s*:`)
crossPlaneRegex = regexp.MustCompile(`\s*\"?apiVersion\"?\s*:\s*(\w+\.)+crossplane\.io/v\w+\s*`)
knativeRegex = regexp.MustCompile(`\s*\"?apiVersion\"?\s*:\s*(\w+\.)+knative\.dev/v\w+\s*`)
pulumiNameRegex = regexp.MustCompile(`\s*name\s*:`)
pulumiRuntimeRegex = regexp.MustCompile(`\s*runtime\s*:`)
pulumiResourcesRegex = regexp.MustCompile(`\s*resources\s*:`)
)

var (
Expand Down Expand Up @@ -86,6 +89,7 @@ var (
"kubernetes": {"kubernetes"},
"openapi": {"openapi"},
"terraform": {"terraform", "cdkTf"},
"pulumi": {"pulumi"},
}
)

Expand Down Expand Up @@ -209,6 +213,13 @@ var types = map[string]regexSlice{
dockerComposeServicesRegex,
},
},
"pulumi": {
[]*regexp.Regexp{
pulumiNameRegex,
pulumiRuntimeRegex,
pulumiResourcesRegex,
},
},
}

// Analyze will go through the slice paths given and determine what type of queries should be loaded
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAnalyzer_Analyze(t *testing.T) {
{
name: "analyze_test_dir_single_path",
paths: []string{filepath.FromSlash("../../test/fixtures/analyzer_test")},
wantTypes: []string{"dockerfile", "googledeploymentmanager", "cloudformation", "crossplane", "knative", "kubernetes", "openapi", "terraform", "ansible", "azureresourcemanager", "dockercompose"},
wantTypes: []string{"dockerfile", "googledeploymentmanager", "cloudformation", "crossplane", "knative", "kubernetes", "openapi", "terraform", "ansible", "azureresourcemanager", "dockercompose", "pulumi"},
wantExclude: []string{},
wantErr: false,
},
Expand Down
54 changes: 23 additions & 31 deletions pkg/engine/source/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,39 +406,31 @@ func ReadMetadata(queryDir string) (map[string]interface{}, error) {
return metadata, nil
}

type supportedPlatforms map[string]string

var supPlatforms = &supportedPlatforms{
"Ansible": "ansible",
"CloudFormation": "cloudFormation",
"Common": "common",
"Crossplane": "crossplane",
"Dockerfile": "dockerfile",
"DockerCompose": "dockerCompose",
"Knative": "knative",
"Kubernetes": "k8s",
"OpenAPI": "openAPI",
"Terraform": "terraform",
"AzureResourceManager": "azureResourceManager",
"GRPC": "grpc",
"GoogleDeploymentManager": "googleDeploymentManager",
"Buildah": "buildah",
"Pulumi": "pulumi",
}

func getPlatform(metadataPlatform string) string {
switch metadataPlatform {
case "Ansible":
return "ansible"
case "CloudFormation":
return "cloudFormation"
case "Common":
return "common"
case "Crossplane":
return "crossplane"
case "Dockerfile":
return "dockerfile"
case "DockerCompose":
return "dockerCompose"
case "Knative":
return "knative"
case "Kubernetes":
return "k8s"
case "OpenAPI":
return "openAPI"
case "Terraform":
return "terraform"
case "AzureResourceManager":
return "azureResourceManager"
case "GRPC":
return "grpc"
case "GoogleDeploymentManager":
return "googleDeploymentManager"
case "Buildah":
return "buildah"
default:
return "unknown"
if p, ok := (*supPlatforms)[metadataPlatform]; ok {
return p
}
return "unknown"
}

func readInputData(inputDataPath string) (string, error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/engine/source/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ func TestListSupportedPlatforms(t *testing.T) {
"Knative",
"Kubernetes",
"OpenAPI",
"Pulumi",
"Terraform",
}
listActual := ListSupportedPlatforms()
Expand Down
1 change: 1 addition & 0 deletions pkg/parser/yaml/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (p *Parser) SupportedTypes() map[string]bool {
"openapi": true,
"googledeploymentmanager": true,
"dockercompose": true,
"pulumi": true,
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/parser/yaml/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestParser_SupportedTypes(t *testing.T) {
"openapi": true,
"googledeploymentmanager": true,
"dockercompose": true,
"pulumi": true,
}, p.SupportedTypes())
}

Expand Down
28 changes: 28 additions & 0 deletions res/demoPulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: aws-eks
runtime: yaml
description: An EKS cluster
variables:
vpcId:
Fn::Invoke:
Function: aws:ec2:getVpc
Arguments:
default: true
Return: id
subnetIds:
Fn::Invoke:
Function: aws:ec2:getSubnetIds
Arguments:
vpcId: ${vpcId}
Return: ids
resources:
cluster:
type: eks:Cluster
properties:
vpcId: ${vpcId}
subnetIds: ${subnetIds}
instanceType: "t2.medium"
desiredCapacity: 2
minSize: 1
maxSize: 2
outputs:
kubeconfig: ${cluster.kubeconfig}
28 changes: 28 additions & 0 deletions test/fixtures/analyzer_test/pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: aws-eks
runtime: yaml
description: An EKS cluster
variables:
vpcId:
Fn::Invoke:
Function: aws:ec2:getVpc
Arguments:
default: true
Return: id
subnetIds:
Fn::Invoke:
Function: aws:ec2:getSubnetIds
Arguments:
vpcId: ${vpcId}
Return: ids
resources:
cluster:
type: eks:Cluster
properties:
vpcId: ${vpcId}
subnetIds: ${subnetIds}
instanceType: "t2.medium"
desiredCapacity: 2
minSize: 1
maxSize: 2
outputs:
kubeconfig: ${cluster.kubeconfig}