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

fix(daemon): require admin access for POSTs and file pull API #406

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

benhoyt
Copy link
Contributor

@benhoyt benhoyt commented Apr 3, 2024

Most of this was introduced in PR #358, when we ported the AccessChecker changes from snapd, but accidentally set all the WriteAccess fields to UserAccess{} instead of AdminAccess{}. Previously there was a r.Method=="GET" check in Command.canAccess that handled this case.

Additionally:

  • We lock down the files "pull" API to require admin. Even though it's a read (GET), this meant any user could potentially read sensitive files.
  • We lock down the task-websocket endpoint to admin. This is a GET endpoint, but these websockets are used by exec to send stdin/out/err and commands to the exec'd process, so they should require admin too.

I've added some tests for these to ensure we don't accidentally change them in future, without noticing. How valuable these tests are I'm not sure, as they only cover a subset of the API endpoints, but it seems better than nothing.

Most of this was introduced in PR #358, when we ported the
AccessChecker changes from snapd, but accidentally set all the
WriteAccess fields to UserAccess{} instead of AdminAccess{}.
Previously there was a r.Method=="GET" check in Command.canAccess that
handled this case.

Additionally:

- We lock down the files "pull" API to require admin. Even though it's
  a read (GET), this meant any user could potentially read sensitive
  files.
- We lock down the task-websocket endpoint to admin. This is a GET
  endpoint, but these websockets are used by exec to send stdin/out/err
  and commands to the exec'd process, so they should require admin too.

I've added some tests for these to ensure we don't accidentally change
them in future, without noticing. How valuable these tests are I'm not
sure, as they only cover a subset of the API endpoints, but it seems
better than nothing.
@benhoyt benhoyt requested a review from hpidcock April 3, 2024 00:24
internals/daemon/api.go Outdated Show resolved Hide resolved
This was actually not working earlier, and fixed (unintentionally) by
the CheckAccess PR.
Copy link
Member

@hpidcock hpidcock left a comment

Choose a reason for hiding this comment

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

I've reviewed each access check and manually tested where reasonable. Thank-you for fixing this.

@benhoyt benhoyt merged commit 55bd548 into master Apr 3, 2024
16 checks passed
@benhoyt benhoyt deleted the fix-api-auth branch April 3, 2024 02:24
benhoyt added a commit that referenced this pull request Apr 3, 2024
Most of this was introduced in PR #358, when we ported the AccessChecker
changes from snapd, but accidentally set all the WriteAccess fields to
UserAccess{} instead of AdminAccess{}. Previously there was a
r.Method=="GET" check in Command.canAccess that handled this case.

Additionally:

- We lock down the files "pull" API to require admin. Even though it's a
read (GET), this meant any user could potentially read sensitive files.
- We lock down the task-websocket endpoint to admin. This is a GET
endpoint, but these websockets are used by exec to send stdin/out/err
and commands to the exec'd process, so they should require admin too.

I've added some tests for these to ensure we don't accidentally change
them in future, without noticing. How valuable these tests are I'm not
sure, as they only cover a subset of the API endpoints, but it seems
better than nothing.
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.

2 participants