Documentation
¶
Index ¶
- Constants
- Variables
- func AddFileExtension(file, ext string) string
- func AreEqualJSON(s1, s2 string) (bool, error)
- func AreEqualJSONBytes(b1, b2 []byte) (bool, error)
- func CheckCategory(ruleCategory string, desiredCategories []string) bool
- func CheckPolicyType(rulePolicyType string, desiredPolicyTypes []string) bool
- func CheckSeverity(ruleSeverity, desiredSeverity string) bool
- func CreateTempFile(content []byte, ext string) (*os.File, error)
- func EnsureUpperCaseTrimmed(s string) string
- func FilterFileInfoBySuffix(allFileList *[]os.FileInfo, filter []string) []*string
- func FilterHiddenDirectories(dirList []string, rootDir string) []string
- func FindAllDirectories(basePath string) ([]string, error)
- func FindFilesBySuffix(basePath string, suffixes []string) (map[string][]*string, error)
- func FindFilesBySuffixInDir(basePath string, suffixes []string) ([]*string, error)
- func GenRandomString(length int) string
- func GenerateTempDir() string
- func GetAbsPath(path string) (string, error)
- func GetAbsPolicyConfigPaths(policyBasePath, policyRepoPath string) (string, string, error)
- func GetFileMode(path string) *os.FileMode
- func GetFileURI(path string) (string, error)
- func GetHomeDir() (terrascanDir string)
- func GetMinMaxSeverity(body string) (minSeverity string, maxSeverity string)
- func GetSkipRules(body string) []output.SkipRule
- func IsDirExists(dir string) bool
- func IsSliceEqual(list1, list2 []string) bool
- func IsWindowsPlatform() bool
- func JQFilterWithQuery(jqQuery string, jsonInput []byte) ([]byte, error)
- func MaxSeverityApplicable(ruleSeverity, maxSeverity string) bool
- func MinSeverityApplicable(ruleSeverity, minSeverity string) bool
- func PrintJSON(data interface{}, writer io.Writer)
- func ReadSkipRulesFromMap(skipRulesMap map[string]interface{}, resourceID string) []output.SkipRule
- func ReadYamlFile(path string) (map[string]interface{}, error)
- func ReplaceCarriageReturnBytes(input []byte) []byte
- func ReplaceWinNewLineBytes(input []byte) []byte
- func ReplaceWinNewLineString(input string) string
- func ValidateCategoryInput(categories []string) (bool, []string)
- func ValidateSeverityInput(severity string) bool
- func WrapError(err, allErrs error) error
- type IacDocument
Constants ¶
const ( // HighSeverity high HighSeverity = "HIGH" // MediumSeverity medium MediumSeverity = "MEDIUM" // LowSeverity low LowSeverity = "LOW" )
const ( // TerrascanSkip key used to detect rules for skipping violations TerrascanSkip = "runterrascan.io/skip" // TerrascanSkipRule key used to detect the rule to be skipped TerrascanSkipRule = "rule" // TerrascanSkipComment key used to detect comment skiupping a give rule TerrascanSkipComment = "comment" // SkipRulesPrefix used to identify and trim the skipping rule patterns SkipRulesPrefix = "#ts:skip=" // MetaDataIDRegex pattern to match Rego Metadata ID MetaDataIDRegex = `(AC_)(AWS|AZURE|GCP|K8S|GITHUB|DOCKER)[_]([\d]{4})` // MetaDataReferenceIDRegex pattern to match Rego Metadata ReferenceID MetaDataReferenceIDRegex = `(([ A-Za-z0-9]+[.-]{1}){2,5})([\d]+)` // SkipRuleCommentRegex used to detect comments in skipped rule SkipRuleCommentRegex = `([ \t]+.*){0,1}` )
const (
// JSONDoc type for json files
JSONDoc = "json"
)
const (
// YAMLDoc type for yaml files
YAMLDoc = "yaml"
)
Variables ¶
var AcceptedCategories []string = []string{
"LOGGING AND MONITORING",
"COMPLIANCE VALIDATION",
"RESILIENCE",
"SECURITY BEST PRACTICES",
"INFRASTRUCTURE SECURITY",
"IDENTITY AND ACCESS MANAGEMENT",
"CONFIGURATION AND VULNERABILITY ANALYSIS",
"DATA PROTECTION",
}
AcceptedCategories is the list of all policy categories
var ( // ErrYamlFileEmpty is return when empty yaml file is being read. ErrYamlFileEmpty = fmt.Errorf("yaml file is empty") )
Functions ¶
func AddFileExtension ¶ added in v1.2.0
AddFileExtension returns full file name string after adding the extension to the filename
func AreEqualJSON ¶ added in v1.7.0
AreEqualJSON validate if two json strings are equal
func AreEqualJSONBytes ¶ added in v1.8.0
AreEqualJSONBytes validate if two json byte arrays are equal
func CheckCategory ¶ added in v1.5.0
CheckCategory validates if the category of policy rule is present in the list of specificed categories
func CheckPolicyType ¶ added in v1.7.0
CheckPolicyType checks if supplied policy type matches desired policy types
func CheckSeverity ¶ added in v1.4.0
CheckSeverity validates if the severity of policy rule is equal or above the desired severity
func CreateTempFile ¶ added in v1.5.0
CreateTempFile creates a file with provided contents in the temp directory
func EnsureUpperCaseTrimmed ¶ added in v1.4.0
EnsureUpperCaseTrimmed make sure the string is in UPPERCASE and TRIMMED
func FilterFileInfoBySuffix ¶
FilterFileInfoBySuffix Given a list of files, returns a subset of files containing a suffix which matches the input filter
func FilterHiddenDirectories ¶ added in v1.6.0
FilterHiddenDirectories filters hidden directories from a list of directories TODO: filtering hidden directories on windows
func FindAllDirectories ¶
FindAllDirectories Walks the file path and returns a list of all directories within
func FindFilesBySuffix ¶ added in v1.1.0
FindFilesBySuffix finds all files within a given directory that have the specified suffixes Returns a map with keys as directories and values as a list of files
func FindFilesBySuffixInDir ¶ added in v1.2.0
FindFilesBySuffixInDir finds all the immediate files within a given directory that have the specified suffixes IT DOES NOT LOOK INTO ANY SUBDIRECTORY. JUST A SINGLE LEVEL FILE SEARCH. Returns an array for string pointers as a list of files
func GenRandomString ¶ added in v1.2.0
GenRandomString creates and returns a random string of provided length
func GenerateTempDir ¶ added in v1.6.0
func GenerateTempDir() string
GenerateTempDir generates a temporary directory
func GetAbsPath ¶
GetAbsPath returns absolute path from passed file path resolving even ~ to user home dir and any other such symbols that are only shell expanded can also be handled here
func GetAbsPolicyConfigPaths ¶ added in v1.5.0
GetAbsPolicyConfigPaths tranforms the provided policy base path and repo path into absolute paths
func GetFileMode ¶ added in v1.8.0
GetFileMode fetches the filemode from a file path
func GetFileURI ¶ added in v1.13.0
GetFileURI returns the rfc3986 format file uri from a path string https://tools.ietf.org/html/rfc3986 always use / and for windows it starts three ///
func GetHomeDir ¶ added in v1.4.0
func GetHomeDir() (terrascanDir string)
GetHomeDir returns the home directory path
func GetMinMaxSeverity ¶ added in v1.7.0
GetMinMaxSeverity returns the min and max severity to be applied to resources. can be set in terraform resource config with the following patterns #ts:minseverity = "High" --> any violation for this resource will be high #ts:maxseverity = "None" --> any violation for this resource will be ignored only one value will be considered
func GetSkipRules ¶ added in v1.3.0
GetSkipRules returns a list of rules to be skipped. The rules to be skipped can be set in terraform resource config with the following pattern: #ts:skip=AWS.S3Bucket.DS.High.1043 #ts:skip=AWS.S3Bucket.DS.High.1044 reason to skip the rule each rule and its optional comment must be in a new line
func IsDirExists ¶ added in v1.7.0
IsDirExists checks wether the provided directory exists or not
func IsSliceEqual ¶ added in v1.4.0
IsSliceEqual checks if two slices of string are equal or not
func IsWindowsPlatform ¶ added in v1.5.0
func IsWindowsPlatform() bool
IsWindowsPlatform checks if os is windows
func JQFilterWithQuery ¶ added in v1.4.0
JQFilterWithQuery runs jq query on the given input and returns the output
func MaxSeverityApplicable ¶ added in v1.7.0
MaxSeverityApplicable verifies if the severity of policy rule need to be changed to the maximum severity level
func MinSeverityApplicable ¶ added in v1.7.0
MinSeverityApplicable verifies if the severity of policy rule need to be changed to the minimum severity level
func ReadSkipRulesFromMap ¶ added in v1.7.0
ReadSkipRulesFromMap returns a list of rules to be skipped. The rules to be skipped can be set in annotations for kubernetes manifests and Resource Metadata in AWS cft: k8s: metadata:
annotations: runterrascan.io/skip: | [{"rule": "accurics.kubernetes.IAM.109", "comment": "reason to skip the rule"}]
cft: Resource:
myResource: Metadata: runterrascan.io/skip: | [{"rule": "AC_AWS_047", "comment": "reason to skip the rule"}]
cft json:
"Resource":{ "myResource":{ "Metadata":{ "runterrascan.io/skip": "[{\"rule\":\"AWS.CloudFormation.Medium.0603\"}]" } } }
each rule and its optional comment must be a string containing an json array like [{rule: ruleID, comment: reason for skipping}]
func ReadYamlFile ¶ added in v1.2.0
ReadYamlFile reads a yaml file and load content in a map[string]interface{} type
func ReplaceCarriageReturnBytes ¶ added in v1.5.0
ReplaceCarriageReturnBytes replaces windows new lines characters in a string
func ReplaceWinNewLineBytes ¶ added in v1.5.0
ReplaceWinNewLineBytes replaces windows new lines with unix new lines in a byte slice
func ReplaceWinNewLineString ¶ added in v1.5.0
ReplaceWinNewLineString replaces windows new lines with unix new lines in a string
func ValidateCategoryInput ¶ added in v1.5.0
ValidateCategoryInput validates input for --category flag
func ValidateSeverityInput ¶ added in v1.4.0
ValidateSeverityInput validates input for --severity flag
Types ¶
type IacDocument ¶ added in v1.1.0
IacDocument contains raw IaC file data and other metadata for a given file
func LoadJSON ¶ added in v1.1.0
func LoadJSON(filePath string) ([]*IacDocument, error)
LoadJSON loads a JSON file into an IacDocument struct
func LoadYAML ¶ added in v1.1.0
func LoadYAML(filePath string) ([]*IacDocument, error)
LoadYAML loads a YAML file. Can return one or more IaC Documents. Besides reading in file data, its main purpose is to determine and store line number and filename metadata
func LoadYAMLString ¶ added in v1.2.0
func LoadYAMLString(data, absFilePath string) ([]*IacDocument, error)
LoadYAMLString loads a YAML String. Can return one or more IaC Documents. Besides reading in file data, its main purpose is to determine and store line number and filename metadata
func ScanIacDocumentsFromYaml ¶ added in v1.2.0
func ScanIacDocumentsFromYaml(scanner *bufio.Scanner, byteArray []byte, filePath string) ([]*IacDocument, error)
ScanIacDocumentsFromYaml provides one or more IaC Documents. Besides reading in file data, its main purpose is to determine and store line number and filename metadata