2021-06-04 02:30:37 +03:00
|
|
|
// Copyright 2021 Security Scorecard Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package checks
|
|
|
|
|
|
|
|
import (
|
2022-01-12 22:49:01 +03:00
|
|
|
"github.com/ossf/scorecard/v4/checker"
|
2022-07-16 00:48:50 +03:00
|
|
|
"github.com/ossf/scorecard/v4/checks/evaluation"
|
|
|
|
"github.com/ossf/scorecard/v4/checks/raw"
|
2022-01-12 22:49:01 +03:00
|
|
|
sce "github.com/ossf/scorecard/v4/errors"
|
2022-06-29 20:10:15 +03:00
|
|
|
"github.com/ossf/scorecard/v4/remediation"
|
2021-06-04 02:30:37 +03:00
|
|
|
)
|
|
|
|
|
2021-08-01 01:31:34 +03:00
|
|
|
// CheckTokenPermissions is the exported name for Token-Permissions check.
|
2022-07-16 00:48:50 +03:00
|
|
|
const CheckTokenPermissions = "Token-Permissions"
|
2021-12-17 02:16:02 +03:00
|
|
|
|
2021-06-04 02:30:37 +03:00
|
|
|
//nolint:gochecknoinits
|
|
|
|
func init() {
|
2022-02-08 03:49:49 +03:00
|
|
|
supportedRequestTypes := []checker.RequestType{
|
|
|
|
checker.FileBased,
|
2022-02-08 06:03:36 +03:00
|
|
|
checker.CommitBased,
|
2022-02-08 03:49:49 +03:00
|
|
|
}
|
|
|
|
if err := registerCheck(CheckTokenPermissions, TokenPermissions, supportedRequestTypes); err != nil {
|
2022-01-13 01:14:18 +03:00
|
|
|
// This should never happen.
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-06-04 02:30:37 +03:00
|
|
|
}
|
|
|
|
|
2022-07-16 00:48:50 +03:00
|
|
|
// TokenPermissions will run the Token-Permissions check.
|
2021-07-30 03:13:01 +03:00
|
|
|
func TokenPermissions(c *checker.CheckRequest) checker.CheckResult {
|
2022-06-29 20:10:15 +03:00
|
|
|
if err := remediation.Setup(c); err != nil {
|
2022-07-16 00:48:50 +03:00
|
|
|
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
|
|
|
|
return checker.CreateRuntimeErrorResult(CheckTokenPermissions, e)
|
2022-05-06 22:52:30 +03:00
|
|
|
}
|
|
|
|
|
2022-07-16 00:48:50 +03:00
|
|
|
rawData, err := raw.TokenPermissions(c)
|
2021-07-21 19:21:43 +03:00
|
|
|
if err != nil {
|
2022-07-16 00:48:50 +03:00
|
|
|
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
|
|
|
|
return checker.CreateRuntimeErrorResult(CheckTokenPermissions, e)
|
2021-08-05 20:10:34 +03:00
|
|
|
}
|
2022-06-01 19:41:20 +03:00
|
|
|
|
2022-07-16 00:48:50 +03:00
|
|
|
// Return raw results.
|
|
|
|
if c.RawResults != nil {
|
|
|
|
c.RawResults.TokenPermissionsResults = rawData
|
2022-06-01 19:41:20 +03:00
|
|
|
}
|
|
|
|
|
2022-07-16 00:48:50 +03:00
|
|
|
// Return the score evaluation.
|
|
|
|
return evaluation.TokenPermissions(CheckTokenPermissions, c.Dlogger, &rawData)
|
2022-06-01 19:41:20 +03:00
|
|
|
}
|