Skip to content

Commit 4b1beee

Browse files
committed
Apply hot fix to resolve issue with untrusted git repository for not-owned checker
1 parent 436c7ac commit 4b1beee

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
with:
4949
distribution: goreleaser
5050
version: latest
51+
5152
args: release --rm-dist
5253
env:
5354
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ COPY --from=deps /usr/bin/xargs /usr/bin/xargs
1616
COPY --from=deps /lib /lib
1717
COPY --from=deps /usr/lib /usr/lib
1818

19-
CMD ["/codeowners-validator"]
19+
ENTRYPOINT ["/codeowners-validator"]

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ Use the following environment variables to configure the application:
128128
| <tt>CHECK_FAILURE_LEVEL</tt> | `warning` | Defines the level on which the application should treat check issues as failures. Defaults to `warning`, which treats both errors and warnings as failures, and exits with error code 3. Possible values are `error` and `warning`. |
129129
| <tt>OWNER_CHECKER_REPOSITORY</tt> <b>*</b> | | The owner and repository name separated by slash. For example, gh-codeowners/codeowners-samples. Used to check if GitHub owner is in the given organization. |
130130
| <tt>OWNER_CHECKER_IGNORED_OWNERS</tt> | `@ghost` | The comma-separated list of owners that should not be validated. Example: `"@owner1,@owner2,@org/team1,example@email.com"`. |
131-
| <tt>OWNER_CHECKER_ALLOW_UNOWNED_PATTERNS</tt> | `true` | Specifies whether CODEOWNERS may have unowned files. For example: <br> <br> `/infra/oncall-rotator/ @sre-team` <br> `/infra/oncall-rotator/oncall-config.yml` <br> <br> The `/infra/oncall-rotator/oncall-config.yml` file is not owned by anyone. |
131+
| <tt>OWNER_CHECKER_ALLOW_UNOWNED_PATTERNS</tt> | `true` | Specifies whether CODEOWNERS may have unowned files. For example: <br> <br> `/infra/oncall-rotator/ @sre-team` <br> `/infra/oncall-rotator/oncall-config.yml` <br> <br> The `/infra/oncall-rotator/oncall-config.yml` file is not owned by anyone. |
132132
| <tt>OWNER_CHEKER_OWNERS_MUST_BE_TEAMS</tt> | `false` | Specifies whether only teams are allowed as owners of files. |
133133
| <tt>NOT_OWNED_CHECKER_SKIP_PATTERNS</tt> | - | The comma-separated list of patterns that should be ignored by `not-owned-checker`. For example, you can specify `*` and as a result, the `*` pattern from the **CODEOWNERS** file will be ignored and files owned by this pattern will be reported as unowned unless a later specific pattern will match that path. It's useful because often we have default owners entry at the begging of the CODOEWNERS file, e.g. `* @global-owner1 @global-owner2` |
134-
| <tt>NOT_OWNED_CHECKER_SUBDIRECTORIES</tt> | - | The comma-separated list of subdirectories to check in `not-owned-checker`. When specified, only files in the listed subdirectories will be checked if they do not have specified owners in CODEOWNERS. |
134+
| <tt>NOT_OWNED_CHECKER_SUBDIRECTORIES</tt> | - | The comma-separated list of subdirectories to check in `not-owned-checker`. When specified, only files in the listed subdirectories will be checked if they do not have specified owners in CODEOWNERS. |
135+
| <tt>NOT_OWNED_CHECKER_TRUST_WORKSPACE</tt> | `false` | Specifies whether the repository path should be marked as safe. See: https://github.com/actions/checkout/issues/766. |
135136

136137
<b>*</b> - Required
137138

action.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,28 @@ inputs:
4444
default: "${{ github.repository }}"
4545

4646
owner_checker_ignored_owners:
47-
description: "The comma-separated list of owners that should not be validated. Example: @owner1,@owner2,@org/team1,example@email.com."
47+
description: "The comma-separated list of owners that should not be validated. Example: @owner1,@owner2,@org/team1,example@email.com."
4848
required: false
4949

5050
owner_checker_allow_unowned_patterns:
51-
description: "Specifies whether CODEOWNERS may have unowned files. For example, `/infra/oncall-rotator/oncall-config.yml` doesn't have owner and this is not reported."
51+
description: "Specifies whether CODEOWNERS may have unowned files. For example, `/infra/oncall-rotator/oncall-config.yml` doesn't have owner and this is not reported."
5252
default: "true"
5353
required: false
5454

5555
owner_checker_owners_must_be_teams:
56-
description: "Specifies whether only teams are allowed as owners of files."
56+
description: "Specifies whether only teams are allowed as owners of files."
5757
default: "false"
5858
required: false
5959

6060
not_owned_checker_subdirectories:
61-
description: "Only check listed subdirectories for CODEOWNERS ownership that don't have owners."
61+
description: "Only check listed subdirectories for CODEOWNERS ownership that don't have owners."
6262
required: false
6363

64+
not_owned_checker_trust_workspace:
65+
description: "Specifies whether the repository path should be marked as safe. See: https://github.com/actions/checkout/issues/766"
66+
required: false
67+
default: "true"
68+
6469
runs:
6570
using: 'docker'
6671
image: 'docker://ghcr.io/mszostok/codeowners-validator:v0.7.3'

internal/check/not_owned_file.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ import (
1616
)
1717

1818
type NotOwnedFileConfig struct {
19+
// TrustWorkspace sets the global gif config
20+
// to trust a given repository path
21+
// see: https://github.com/actions/checkout/issues/766
22+
TrustWorkspace bool `envconfig:"default=false"`
1923
SkipPatterns []string `envconfig:"optional"`
2024
Subdirectories []string `envconfig:"optional"`
2125
}
2226

2327
type NotOwnedFile struct {
2428
skipPatterns map[string]struct{}
2529
subDirectories []string
30+
trustWorkspace bool
2631
}
2732

2833
func NewNotOwnedFile(cfg NotOwnedFileConfig) *NotOwnedFile {
@@ -34,6 +39,7 @@ func NewNotOwnedFile(cfg NotOwnedFileConfig) *NotOwnedFile {
3439
return &NotOwnedFile{
3540
skipPatterns: skip,
3641
subDirectories: cfg.Subdirectories,
42+
trustWorkspace: cfg.TrustWorkspace,
3743
}
3844
}
3945

@@ -51,6 +57,10 @@ func (c *NotOwnedFile) Check(ctx context.Context, in Input) (output Output, err
5157

5258
patterns := c.patternsToBeIgnored(in.CodeownersEntries)
5359

60+
if err := c.trustWorkspaceIfNeeded(in.RepoDir); err != nil {
61+
return Output{}, err
62+
}
63+
5464
statusOut, err := c.GitCheckStatus(in.RepoDir)
5565
if err != nil {
5666
return Output{}, err
@@ -187,6 +197,20 @@ func (c *NotOwnedFile) GitListFiles(repoDir string) (string, error) {
187197
return string(stdout), nil
188198
}
189199

200+
func (c *NotOwnedFile) trustWorkspaceIfNeeded(repo string) error {
201+
if !c.trustWorkspace {
202+
return nil
203+
}
204+
205+
gitadd := pipe.Exec("git", "config", "--global", "--add", "safe.directory", repo)
206+
_, stderr, err := pipe.DividedOutput(gitadd)
207+
if err != nil {
208+
return errors.Wrap(err, string(stderr))
209+
}
210+
211+
return nil
212+
}
213+
190214
func (c *NotOwnedFile) skipPatternsList() string {
191215
list := make([]string, 0, len(c.skipPatterns))
192216
for k := range c.skipPatterns {
@@ -206,7 +230,7 @@ func (c *NotOwnedFile) ListFormatFunc(es []string) string {
206230
return strings.Join(points, "\n")
207231
}
208232

209-
// Name returns human readable name of the validator
233+
// Name returns human-readable name of the validator
210234
func (NotOwnedFile) Name() string {
211235
return "[Experimental] Not Owned File Checker"
212236
}

internal/check/valid_owner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ var reqScopes = map[github.Scope]struct{}{
2020
}
2121

2222
type ValidOwnerConfig struct {
23+
// Repository represents the GitHub repository against which
24+
// the external checks like teams and members validation should be executed.
25+
// It is in form 'owner/repository'.
2326
Repository string
2427
// IgnoredOwners contains a list of owners that should not be validated.
2528
// Defaults to @ghost.

0 commit comments

Comments
 (0)