-
Notifications
You must be signed in to change notification settings - Fork 27
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
Support for Pipeline As Code Tekton #174
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b564aa
parse pipeline as code tekton
SUSTAPLE117 9c7926b
parse script properly
SUSTAPLE117 11202b7
untrusted checkout pipeline as code tekton
SUSTAPLE117 77012b4
forgot print
SUSTAPLE117 8960f9e
added injection detection for script steps
SUSTAPLE117 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package models | ||
|
||
import "gopkg.in/yaml.v3" | ||
|
||
type PipelineAsCodeTekton struct { | ||
ApiVersion string `json:"api_version" yaml:"apiVersion"` | ||
Kind string `json:"kind"` | ||
Metadata struct { | ||
Name string `json:"name"` | ||
Annotations map[string]string `json:"annotations"` | ||
} `json:"metadata"` | ||
Spec PipelineRunSpec `json:"spec,omitempty" yaml:"spec"` | ||
|
||
Path string `json:"path" yaml:"-"` | ||
} | ||
|
||
type PipelineRunSpec struct { | ||
PipelineSpec *PipelineSpec `json:"pipeline_spec,omitempty" yaml:"pipelineSpec"` | ||
} | ||
|
||
type PipelineSpec struct { | ||
Tasks []PipelineTask `json:"tasks,omitempty" yaml:"tasks"` | ||
} | ||
|
||
type PipelineTask struct { | ||
Name string `json:"name,omitempty"` | ||
|
||
TaskSpec *TaskSpec `json:"task_spec,omitempty" yaml:"taskSpec"` | ||
} | ||
|
||
type TaskSpec struct { | ||
Steps []Step `json:"steps,omitempty"` | ||
} | ||
|
||
type Step struct { | ||
Name string `json:"name"` | ||
Script string `json:"script,omitempty"` | ||
Lines map[string]int `json:"lines" yaml:"-"` | ||
} | ||
|
||
func (o *Step) UnmarshalYAML(node *yaml.Node) error { | ||
type step Step | ||
var s step | ||
if err := node.Decode(&s); err != nil { | ||
return err | ||
} | ||
|
||
if node.Kind == yaml.MappingNode { | ||
s.Lines = map[string]int{"start": node.Line} | ||
for i := 0; i < len(node.Content); i += 2 { | ||
key := node.Content[i].Value | ||
switch key { | ||
case "script": | ||
s.Lines[key] = node.Content[i+1].Line | ||
} | ||
} | ||
} | ||
|
||
*o = Step(s) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ build_commands[cmd] = { | |
"bundler": {"bundle install", "bundle exec "}, | ||
"ant": {"^ant "}, | ||
"mkdocs": {"mkdocs build"}, | ||
"vale": {"vale "}, | ||
}[cmd] | ||
|
||
results contains poutine.finding(rule, pkg_purl, { | ||
|
@@ -134,3 +135,26 @@ find_ado_checkout(stage) := xs if { | |
s[step_attr] == "self" | ||
} | ||
} | ||
|
||
# Pipeline As Code Tekton | ||
|
||
results contains poutine.finding(rule, pkg.purl, { | ||
"path": pipeline.path, | ||
"job": task.name, | ||
"step": step_idx, | ||
"line": step.lines["script"], | ||
"details": sprintf("Detected usage of `%s`", [cmd]), | ||
}) if { | ||
pkg := input.packages[_] | ||
pipeline := pkg.pipeline_as_code_tekton[_] | ||
contains(pipeline.api_version, "tekton.dev") | ||
pipeline.kind == "PipelineRun" | ||
contains(pipeline.metadata.annotations["pipelinesascode.tekton.dev/on-event"], "pull_request") | ||
contains(pipeline.metadata.annotations["pipelinesascode.tekton.dev/task"], "git-clone") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we can ship with just that, I'll file an issue #185 |
||
task := pipeline.spec.pipeline_spec.tasks[_] | ||
step := task.task_spec.steps[step_idx] | ||
regex.match( | ||
sprintf("([^a-z]|^)(%v)", [concat("|", build_commands[cmd])]), | ||
step.script, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: linters | ||
annotations: | ||
pipelinesascode.tekton.dev/on-event: "[push, pull_request]" | ||
pipelinesascode.tekton.dev/on-target-branch: "[*]" | ||
pipelinesascode.tekton.dev/task: "[git-clone]" | ||
spec: | ||
params: | ||
- name: repo_url | ||
value: "{{repo_url}}" | ||
- name: revision | ||
value: "{{revision}}" | ||
pipelineSpec: | ||
params: | ||
- name: repo_url | ||
- name: revision | ||
tasks: | ||
- name: fetchit | ||
displayName: "Fetch git repository" | ||
params: | ||
- name: url | ||
value: $(params.repo_url) | ||
- name: revision | ||
value: $(params.revision) | ||
taskRef: | ||
name: git-clone | ||
workspaces: | ||
- name: output | ||
workspace: source | ||
- name: vale | ||
displayName: "Spelling and Grammar" | ||
runAfter: | ||
- fetchit | ||
taskSpec: | ||
workspaces: | ||
- name: source | ||
steps: | ||
- name: vale-lint | ||
image: jdkato/vale | ||
workingDir: $(workspaces.source.path) | ||
script: | | ||
vale docs/content --minAlertLevel=error --output=line | ||
- name: injection | ||
image: jdkato/vale | ||
workingDir: $(workspaces.source.path) | ||
script: | | ||
binary {{body.pull_request.body}} | ||
workspaces: | ||
- name: source | ||
workspace: source | ||
workspaces: | ||
- name: source | ||
workspaces: | ||
- name: source | ||
volumeClaimTemplate: | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 5Gi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed an issue #184 to add more