@@ -132,11 +132,31 @@ is that what you want? make sure you use -n when generating the secret, eg: echo
132
132
return repo , err
133
133
}
134
134
135
+ // Verify whether the sender of the GitOps command (e.g., /test) has the appropriate permissions to
136
+ // trigger CI on the repository, as any user is able to comment on a pushed commit in open-source repositories.
137
+ if p .event .TriggerTarget == triggertype .Push && opscomments .IsAnyOpsEventType (p .event .EventType ) {
138
+ status := provider.StatusOpts {
139
+ Status : CompletedStatus ,
140
+ Title : "Permission denied" ,
141
+ Conclusion : failureConclusion ,
142
+ DetailsURL : p .event .URL ,
143
+ }
144
+ if allowed , err := p .checkAccessOrErrror (ctx , repo , status , "by GitOps comment" ); ! allowed {
145
+ return nil , err
146
+ }
147
+ }
148
+
135
149
// Check if the submitter is allowed to run this.
136
150
// on push we don't need to check the policy since the user has pushed to the repo so it has access to it.
137
151
// on comment we skip it for now, we are going to check later on
138
152
if p .event .TriggerTarget != triggertype .Push && p .event .EventType != opscomments .NoOpsCommentEventType .String () {
139
- if allowed , err := p .checkAccessOrErrror (ctx , repo , "via " + p .event .TriggerTarget .String ()); ! allowed {
153
+ status := provider.StatusOpts {
154
+ Status : queuedStatus ,
155
+ Title : "Pending approval, needs /ok-to-test" ,
156
+ Conclusion : pendingConclusion ,
157
+ DetailsURL : p .event .URL ,
158
+ }
159
+ if allowed , err := p .checkAccessOrErrror (ctx , repo , status , "via " + p .event .TriggerTarget .String ()); ! allowed {
140
160
return nil , err
141
161
}
142
162
}
@@ -245,7 +265,13 @@ func (p *PacRun) getPipelineRunsFromRepo(ctx context.Context, repo *v1alpha1.Rep
245
265
// if the event is a comment event, but we don't have any match from the keys.OnComment then do the ACL checks again
246
266
// we skipped previously so we can get the match from the event to the pipelineruns
247
267
if p .event .EventType == opscomments .NoOpsCommentEventType .String () || p .event .EventType == opscomments .OnCommentEventType .String () {
248
- if allowed , err := p .checkAccessOrErrror (ctx , repo , "by gitops comment" ); ! allowed {
268
+ status := provider.StatusOpts {
269
+ Status : queuedStatus ,
270
+ Title : "Pending approval, needs /ok-to-test" ,
271
+ Conclusion : pendingConclusion ,
272
+ DetailsURL : p .event .URL ,
273
+ }
274
+ if allowed , err := p .checkAccessOrErrror (ctx , repo , status , "by GitOps comment" ); ! allowed {
249
275
return nil , err
250
276
}
251
277
}
@@ -370,7 +396,7 @@ func (p *PacRun) checkNeedUpdate(_ string) (string, bool) {
370
396
return "" , false
371
397
}
372
398
373
- func (p * PacRun ) checkAccessOrErrror (ctx context.Context , repo * v1alpha1.Repository , viamsg string ) (bool , error ) {
399
+ func (p * PacRun ) checkAccessOrErrror (ctx context.Context , repo * v1alpha1.Repository , status provider. StatusOpts , viamsg string ) (bool , error ) {
374
400
allowed , err := p .vcx .IsAllowed (ctx , p .event )
375
401
if err != nil {
376
402
return false , err
@@ -383,13 +409,7 @@ func (p *PacRun) checkAccessOrErrror(ctx context.Context, repo *v1alpha1.Reposit
383
409
msg = fmt .Sprintf ("User: %s AccountID: %s is not allowed to trigger CI %s on this repo." , p .event .Sender , p .event .AccountID , viamsg )
384
410
}
385
411
p .eventEmitter .EmitMessage (repo , zap .InfoLevel , "RepositoryPermissionDenied" , msg )
386
- status := provider.StatusOpts {
387
- Status : queuedStatus ,
388
- Title : "Pending approval, needs /ok-to-test" ,
389
- Conclusion : pendingConclusion ,
390
- Text : msg ,
391
- DetailsURL : p .event .URL ,
392
- }
412
+ status .Text = msg
393
413
if err := p .vcx .CreateStatus (ctx , p .event , status ); err != nil {
394
414
return false , fmt .Errorf ("failed to run create status, user is not allowed to run the CI:: %w" , err )
395
415
}
0 commit comments