Support multiple IDs in grants (#3263)
This allows specifying multiple IDs in grants via an `ids` field, which will eventually become the normal way to specify IDs. Internally, each grant with multiple IDs turns into multiple ACL grants each with a single ID; to make this distinction clearer and allow for better separation of concerns an AclGrant type has been introduced, so really multiple IDs in a Grant turn into multiple AclGrants. The nice thing about doing it this way is that it becomes purely a parsing concern; no actual validation logic has changed. For backwards compatibility with grants already stored in roles, we do not error out if `id` is specified. However, eventually we will simply not support grants with `id` coming via the API; they will fail API validation, such that new grants will require the use of the updated `ids` field. A follow-on PR will plumb this through the service handlers/API/CLI, but I decided to do it in separate chunks to make reviewing easier, given that they are easily separable into the internal and external aspects of the change. * Add CLI/API checks around using ID in grants (#3264) * Plumb through some contexts to remove a lot of deprecated errors (#3268)
This commit is contained in:
1 parent
8acc73dc6e
commit
feb3aea38f
25 files changed
+1043
-381
No files matched your search
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/boundary/version"
|
||||
"github.com/mitchellh/go-wordwrap"
|
||||
)
|
||||
|
||||
@@ -218,11 +219,20 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]roles.Opti
|
||||
|
||||
if len(c.flagGrants) > 0 {
|
||||
for _, grant := range c.flagGrants {
|
||||
_, err := perms.Parse(scope.Global.String(), grant)
|
||||
parsed, err := perms.Parse(c.Context, scope.Global.String(), grant)
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Errorf("Grant %q could not be parsed successfully: %w", grant, err).Error())
|
||||
return false
|
||||
}
|
||||
switch {
|
||||
case parsed.Id() == "":
|
||||
// Nothing
|
||||
case version.SupportsFeature(version.Binary, version.SupportIdInGrants):
|
||||
c.UI.Warn(fmt.Sprintf("Grant %q uses the %q field, which is deprecated and will not be allowed in version 0.15.0+. Please use %q instead.", grant, "id", "ids"))
|
||||
default:
|
||||
c.UI.Error(fmt.Sprintf("Grant %q uses the %q field which is no longer supported. Please use %q instead.", grant, "id", "ids"))
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -346,7 +346,10 @@ func DevWorker(opt ...Option) (*Config, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing dev config: %w", err)
|
||||
}
|
||||
opts := getOpts(opt...)
|
||||
opts, err := getOpts(opt...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing options: %w", err)
|
||||
}
|
||||
parsed.Eventing.AuditEnabled = opts.withAuditEventsEnabled
|
||||
parsed.Eventing.ObservationsEnabled = opts.withObservationsEnabled
|
||||
parsed.Eventing.SysEventsEnabled = opts.withSysEventsEnabled
|
||||
@@ -389,7 +392,10 @@ func DevController(opt ...Option) (*Config, error) {
|
||||
parsed.DevWorkerAuthKey = workerAuthKey
|
||||
parsed.DevBsrKey = bsrKey
|
||||
parsed.DevRecoveryKey = recoveryKey
|
||||
opts := getOpts(opt...)
|
||||
opts, err := getOpts(opt...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing options: %w", err)
|
||||
}
|
||||
parsed.Eventing.AuditEnabled = opts.withAuditEventsEnabled
|
||||
parsed.Eventing.ObservationsEnabled = opts.withObservationsEnabled
|
||||
parsed.Eventing.SysEventsEnabled = opts.withSysEventsEnabled
|
||||
|
||||
@@ -5,19 +5,30 @@ package config
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/go-secure-stdlib/parseutil"
|
||||
)
|
||||
|
||||
// getOpts - iterate the inbound Options and return a struct
|
||||
func getOpts(opt ...Option) options {
|
||||
opts := getDefaultOptions()
|
||||
for _, o := range opt {
|
||||
o(&opts)
|
||||
func getOpts(opt ...Option) (options, error) {
|
||||
opts, err := getDefaultOptions()
|
||||
if err != nil {
|
||||
return opts, err
|
||||
}
|
||||
return opts
|
||||
for _, o := range opt {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
err = o(&opts)
|
||||
if err != nil {
|
||||
return opts, err
|
||||
}
|
||||
}
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// Option - how Options are passed as arguments
|
||||
type Option func(*options)
|
||||
type Option func(*options) error
|
||||
|
||||
// options = how options are represented
|
||||
type options struct {
|
||||
@@ -27,50 +38,65 @@ type options struct {
|
||||
testWithErrorEventsEnabled bool
|
||||
}
|
||||
|
||||
func getDefaultOptions() options {
|
||||
func getDefaultOptions() (options, error) {
|
||||
opts := options{}
|
||||
|
||||
if os.Getenv("BOUNDARY_ENABLE_TEST_SYS_EVENTS") != "" {
|
||||
opts.withSysEventsEnabled = true
|
||||
}
|
||||
if os.Getenv("BOUNDARY_ENABLE_TEST_AUDIT_EVENTS") != "" {
|
||||
opts.withAuditEventsEnabled = true
|
||||
}
|
||||
if os.Getenv("BOUNDARY_ENABLE_TEST_OBSERVATIONS") != "" {
|
||||
opts.withObservationsEnabled = true
|
||||
}
|
||||
if os.Getenv("BOUNDARY_ENABLE_TEST_ERROR_EVENTS") != "" {
|
||||
opts.testWithErrorEventsEnabled = true
|
||||
sysEvents, err := parseutil.ParseBool(os.Getenv("BOUNDARY_ENABLE_TEST_SYS_EVENTS"))
|
||||
if err != nil {
|
||||
return opts, err
|
||||
}
|
||||
opts.withSysEventsEnabled = sysEvents
|
||||
|
||||
return opts
|
||||
auditEvents, err := parseutil.ParseBool(os.Getenv("BOUNDARY_ENABLE_TEST_AUDIT_EVENTS"))
|
||||
if err != nil {
|
||||
return opts, err
|
||||
}
|
||||
opts.withAuditEventsEnabled = auditEvents
|
||||
|
||||
obs, err := parseutil.ParseBool(os.Getenv("BOUNDARY_ENABLE_TEST_OBSERVATIONS"))
|
||||
if err != nil {
|
||||
return opts, err
|
||||
}
|
||||
opts.withObservationsEnabled = obs
|
||||
|
||||
errEvents, err := parseutil.ParseBool(os.Getenv("BOUNDARY_ENABLE_TEST_ERROR_EVENTS"))
|
||||
if err != nil {
|
||||
return opts, err
|
||||
}
|
||||
opts.testWithErrorEventsEnabled = errEvents
|
||||
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// WithSysEventsEnabled provides an option for enabling system events
|
||||
func WithSysEventsEnabled(enable bool) Option {
|
||||
return func(o *options) {
|
||||
return func(o *options) error {
|
||||
o.withSysEventsEnabled = enable
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithAuditEventsEnabled provides an option for enabling audit events
|
||||
func WithAuditEventsEnabled(enable bool) Option {
|
||||
return func(o *options) {
|
||||
return func(o *options) error {
|
||||
o.withAuditEventsEnabled = enable
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithObservationsEnabled provides an option for enabling observation events
|
||||
func WithObservationsEnabled(enable bool) Option {
|
||||
return func(o *options) {
|
||||
return func(o *options) error {
|
||||
o.withObservationsEnabled = enable
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// TestWithErrorEventsEnabled provides an option for enabling error events
|
||||
// during tests.
|
||||
func TestWithErrorEventsEnabled(_ testing.TB, enable bool) Option {
|
||||
return func(o *options) {
|
||||
return func(o *options) error {
|
||||
o.testWithErrorEventsEnabled = enable
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user