Add ability for the controller/worker name to be read from env/file (#1181)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-05-04 09:37:56 -04:00
1 parent f130563da7
commit f32e7f9144
5 files changed
+86 -12

No files matched your search

+8 -6
View File
@@ -37,16 +37,16 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
* cli/api/sdk: Add support to request additional OIDC claims scope values from
the OIDC provider when making an authentication request.
([PR](https://github.com/hashicorp/boundary/pull/1175)).
By default, Boundary only requests the "openid" claims scope value. Many
providers, like Okta and Auth0 for example, will not return the standard claims
of email and name when you request the default claims scope (openid).
Boundary uses the standard email and name claims to populated an OIDC
account's `Email` and `FullName` attributes. If you'd like these account
attributes populated, you'll need reference your OIDC provider's documentation
to learn which claims scopes are required to have these claims returned during
the authentication process.
the authentication process.
Boundary now provides a new OIDC auth method parameter `claims_scopes` which
allows you to add multiple additional claims scope values to an OIDC auth
@@ -54,8 +54,7 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
For information on claims scope values see: [Scope Claims in the OIDC
specification](https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims)
* cli: Match JSON format output with the across-the-wire API JSON format
([PR](https://github.com/hashicorp/boundary/pull/1155))
* api: Return `204` instead of an empty object on successful `delete` operations
@@ -72,7 +71,7 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
* Login Name
* Full Name
* Email
These new user attributes correspond to attributes from the user's primary
auth method account. These attributes will be empty when the user has no
account in the primary auth method for their scope, or there is no designated
@@ -85,6 +84,9 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
* cli: New `logout` command deletes the current token in Boundary and forgets it
from the local system credential store
([PR](https://github.com/hashicorp/boundary/pull/1134))
* config: The `name` field for workers and controllers now supports being set
from environment variables or a file on disk
([PR](https://github.com/hashicorp/boundary/pull/1181))
### Bug Fixes
+13 -3
View File
@@ -238,6 +238,10 @@ func Parse(d string) (*Config, error) {
// Perform controller configuration overrides for auth token settings
if result.Controller != nil {
result.Controller.Name, err = ParseAddress(result.Controller.Name)
if err != nil && err != ErrNotAUrl {
return nil, fmt.Errorf("Error parsing controller name: %w", err)
}
if result.Controller.Name != strings.ToLower(result.Controller.Name) {
return nil, errors.New("Controller name must be all lower-case")
}
@@ -263,6 +267,10 @@ func Parse(d string) (*Config, error) {
// Parse worker tags
if result.Worker != nil {
result.Worker.Name, err = ParseAddress(result.Worker.Name)
if err != nil && err != ErrNotAUrl {
return nil, fmt.Errorf("Error parsing worker name: %w", err)
}
if result.Worker.Name != strings.ToLower(result.Worker.Name) {
return nil, errors.New("Worker name must be all lower-case")
}
@@ -378,9 +386,11 @@ var ErrNotAUrl = errors.New("not a url")
// ParseAddress parses a URL with schemes file://, env://, or any other.
// Depending on the scheme it will return specific types of data:
//
// * file:// will return a string with the file's contents * env:// will return
// a string with the env var's contents * anything else will return the string
// as it was
// * file:// will return a string with the file's contents
//
// * env:// will return a string with the env var's contents
//
// * Anything else will return the string as it was
//
// On error, we return the original string along with the error. The caller can
// switch on ErrNotAUrl to understand whether it was the parsing step that
+57
View File
@@ -1,11 +1,14 @@
package config
import (
"fmt"
"os"
"testing"
"time"
"github.com/hashicorp/shared-secure-libs/configutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDevController(t *testing.T) {
@@ -274,3 +277,57 @@ func TestDevWorker(t *testing.T) {
_, err = Parse(devConfig + devWorkerKeyValueConfig)
assert.Error(t, err)
}
func TestParsingName(t *testing.T) {
t.Parallel()
config := `
controller {
name = "%s"
}
worker {
name = "%s"
}
`
controllerEnv := "FOOENV"
workerEnv := "BARENV"
cases := []struct {
name string
templateController string
templateWorker string
envController string
envWorker string
expectedController string
expectedWorker string
}{
{
name: "no env",
templateController: "foobar",
templateWorker: "barfoo",
expectedController: "foobar",
expectedWorker: "barfoo",
},
{
name: "env",
templateController: fmt.Sprintf("env://%s", controllerEnv),
templateWorker: fmt.Sprintf("env://%s", workerEnv),
envController: "foobar2",
envWorker: "barfoo2",
expectedController: "foobar2",
expectedWorker: "barfoo2",
},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
if tt.envController != "" {
os.Setenv(controllerEnv, tt.envController)
}
if tt.envWorker != "" {
os.Setenv(workerEnv, tt.envWorker)
}
out, err := Parse(fmt.Sprintf(config, tt.templateController, tt.templateWorker))
require.NoError(t, err)
assert.Equal(t, tt.expectedController, out.Controller.Name)
assert.Equal(t, tt.expectedWorker, out.Worker.Name)
})
}
}
@@ -20,7 +20,10 @@ controller {
}
```
- `name` - Specifies a unique name of this controller within the Boundary controller cluster.
- `name` - Specifies a unique name of this controller within the Boundary
cluster. This value can be a direct name string, can refer to a file on disk
(file://) from which an name will be read; or an env var (env://) from which
the name will be read.
- `description` - Specifies a friendly description of this controller.
@@ -17,8 +17,10 @@ worker {
}
```
- `name` - Specifies a unique name of this worker within the Boundary worker
cluster.
- `name` - Specifies a unique name of this worker within the Boundary
cluster. This value can be a direct name string, can refer to a file on disk
(file://) from which an name will be read; or an env var (env://) from which
the name will be read.
- `description` - Specifies a friendly description of this worker.