Skip to content

Commit 9940c9e

Browse files
committed
update: Set remeber-ok-to-test settings to false by default
`remeber-ok-to-test` setting is set to false by default to mitigate security risks of enabling an attacker to gain trust of repo owner and push malicious code. fixes: #1798 https://issues.redhat.com/browse/SRVKP-7238 Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 8ce32f3 commit 9940c9e

File tree

20 files changed

+123
-22
lines changed

20 files changed

+123
-22
lines changed

config/302-pac-configmap.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ data:
129129
# pull request if ok-to-test is done once
130130
#
131131
# you may want to disable this if ok-to-test should be done on each iteration
132-
remember-ok-to-test: "true"
132+
remember-ok-to-test: "false"
133133

134134
# Configure a custom console here, the driver support custom parameters from
135135
# Repo CR along a few other template variable, see documentation for more

docs/content/docs/install/settings.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,13 @@ There is a few things you can configure through the config map
130130
case of push event on pull request either through new commit or amend, then CI will
131131
re-run automatically
132132

133-
You can disable by setting false if you want to provide `ok-to-test` on every iteration
133+
By default, the `remember-ok-to-test` setting is set to false in Pipelines-as-Code to mitigate serious security risks.
134+
An attacker could submit a seemingly harmless PR to gain the repository owner's trust, and later
135+
inject malicious code designed to compromise the build system, such as exfiltrating secrets.
136+
137+
Enabling this feature increases the risk of unauthorized access and is therefore strongly discouraged
138+
unless absolutely necessary. If you choose to enable it you can set it to true, you do so at your own
139+
risk and should be aware of the potential security vulnerabilities.
134140
(only GitHub and Gitea is supported at the moment).
135141

136142
### Tekton Hub support

pkg/formatting/starting.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ import (
77
)
88

99
//go:embed templates/starting.go.tmpl
10-
var StartingPipelineRunText string
10+
var StartingPipelineRunHTML string
11+
12+
//go:embed templates/starting.markdown.go.tmpl
13+
var StartingPipelineRunMarkdown string
1114

1215
//go:embed templates/queuing.go.tmpl
13-
var QueuingPipelineRunText string
16+
var QueuingPipelineRunHTML string
17+
18+
//go:embed templates/queuing.markdown.go.tmpl
19+
var QueuingPipelineRunMarkdown string
1420

1521
//go:embed templates/pipelinerunstatus.tmpl
16-
var PipelineRunStatusText string
22+
var PipelineRunStatusHTML string
23+
24+
//go:embed templates/pipelinerunstatus_markdown.tmpl
25+
var PipelineRunStatusMarkDown string
1726

1827
type MessageTemplate struct {
1928
PipelineRunName string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- **Namespace**: [{{ .Mt.Namespace }}]({{ .Mt.NamespaceURL }})
2+
- **PipelineRun**: [{{ .Mt.PipelineRunName }}]({{ .Mt.ConsoleURL }})
3+
4+
---
5+
6+
### Task Statuses:
7+
8+
| **Status** | **Name** | **Duration** |
9+
|------------|----------|--------------|
10+
{{ .Mt.TaskStatus }}
11+
12+
{{- if not (eq .Mt.FailureSnippet "")}}
13+
---
14+
15+
### Failure snippet:
16+
{{ .Mt.FailureSnippet }}
17+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PipelineRun **{{ .Mt.PipelineRunName }}** has been queued in namespace **{{ .Mt.Namespace }}**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Starting PipelineRun **{{ .Mt.PipelineRunName }}** in namespace **{{ .Mt.Namespace }}**
2+
3+
You can monitor the execution using the [{{ .Mt.ConsoleName }}]({{ .Mt.ConsoleURL }}) PipelineRun viewer or through the command line by using the [{{ .Mt.TknBinary }}]({{ .Mt.TknBinaryURL }}) CLI with the following command:
4+
5+
`{{ .Mt.TknBinary }} pr logs -n {{ .Mt.Namespace }} {{ .Mt.PipelineRunName }} -f`

pkg/params/settings/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type Settings struct {
6969
CustomConsolePRTaskLog string `json:"custom-console-url-pr-tasklog"`
7070
CustomConsoleNamespaceURL string `json:"custom-console-url-namespace"`
7171

72-
RememberOKToTest bool `default:"true" json:"remember-ok-to-test"`
72+
RememberOKToTest bool `json:"remember-ok-to-test"`
7373
}
7474

7575
func (s *Settings) DeepCopy(out *Settings) {

pkg/params/settings/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestSyncConfig(t *testing.T) {
4343
CustomConsolePRdetail: "",
4444
CustomConsolePRTaskLog: "",
4545
CustomConsoleNamespaceURL: "",
46-
RememberOKToTest: true,
46+
RememberOKToTest: false,
4747
},
4848
},
4949
{

pkg/params/settings/convert_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestConvert(t *testing.T) {
3636
"hub-catalog-name": "tekton",
3737
"hub-url": "https://api.hub.tekton.dev/v1",
3838
"max-keep-run-upper-limit": "0",
39-
"remember-ok-to-test": "true",
39+
"remember-ok-to-test": "false",
4040
"remote-tasks": "true",
4141
"secret-auto-create": "true",
4242
"secret-github-app-scope-extra-repos": "",
@@ -74,7 +74,7 @@ func TestConvert(t *testing.T) {
7474
"hub-catalog-name": "tekton",
7575
"hub-url": "https://api.hub.tekton.dev/v1",
7676
"max-keep-run-upper-limit": "0",
77-
"remember-ok-to-test": "true",
77+
"remember-ok-to-test": "false",
7878
"remote-tasks": "true",
7979
"secret-auto-create": "true",
8080
"secret-github-app-scope-extra-repos": "",
@@ -113,7 +113,7 @@ func TestConvert(t *testing.T) {
113113
"hub-catalog-name": "test tekton",
114114
"hub-url": "https://api.hub.tekton.dev/v2",
115115
"max-keep-run-upper-limit": "0",
116-
"remember-ok-to-test": "true",
116+
"remember-ok-to-test": "false",
117117
"remote-tasks": "true",
118118
"secret-auto-create": "true",
119119
"secret-github-app-scope-extra-repos": "",
@@ -164,7 +164,7 @@ func TestConvert(t *testing.T) {
164164
"hub-catalog-name": "test tekton",
165165
"hub-url": "https://api.hub.tekton.dev/v2",
166166
"max-keep-run-upper-limit": "0",
167-
"remember-ok-to-test": "true",
167+
"remember-ok-to-test": "false",
168168
"remote-tasks": "true",
169169
"secret-auto-create": "true",
170170
"secret-github-app-scope-extra-repos": "",

pkg/pipelineascode/pipelineascode.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ func (p *PacRun) startPR(ctx context.Context, match matcher.Match) (*tektonv1.Pi
226226
TknBinary: settings.TknBinaryName,
227227
TknBinaryURL: settings.TknBinaryURL,
228228
}
229-
msg, err := mt.MakeTemplate(formatting.StartingPipelineRunText)
229+
230+
msg, err := mt.MakeTemplate(p.vcx.GetTemplate(provider.StartingPipelineType))
230231
if err != nil {
231232
return nil, fmt.Errorf("cannot create message template: %w", err)
232233
}
@@ -243,7 +244,7 @@ func (p *PacRun) startPR(ctx context.Context, match matcher.Match) (*tektonv1.Pi
243244
// if pipelineRun is in pending state then report status as queued
244245
if pr.Spec.Status == tektonv1.PipelineRunSpecStatusPending {
245246
status.Status = queuedStatus
246-
if status.Text, err = mt.MakeTemplate(formatting.QueuingPipelineRunText); err != nil {
247+
if status.Text, err = mt.MakeTemplate(p.vcx.GetTemplate(provider.QueueingPipelineType)); err != nil {
247248
return nil, fmt.Errorf("cannot create message template: %w", err)
248249
}
249250
}

pkg/provider/bitbucketcloud/bitbucket.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type Provider struct {
2929
Token, APIURL *string
3030
Username *string
3131
provenance string
32+
eventEmitter *events.EventEmitter
33+
repo *v1alpha1.Repository
3234
}
3335

3436
// CheckPolicyAllowing TODO: Implement ME.
@@ -45,9 +47,7 @@ func (v *Provider) SetPacInfo(pacInfo *info.PacOpts) {
4547
v.pacInfo = pacInfo
4648
}
4749

48-
const taskStatusTemplate = `| **Status** | **Duration** | **Name** |
49-
| --- | --- | --- |
50-
{{range $taskrun := .TaskRunList }}|{{ formatCondition $taskrun.PipelineRunTaskRunStatus.Status.Conditions }}|{{ formatDuration $taskrun.PipelineRunTaskRunStatus.Status.StartTime $taskrun.PipelineRunTaskRunStatus.Status.CompletionTime }}|{{ $taskrun.ConsoleLogURL }}|
50+
const taskStatusTemplate = `{{range $taskrun := .TaskRunList }} | **{{ formatCondition $taskrun.PipelineRunTaskRunStatus.Status.Conditions }}** | {{ $taskrun.ConsoleLogURL }} | *{{ formatDuration $taskrun.PipelineRunTaskRunStatus.Status.StartTime $taskrun.PipelineRunTaskRunStatus.Status.CompletionTime }}* |
5151
{{ end }}`
5252

5353
func (v *Provider) Validate(_ context.Context, _ *params.Run, _ *info.Event) error {
@@ -110,7 +110,10 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusopts
110110

111111
_, err := v.Client.Repositories.Commits.CreateCommitStatus(cmo, cso)
112112
if err != nil {
113-
return err
113+
// Only emit an event to notify the user that something went wrong with the commit status API,
114+
// and proceed with creating the comment (if applicable).
115+
v.eventEmitter.EmitMessage(v.repo, zap.ErrorLevel, "FailedToSetCommitStatus",
116+
"cannot set status with the Bitbucket Cloud token because of: "+err.Error())
114117
}
115118

116119
eventType := triggertype.IsPullRequestType(event.EventType)
@@ -176,7 +179,7 @@ func (v *Provider) GetFileInsideRepo(_ context.Context, event *info.Event, path,
176179
return v.getBlob(event, revision, path)
177180
}
178181

179-
func (v *Provider) SetClient(_ context.Context, run *params.Run, event *info.Event, _ *v1alpha1.Repository, _ *events.EventEmitter) error {
182+
func (v *Provider) SetClient(_ context.Context, run *params.Run, event *info.Event, repo *v1alpha1.Repository, eventEmitter *events.EventEmitter) error {
180183
if event.Provider.Token == "" {
181184
return fmt.Errorf("no git_provider.secret has been set in the repo crd")
182185
}
@@ -187,6 +190,8 @@ func (v *Provider) SetClient(_ context.Context, run *params.Run, event *info.Eve
187190
v.Token = &event.Provider.Token
188191
v.Username = &event.Provider.User
189192
v.run = run
193+
v.eventEmitter = eventEmitter
194+
v.repo = repo
190195
return nil
191196
}
192197

@@ -297,3 +302,7 @@ func (v *Provider) GetFiles(_ context.Context, _ *info.Event) (changedfiles.Chan
297302
func (v *Provider) CreateToken(_ context.Context, _ []string, _ *info.Event) (string, error) {
298303
return "", nil
299304
}
305+
306+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
307+
return provider.GetMarkdownTemplate(commentType)
308+
}

pkg/provider/bitbucketdatacenter/bitbucketdatacenter.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323
"go.uber.org/zap"
2424
)
2525

26-
const taskStatusTemplate = `
27-
{{range $taskrun := .TaskRunList }}* **{{ formatCondition $taskrun.PipelineRunTaskRunStatus.Status.Conditions }}** {{ $taskrun.ConsoleLogURL }} *{{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }}*
26+
const taskStatusTemplate = `{{range $taskrun := .TaskRunList }}| **{{ formatCondition $taskrun.PipelineRunTaskRunStatus.Status.Conditions }}** | {{ $taskrun.ConsoleLogURL }} | *{{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }}* |
2827
{{ end }}`
2928
const apiResponseLimit = 100
3029

@@ -418,3 +417,7 @@ func (v *Provider) GetFiles(ctx context.Context, runevent *info.Event) (changedf
418417
func (v *Provider) CreateToken(_ context.Context, _ []string, _ *info.Event) (string, error) {
419418
return "", nil
420419
}
420+
421+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
422+
return provider.GetMarkdownTemplate(commentType)
423+
}

pkg/provider/gitea/gitea.go

+4
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,7 @@ func (v *Provider) GetFiles(_ context.Context, runevent *info.Event) (changedfil
403403
func (v *Provider) CreateToken(_ context.Context, _ []string, _ *info.Event) (string, error) {
404404
return "", nil
405405
}
406+
407+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
408+
return provider.GetHTMLTemplate(commentType)
409+
}

pkg/provider/github/github.go

+4
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,7 @@ func (v *Provider) isHeadCommitOfBranch(ctx context.Context, runevent *info.Even
603603
}
604604
return fmt.Errorf("provided SHA %s is not the HEAD commit of the branch %s", runevent.SHA, branchName)
605605
}
606+
607+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
608+
return provider.GetHTMLTemplate(commentType)
609+
}

pkg/provider/gitlab/gitlab.go

+4
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,7 @@ func (v *Provider) isHeadCommitOfBranch(runevent *info.Event, branchName string)
460460

461461
return fmt.Errorf("provided SHA %s is not the HEAD commit of the branch %s", runevent.SHA, branchName)
462462
}
463+
464+
func (v *Provider) GetTemplate(commentType provider.CommentType) string {
465+
return provider.GetHTMLTemplate(commentType)
466+
}

pkg/provider/interface.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Interface interface {
4545
GetTaskURI(ctx context.Context, event *info.Event, uri string) (bool, string, error)
4646
CreateToken(context.Context, []string, *info.Event) (string, error)
4747
CheckPolicyAllowing(context.Context, *info.Event, []string) (bool, string)
48+
GetTemplate(CommentType) string
4849
}
4950

5051
const DefaultProviderAPIUser = "git"

pkg/provider/provider.go

+33
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"regexp"
77
"strings"
88

9+
"github.com/openshift-pipelines/pipelines-as-code/pkg/formatting"
910
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
1011
"gopkg.in/yaml.v2"
1112
)
@@ -28,6 +29,38 @@ const (
2829
GitHubApp = "GitHubApp"
2930
)
3031

32+
type CommentType int
33+
34+
const (
35+
StartingPipelineType CommentType = iota
36+
PipelineRunStatusType
37+
QueueingPipelineType
38+
)
39+
40+
func GetHTMLTemplate(commentType CommentType) string {
41+
switch commentType {
42+
case StartingPipelineType:
43+
return formatting.StartingPipelineRunHTML
44+
case PipelineRunStatusType:
45+
return formatting.PipelineRunStatusHTML
46+
case QueueingPipelineType:
47+
return formatting.QueuingPipelineRunHTML
48+
}
49+
return ""
50+
}
51+
52+
func GetMarkdownTemplate(commentType CommentType) string {
53+
switch commentType {
54+
case StartingPipelineType:
55+
return formatting.StartingPipelineRunMarkdown
56+
case PipelineRunStatusType:
57+
return formatting.PipelineRunStatusMarkDown
58+
case QueueingPipelineType:
59+
return formatting.QueuingPipelineRunMarkdown
60+
}
61+
return ""
62+
}
63+
3164
func Valid(value string, validValues []string) bool {
3265
for _, v := range validValues {
3366
if v == value {

pkg/reconciler/reconciler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (r *Reconciler) updatePipelineRunToInProgress(ctx context.Context, logger *
276276
TknBinary: settings.TknBinaryName,
277277
TknBinaryURL: settings.TknBinaryURL,
278278
}
279-
msg, err := mt.MakeTemplate(formatting.StartingPipelineRunText)
279+
msg, err := mt.MakeTemplate(detectedProvider.GetTemplate(provider.StartingPipelineType))
280280
if err != nil {
281281
return fmt.Errorf("cannot create message template: %w", err)
282282
}

pkg/reconciler/status.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (r *Reconciler) postFinalStatus(ctx context.Context, logger *zap.SugaredLog
138138
}
139139
}
140140
var tmplStatusText string
141-
if tmplStatusText, err = mt.MakeTemplate(formatting.PipelineRunStatusText); err != nil {
141+
if tmplStatusText, err = mt.MakeTemplate(vcx.GetTemplate(provider.PipelineRunStatusType)); err != nil {
142142
return nil, fmt.Errorf("cannot create message template: %w", err)
143143
}
144144

pkg/test/provider/testwebvcs.go

+4
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@ func (v *TestProviderImp) GetFiles(_ context.Context, _ *info.Event) (changedfil
120120
func (v *TestProviderImp) CreateToken(_ context.Context, _ []string, _ *info.Event) (string, error) {
121121
return "", nil
122122
}
123+
124+
func (v *TestProviderImp) GetTemplate(commentType provider.CommentType) string {
125+
return provider.GetHTMLTemplate(commentType)
126+
}

0 commit comments

Comments
 (0)