-
Notifications
You must be signed in to change notification settings - Fork 96
[2/3] Add permissions command #479
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
Merged
EthanHeilman
merged 7 commits into
openpubkey:main
from
fdcastel:add-permissions-command
Mar 23, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ec1fa7f
Add permissions command and refactor audit infrastructure
fdcastel 77648e4
Address PR #479 review feedback
fdcastel 5d02dd9
Introduce unified FileSystem interface for permissions and audit
fdcastel 3d9767d
Fix test failures: add WithCmdRunner option, fix gofmt alignment
fdcastel 6ab0a33
Merge branch 'main' into add-permissions-command
EthanHeilman d49f93a
Address PR review feedback: rename fields, fix providers/config, remo…
fdcastel 15c8494
Check ACL results for providers and config files, not just system policy
fdcastel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| //go:build !windows | ||
| // +build !windows | ||
|
|
||
| // Copyright 2026 OpenPubkey | ||
| // | ||
| // 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. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| // enumerateUserHomeDirs returns the list of user home directories by reading | ||
| // /etc/passwd. This is the Unix implementation. | ||
| func (a *AuditCmd) enumerateUserHomeDirs() ([]userHomeEntry, error) { | ||
| passwdPath := "/etc/passwd" | ||
| exists, err := a.Fs.Exists(passwdPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to check /etc/passwd: %w", err) | ||
| } | ||
| if !exists { | ||
| return nil, fmt.Errorf("/etc/passwd not found (needed to enumerate user home policies)") | ||
| } | ||
|
|
||
| etcPasswdContent, err := a.Fs.ReadFile(passwdPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read /etc/passwd: %w", err) | ||
| } | ||
|
|
||
| return getHomeDirsFromEtcPasswd(string(etcPasswdContent)), nil | ||
| } |
This file contains hidden or 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,65 @@ | ||
| //go:build !windows | ||
| // +build !windows | ||
|
|
||
| // Copyright 2026 OpenPubkey | ||
| // | ||
| // 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. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package commands | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/openpubkey/opkssh/policy/files" | ||
| "github.com/spf13/afero" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestEnumerateUserHomeDirs_Unix(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| vfs := afero.NewMemMapFs() | ||
| passwdContent := "root:x:0:0:root:/root:/bin/bash\nalice:x:1000:1000::/home/alice:/bin/sh\n" | ||
| require.NoError(t, afero.WriteFile(vfs, "/etc/passwd", []byte(passwdContent), 0o644)) | ||
|
|
||
| cmd := &AuditCmd{ | ||
| Fs: files.NewFileSystem(vfs, files.WithCmdRunner(func(string, ...string) ([]byte, error) { return nil, nil })), | ||
| Out: &bytes.Buffer{}, | ||
| } | ||
|
|
||
| entries, err := cmd.enumerateUserHomeDirs() | ||
| require.NoError(t, err) | ||
| require.Len(t, entries, 2) | ||
| require.Equal(t, "root", entries[0].Username) | ||
| require.Equal(t, "/root", entries[0].HomeDir) | ||
| require.Equal(t, "alice", entries[1].Username) | ||
| require.Equal(t, "/home/alice", entries[1].HomeDir) | ||
| } | ||
|
|
||
| func TestEnumerateUserHomeDirs_Unix_MissingPasswd(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| vfs := afero.NewMemMapFs() | ||
|
|
||
| cmd := &AuditCmd{ | ||
| Fs: files.NewFileSystem(vfs, files.WithCmdRunner(func(string, ...string) ([]byte, error) { return nil, nil })), | ||
| Out: &bytes.Buffer{}, | ||
| } | ||
|
|
||
| _, err := cmd.enumerateUserHomeDirs() | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "/etc/passwd not found") | ||
| } |
This file contains hidden or 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,26 @@ | ||
| //go:build windows | ||
| // +build windows | ||
|
|
||
| // Copyright 2026 OpenPubkey | ||
| // | ||
| // 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. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package commands | ||
|
|
||
| // enumerateUserHomeDirs returns the list of user home directories by reading | ||
| // the Windows registry ProfileList. This is the Windows implementation. | ||
| func (a *AuditCmd) enumerateUserHomeDirs() ([]userHomeEntry, error) { | ||
| return getHomeDirsFromProfileList() | ||
| } |
This file contains hidden or 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,49 @@ | ||
| //go:build windows | ||
| // +build windows | ||
|
|
||
| // Copyright 2026 OpenPubkey | ||
| // | ||
| // 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. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package commands | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/openpubkey/opkssh/policy/files" | ||
| "github.com/spf13/afero" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestEnumerateUserHomeDirs_Windows(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| vfs := afero.NewMemMapFs() | ||
| cmd := &AuditCmd{ | ||
| Fs: files.NewFileSystem(vfs, files.WithCmdRunner(func(string, ...string) ([]byte, error) { return nil, nil })), | ||
| Out: &bytes.Buffer{}, | ||
| } | ||
|
|
||
| entries, err := cmd.enumerateUserHomeDirs() | ||
| require.NoError(t, err) | ||
| // On a running Windows machine there should be at least one user profile | ||
| require.NotEmpty(t, entries, "expected at least one user profile from Windows registry") | ||
|
|
||
| for _, e := range entries { | ||
| require.NotEmpty(t, e.Username, "username should not be empty") | ||
| require.NotEmpty(t, e.HomeDir, "home directory should not be empty") | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.