f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#! /usr/bin/ksh -p
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/include/libtest.shlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# DESCRIPTION:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The RBAC profile "ZFS File System Management" works
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The following actions are taken, both using profile execution (pfexec)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and without profile execution - we make sure that the latter should
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# always fail.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# (create)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1. As a normal user, try to create a filesystem - which should fail.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 2. Assign "ZFS File System Management" profile, try to create fs again,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# which should succeed.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# (pools)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 3. Ensure a user with this profile can't perform pool administration
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# by attempting to destroy a pool.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# (destroy)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 5. Remove the FS profile, then attempt to destroy the fs, which
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# should fail.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 6. Assign the FS profile, then attempt to destroy the fs, which
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# should succeed.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_runnable "both"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "The RBAC profile \"ZFS File System Management\" works"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren KennedyZFS_USER=$(cat /tmp/zfs-privs-test-user.txt)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Set a $DATASET where we can create child files systems
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zpool create -f $TESTPOOL $DISKS
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy DATASET=$TESTPOOL
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyelse
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy DATASET=zonepool/zonectr0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# A user shouldn't be able to create filesystems
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_mustnot su $ZFS_USER -c "zfs create $DATASET/zfsprivfs"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Insist this invocation of usermod works
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must usermod -P "ZFS File System Management" $ZFS_USER
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Now try to create file systems as the user
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_mustnot su $ZFS_USER -c "zfs create $DATASET/zfsprivfs"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must su $ZFS_USER -c "pfexec zfs create $DATASET/zfsprivfs"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Ensure the user can't do anything to pools in this state:
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_mustnot su $ZFS_USER -c "zpool destroy $DATASET"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_mustnot su $ZFS_USER -c "pfexec zpool destroy $DATASET"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# revoke File System Management profile
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyusermod -P, $ZFS_USER
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Ensure the user can't create more filesystems
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_mustnot su $ZFS_USER -c "zfs create $DATASET/zfsprivfs2"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_mustnot su $ZFS_USER -c "pfexec zfs create $DATASET/zfsprivfs2"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# assign the profile again and destroy the fs.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyusermod -P "ZFS File System Management" $ZFS_USER
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must su $ZFS_USER -c "pfexec zfs destroy $DATASET/zfsprivfs"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedyusermod -P, $ZFS_USER
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "The RBAC profile \"ZFS File System Management\" works"