Git Product home page Git Product logo

Comments (4)

cx-henriqueAlvelos avatar cx-henriqueAlvelos commented on September 24, 2024

Hello!
REGO playground doesn't have data.generic.cloudformation because it is not a default library. This redirects to a file in our source code with multiple policies which is included get_resource_name and getPath.
Also, you can notice that this file imports another file which references to here
You could do this in two ways:

  1. Import all these functions to REGO Playground and then run it (after that you need to delete import data.generic.cloudformation as cf_lib line and remove all occurRences of cf_lib
  2. Create a new query in this folder.

If you choose the second option, you need to:

  1. Create a folder;
  2. Create a metadata file with some attributes (check other queries);
  3. Create a query.rego file with your code
  4. Run it with go run ./cmd/console/main.go scan -d payload -o out -v -q <PATH_TO_QUERY_FOLDER> -p <PATH_TO_YOUR_FILE>

from kics.

tblinux avatar tblinux commented on September 24, 2024

from kics.

cx-henriqueAlvelos avatar cx-henriqueAlvelos commented on September 24, 2024

Hello.
Basically copy those policies to rego playground. Like this:

package Cx

// From assets/libraries/common.rego
get_tag_name_if_exists(resource) = name {
	name := resource.tags.Name
} else = name {
	tag := resource.Properties.Tags[_]
	tag.Key == "Name"
	name := tag.Value
} else = name {
	tag := resource.Properties.FileSystemTags[_]
	tag.Key == "Name"
	name := tag.Value
} else = name {
	tag := resource.Properties.Tags[key]
	key == "Name"
	name := tag
} else = name {
	tag := resource.spec.forProvider.tags[_]
	tag.key == "Name"
	name := tag.value
} else = name {
	tag := resource.properties.tags[key]
	key == "Name"
	name := tag
}

//From assets/libraries/cloudFormation.rego
get_resource_name(resource, resourceDefinitionName) = name {
	field := resourceFieldName[resource.Type]
	name := resource.Properties[field]
} else = name {
        //changed common_lib.get_tag_name_if_exists to get_tag_name_if_exists
	name := get_tag_name_if_exists(resource)
} else = name {
	name := resourceDefinitionName
}

//this is your code
CxPolicy[result] {
	docs := input.document[i]
	[path, Resources] := walk(docs)
	resource := Resources[name]
	ports := [20, 21, 22, 23, 115, 137, 138, 139, 2049, 3389]

	check_security_groups_ingress(resource.Properties, ports)

	result := {
		"documentId": input.document[i].id,
		"resourceType": resource.Type,
                //changed  cf_lib.get_resource_name to get_resource_name
		"resourceName": get_resource_name(resource, name),
		"searchKey": sprintf("%s%s.Properties.SecurityGroupIngress", [cf_lib.getPath(path), name]),
		"issueType": "IncorrectValue",
		"keyExpectedValue": sprintf("None of the Resources.%s.Properties.SecurityGroupIngress should have an exposed port", [name]),
		"keyActualValue": sprintf("One of the Resources.%s.Properties.SecurityGroupIngress has a exposed port (20,21,22,23,115,137,138,2049,3389)", [name]),
	}
}

check_security_groups_ingress(group, ports) {
	some p
	group.SecurityGroupIngress[_].FromPort == ports[p]
}

check_security_groups_ingress(group, ports) {
	some p
	group.SecurityGroupIngress[_].ToPort == ports[p]
}

You just need to pay attention when policies call other policies, because you need to copy
Best regards

from kics.

tblinux avatar tblinux commented on September 24, 2024

Oh Okay! In this case, Second approach looks much better!

Thanks for the help.

from kics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.