-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Added independent probe for required MFA
Signed-off-by: Eddie Knight <[email protected]>
- Loading branch information
1 parent
1703089
commit 1b9a198
Showing
11 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
outcome: | ||
- If MFA is found to be required, the probe returns OutcomeTrue | ||
- IF MFA is not found to be required, 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// 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) { | ||
probeName = Probe | ||
if raw == nil { | ||
err = fmt.Errorf("raw results is nil: %w", uerror.ErrNil) | ||
return | ||
} | ||
|
||
mfaRequired, err := raw.RepoClient.GetMFARequired() | ||
if err != nil { | ||
err = fmt.Errorf("getting MFA required: %w", err) | ||
return | ||
} | ||
|
||
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 = append(found, *result) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package orgRequiresMFA | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/ossf/scorecard/v5/checker" | ||
mockrepo "github.com/ossf/scorecard/v5/clients/mockclients" | ||
"github.com/ossf/scorecard/v5/finding" | ||
"github.com/ossf/scorecard/v5/probes/internal/utils/uerror" | ||
) | ||
|
||
// ConfigurableMockRepoClient mocks RepoClient with configurable return values. | ||
type ConfigurableMockRepoClient struct { | ||
mockrepo.MockRepoClient | ||
MFARequired bool | ||
ReturnError error | ||
} | ||
|
||
// GetMFARequired returns the pre-set value for MFA requirement. | ||
func (m *ConfigurableMockRepoClient) GetMFARequired() (bool, error) { | ||
return m.MFARequired, m.ReturnError | ||
} | ||
|
||
func (m *ConfigurableMockRepoClient) Close() error { return nil } | ||
|
||
func TestProbeCodeApproved(t *testing.T) { | ||
t.Parallel() | ||
probeTests := []struct { | ||
name string | ||
rawResults *checker.CheckRequest | ||
expectedError error | ||
expectedCount int | ||
expectedOutcome finding.Outcome | ||
}{ | ||
{ | ||
name: "mfa check succeeded", | ||
rawResults: &checker.CheckRequest{ | ||
RepoClient: &ConfigurableMockRepoClient{MFARequired: true, ReturnError: nil}, | ||
}, | ||
expectedError: nil, | ||
expectedCount: 1, | ||
expectedOutcome: finding.OutcomeTrue, | ||
}, | ||
{ | ||
name: "error retrieving MFA status", | ||
rawResults: &checker.CheckRequest{ | ||
RepoClient: &ConfigurableMockRepoClient{ReturnError: uerror.ErrNil}, | ||
}, | ||
expectedError: uerror.ErrNil, | ||
expectedCount: 0, | ||
expectedOutcome: finding.OutcomeFalse, | ||
}, | ||
{ | ||
name: "nil raw results", | ||
rawResults: nil, | ||
expectedError: uerror.ErrNil, | ||
expectedCount: 0, | ||
expectedOutcome: finding.OutcomeFalse, | ||
}, | ||
} | ||
|
||
for _, tt := range probeTests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
found, probeName, err := Run(tt.rawResults) | ||
|
||
if probeName != Probe { | ||
t.Errorf("unexpected probe name: got %v, want %v", probeName, Probe) | ||
} | ||
|
||
if !errors.Is(err, tt.expectedError) { | ||
t.Errorf("unexpected error: got %v, want %v", err, tt.expectedError) | ||
} | ||
|
||
if len(found) != tt.expectedCount { | ||
t.Errorf("unexpected number of findings: got %d, want %d", len(found), tt.expectedCount) | ||
} | ||
|
||
if len(found) > 0 && found[0].Outcome != tt.expectedOutcome { | ||
t.Errorf("unexpected outcome: got %v, want %v", found[0].Outcome, tt.expectedOutcome) | ||
} | ||
}) | ||
} | ||
} |