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:
Jeff Mitchell authored and GitHub committed 2021-02-11 13:14:18 -05:00
1 parent d279a906ce
commit 22462cdd84
28 files changed
+626 -196

No files matched your search

+49 -5
View File
@@ -18,6 +18,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/sdk/strutil"
"github.com/hashicorp/go-hclog"
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/hashicorp/vault/sdk/helper/base62"
@@ -25,9 +26,11 @@ import (
)
const (
DefaultTestAuthMethodId = "ampw_1234567890"
DefaultTestLoginName = "user"
DefaultTestPassword = "passpass"
DefaultTestAuthMethodId = "ampw_1234567890"
DefaultTestLoginName = "admin"
DefaultTestUnprivilegedLoginName = "user"
DefaultTestPassword = "passpass"
DefaultTestUserId = "u_1234567890"
)
// TestController wraps a base.Server and Controller to provide a
@@ -46,6 +49,11 @@ type TestController struct {
opts *TestControllerOpts
}
// Server returns the underlying base server
func (tc *TestController) Server() *base.Server {
return tc.b
}
// Controller returns the underlying controller
func (tc *TestController) Controller() *Controller {
return tc.c
@@ -135,6 +143,26 @@ func (tc *TestController) Token() *authtokens.AuthToken {
return token.Item
}
func (tc *TestController) UnprivilegedToken() *authtokens.AuthToken {
if tc.opts.DisableAuthMethodCreation {
tc.t.Error("no default auth method ID configured")
return nil
}
token, err := authmethods.NewClient(tc.Client()).Authenticate(
tc.Context(),
tc.b.DevAuthMethodId,
map[string]interface{}{
"login_name": tc.b.DevUnprivilegedLoginName,
"password": tc.b.DevUnprivilegedPassword,
},
)
if err != nil {
tc.t.Error(fmt.Errorf("error logging in: %w", err))
return nil
}
return token.Item
}
func (tc *TestController) addrs(purpose string) []string {
var prefix string
switch purpose {
@@ -242,10 +270,13 @@ type TestControllerOpts struct {
// DefaultAuthMethodId is the default auth method ID to use, if set.
DefaultAuthMethodId string
// DefaultLoginName is the login name used when creating the default account.
// DefaultLoginName is the login name used when creating the default admin account.
DefaultLoginName string
// DefaultPassword is the password used when creating the default account.
// DefaultUnprivilegedLoginName is the login name used when creating the default unprivileged account.
DefaultUnprivilegedLoginName string
// DefaultPassword is the password used when creating the default accounts.
DefaultPassword string
// DisableInitialLoginRoleCreation can be set true to disable creating the
@@ -360,10 +391,17 @@ func NewTestController(t *testing.T, opts *TestControllerOpts) *TestController {
} else {
tc.b.DevLoginName = DefaultTestLoginName
}
if opts.DefaultUnprivilegedLoginName != "" {
tc.b.DevUnprivilegedLoginName = opts.DefaultUnprivilegedLoginName
} else {
tc.b.DevUnprivilegedLoginName = DefaultTestUnprivilegedLoginName
}
if opts.DefaultPassword != "" {
tc.b.DevPassword = opts.DefaultPassword
tc.b.DevUnprivilegedPassword = opts.DefaultPassword
} else {
tc.b.DevPassword = DefaultTestPassword
tc.b.DevUnprivilegedPassword = DefaultTestPassword
}
// Start a logger
@@ -396,7 +434,11 @@ func NewTestController(t *testing.T, opts *TestControllerOpts) *TestController {
tc.b.DevProjectId = "p_" + suffix
tc.b.DevTargetId = "ttcp_" + suffix
tc.b.DevUserId = "u_" + suffix
tc.b.DevUnprivilegedUserId = "u_" + strutil.Reverse(strings.TrimPrefix(tc.b.DevUserId, "u_"))
} else {
tc.b.DevUserId = DefaultTestUserId
}
tc.b.DevUnprivilegedUserId = "u_" + strutil.Reverse(strings.TrimPrefix(tc.b.DevUserId, "u_"))
// Set up KMSes
switch {
@@ -509,6 +551,8 @@ func (tc *TestController) AddClusterControllerMember(t *testing.T, opts *TestCon
RecoveryKms: tc.c.conf.RecoveryKms,
Name: opts.Name,
Logger: tc.c.conf.Logger,
DefaultLoginName: tc.b.DevLoginName,
DefaultPassword: tc.b.DevPassword,
DisableKmsKeyCreation: true,
DisableAuthMethodCreation: true,
}