@@ -38,6 +38,7 @@ const errorMissingAction = "KnownIssue-4: Action %s is not in the knowledge base
38
38
const errorAlreadyHasPermissions = "KnownIssue-5: Permissions were not added to the job since it already had permissions defined"
39
39
const errorDockerAction = "KnownIssue-6: Action %s is a docker action which uses Github token. Docker actions that uses token are not supported"
40
40
const errorReusableWorkflow = "KnownIssue-7: Action %s is a reusable workflow. Reusable workflows are not supported as of now."
41
+ const errorGithubTokenInJobEnv = "KnownIssue-8: Permissions were not added to the jobs since it has GITHUB_TOKEN in job level env variable"
41
42
const errorIncorrectYaml = "Unable to parse the YAML workflow file"
42
43
43
44
// To avoid a typo while adding the permissions
@@ -78,6 +79,15 @@ func alreadyHasWorkflowPermissions(workflow metadata.Workflow) bool {
78
79
return workflow .Permissions .IsSet
79
80
}
80
81
82
+ func githubTokenInJobLevelEnv (job metadata.Job ) bool {
83
+ for _ , envValue := range job .Env {
84
+ if strings .Contains (envValue , "secrets.GITHUB_TOKEN" ) || strings .Contains (envValue , "github.token" ) {
85
+ return true
86
+ }
87
+ }
88
+ return false
89
+ }
90
+
81
91
func AddWorkflowLevelPermissions (inputYaml string , addProjectComment bool ) (string , error ) {
82
92
workflow := metadata.Workflow {}
83
93
@@ -177,6 +187,12 @@ func AddJobLevelPermissions(inputYaml string) (*SecureWorkflowReponse, error) {
177
187
continue
178
188
}
179
189
190
+ if githubTokenInJobLevelEnv (job ) {
191
+ fixWorkflowPermsReponse .HasErrors = true
192
+ errors [jobName ] = append (errors [jobName ], errorGithubTokenInJobEnv )
193
+ continue
194
+ }
195
+
180
196
if metadata .IsCallingReusableWorkflow (job ) {
181
197
fixWorkflowPermsReponse .HasErrors = true
182
198
errors [jobName ] = append (errors [jobName ], fmt .Sprintf (errorReusableWorkflow , job .Uses ))
0 commit comments