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

cockpit: support setting owner/group in fsreplace1 #21128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jelly
Copy link
Member

@jelly jelly commented Oct 16, 2024

Cockpit-files wants to support uploading or creating a file owned by the current directory which might be different from the logged in user.

For example as superuser uploading a database into /var/lib/postgresql which would be owned by postgres and the database file should receive the same permissions.

@jelly jelly added the no-test For doc/workflow changes, or experiments which don't need a full CI run, label Oct 16, 2024
@jelly jelly force-pushed the fsreplace1-chown branch 2 times, most recently from 2602089 to 489d3f5 Compare November 1, 2024 14:48
@jelly jelly marked this pull request as ready for review November 14, 2024 15:50
@jelly jelly marked this pull request as draft November 14, 2024 15:50
@jelly jelly force-pushed the fsreplace1-chown branch 6 times, most recently from 20ea543 to 8554761 Compare November 21, 2024 13:52
pkg/lib/cockpit.d.ts Outdated Show resolved Hide resolved
pkg/playground/test.js Outdated Show resolved Hide resolved
@jelly jelly requested review from mvollmer, allisonkarlitskaya and martinpitt and removed request for mvollmer November 21, 2024 15:35
@jelly jelly marked this pull request as ready for review November 21, 2024 15:35
@jelly
Copy link
Member Author

jelly commented Nov 21, 2024

Only triggered Fedora for now, lets review one round and then run all tests.

@jelly jelly closed this Nov 21, 2024
@jelly jelly reopened this Nov 21, 2024
@jelly jelly removed the no-test For doc/workflow changes, or experiments which don't need a full CI run, label Nov 21, 2024
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks! Nice unit tests with the mocking!

doc/protocol.md Outdated Show resolved Hide resolved
doc/protocol.md Outdated Show resolved Hide resolved
doc/protocol.md Outdated
Comment on lines 1077 to 1078
* `uid`: an integer, the uid of the file owner (`st_uid`)
* `owner`: a string, or an integer, the uid of the file owner (`st_uid`)
Copy link
Member

Choose a reason for hiding this comment

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

These conflict. Please document which one wins, or that specifying both is an error. Same for group.

Is there some deeper reason to allow both? AFAIUI, owner can take an uid, so this feels redundant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well @allisonkarlitskaya argued that this should take the fsinfo fields so those are uid/gid/owner/group

Copy link
Member

Choose a reason for hiding this comment

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

fwiw, fsinfo calls this user, not owner.

We also discussed this in a call: we should just implement user and group (supporting either strings or ints), not uid and gid.

pkg/playground/test.js Outdated Show resolved Hide resolved
})
.catch(exc => {
console.log(exc);
fsreplace_error.textContent = exc;
Copy link
Member

Choose a reason for hiding this comment

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

Hm, doesn't this need a .toString() Otherwise you'll just get some useless "[Object]".

Copy link
Member Author

Choose a reason for hiding this comment

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

For one instance it worked, but yeah safer to toString()

Copy link
Member

Choose a reason for hiding this comment

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

Still no .toString(), reopening.

pkg/playground/test.js Show resolved Hide resolved
src/cockpit/channels/filesystem.py Outdated Show resolved Hide resolved
src/cockpit/channels/filesystem.py Outdated Show resolved Hide resolved
src/cockpit/channels/filesystem.py Outdated Show resolved Hide resolved
@@ -257,9 +257,16 @@ declare module 'cockpit' {
remove(): void;
}

interface ReplaceAttrs {
Copy link
Member

Choose a reason for hiding this comment

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

At least mode should also get added while you're at it. I think. I'm not 100% sure what we should do with this and its interaction with umask...

size is also in the fsinfo blob. This would be been an interesting alternative to the size-hint attribute we added at the top level. I think maybe the ship has sailed on that one already?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah but many fields are already not possible from fsinfo so hmm tagging that along seems arbitrary.

Mode does not make sense but I don't want to add it now.

Copy link
Member Author

Choose a reason for hiding this comment

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

BTW, we want to use this in files soon (tm) but we ofcourse have no hint that we support this. As passing attrs={} just silently ignores it. But maybe we can read the tag, which I hope is returned by await file.replace("").

@jelly jelly force-pushed the fsreplace1-chown branch 2 times, most recently from 96db00e to 2764d3e Compare November 26, 2024 16:39
@jelly jelly requested a review from martinpitt November 27, 2024 09:14
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks!

doc/protocol.md Outdated
Comment on lines 1077 to 1078
- `owner`: a string, or an integer, the uid of the file owner (`st_uid`)
- `group`: a string, or an integer, the gid of the file group (`st_gid`)
Copy link
Member

Choose a reason for hiding this comment

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

This renders wrong: https://github.com/jelly/cockpit/blob/fsreplace1-chown/doc/protocol.md#payload-fsreplace1

You may have to indent these two a bit more. Please also document that you (currently) have to set both of these.

Also see the outstanding thread to rename owner → user for consistency (I agree to this).

})
.catch(exc => {
console.log(exc);
fsreplace_error.textContent = exc;
Copy link
Member

Choose a reason for hiding this comment

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

Still no .toString(), reopening.

src/cockpit/channels/filesystem.py Show resolved Hide resolved
Comment on lines 183 to 184
if owner is None or group is None:
raise ChannelError('protocol-error', message='"owner" or "group" attribute is empty')
Copy link
Member

Choose a reason for hiding this comment

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

So that means as soon as you specify any attrs in fsreplace1, you always have to specify user and group. This is fine right now, but we'll have to relax this in the future once we start supporting other attributes. We only need to enforce "neither or both", not "always both".

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but the logic here would have be if you specify owner you have to specify group and vice-versa

Copy link
Member

Choose a reason for hiding this comment

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

Right, but right now it's not "if", it's "you always have to specify user and group". E.g. you couldn't call file.replace({ mode: 0755 }) (in a future where we support more attributes)

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, I've added this new logic which also gives a better error message.

Cockpit-files wants to support uploading or creating a file owned by the
current directory which might be different from the logged in user.

For example as superuser uploading a database into `/var/lib/postgresql`
which would be owned by `postgres` and the database file should receive
the same permissions.
Comment on lines +149 to +150
.catch(exc => {
fsreplace_error.textContent = exc.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 added lines are not executed by any test.

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.

4 participants