Add target resource listing to default roles (#1803)
This addresses the issue of a user being created in a normal or dev environment that is given access to authorize sessions against specific targets but the permission hasn't been configured for the UI clients to actually list them. Resolves #1791
This commit is contained in:
1 parent
cf0a95f260
commit
5d33393cbd
4 files changed
+56
-5
No files matched your search
@@ -295,6 +295,12 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o
|
||||
}
|
||||
grants = append(grants, roleGrant)
|
||||
|
||||
roleGrant, err = NewRoleGrant(defaultRolePublicId, "type=target;actions=list")
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to create in memory role grant"))
|
||||
}
|
||||
grants = append(grants, roleGrant)
|
||||
|
||||
default:
|
||||
roleGrant, err := NewRoleGrant(defaultRolePublicId, "id=*;type=scope;actions=list,no-op")
|
||||
if err != nil {
|
||||
|
||||
+19
-3
@@ -77,7 +77,7 @@ func TestScopes(t *testing.T, repo *Repository, opt ...Option) (org *Scope, prj
|
||||
return
|
||||
}
|
||||
|
||||
func TestOrg(t *testing.T, repo *Repository, opt ...Option) (org *Scope) {
|
||||
func TestOrg(t *testing.T, repo *Repository, opt ...Option) *Scope {
|
||||
t.Helper()
|
||||
require := require.New(t)
|
||||
|
||||
@@ -85,12 +85,28 @@ func TestOrg(t *testing.T, repo *Repository, opt ...Option) (org *Scope) {
|
||||
|
||||
org, err := NewOrg(opt...)
|
||||
require.NoError(err)
|
||||
org, err = repo.CreateScope(context.Background(), org, opts.withUserId)
|
||||
org, err = repo.CreateScope(context.Background(), org, opts.withUserId, opt...)
|
||||
require.NoError(err)
|
||||
require.NotNil(org)
|
||||
require.NotEmpty(org.GetPublicId())
|
||||
|
||||
return
|
||||
return org
|
||||
}
|
||||
|
||||
func TestProject(t *testing.T, repo *Repository, orgId string, opt ...Option) *Scope {
|
||||
t.Helper()
|
||||
require := require.New(t)
|
||||
|
||||
opts := getOpts(opt...)
|
||||
|
||||
proj, err := NewProject(orgId, opt...)
|
||||
require.NoError(err)
|
||||
proj, err = repo.CreateScope(context.Background(), proj, opts.withUserId, opt...)
|
||||
require.NoError(err)
|
||||
require.NotNil(proj)
|
||||
require.NotEmpty(proj.GetPublicId())
|
||||
|
||||
return proj
|
||||
}
|
||||
|
||||
func testOrg(t *testing.T, repo *Repository, name, description string) (org *Scope) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package targets_test
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"github.com/hashicorp/boundary/api/credentialstores"
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/api/hostsets"
|
||||
"github.com/hashicorp/boundary/api/roles"
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/internal/credential/vault"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
@@ -130,6 +132,24 @@ func TestList(t *testing.T) {
|
||||
client.SetToken(token.Token)
|
||||
_, proj := iam.TestScopes(t, tc.IamRepo(), iam.WithUserId(token.UserId))
|
||||
|
||||
// Add unpriv user to default role in new project. Also add create grant as
|
||||
// it will be needed later in the test and no-op for listing visibility.
|
||||
rls, err := roles.NewClient(client).List(tc.Context(), proj.GetPublicId())
|
||||
require.NoError(err)
|
||||
var defaultRoleId string
|
||||
for _, rl := range rls.Items {
|
||||
if strings.Contains(rl.Name, "Default") {
|
||||
defaultRoleId = rl.Id
|
||||
break
|
||||
}
|
||||
}
|
||||
require.NotEmpty(defaultRoleId)
|
||||
unprivToken := tc.UnprivilegedToken()
|
||||
iam.TestUserRole(t, tc.DbConn(), defaultRoleId, unprivToken.UserId)
|
||||
iam.TestRoleGrant(t, tc.DbConn(), defaultRoleId, "type=target;actions=create")
|
||||
iam.TestRoleGrant(t, tc.DbConn(), defaultRoleId, "id=*;type=target;actions=no-op")
|
||||
|
||||
client.SetToken(unprivToken.Token)
|
||||
tarClient := targets.NewClient(client)
|
||||
ul, err := tarClient.List(tc.Context(), proj.GetPublicId())
|
||||
require.NoError(err)
|
||||
|
||||
Reference in new issue
Block a user