-
Notifications
You must be signed in to change notification settings - Fork 500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ New probe for required MFA #4398
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,11 @@ func (client *Client) GetCreatedAt() (time.Time, error) { | |
return client.project.getCreatedAt() | ||
} | ||
|
||
func (c *Client) GetMFARequired() (required bool, err error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appears this is available on GitLab for group namespaces as well: |
||
err = fmt.Errorf("GetMFARequired: %w", clients.ErrUnsupportedFeature) | ||
return | ||
} | ||
|
||
func (client *Client) GetOrgRepoClient(ctx context.Context) (clients.RepoClient, error) { | ||
return nil, fmt.Errorf("GetOrgRepoClient (GitLab): %w", clients.ErrUnsupportedFeature) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ type RepoClient interface { | |
GetCreatedAt() (time.Time, error) | ||
GetDefaultBranchName() (string, error) | ||
GetDefaultBranch() (*BranchRef, error) | ||
GetMFARequired() (bool, error) | ||
Comment on lines
46
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to reach a decision on #4049 This is technically a breaking change. |
||
GetOrgRepoClient(context.Context) (RepoClient, error) | ||
ListCommits() ([]Commit, error) | ||
ListIssues() ([]Issue, error) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2024 OpenSSF 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. | ||
|
||
id: orgRequiresMFA # required | ||
lifecycle: experimental # required | ||
short: A short description of this probe | ||
motivation: > | ||
What is the motivation for this probe? | ||
implementation: > | ||
How does this probe work under-the-hood? | ||
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add these fields to the documentation? |
||
outcome: | ||
- If MFA is required by the organization that owns the repo, the probe returns OutcomeTrue | ||
- IF MFA is not required by the organization that owns the repo, the probe returns OutcomeFalse | ||
- If the runtime environment does not have authentication for the target project, the probe returns OutcomeNotAvailable | ||
remediation: | ||
onOutcome: False # required | ||
effort: Low # required | ||
text: | ||
- In your project settings, require MFA for all collaborators. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2024 OpenSSF 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. | ||
|
||
//nolint:stylecheck | ||
package orgRequiresMFA | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
|
||
"github.com/ossf/scorecard/v5/checker" | ||
"github.com/ossf/scorecard/v5/finding" | ||
"github.com/ossf/scorecard/v5/internal/probes" | ||
"github.com/ossf/scorecard/v5/probes/internal/utils/uerror" | ||
) | ||
|
||
//go:embed *.yml | ||
var fs embed.FS | ||
|
||
const ( | ||
Probe = "orgRequiresMFA" | ||
) | ||
|
||
func init() { | ||
// Register independently of any checks | ||
probes.MustRegisterIndependent(Probe, Run) | ||
} | ||
|
||
func Run(raw *checker.CheckRequest) (found []finding.Finding, probeName string, err error) { | ||
if raw == nil { | ||
err = fmt.Errorf("raw results is nil: %w", uerror.ErrNil) | ||
return found, Probe, err | ||
} | ||
|
||
mfaRequired, err := raw.RepoClient.GetMFARequired() | ||
if err != nil { | ||
err = fmt.Errorf("getting MFA required: %w", err) | ||
return found, Probe, err | ||
} | ||
|
||
var outcome finding.Outcome | ||
if mfaRequired { | ||
outcome = finding.OutcomeTrue | ||
} else { | ||
outcome = finding.OutcomeFalse | ||
} | ||
|
||
result, err := finding.NewWith( | ||
fs, | ||
Probe, | ||
"Collaborators require MFA", | ||
nil, | ||
outcome, | ||
) | ||
if err != nil { | ||
err = fmt.Errorf("creating finding: %w", err) | ||
return found, Probe, err | ||
} | ||
|
||
found = append(found, *result) | ||
|
||
return found, Probe, err | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add e2e tests of this on: