Skip to content

Commit 6400f4f

Browse files
authored
Allow trusted bot comments via trusted_appIDs (#2554)
Allow a list of AppIDs whoe comments will not be ignored Allow comments from all bot accounts with the digger:allowbot PR label Refs #2553
1 parent f8d5962 commit 6400f4f

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

backend/controllers/github.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ func (d DiggerController) GithubAppWebHook(c *gin.Context) {
113113
"issueNumber", *event.Issue.Number,
114114
)
115115

116-
if event.Sender.Type != nil && *event.Sender.Type == "Bot" {
117-
slog.Debug("Ignoring bot comment", "senderType", *event.Sender.Type)
118-
c.String(http.StatusOK, "OK")
119-
return
120-
}
121116
go func(ctx context.Context) {
122117
defer logging.InheritRequestLogger(ctx)()
123118
handleIssueCommentEvent(gh, event, d.CiBackendProvider, appId64, d.GithubWebhookPostIssueCommentHooks)

backend/controllers/github_comment.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,27 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
173173
return fmt.Errorf("error getting digger config")
174174
}
175175

176+
if payload.Sender.GetType() == "Bot" {
177+
if lo.Contains(prLabelsStr, "digger:allowbot") {
178+
slog.Info("Allowing bot comment due to label override",
179+
"issueNumber", issueNumber,
180+
"label", "digger:allowbot",
181+
)
182+
} else {
183+
commentUserID := payload.GetComment().GetUser().GetID()
184+
if commentUserID == 0 {
185+
commentUserID = payload.GetSender().GetID()
186+
}
187+
if !lo.Contains(config.TrustedAppIDs, commentUserID) {
188+
slog.Info("Ignoring bot comment from untrusted app",
189+
"issueNumber", issueNumber,
190+
"commentUserId", commentUserID,
191+
)
192+
return nil
193+
}
194+
}
195+
}
196+
176197
if config.DisableDiggerApplyComment && strings.HasPrefix(cleanedComment, "digger apply") {
177198
slog.Info("Digger configured to disable apply comment in PRs, ignoring comment", "DisableDiggerApplyComment", config.DisableDiggerApplyComment)
178199
if os.Getenv("DIGGER_REPORT_BEFORE_LOADING_CONFIG") == "1" {

docs/ce/reference/digger.yml.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ report_terraform_outputs: true
3535
mention_drifted_projects_in_pr: false
3636
disable_digger_apply_comment: false
3737
disable_digger_apply_status_check: false
38+
trusted_appIDs:
39+
- 41898282
3840
respect_layers: false
3941
reporting:
4042
ai_summary: false
@@ -201,6 +203,10 @@ workflows:
201203
Disable the status check that verifies apply was executed.
202204
</ParamField>
203205

206+
<ParamField path="trusted_appIDs" type="array" default="[]">
207+
Allow bot comments from these GitHub user IDs. Example: `trusted_appIDs: [41898282]` for GitHub Actions.
208+
</ParamField>
209+
204210
<ParamField path="comment_render_mode" type="string" default="basic">
205211
How to render plan output in comments. Options: `basic`, `detailed`.
206212
</ParamField>

libs/digger_config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type DiggerConfig struct {
2525
AutoMerge bool
2626
AutoMergeStrategy AutomergeStrategy
2727
Telemetry bool
28+
TrustedAppIDs []int64
2829
Workflows map[string]Workflow
2930
MentionDriftedProjectsInPR bool
3031
TraverseToNestedProjects bool

libs/digger_config/converters.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ func ConvertDiggerYamlToConfig(diggerYaml *DiggerConfigYaml) (*DiggerConfig, gra
280280
diggerConfig.CommentRenderMode = CommentRenderModeBasic
281281
}
282282

283+
if diggerYaml.TrustedAppIDs != nil {
284+
diggerConfig.TrustedAppIDs = append([]int64(nil), diggerYaml.TrustedAppIDs...)
285+
} else {
286+
diggerConfig.TrustedAppIDs = []int64{}
287+
}
288+
283289
if diggerYaml.MentionDriftedProjectsInPR != nil {
284290
diggerConfig.MentionDriftedProjectsInPR = *diggerYaml.MentionDriftedProjectsInPR
285291
} else {

libs/digger_config/yaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type DiggerConfigYaml struct {
1919
Projects []*ProjectYaml `yaml:"projects"`
2020
AutoMerge *bool `yaml:"auto_merge"`
2121
AutoMergeStrategy *string `yaml:"auto_merge_strategy"`
22+
TrustedAppIDs []int64 `yaml:"trusted_appIDs,omitempty"`
2223
CommentRenderMode *string `yaml:"comment_render_mode"`
2324
Workflows map[string]*WorkflowYaml `yaml:"workflows"`
2425
Telemetry *bool `yaml:"telemetry,omitempty"`

0 commit comments

Comments
 (0)