Add read:self and cancel:self to sessions; add dev unpriv user (#923)
* Sessions support for read:self and cancel:self permissions. This is automatic with fallback; no API change is needed. * Strips out values from listing if only self actions are allowed on the resource and the user ID is different. This prevents a default ACL of id=*;type=session;actions=read:self,cancel:self from causing all values to be visible when listing. * Adds an unprivileged user to development/testing instances. This user has only default permissions plus the ability to authorize sessions in the default target.
This commit is contained in:
1 parent
d279a906ce
commit
22462cdd84
28 files changed
+626
-196
No files matched your search
@@ -1,6 +1,7 @@
|
||||
export BOUNDARY_ADDR="${BOUNDARY_ADDR:-http://127.0.0.1:9200}"
|
||||
export DEFAULT_PASSWORD="${DEFAULT_PASSWORD:-password}"
|
||||
export DEFAULT_LOGIN="${DEFAULT_LOGIN:-admin}"
|
||||
export DEFAULT_UNPRIVILEGED_LOGIN="${DEFAULT_UNPRIVILEGED_LOGIN:-user}"
|
||||
export DEFAULT_AMPW="${DEFAULT_AMPW:-ampw_1234567890}"
|
||||
export DEFAULT_P_ID='p_1234567890'
|
||||
export DEFAULT_O_ID='o_1234567890'
|
||||
@@ -10,6 +11,7 @@ export DEFAULT_HOST_SET='hsst_1234567890'
|
||||
export DEFAULT_HOST_CATALOG='hcst_1234567890'
|
||||
export DEFAULT_HOST='hst_1234567890'
|
||||
export DEFAULT_USER='u_1234567890'
|
||||
export DEFAULT_UNPRIVILEGED_USER='u_0987654321'
|
||||
export DEFAULT_GLOBAL='global'
|
||||
|
||||
function strip() {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
load _authorized_actions
|
||||
|
||||
function list_sessions() {
|
||||
boundary sessions list -scope-id $1 -format json
|
||||
}
|
||||
|
||||
function count_sessions() {
|
||||
list_sessions $1 | jq '. | length'
|
||||
}
|
||||
|
||||
function cancel_session() {
|
||||
boundary sessions cancel -id $1
|
||||
}
|
||||
|
||||
function read_session() {
|
||||
boundary sessions read -id $1
|
||||
}
|
||||
@@ -31,7 +31,7 @@ function assoc_host_sets() {
|
||||
boundary targets add-host-sets -id $id -host-set $hst
|
||||
}
|
||||
|
||||
function target_id() {
|
||||
function target_id_from_name() {
|
||||
local sid=$1
|
||||
local name=$2
|
||||
strip $(list_targets $sid | jq -c ".[] | select(.name | contains(\"$name\")) | .[\"id\"]")
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load _auth
|
||||
load _connect
|
||||
load _sessions
|
||||
load _helpers
|
||||
|
||||
@test "boundary/session: admin user can connect to default target" {
|
||||
run login $DEFAULT_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run connect_nc $DEFAULT_TARGET
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# Run twice so we have two values for later testing
|
||||
run connect_nc $DEFAULT_TARGET
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/session/connect: unpriv user can connect to default target" {
|
||||
run login $DEFAULT_UNPRIVILEGED_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run connect_nc $DEFAULT_TARGET
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# Run twice so we have two values for later testing
|
||||
run connect_nc $DEFAULT_TARGET
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
# Note: there seems to be an issue with jq's length calculation -- an increase
|
||||
# in the returned array by 2 shows up as a 4 or more increase in jq's length count.
|
||||
# So for now, verify they're not the same.
|
||||
@test "boundary/session: verify admin and unpriv user see different counts" {
|
||||
run login $DEFAULT_UNPRIVILEGED_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run count_sessions $DEFAULT_P_ID
|
||||
[ "$status" -eq 0 ]
|
||||
unpriv_sessions="$output"
|
||||
|
||||
run login $DEFAULT_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run count_sessions $DEFAULT_P_ID
|
||||
[ "$status" -eq 0 ]
|
||||
admin_sessions="$output"
|
||||
|
||||
[ "$unpriv_sessions" -lt "$admin_sessions" ]
|
||||
}
|
||||
|
||||
@test "boundary/session: verify read and cancelation permissions on admin session" {
|
||||
# Find an admin session
|
||||
run login $DEFAULT_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run list_sessions $DEFAULT_P_ID
|
||||
[ "$status" -eq 0 ]
|
||||
id=$(echo "$output" | jq -r '[.[]|select(.user_id == "u_1234567890")][0].id')
|
||||
|
||||
# Check unpriv cannot read or cancel an admin's session
|
||||
run login $DEFAULT_UNPRIVILEGED_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run read_session $id
|
||||
[ "$status" -eq 1 ]
|
||||
run cancel_session $id
|
||||
[ "$status" -eq 1 ]
|
||||
|
||||
# Check that admin _can_
|
||||
run login $DEFAULT_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run read_session $id
|
||||
[ "$status" -eq 0 ]
|
||||
run cancel_session $id
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/session: verify read and cancelation permissions on unpriv session" {
|
||||
# Find an unpriv session
|
||||
run login $DEFAULT_UNPRIVILEGED_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run list_sessions $DEFAULT_P_ID
|
||||
[ "$status" -eq 0 ]
|
||||
id=$(echo "$output" | jq -r '[.[]|select(.user_id == "u_0987654321")][0].id')
|
||||
|
||||
# Check unpriv can read and cancel their own session
|
||||
run login $DEFAULT_UNPRIVILEGED_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run read_session $id
|
||||
[ "$status" -eq 0 ]
|
||||
run cancel_session $id
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# Check that admin can too
|
||||
run login $DEFAULT_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
run read_session $id
|
||||
[ "$status" -eq 0 ]
|
||||
run cancel_session $id
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
@@ -6,35 +6,61 @@ load _targets
|
||||
load _helpers
|
||||
|
||||
|
||||
@test "boundary/login: can login as default user" {
|
||||
@test "boundary/login: can login as admin user" {
|
||||
run login $DEFAULT_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target/connect: default user can connect to default target" {
|
||||
@test "boundary/target/connect: admin user can connect to default target" {
|
||||
run connect_nc $DEFAULT_TARGET
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: default user can create target" {
|
||||
@test "boundary/target: admin user can read default target" {
|
||||
run read_target $DEFAULT_TARGET
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/login: can login as unpriv user" {
|
||||
run login $DEFAULT_UNPRIVILEGED_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target/connect: unpriv user can connect to default target" {
|
||||
run connect_nc $DEFAULT_TARGET
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: unpriv user can not read default target" {
|
||||
run read_target $DEFAULT_TARGET
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "boundary/login: login back in as admin user" {
|
||||
run login $DEFAULT_LOGIN
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: admin user can create target" {
|
||||
run create_tcp_target $DEFAULT_P_ID 22 $TGT_NAME
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: default user can not create already created target" {
|
||||
@test "boundary/target: admin user can not create already created target" {
|
||||
run create_tcp_target $DEFAULT_P_ID 22 $TGT_NAME
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: default user can read created target" {
|
||||
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
|
||||
@test "boundary/target: admin user can read created target" {
|
||||
local id=$(target_id_from_name $DEFAULT_P_ID $TGT_NAME)
|
||||
run read_target $id
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: the $TGT_NAME target contains default authorized-actions" {
|
||||
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
|
||||
local id=$(target_id_from_name $DEFAULT_P_ID $TGT_NAME)
|
||||
local out=$(read_target $id)
|
||||
|
||||
run has_default_target_actions "$out"
|
||||
@@ -42,35 +68,35 @@ load _helpers
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: default user can add default host set to created target" {
|
||||
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
|
||||
@test "boundary/target: admin user can add default host set to created target" {
|
||||
local id=$(target_id_from_name $DEFAULT_P_ID $TGT_NAME)
|
||||
run assoc_host_sets $id $DEFAULT_HOST_SET
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: created target has default host set" {
|
||||
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
|
||||
local id=$(target_id_from_name $DEFAULT_P_ID $TGT_NAME)
|
||||
run target_has_host_set_id $id $DEFAULT_HOST_SET
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target/connect: default user can connect to created target" {
|
||||
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
|
||||
local id=$(target_id_from_name $DEFAULT_P_ID $TGT_NAME)
|
||||
run connect_nc $id
|
||||
echo "connecting to $id: $output"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: default user can delete target" {
|
||||
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
|
||||
local id=$(target_id_from_name $DEFAULT_P_ID $TGT_NAME)
|
||||
run delete_target $id
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "boundary/target: default user can not read deleted target" {
|
||||
local id=$(target_id $DEFAULT_P_ID $TGT_NAME)
|
||||
local id=$(target_id_from_name $DEFAULT_P_ID $TGT_NAME)
|
||||
run read_target $id
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
Reference in new issue
Block a user