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

tests: new test for cifs-mount interface #5714

Conversation

sergiocazzolato
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@bboozzoo bboozzoo left a comment

Choose a reason for hiding this comment

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

Looking good. Some comments inline.

snap install test-snapd-cifs-mount

# Create linux and samba users
sudo useradd -s /bin/true test-cifs
Copy link
Collaborator

Choose a reason for hiding this comment

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

The tests are executed by root anyway, no need to use sudo.


# Configure samba
cp /etc/samba/smb.conf /etc/samba/smb.conf.back
echo "[data]" >> /etc/samba/smb.conf
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should work too:

[data]
path=$(pwd)/local_share
writable=yes
browsable=yes

shellcheck will probably suggest something like this:

(echo "[data]"
echo "path=$(pwd)/local_share"
echo "writable=yes"
echo "browsable=yes" ) > /etc/samba/smb.conf

echo "browsable=yes" >> /etc/samba/smb.conf

systemctl restart smbd.service
systemctl restart nmbd.service
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need to touch nmbd, IIRC it's only used for NetBIOS name resolution and shouldn't matter here.

snap connect test-snapd-cifs-mount:cifs-mount

echo "Then the snap is able to mount and umount a cifs fs"
test-snapd-cifs-mount.sh -c "mount -t cifs //127.0.0.1/data /var/snap/test-snapd-cifs-mount/current/local_mount -o user=test-cifs,passowrd=test"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thin this line and ones below should use $SNAP_DATA, eg:

test-snapd-cifs-mount.sh -c "mount -t cifs //127.0.0.1/data \$SNAP_DATA/local_mount -o user=test-cifs,passowrd=test"

snap connect test-snapd-cifs-mount:cifs-mount

echo "Then the snap is able to mount and umount a cifs fs"
test-snapd-cifs-mount.sh -c "mount -t cifs //127.0.0.1/data /var/snap/test-snapd-cifs-mount/current/local_mount -o user=test-cifs,passowrd=test"
Copy link
Collaborator

Choose a reason for hiding this comment

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

And you probably need to mkdir the mount point first too:

test-snapd-cifs-mount.sh -c "mkdir \$SNAP_DATA/local_mount"

@sergiocazzolato
Copy link
Collaborator Author

@bboozzoo thanks for reviewing this, all the commest have been addressed.

@bboozzoo
Copy link
Collaborator

bboozzoo commented Aug 28, 2018

2018-08-27 16:02:15 Error executing google:ubuntu-16.04-64:tests/main/interfaces-cifs-mount : 
-----
+ echo 'The interface is not connected by default'
The interface is not connected by default
+ MATCH -- '^- +test-snapd-cifs-mount:cifs-mount'
+ snap interfaces -i cifs-mount
+ echo 'When the interface is connected'
When the interface is connected
+ snap connect test-snapd-cifs-mount:cifs-mount
+ echo 'Then the snap is able to mount and umount a cifs fs'
Then the snap is able to mount and umount a cifs fs
+ test-snapd-cifs-mount.sh -c 'mount -t cifs //127.0.0.1/data $SNAP_DATA/local_mount -o user=test-cifs,passowrd=test'
/bin/sh: 1: mount: Permission denied
-----
...
[Mon Aug 27 16:02:14 2018] audit: type=1400 audit(1535385735.584:105): 
   apparmor="DENIED" operation="exec" 
   profile="snap.test-snapd-cifs-mount.sh" name="/bin/mount" 
   pid=25232 comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0

Maybe the interface should add (u)mount to the interface?

/usr/bin/mount ixr,
/usr/bin/umount ixr,

Otherwise when you have for eg. a simple Python app, you cannot really use the interface unless you poke the libc via ctypes or somesuch. @zyga @jdstrand wdyt?

@niemeyer
Copy link
Contributor

@bboozzoo This interface is paired with mount-observe to have access to reading the current mounts.

@sergiocazzolato You'll probably need that too.

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

Some comments, and LGTM once you're happy about their consideration.


# Configure samba
cp /etc/samba/smb.conf /etc/samba/smb.conf.back
{ echo "[data]"; echo "path=$(pwd)/local_share"; echo "writable=yes"; echo "browsable=yes"; } >> /etc/samba/smb.conf
Copy link
Contributor

Choose a reason for hiding this comment

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

$ echo -e "foo\nbar"
foo
bar

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

apps:
sh:
command: sh
plugs: [cifs-mount]
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably needs mount-observe, per comments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@niemeyer , thanks for reviewing this. I tried by adding the mount-observe plug but still having the same denial. testlog: https://paste.ubuntu.com/p/X56wt4CHrw/

The cifs-mount interface allows mounting and unmounting CIFS filesystems.

prepare: |
snap install test-snapd-cifs-mount
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be installing the local snap?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I need some dependencies as part of this snap, I had to create a snap and upload it to the store.


execute: |
echo "The interface is not connected by default"
snap interfaces -i cifs-mount | MATCH -- '^- +test-snapd-cifs-mount:cifs-mount'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the --?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not strictly needed here because '^.. will be detected as part of the pattern and handled porperly. However, the pattern MATCH '- +test..' will fail because '- will be seen as a -foo switch. So it's either MATCH -- <pattern>. We could use grep .. -e switch which makes grep expec <pattern> as the next argument.

@bboozzoo
Copy link
Collaborator

bboozzoo commented Aug 29, 2018

This interface is paired with mount-observe to have access to reading the current mounts.

We're not even getting that far. The problem is that currently the only way of doing the mount is via mount(2) because the policy does not allow executing mount|umount. Looking and udisks2, there's the following entry in the policy (which I think we need in cifs-mount too):

# udisksd execs mount/umount to do the actual operations
/bin/mount ixr,
/bin/umount ixr,

# mount/umount (via libmount) track some mount info in these files
/run/mount/utab* wrl,

Edit: and sorry for accidentally closing the PR, I've clicked the wrong button.

@bboozzoo bboozzoo closed this Aug 29, 2018
@bboozzoo bboozzoo reopened this Aug 29, 2018
@chipaca
Copy link
Contributor

chipaca commented Oct 17, 2018

Can't we call mount.cifs directly?

@sergiocazzolato
Copy link
Collaborator Author

@chipaca, in the test we are already using mount.cifs.

test-snapd-cifs-mount.sh -c "mount.cifs //127.0.0.1/data1 $SNAP_DATA/local_mount -o user=test-cifs,passowrd=test"

Copy link
Collaborator

@zyga zyga left a comment

Choose a reason for hiding this comment

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

LGTM

@zyga
Copy link
Collaborator

zyga commented Oct 26, 2018

+ smbpasswd -x test-cifs
/bin/bash: line 64: smbpasswd: command not found

It looks like we need to patch the test to install another package @sergiocazzolato

@zyga
Copy link
Collaborator

zyga commented Oct 26, 2018

When the interface is connected
+ snap connect test-snapd-cifs-mount:cifs-mount
+ snap connect test-snapd-cifs-mount:network-control
error: snap "test-snapd-cifs-mount" has no plug named "network-control"

@zyga
Copy link
Collaborator

zyga commented Oct 26, 2018

This is now failing on:

+ test-snapd-cifs-mount.sh -c 'mount.cifs //127.0.0.1/data1 $SNAP_DATA/local_mount -o user=test-cifs,passowrd=test'
/bin/sh: 1: mount.cifs: not found

@sergiocazzolato can you look at this next week please. Feels like we are missing something :)

@sergiocazzolato
Copy link
Collaborator Author

It is blocked until we find a solution for the denial trying to access to /run/mount/utab

@sergiocazzolato
Copy link
Collaborator Author

Closeing the PR until a solution to the denial is found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants