diff --git a/powershell/tests/functions/Test-MtCisGitHubOrganizationSettings.Tests.ps1 b/powershell/tests/functions/Test-MtCisGitHubOrganizationSettings.Tests.ps1 index 701d1bc289..f03384dbb4 100644 --- a/powershell/tests/functions/Test-MtCisGitHubOrganizationSettings.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisGitHubOrganizationSettings.Tests.ps1 @@ -20,6 +20,7 @@ Describe 'CIS GitHub organization setting tests' { } $script:orgResponse = [PSCustomObject]@{ + id = 1001 login = 'myorg' members_can_create_public_repositories = $false members_can_create_private_repositories = $false @@ -31,7 +32,12 @@ Describe 'CIS GitHub organization setting tests' { default_repository_permission = 'read' } - Mock Invoke-MtGitHubRequest -ModuleName Maester { $script:orgResponse } + Mock Invoke-MtGitHubRequest -ModuleName Maester { + if ($IncludeMetadata) { + return [pscustomobject]@{ Data = $script:orgResponse; ContentKind = 'Object'; CollectionIntegrityValid = $true; PaginationComplete = $false; Issues = @() } + } + $script:orgResponse + } Mock Add-MtTestResultDetail -ModuleName Maester { } } @@ -382,3 +388,273 @@ Describe 'CIS GitHub organization setting tests' { } } } + +Describe 'CIS GitHub evidence through the native transport and parser path' { + BeforeAll { + $script:validBody = '{"id":1001,"login":"synthetic-org","members_can_create_public_repositories":false,"members_can_create_private_repositories":false,"members_can_create_internal_repositories":false,"members_can_delete_repositories":false,"members_can_delete_issues":false,"members_can_create_teams":false,"default_repository_permission":"read"}' + } + + BeforeEach { + $script:rawBody = $script:validBody + $script:expectedUri = 'https://api.github.com/orgs/synthetic-org' + InModuleScope Maester { + $__MtSession.GitHubConnection = [PSCustomObject]@{ + Connected = $true + Organization = 'synthetic-org' + ApiBaseUri = 'https://api.github.com' + ApiVersion = '2026-03-10' + } + $__MtSession.GitHubAuthHeader = @{ 'X-GitHub-Api-Version' = '2026-03-10' } + $__MtSession.GitHubCache = @{} + } + # Only replace transport: real JSON parsing, request cache, native check and result collector run. + Mock Invoke-WebRequest -ModuleName Maester { + if ($Method -ne 'GET') { throw 'Unexpected transport method blocked by fixture.' } + if ($Uri -eq "$script:expectedUri/members?role=admin&per_page=100") { + return [PSCustomObject]@{ Content = '[{"id":11,"login":"synthetic-owner"}]'; Headers = @{} } + } + if ($Uri -eq "$script:expectedUri/repos?type=all&per_page=100") { + return [PSCustomObject]@{ Content = '[{"id":200,"name":"synthetic-repo","full_name":"synthetic-org/synthetic-repo","owner":{"login":"synthetic-org"}}]'; Headers = @{} } + } + if ($Uri -eq 'https://api.github.com/repos/synthetic-org/synthetic-repo/collaborators?affiliation=all&per_page=100') { + return [PSCustomObject]@{ Content = '[{"id":11,"permissions":{"admin":true}},{"id":12,"permissions":{"admin":true}}]'; Headers = @{} } + } + if ($Uri -ne $script:expectedUri) { + throw 'Unexpected transport request blocked by fixture.' + } + [PSCustomObject]@{ Content = $script:rawBody; Headers = @{} } + } + } + + AfterEach { + InModuleScope Maester { + $__MtSession.GitHubConnection = $null + $__MtSession.GitHubAuthHeader = $null + $__MtSession.GitHubCache = @{} + $__MtSession.MaesterConfig = $null + } + } + + $checkCases = @( + @{ Id = 'CIS.GH.1.2.2' } + @{ Id = 'CIS.GH.1.3.2' } + @{ Id = 'CIS.GH.1.3.8' } + ) + + It 'Discovers exactly the five intended valid native checks' { + $expected = @('CIS.GH.1.2.2', 'CIS.GH.1.2.3', 'CIS.GH.1.2.4', 'CIS.GH.1.3.2', 'CIS.GH.1.3.8') + $actual = @(Get-MtTest -Id 'CIS.GH.*') + $actual.Count | Should -Be 5 + Compare-Object ($expected | Sort-Object) ($actual.Id | Sort-Object) | Should -BeNullOrEmpty + foreach ($test in $actual) { + $test.IsValid | Should -BeTrue + $test.Errors | Should -BeNullOrEmpty + } + Should -Invoke Invoke-WebRequest -ModuleName Maester -Times 0 -Exactly + } + + Context 'Known configuration evidence' { + $creationCases = foreach ($public in $false, $true) { + foreach ($private in $false, $true) { + @{ Public = $public; Private = $private; Expected = $(if ($public -or $private) { 'Failed' } else { 'Passed' }) } + } + } + It 'Evaluates public=, private= independently of the deprecated umbrella field' -ForEach $creationCases { + $script:rawBody = '{"members_can_create_public_repositories":' + "$Public".ToLowerInvariant() + ',"members_can_create_private_repositories":' + "$Private".ToLowerInvariant() + ',"members_allowed_repository_creation_type":"' + $(if ($Expected -eq 'Passed') { 'all' } else { 'none' }) + '"}' + $row = @(Invoke-MtTest -Id 'CIS.GH.1.2.2') + $row.Count | Should -Be 1 + $row[0].Result | Should -Be $Expected + } + + It 'Keeps internal creation informational when it is ' -ForEach @(@{ Internal = 'true' }, @{ Internal = 'false' }) { + $script:rawBody = $script:validBody.Replace('"members_can_create_internal_repositories":false', '"members_can_create_internal_repositories":' + $Internal) + (Invoke-MtTest -Id 'CIS.GH.1.2.2').Result | Should -Be 'Passed' + } + + It 'Evaluates team creation as ' -ForEach @( + @{ Json = 'false'; Expected = 'Passed' } + @{ Json = 'true'; Expected = 'Failed' } + ) { + $script:rawBody = '{"members_can_create_teams":' + $Json + '}' + (Invoke-MtTest -Id 'CIS.GH.1.3.2').Result | Should -Be $Expected + } + + It 'Evaluates base permission as ' -ForEach @( + @{ Value = 'none'; Expected = 'Passed' } + @{ Value = 'read'; Expected = 'Passed' } + @{ Value = 'Read'; Expected = 'Passed' } + @{ Value = 'write'; Expected = 'Failed' } + @{ Value = 'admin'; Expected = 'Failed' } + ) { + $script:rawBody = '{"default_repository_permission":"' + $Value + '"}' + (Invoke-MtTest -Id 'CIS.GH.1.3.8').Result | Should -Be $Expected + } + } + + Context 'Unusable field evidence is indeterminate' { + $booleanCases = foreach ($check in @( + @{ Id = 'CIS.GH.1.2.2'; Field = 'members_can_create_public_repositories' } + @{ Id = 'CIS.GH.1.2.2'; Field = 'members_can_create_private_repositories' } + @{ Id = 'CIS.GH.1.3.2'; Field = 'members_can_create_teams' } + )) { + # These invalid values are defensive fixtures, not documented GitHub Boolean contracts. + foreach ($json in 'null', '"false"', '0', '[]', '[false]', '{}') { + @{ Id = $check.Id; Field = $check.Field; Json = $json } + } + } + It 'Skips when contains unusable ' -ForEach $booleanCases { + $script:rawBody = $script:validBody.Replace('"' + $Field + '":false', '"' + $Field + '":' + $Json) + $row = @(Invoke-MtTest -Id $Id) + $row.Count | Should -Be 1 + $row[0].Result | Should -Be 'Skipped' + $row[0].ReasonCode | Should -Be 'TestSkipped' + $row[0].ReasonDetail | Should -Match 'Indeterminate' + $row[0].ReasonDetail | Should -Match $Field + } + + It 'Skips nullable or unrecognized base permission ' -ForEach @( + @{ Json = 'null' } + @{ Json = '""' } + @{ Json = '" "' } + @{ Json = '"unknown-permission"' } + @{ Json = 'false' } + @{ Json = '0' } + @{ Json = '["read"]' } + @{ Json = '{}' } + ) { + $script:rawBody = '{"default_repository_permission":' + $Json + '}' + $row = Invoke-MtTest -Id 'CIS.GH.1.3.8' + $row.Result | Should -Be 'Skipped' + $row.ReasonCode | Should -Be 'TestSkipped' + $row.ReasonDetail | Should -Match 'Indeterminate' + $row.ReasonDetail | Should -Match 'default_repository_permission' + $row.ReasonDetail | Should -Not -Match 'unknown-permission' + } + + It 'Skips for missing required organization evidence' -ForEach $checkCases { + $script:rawBody = '{}' + $row = Invoke-MtTest -Id $Id + $row.Result | Should -Be 'Skipped' + $row.ReasonCode | Should -Be 'TestSkipped' + $row.ReasonDetail | Should -Match 'Indeterminate' + } + } + + Context 'Shapes still visible after existing normalization' { + $shapeCases = foreach ($check in $checkCases) { + foreach ($body in '', 'null', '[]', 'false', '0', '"text"', '[{},{}]') { + @{ Id = $check.Id; Body = $body } + } + } + It 'Skips for unusable response body ' -ForEach $shapeCases { + $script:rawBody = $Body + $row = Invoke-MtTest -Id $Id + $row.Result | Should -Be 'Skipped' + $row.ReasonCode | Should -Be 'TestSkipped' + $row.ReasonDetail | Should -Match 'Indeterminate' + } + } + + It 'Requires both public and private evidence when only is returned' -ForEach @( + @{ Field = 'members_can_create_public_repositories' } + @{ Field = 'members_can_create_private_repositories' } + ) { + $script:rawBody = '{"' + $Field + '":false}' + $row = Invoke-MtTest -Id 'CIS.GH.1.2.2' + $row.Result | Should -Be 'Skipped' + $row.ReasonCode | Should -Be 'TestSkipped' + $row.ReasonDetail | Should -Match 'Indeterminate' + } + + + It 'Fails creation when Boolean true is decisive despite an unusable companion (, )' -ForEach @( + foreach ($field in 'members_can_create_public_repositories', 'members_can_create_private_repositories') { + foreach ($companion in 'missing', 'null', '"false"', '0', '{}') { @{ Field = $field; Companion = $companion } } + } + ) { + $other = if ($Field -eq 'members_can_create_public_repositories') { 'members_can_create_private_repositories' } else { 'members_can_create_public_repositories' } + $script:rawBody = '{"' + $Field + '":true' + $(if ($Companion -ne 'missing') { ',"' + $other + '":' + $Companion }) + '}' + $row = Invoke-MtTest -Id 'CIS.GH.1.2.2' + $row.Result | Should -Be 'Failed' + $row.ResultDetail.TestResult | Should -Match 'True' + $row.ResultDetail.TestResult | Should -Match 'Unavailable' + } + + It 'Uses check-visible evidence on configured host , with missing fields still indeterminate' -ForEach @( + @{ BaseUri = 'https://api.github.com' } + @{ BaseUri = 'https://api.synthetic.ghe.com' } + ) { + # A synthetic connected session tests request routing, not device-flow or live-platform qualification. + InModuleScope Maester -Parameters @{ BaseUri = $BaseUri } { + $__MtSession.GitHubConnection.ApiBaseUri = $BaseUri + } + $script:expectedUri = "$BaseUri/orgs/synthetic-org" + (Invoke-MtTest -Id 'CIS.GH.1.2.2').Result | Should -Be 'Passed' + InModuleScope Maester { $__MtSession.GitHubCache = @{} } + $script:rawBody = '{"members_can_create_private_repositories":false}' + $row = Invoke-MtTest -Id 'CIS.GH.1.2.2' + $row.Result | Should -Be 'Skipped' + $row.ReasonDetail | Should -Match 'Indeterminate' + Should -Invoke Invoke-WebRequest -ModuleName Maester -Times 2 -Exactly + } + + Context 'Existing singleton-array normalization limitation (characterization only)' { + # Array-wrapped organization objects are NOT an endorsed GitHub response contract. + # Current parsing/pipeline enumeration can erase their wrappers before a check sees them. + # Future parser rejection is allowed: these fixtures must not require preserving that limitation. + It 'Characterizes an array wrapper without promising complete raw-schema validation: ' -ForEach @( + @{ Wrapper = 'single' } + @{ Wrapper = 'nested' } + ) { + $script:rawBody = if ($Wrapper -eq 'single') { '[' + $script:validBody + ']' } else { '[[' + $script:validBody + ']]' } + $row = Invoke-MtTest -Id 'CIS.GH.1.3.2' + $row.Result | Should -BeIn @('Passed', 'Skipped', 'Error') + if ($row.Result -eq 'Passed') { + $parsed = InModuleScope Maester { Get-MtGitHubOrganization } + ($parsed -is [System.Array]) | Should -BeFalse + $parsed.members_can_create_teams | Should -BeOfType [bool] + $parsed.members_can_create_teams | Should -BeFalse + } + } + } + + Context 'Transport and parsing failures retain Error' { + It 'Reports malformed JSON as Error for ' -ForEach $checkCases { + $script:rawBody = '{' + $row = Invoke-MtTest -Id $Id + $row.Result | Should -Be 'Error' + $row.ReasonCode | Should -Be 'TestError' + } + + $httpCases = foreach ($check in $checkCases) { + foreach ($status in 401, 403, 404, 429, 500, 503) { @{ Id = $check.Id; Status = $status } } + } + It 'Reports HTTP as Error for ' -ForEach $httpCases { + Mock Invoke-WebRequest -ModuleName Maester { + $response = [System.Net.Http.HttpResponseMessage]::new([System.Net.HttpStatusCode]$Status) + throw [Microsoft.PowerShell.Commands.HttpResponseException]::new('Synthetic GitHub HTTP failure', $response) + } + $row = Invoke-MtTest -Id $Id + $row.Result | Should -Be 'Error' + $row.ReasonCode | Should -Be 'TestError' + Should -Invoke Invoke-WebRequest -ModuleName Maester -Times 1 -Exactly + } + } + + It 'Routes requested version and stores its version-qualified cache key' -ForEach @( + @{ Version = '2022-11-28' } + @{ Version = '2026-03-10' } + ) { + InModuleScope Maester -Parameters @{ Version = $Version } { + $__MtSession.GitHubConnection.ApiVersion = $Version + $__MtSession.GitHubAuthHeader['X-GitHub-Api-Version'] = $Version + } + (Invoke-MtTest -Id 'CIS.GH.1.3.2').Result | Should -Be 'Passed' + Should -Invoke Invoke-WebRequest -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Headers['X-GitHub-Api-Version'] -eq $Version + } + InModuleScope Maester -Parameters @{ Version = $Version } { + $__MtSession.GitHubCache.ContainsKey("$Version|https://api.github.com/orgs/synthetic-org") | Should -BeTrue + } + } +} diff --git a/tests/cis/Test.CIS.GH.1.2.2.md b/tests/cis/Test.CIS.GH.1.2.2.md index 4c9a7d3048..cbb251de3b 100644 --- a/tests/cis/Test.CIS.GH.1.2.2.md +++ b/tests/cis/Test.CIS.GH.1.2.2.md @@ -1,52 +1,32 @@ -1.2.2 (L1) Ensure repository creation is limited to specific members +Organization members cannot create public or private repositories. -CIS Benchmark: CIS GitHub Benchmark v1.2.0 +Limiting repository creation makes ownership and access easier to review and reduces the risk of code or data being exposed through an unmanaged repository. Members who need a new repository may need an owner, administrator, or approved internal process to create it. -Assessment Status: Manual +CIS GitHub Benchmark v1.2.0 lists section 1.2.2 as a Manual assessment. This test checks the connected organization's repository-creation settings from `GET /orgs/{org}`; it does not replace the rest of the manual review. -#### Rationale +The test passes when `members_can_create_public_repositories` and `members_can_create_private_repositories` are both Boolean `false`. Either value being Boolean `true` is enough to fail, even if the other value is missing or invalid. Otherwise, a missing, null, or non-Boolean value produces **Skipped**, with a reason explaining what could not be checked. Request or JSON parsing failures produce **Error**. -Repository sprawl makes source ownership, visibility, and review harder to manage. Limiting who can create public and private repositories reduces the chance that organization code or data is exposed through an unmanaged repository and keeps the repository inventory easier to monitor. +The report also shows `members_can_create_internal_repositories` and the legacy `members_allowed_repository_creation_type` when GitHub returns them. Neither decides the result: the CIS audit covers public and private repository creation, and Maester uses the separate settings for those repository types. -#### Impact - -Members who previously created repositories directly may need an owner, administrator, or approved internal process to create new repositories for them. - -#### Maester automation note - -CIS marks this recommendation as Manual. This Maester test automates the portion of CIS GH 1.2.2 that maps to documented GitHub REST API evidence. It should be treated as automated evidence collection for the corresponding GitHub setting, not as a claim that every possible manual review path has been fully evaluated. - -This test checks the organization member privilege settings returned by `GET /orgs/{org}`. - -#### API evidence - -Endpoint: `GET /orgs/{org}` - -Evidence fields: - -- `members_can_create_public_repositories` -- `members_can_create_private_repositories` -- `members_can_create_internal_repositories` when returned, shown as informational -- `members_allowed_repository_creation_type` is displayed when returned, but is not decisive - -The test passes when public and private repository creation are `false`. Internal repository creation is shown as additional enterprise/GHEC context only because the CIS GH 1.2.2 literal audit covers public and private repository creation. +The test covers the connected organization's returned settings. It does not scan other organizations or reconstruct inherited policies. Maester checks these fields after parsing the response, rather than validating the entire response schema. Missing data does not mean a setting is disabled or the recommendation does not apply. #### Permissions required -GitHub requires organization-owner visibility for full organization details. Use `Connect-MtGitHub` with a classic PAT that has `admin:org`, or a fine-grained PAT with organization Members read and Administration read permissions. - -#### Remediation summary +Use an organization owner with a classic PAT or OAuth token carrying `admin:org` to read the full organization settings. With fine-grained PATs, the connection's membership check uses organization **Members: read**, and its separate administration check uses **Administration: read**. A successful connection does not guarantee that GitHub returns the fields this test needs. See [Connect-MtGitHub](https://maester.dev/docs/commands/Connect-MtGitHub) for the connection checks. -In the organization settings, open **Member privileges** and clear the public and private repository creation options for members. For GHEC organizations associated with an enterprise, review internal repository creation separately as an enterprise governance decision. +For GHE.com, use `https://api.SUBDOMAIN.ghe.com` and a token for that host; do not assume the github.com device flow applies. The same missing-data rules apply to GHEC, Enterprise Managed Users, and GHE.com. -#### Known limitations +#### Remediation action -This test uses the granular repository creation fields because GitHub is replacing the legacy `members_allowed_repository_creation_type` umbrella field. That umbrella value is displayed when returned, but is not decisive. If required granular fields are not returned, the test skips with a field-specific reason. +1. On the connected GitHub web host (`github.com` or your enterprise's `SUBDOMAIN.ghe.com`), open **Your organizations**, select the organization, then go to **Settings** > **Access** > **Member privileges**. +2. Clear the public and private repository-creation options for members and save the changes. If an enterprise policy controls the options, ask an enterprise owner to make the change. +3. Review internal repository creation separately; it does not decide this check. #### Related links * [CIS GitHub Benchmark v1.2.0 - Section 1.2.2](https://www.cisecurity.org/benchmark/github) -* [GitHub REST API: Get an organization](https://docs.github.com/en/rest/orgs/orgs#get-an-organization) +* [GitHub: Restricting repository creation](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-organization-settings/restricting-repository-creation-in-your-organization) +* [GitHub REST API: Get an organization](https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2026-03-10#get-an-organization) %TestResult% diff --git a/tests/cis/Test.CIS.GH.1.2.2.ps1 b/tests/cis/Test.CIS.GH.1.2.2.ps1 index 0702f8b701..104b20ad31 100644 --- a/tests/cis/Test.CIS.GH.1.2.2.ps1 +++ b/tests/cis/Test.CIS.GH.1.2.2.ps1 @@ -42,22 +42,30 @@ $requiredFields = @('members_can_create_public_repositories', 'members_can_create_private_repositories') $missingFields = @($requiredFields | Where-Object { -not (Test-MtGitHubObjectProperty -InputObject $org -PropertyName $_) }) - if ($missingFields.Count -gt 0) { - Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "GitHub organization response did not include required field(s): $($missingFields -join ', '). These fields are required to evaluate CIS.GH.1.2.2 and may be missing because of permissions, plan, API version, or organization type." + $hasViolation = @($requiredFields | Where-Object { $org.$_ -is [bool] -and $org.$_ -eq $true }).Count -gt 0 + + if (-not $hasViolation -and $missingFields.Count -gt 0) { + Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "Indeterminate: GitHub organization response did not include required field(s): $($missingFields -join ', '). These fields are required to evaluate CIS.GH.1.2.2 and may be missing because of permissions, plan, API version, or organization type." + return $null + } + + $invalidFields = @($requiredFields | Where-Object { $org.$_ -isnot [bool] }) + if (-not $hasViolation -and $invalidFields.Count -gt 0) { + Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "Indeterminate: GitHub organization field(s) must be Boolean values to evaluate CIS.GH.1.2.2: $($invalidFields -join ', '). No configuration verdict was produced." return $null } $checks = @( [PSCustomObject]@{ Field = 'members_can_create_public_repositories' - Actual = $org.members_can_create_public_repositories + Actual = if ($org.members_can_create_public_repositories -is [bool]) { $org.members_can_create_public_repositories } else { 'Unavailable' } Expected = $false Decisive = $true Pass = $org.members_can_create_public_repositories -eq $false } [PSCustomObject]@{ Field = 'members_can_create_private_repositories' - Actual = $org.members_can_create_private_repositories + Actual = if ($org.members_can_create_private_repositories -is [bool]) { $org.members_can_create_private_repositories } else { 'Unavailable' } Expected = $false Decisive = $true Pass = $org.members_can_create_private_repositories -eq $false @@ -77,7 +85,8 @@ $internalRepositoryNote = "The internal-repository row is informational. CIS GH 1.2.2's literal audit covers public and private only." } - $result = @($checks | Where-Object { $_.Decisive -eq $true -and $_.Pass -ne $true }).Count -eq 0 + # One validated Boolean true disproves the requirement even when its companion is unusable. + $result = -not $hasViolation $detailRows = $checks | ForEach-Object { "| ``$($_.Field)`` | ``$($_.Actual)`` | ``$($_.Expected)`` |" } @@ -87,7 +96,14 @@ "Deprecated umbrella field ``members_allowed_repository_creation_type`` was not returned. The granular fields above are the decisive checks." } + $resultSummary = if ($result) { + 'Well done. Members cannot create public or private repositories.' + } else { + 'Members can create public or private repositories. Disable both member repository-creation options in organization Member privileges.' + } $resultMarkdown = @" +$resultSummary + CIS.GH.1.2.2 automated evidence from ``GET /orgs/{org}``. | Field | Actual | Expected | @@ -98,6 +114,9 @@ $internalRepositoryNote $legacyValue "@ + if ($invalidFields.Count -gt 0) { + $resultMarkdown += "`n`nAdditional evidence is unavailable or not Boolean: $($invalidFields -join ', '). The observed Boolean true still establishes the violation." + } Add-MtTestResultDetail -Result $resultMarkdown return $result } diff --git a/tests/cis/Test.CIS.GH.1.3.2.md b/tests/cis/Test.CIS.GH.1.3.2.md index 6c899eec3b..eb029b3805 100644 --- a/tests/cis/Test.CIS.GH.1.3.2.md +++ b/tests/cis/Test.CIS.GH.1.3.2.md @@ -1,45 +1,30 @@ -1.3.2 (L1) Ensure team creation is limited to specific members +Organization members cannot create teams. -CIS Benchmark: CIS GitHub Benchmark v1.2.0 +Teams can grant access to organization repositories. Restricting who can create them helps prevent unplanned access and makes the organization's permissions easier to manage. Members who need a new team may need an owner, administrator, or approved access-management process to create it. -Assessment Status: Manual +CIS GitHub Benchmark v1.2.0 lists section 1.3.2 as a Manual assessment. This test checks `members_can_create_teams` from `GET /orgs/{org}` for the connected organization. It does not review the organization's process for requesting or approving new teams. -#### Rationale +The test passes when the field is Boolean `false` and fails when it is Boolean `true`. A missing, null, or non-Boolean value produces **Skipped**, with a reason explaining what could not be checked. Request or JSON parsing failures produce **Error**. Missing data does not mean team creation is disabled or the recommendation does not apply. -Teams can inherit access and quickly become part of the organization's permission model. Restricting team creation helps prevent shadow teams, accidental privilege expansion, and unnecessary organizational clutter. - -#### Impact - -Members who previously created teams directly may need an owner, administrator, or approved access-management process to create new teams. - -#### Maester automation note - -CIS marks this recommendation as Manual. This Maester test automates the portion of CIS GH 1.3.2 that maps to documented GitHub REST API evidence. It should be treated as automated evidence collection for the corresponding GitHub setting, not as a claim that every possible manual review path has been fully evaluated. - -#### API evidence - -Endpoint: `GET /orgs/{org}` - -Evidence field: `members_can_create_teams` - -The test passes when `members_can_create_teams` is `false`. +The test covers the connected organization's returned setting. It does not scan other organizations or reconstruct inherited policies. Maester checks this field after parsing the response, rather than validating the entire response schema. #### Permissions required -GitHub requires organization-owner visibility for full organization details. Use `Connect-MtGitHub` with a classic PAT that has `admin:org`, or a fine-grained PAT with organization Members read and Administration read permissions. - -#### Remediation summary +Use an organization owner with a classic PAT or OAuth token carrying `admin:org` to read the full organization settings. With fine-grained PATs, the connection's membership check uses organization **Members: read**, and its separate administration check uses **Administration: read**. A successful connection does not guarantee that GitHub returns the field this test needs. See [Connect-MtGitHub](https://maester.dev/docs/commands/Connect-MtGitHub) for the connection checks. -In the organization settings, open **Member privileges** and disable **Allow members to create teams**. +For GHE.com, use `https://api.SUBDOMAIN.ghe.com` and a token for that host; do not assume the github.com device flow applies. The same missing-data rules apply to GHEC, Enterprise Managed Users, and GHE.com. -#### Known limitations +#### Remediation action -This test verifies the organization-level team creation setting. It does not review custom operational processes for who may request or approve new teams. +1. On the connected GitHub web host (`github.com` or your enterprise's `SUBDOMAIN.ghe.com`), open **Your organizations**, select the organization, then go to **Settings** > **Access** > **Member privileges**. +2. Under **Team creation rules**, clear **Allow members to create teams**. +3. Save the change and use the organization's approved process for new-team requests. #### Related links * [CIS GitHub Benchmark v1.2.0 - Section 1.3.2](https://www.cisecurity.org/benchmark/github) -* [GitHub REST API: Get an organization](https://docs.github.com/en/rest/orgs/orgs#get-an-organization) +* [GitHub: Team creation permissions](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-organization-settings/setting-team-creation-permissions-in-your-organization) +* [GitHub REST API: Get an organization](https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2026-03-10#get-an-organization) %TestResult% diff --git a/tests/cis/Test.CIS.GH.1.3.2.ps1 b/tests/cis/Test.CIS.GH.1.3.2.ps1 index a98cded8fd..44b1c65c1d 100644 --- a/tests/cis/Test.CIS.GH.1.3.2.ps1 +++ b/tests/cis/Test.CIS.GH.1.3.2.ps1 @@ -40,12 +40,24 @@ $org = Get-MtGitHubOrganization $field = 'members_can_create_teams' if (-not (Test-MtGitHubObjectProperty -InputObject $org -PropertyName $field)) { - Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "GitHub organization response did not include required field '$field'. This field is required to evaluate CIS.GH.1.3.2 and may be missing because of permissions, plan, API version, or organization type." + Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "Indeterminate: GitHub organization response did not include required field '$field'. This field is required to evaluate CIS.GH.1.3.2 and may be missing because of permissions, plan, API version, or organization type." + return $null + } + + if ($org.$field -isnot [bool]) { + Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "Indeterminate: GitHub organization field '$field' must be a Boolean to evaluate CIS.GH.1.3.2. No configuration verdict was produced." return $null } $result = $org.$field -eq $false + $resultSummary = if ($result) { + 'Well done. Members cannot create teams.' + } else { + 'Members can create teams. Disable Allow members to create teams in organization Member privileges.' + } $resultMarkdown = @" +$resultSummary + CIS.GH.1.3.2 automated evidence from ``GET /orgs/{org}``. | Field | Actual | Expected | diff --git a/tests/cis/Test.CIS.GH.1.3.8.md b/tests/cis/Test.CIS.GH.1.3.8.md index b5405218b5..e2a2f62ba9 100644 --- a/tests/cis/Test.CIS.GH.1.3.8.md +++ b/tests/cis/Test.CIS.GH.1.3.8.md @@ -1,45 +1,30 @@ -1.3.8 (L1) Ensure strict base permissions are set for repositories +Organization base permissions grant members no repository access or read access only. -CIS Benchmark: CIS GitHub Benchmark v1.2.0 +Base permissions apply across organization repositories. Keeping them at **None** or **Read** prevents the default from giving every member permission to change code. Members who contribute changes may need explicit repository, team, or role assignments after the default is reduced. -Assessment Status: Manual +CIS GitHub Benchmark v1.2.0 lists section 1.3.8 as a Manual assessment. This test checks `default_repository_permission` from `GET /orgs/{org}` for the connected organization. It does not review individual repository collaborators, teams, or custom access grants. -#### Rationale +The test passes for `none` or `read` and fails for `write` or `admin`, without regard to letter case. A missing, null, empty, unrecognized, or non-string value produces **Skipped**, with a reason explaining what could not be checked. Request or JSON parsing failures produce **Error**. Missing data does not mean the default is safe or the recommendation does not apply. -Base permissions apply broadly across organization repositories. Keeping the default at none or read follows least privilege and lowers the chance that every member can change code where they do not have a specific business need. - -#### Impact - -Some members may lose default write access and require explicit repository, team, or role assignments before they can contribute changes. - -#### Maester automation note - -CIS marks this recommendation as Manual. This Maester test automates the portion of CIS GH 1.3.8 that maps to documented GitHub REST API evidence. It should be treated as automated evidence collection for the corresponding GitHub setting, not as a claim that every possible manual review path has been fully evaluated. - -#### API evidence - -Endpoint: `GET /orgs/{org}` - -Evidence field: `default_repository_permission` - -The test passes when `default_repository_permission` is `none` or `read`. It fails when the value is `write` or `admin`. +The test covers the connected organization's returned setting. It does not scan other organizations or reconstruct inherited policies. Maester checks this field after parsing the response, rather than validating the entire response schema. #### Permissions required -GitHub requires organization-owner visibility for full organization details. Use `Connect-MtGitHub` with a classic PAT that has `admin:org`, or a fine-grained PAT with organization Members read and Administration read permissions. - -#### Remediation summary +Use an organization owner with a classic PAT or OAuth token carrying `admin:org` to read the full organization settings. With fine-grained PATs, the connection's membership check uses organization **Members: read**, and its separate administration check uses **Administration: read**. A successful connection does not guarantee that GitHub returns the field this test needs. See [Connect-MtGitHub](https://maester.dev/docs/commands/Connect-MtGitHub) for the connection checks. -In the organization settings, open **Member privileges** and set **Base permissions** to **None** or **Read**. +For GHE.com, use `https://api.SUBDOMAIN.ghe.com` and a token for that host; do not assume the github.com device flow applies. The same missing-data rules apply to GHEC, Enterprise Managed Users, and GHE.com. -#### Known limitations +#### Remediation action -This test verifies the organization default repository permission only. It does not review per-repository collaborators, teams, or custom access grants. +1. Plan explicit repository or team access for members who need to contribute after the default changes. Coordinate those grants with the relevant repository owners. +2. On the connected GitHub web host (`github.com` or your enterprise's `SUBDOMAIN.ghe.com`), open **Your organizations**, select the organization, then go to **Settings** > **Access** > **Member privileges**. +3. Set **Base permissions** to **None** or **Read**, review the changes, and confirm the default-permission change. #### Related links * [CIS GitHub Benchmark v1.2.0 - Section 1.3.8](https://www.cisecurity.org/benchmark/github) -* [GitHub REST API: Get an organization](https://docs.github.com/en/rest/orgs/orgs#get-an-organization) +* [GitHub: Organization base permissions](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-user-access-to-your-organizations-repositories/managing-repository-roles/setting-base-permissions-for-an-organization) +* [GitHub REST API: Get an organization](https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2026-03-10#get-an-organization) %TestResult% diff --git a/tests/cis/Test.CIS.GH.1.3.8.ps1 b/tests/cis/Test.CIS.GH.1.3.8.ps1 index 179ce4216a..b25d68debb 100644 --- a/tests/cis/Test.CIS.GH.1.3.8.ps1 +++ b/tests/cis/Test.CIS.GH.1.3.8.ps1 @@ -39,14 +39,27 @@ $org = Get-MtGitHubOrganization $field = 'default_repository_permission' if (-not (Test-MtGitHubObjectProperty -InputObject $org -PropertyName $field)) { - Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "GitHub organization response did not include required field '$field'. This field is required to evaluate CIS.GH.1.3.8 and may be missing because of permissions, plan, API version, or organization type." + Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "Indeterminate: GitHub organization response did not include required field '$field'. This field is required to evaluate CIS.GH.1.3.8 and may be missing because of permissions, plan, API version, or organization type." + return $null + } + + $actual = $org.$field + $recognizedValues = @('none', 'read', 'write', 'admin') + if ($actual -isnot [string] -or $recognizedValues -notcontains $actual) { + Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "Indeterminate: GitHub organization field '$field' must be a recognized permission string (none, read, write, or admin) to evaluate CIS.GH.1.3.8. No configuration verdict was produced." return $null } $allowedValues = @('none', 'read') - $actual = [string]$org.$field $result = $allowedValues -contains $actual + $resultSummary = if ($result) { + 'Well done. Organization base permissions are limited to none or read.' + } else { + 'Organization base permissions grant write or administrator access. Set Base permissions to None or Read and review explicit access grants.' + } $resultMarkdown = @" +$resultSummary + CIS.GH.1.3.8 automated evidence from ``GET /orgs/{org}``. | Field | Actual | Expected |