Skip to content

cephadm: Add shell '--mount' option to mount host file or directory#34773

Merged
sebastian-philipp merged 1 commit intoceph:masterfrom
ricardoasmarques:cephadm-shell-mount
May 5, 2020
Merged

cephadm: Add shell '--mount' option to mount host file or directory#34773
sebastian-philipp merged 1 commit intoceph:masterfrom
ricardoasmarques:cephadm-shell-mount

Conversation

@ricardoasmarques
Copy link
Contributor

The Problem:

I have a file on my host, that I would like to use to set a "config-key":

master:/etc/ceph # head -1 /tmp/ceph-salt-ssh-id_rsa
-----BEGIN RSA PRIVATE KEY-----

But when I try to use that file, I get an error because the file is not accessible inside the container:

master:/etc/ceph # cephadm shell -- ceph config-key set mgr/cephadm/ssh_identity_key -i /tmp/ceph-salt-ssh-id_rsa
...
Can't open input file /tmp/ceph-salt-ssh-id_rsa: [Errno 2] No such file or directory: '/tmp/c

Proposed Solution

Add a new --mount option to cephadm shell, that allows to mount a host file or directory:

master:~ # cephadm shell --help
...
  --mount MOUNT, -m MOUNT
                        file or directory path that will be mounted in
                        container /mnt
...
master:~ # cephadm shell --mount /tmp/ceph-salt-ssh-id_rsa -- ceph config-key set mgr/cephadm/ssh_identity_key -i /mnt/tmp/ceph-salt-ssh-id_rsa
...
set mgr/cephadm/ssh_identity_key

Fixes: https://tracker.ceph.com/issues/45284

Signed-off-by: Ricardo Marques rimarques@suse.com

Checklist

  • References tracker ticket
  • Updates documentation if necessary
  • Includes tests for new functionality or reproducer for bug

Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard backend
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox

@ricardoasmarques ricardoasmarques requested a review from a team as a code owner April 27, 2020 14:24
@ricardoasmarques ricardoasmarques changed the title cephadm: Add '--mount' option to mount host file or directory cephadm: Add shell '--mount' option to mount host file or directory Apr 27, 2020
mgfritch
mgfritch previously approved these changes Apr 27, 2020
Copy link
Contributor

@mgfritch mgfritch left a comment

Choose a reason for hiding this comment

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

I really want to avoid adding an additional argument, but I don't see a safe way to pass secrets (via the environment, cmdline, or otherwise)

Copy link
Contributor

@matthewoliver matthewoliver left a comment

Choose a reason for hiding this comment

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

I needed this exact option today to modify the ceph crushmap in ses7. As you need the compiled crushmap in the cephadm shell container to be able to run crushtool on it. When I applied these changes:

master:~ # ceph osd getcrushmap -o cm.compiled
master:~ # cephadm shell --mount ./
[ceph: root@master /]# crushtool -d /mnt/cm.compiled -o /mnt/cm.txt
master:~ # ls
bin  cm.compiled  cm.txt

It worked perfectly. Big +1 from me.

@ricardoasmarques
Copy link
Contributor Author

@mgfritch @matthewoliver I've updated this PR to always mount the file or directory under /mnt, without relying on the args.mount:

-        mounts[pathify(args.mount)] = '/mnt/{}:z'.format(args.mount)
+        mount = pathify(args.mount)
+        filename = ''
+        if os.path.isfile(mount):
+            _, filename = os.path.split(mount)
+        mounts[mount] = '/mnt/{}:z'.format(filename)

@sebastian-philipp
Copy link
Contributor

I don't have a good answer here. Maybe we can by default also mount $PWD?

@ricardoasmarques
Copy link
Contributor Author

I don't have a good answer here. Maybe we can by default also mount $PWD?

@sebastian-philipp I've updated this PR to mount $PWD when no --mount option is specified. Also, I've now documented the --mount behavior on install.rst.

Copy link
Contributor

@matthewoliver matthewoliver left a comment

Choose a reason for hiding this comment

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

Nice, I like this alot more. Now we don't have to assume the --mount option to make changes to things, only if you want to mount something other then cwd. Making it much easier to use.

Run it and you still have access to your current directory.

One thought. When I run cephadm shell it always dumps me in / I wonder if we should get it to dump us in /mnt now that it'll always be mounted. It'll make workflows easier maybe?

Though this could be a follow up patch, kind out of scope.

Maybe something like this will do it:

diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm
index 23c838e79b..56bdcfcdd2 100755
--- a/src/cephadm/cephadm
+++ b/src/cephadm/cephadm
@@ -2767,6 +2767,7 @@ def command_shell():
             '-it',
             '-e', 'LANG=C',
             '-e', "PS1=%s" % CUSTOM_PS1,
+            '-w', '/mnt',
         ]
         if args.fsid:
             home = os.path.join(args.data_dir, args.fsid, 'home')

Of course making it something like ~/ might also be as useful. Anyway just a NIT not a blocker.

UPDATE: Just tested that ^^ locally and it worked for me.

@mgfritch mgfritch self-requested a review April 30, 2020 02:43
@mgfritch mgfritch dismissed their stale review April 30, 2020 02:52

I don't have a good answer here. Maybe we can by default also mount $PWD? > > @sebastian-philipp I've updated this PR to mount $PWD when no --mount option is specified. Also, I've now documented the --mount behavior on install.rst. Are we sure we want to default mount $PWD rather than forcing this option to be explicit? This could leave random files laying around in random places on the container host ...

@mgfritch
Copy link
Contributor

I don't have a good answer here. Maybe we can by default also mount $PWD?

@sebastian-philipp I've updated this PR to mount $PWD when no --mount option is specified. Also, I've now documented the --mount behavior on install.rst.

Are we sure we want to default mount $PWD rather than forcing this option to be explicit? This could leave random files laying around in random places on the container host ...

@trociny
Copy link
Contributor

trociny commented Apr 30, 2020

I am also not very happy about default mount $PWD.

If this form does not look very convenient:

cephadm shell --mount /tmp/ceph-salt-ssh-id_rsa -- ceph config-key set mgr/cephadm/ssh_identity_key -i /mnt/tmp/ceph-salt-ssh-id_rsa

Then may be we can a provide a possibility to specify this like:

cephadm shell -- ceph config-key set mgr/cephadm/ssh_identity_key -i host://mnt/tmp/ceph-salt-ssh-id_rsa

Which would be preparsed by the cephadm and converted to the first form automatically?

@ricardoasmarques ricardoasmarques force-pushed the cephadm-shell-mount branch 2 times, most recently from bf220f3 to d3e92c0 Compare April 30, 2020 13:21
@ricardoasmarques
Copy link
Contributor Author

I've updated this PR to NOT mount $PWD by default as this is the less intrusive approach.

Copy link
Contributor

@mgfritch mgfritch left a comment

Choose a reason for hiding this comment

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

lgtm!

Comment on lines +2754 to +2786
filename = ''
if os.path.isfile(mount):
_, filename = os.path.split(mount)
mounts[mount] = '/mnt/{}:z'.format(filename)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
filename = ''
if os.path.isfile(mount):
_, filename = os.path.split(mount)
mounts[mount] = '/mnt/{}:z'.format(filename)
mounts[mount] = '/mnt/{}:z'.format(os.path.basename(mount))

this doesn't work with symlinks, char/block devs, etc.

maybe just use the basename instead?

@ricardoasmarques
Copy link
Contributor Author

@sebastian-philipp rebased

@mgfritch
Copy link
Contributor

mgfritch commented May 5, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants