Skip to content
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

Lock down file permissions #1770

Merged
merged 1 commit into from
Sep 27, 2021
Merged

Conversation

carolynvs
Copy link
Member

@carolynvs carolynvs commented Sep 21, 2021

What does this change

Only give permission to the current user, never to the group or other. Only mixins/plugins and scripts should be executable.

Note that on Windows, Go can't accurately report file permissions. Since files by default on Windows are not shared with other users, I am excluding windows from the permission check.

What issue does it fix

Closes #1765

Notes for the reviewer

At this point the cnab-go version that porter v0.38 uses and the one that porter v1 use have diverged quite a bit. I have a branch of cnab-go in porter's fork that lets me make small patches just for our stable branch.

I did not submit the cnab-go patch that we are using in this PR here upstream to cnab-go because that code is going to be deleted very soon, because the crud package is being removed from cnab-go entirely. There's no point it patching it upstream.

getporter/cnab-go@59a143b

Checklist

  • Unit Tests
  • Documentation
  • Schema (porter.yaml)

@@ -62,7 +84,7 @@ func TestPorter_Build(t *testing.T) {

stamp, err := configadapter.LoadStamp(*bun)
require.NoError(t, err)
assert.Equal(t, "d421a6249dfbdba79e26e866da7533d59590565708dfdb32423cf989f588d0ea", stamp.ManifestDigest)
assert.NotEmpty(t, stamp.ManifestDigest)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most awful and unhelpful check, so I've fixed it to just make sure a stamp exists, but not the exact hash. This fix is already included the release/v1 branch.

@carolynvs carolynvs force-pushed the file-permissions branch 4 times, most recently from fa39417 to 7be3a54 Compare September 22, 2021 16:58
@carolynvs
Copy link
Member Author

/azp run porter-integration

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@carolynvs carolynvs force-pushed the file-permissions branch 4 times, most recently from 3943b2a to 7bc58f1 Compare September 23, 2021 19:40
@carolynvs carolynvs marked this pull request as ready for review September 23, 2021 19:54
@carolynvs carolynvs marked this pull request as draft September 23, 2021 19:54
@carolynvs
Copy link
Member Author

Oops sorry I accidentally flipped this out of draft but I'm still fixing stuff!

Only give permission to the current user, never to the group or other.
Only mixins/plugins and scripts should be executable.
When porter accesses files, it checks that there aren't any
credentials/parameteres/claims with wide-open permissions.
This check is skipped on Windows because files by default are not
shared, and Go can't accurately report file permissions on Windows.

$ porter --debug list --debug-plugins
Resolved porter binary from /usr/local/bin/porter to /Users/carolynvs/.porter/porter
Resolved storage plugin to storage.porter.filesystem
/Users/carolynvs/.porter/porter plugin run storage.porter.filesystem
PORTER HOME: /Users/carolynvs/.porter
Checking file permissions in /Users/carolynvs/.porter

Error: could not list installations: could not read storage schema document: incorrect file permissions on /Users/carolynvs/.porter/config.toml, it should be 600. Correct it manually or by running porter storage fix-permissions.

$ porter storage fix-permissions
Resetting file permissions in /Users/carolynvs/.porter...

$ porter --debug list --debug-plugins
Resolved porter binary from /usr/local/bin/porter to /Users/carolynvs/.porter/porter
Resolved storage plugin to storage.porter.filesystem
/Users/carolynvs/.porter/porter plugin run storage.porter.filesystem
Checking file permissions in /Users/carolynvs/.porter

NAME                   CREATED      MODIFIED     LAST ACTION   LAST STATUS
bug                    2021-09-20   2021-09-20   install       succeeded
porter-hello           2021-09-20   2021-09-20   install       failed
whalegap               2021-09-14   2021-09-14   install       succeeded
mas-whales             2021-09-14   2021-09-14   install       failed
mybuns                 2021-08-10   2021-08-10   install       succeeded
spike-helm3-mysql      2021-08-02   2021-08-02   install       succeeded
helm3-mysql            2021-07-29   2021-07-29   install       succeeded
hello-keyvault         2021-07-27   2021-07-27   install       succeeded
helm-mysql             2021-06-30   2021-06-30   install       succeeded
tmp                    2021-06-30   2021-06-30   upgrade       succeeded
credentials-tutorial   2021-06-29   2021-06-29   install       succeeded
porterops              2021-06-10   2021-06-10   install       succeeded
kubernetes             2020-08-24   2020-08-24   install       succeeded
HELLO                  2020-08-17   2020-08-17   uninstall     succeeded

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
@@ -1,29 +1,36 @@
// +build integration
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this an integration test because it hits the filesystem and relies on build having been run first.

@carolynvs
Copy link
Member Author

/azp run porter-integration

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@carolynvs carolynvs marked this pull request as ready for review September 24, 2021 17:56
Copy link
Member

@vdice vdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔐 👏

@carolynvs carolynvs merged commit 1211300 into getporter:main Sep 27, 2021
@carolynvs carolynvs deleted the file-permissions branch September 27, 2021 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lock down file permissions
2 participants