Commit Graph
87 Commits
Author SHA1 Message Date
Timothy Messier 6b95d5f1fb doc(classification): Add initial rubric 2022-04-20 13:32:31 -04:00
Timothy Messier 0fc5cd5a33 test(account): Use require to prevent panic on test failure
If these assertions failed, then next assersions would result in a panic
when accessing the slice.
2022-04-20 13:32:31 -04:00
Timothy Messier 64ef193cfc test(account): Fix parallel validation tests 2022-04-20 13:32:31 -04:00
Timothy Messier e76c48ad36 feat(account): Mark auth_method_id as a source id for subtypes 2022-04-20 13:32:31 -04:00
Timothy Messier cc7e7429ab feat(account): Add domain file option 2022-04-20 13:32:31 -04:00
Timothy Messier 349e32afe4 feat(account): Use new filterable function to support filtering 2022-04-20 13:32:31 -04:00
Timothy Messier 3d58ce5f5c feat(subtypes): Add function to convert protobuf for filtering
This will transform a protobuf message with a oneof for attributes into
the API format to support filtering for list endpoints.
2022-04-20 13:32:31 -04:00
Timothy Messier 198a39ef1e feat(subtypes): Add grpc interceptor for transforming attributes
This interceptor is responsible for maintaining compatability with the
JSON API with the change to the protobuf messages. The messages are
changing from a single attribue field to a oneof to explicitly associate
subtype attribute messages with the resource message. The interceptor
transforms the request prior to the auditReqeust interceptor, and
transforms the response after the auditResponse interceptor. This allows
the audit interceptors to use all the necessary classification
information when creating the audit events.
2022-04-20 13:32:31 -04:00
Timothy Messier af93f7fccb feat(subtypes): Attribute field registration and lookup 2022-04-20 13:32:31 -04:00
Timothy Messier 185d8b392d refact(auth): Move subtype registration into global registry 2022-04-20 13:32:31 -04:00
Timothy Messier 31ef40ec5a feat(subtype): Add global registry 2022-04-20 13:32:31 -04:00
Timothy Messier 8cbbfbe3a0 feat(proto): Add new field option to indicate a in id for subtypes
This allows for marking a field in a message as an id that can be used
to determine the message's subtype. When creating some resources, an id
from a related resource is used to indicate the resource's subtype,
since the resource must have the same subtype as the related resource.
2022-04-20 13:32:31 -04:00
Timothy Messier 760b090567 feat(proto): Add new option for proto files to set domain
This allows for associating all of the messages in a file with a domain.
This will be used by the global subtype registry to group subtypes
within a domain. When registering a subtype, it must be unique within a
domain. This allows for cases where two domains have the same subtypes,
such as two domains both having a "plugin" subtype.
2022-04-20 13:32:31 -04:00
Timothy Messier ec0f107ef5 fix(build): Run plugin script directly instead of with sh (#2025)
These github actions run on Ubuntu based machine. Ubuntu by default
links `/bin/sh` to dash. So by invoking the plugin.sh script as `/bin/sh
./plugins.sh` the script would run under `dash` despite the shebang
line. A recent change that unified some of the build process, introduced
additional bashisms into this script which is caused the build to fail.

This updated the build system to just run the script directly, which
will honor the shebang line. This seems like the best approach since the
ubuntu machine has bash and the shebang line points to bash, so it is
natural for developers to assume bashisms will work.

See:
    f370abc1da
    https://github.com/actions/virtual-environments/blob/ubuntu20/20220410.2/images/linux/Ubuntu2004-Readme.md
    https://wiki.ubuntu.com/DashAsBinSh
2022-04-19 10:00:41 -04:00
Timothy Messier b5080c30c1 fix(config): Prevent panic when setting audit config filter orverrides (#2021)
This updates the config parsing for this stanza so prevent panics like
the following:

    panic: reflect.Value.MapIndex: value of type string is not assignable to type event.DataClassification

    goroutine 1 [running]:
    reflect.Value.assignTo({0x13fbb20, 0xc000a28700, 0x461367}, {0x1693f9d, 0x16}, 0x14375c0, 0x0)
            /usr/lib/go/src/reflect/value.go:2810 +0x2ad
    reflect.Value.MapIndex({0x145b1c0, 0xc000a16570, 0xc00072ff20}, {0x13fbb20, 0xc000a28700, 0x98})
            /usr/lib/go/src/reflect/value.go:1535 +0x7e
    github.com/hashicorp/hcl.(*decoder).decodeMap(0x8, {0xc00012b0b0, 0x28}, {0x67b40a8, 0xc0005fdc80}, {0x14bac80, 0xc0005fdc20, 0x1})
            /go/pkg/mod/github.com/hashicorp/hcl@v1.0.0/decoder.go:380 +0xa95
    github.com/hashicorp/hcl.(*decoder).decode(0xc000731360, {0xc00012b0b0, 0x28}, {0x67b40a8, 0xc0005fdc80}, {0x14bac80, 0xc0005fdc20, 0x0})
            /go/pkg/mod/github.com/hashicorp/hcl@v1.0.0/decoder.go:100 +0x395
    github.com/hashicorp/hcl.(*decoder).decodeStruct(0x203000, {0xc0005bf500, 0x11}, {0x67b40a8, 0xc0005fdc08}, {0x14fada0, 0xc0005fdc20, 0x7296ce0})
            /go/pkg/mod/github.com/hashicorp/hcl@v1.0.0/decoder.go:702 +0x1349
    github.com/hashicorp/hcl.(*decoder).decode(0xc000731360, {0xc0005bf500, 0x11}, {0x67b40a8, 0xc0005fdc08}, {0x14fada0, 0xc0005fdc20, 0x0})
            /go/pkg/mod/github.com/hashicorp/hcl@v1.0.0/decoder.go:108 +0x62f
    github.com/hashicorp/hcl.(*decoder).decodePtr(0x8, {0xc0005bf500, 0x11}, {0x67b40a8, 0xc0005fdc08}, {0x1442220, 0xc0005ca2f0, 0x1})
            /go/pkg/mod/github.com/hashicorp/hcl@v1.0.0/decoder.go:405 +0xd3
    github.com/hashicorp/hcl.(*decoder).decode(0xc000731360, {0xc0005bf500, 0x11}, {0x67b40a8, 0xc0005fdc08}, {0x1442220, 0xc0005ca2f0, 0x12})
            /go/pkg/mod/github.com/hashicorp/hcl@v1.0.0/decoder.go:102 +0x3e8
    github.com/hashicorp/hcl.(*decoder).decodeStruct(0x7f8c99b698f0, {0x1676310, 0x4}, {0x67b40d0, 0xc0005c82a0}, {0x1621c80, 0xc0005ca240, 0x0})
            /go/pkg/mod/github.com/hashicorp/hcl@v1.0.0/decoder.go:702 +0x1349
    github.com/hashicorp/hcl.(*decoder).decode(0xc000731360, {0x1676310, 0x4}, {0x67b40d0, 0xc0005c82a0}, {0x1621c80, 0xc0005ca240, 0xc0005ca240})
            /go/pkg/mod/github.com/hashicorp/hcl@v1.0.0/decoder.go:108 +0x62f
    github.com/hashicorp/hcl.DecodeObject({0x1442400, 0xc0005ca240}, {0x67b40d0, 0xc0005c82a0})
            /go/pkg/mod/github.com/hashicorp/hcl@v1.0.0/decoder.go:60 +0x126
    github.com/hashicorp/boundary/internal/cmd/config.parseEventing(0xc0005fa2a0)
            /go/src/github.com/hashicorp/boundary/internal/cmd/config/config.go:622 +0x1ec
    github.com/hashicorp/boundary/internal/cmd/config.Parse({0xc000683100, 0x66c})
            /go/src/github.com/hashicorp/boundary/internal/cmd/config/config.go:553 +0x149b
    github.com/hashicorp/boundary/internal/cmd/config.LoadFile({0x7fff4c8fdeef, 0xc0008e2d40}, {0x0, 0x0})
            /go/src/github.com/hashicorp/boundary/internal/cmd/config/config.go:306 +0x6f
    github.com/hashicorp/boundary/internal/cmd/commands/database.(*InitCommand).ParseFlagsAndConfig(0xc0005ae000, {0xc000132030, 0x2, 0x2})
            /go/src/github.com/hashicorp/boundary/internal/cmd/commands/database/init.go:516 +0x605
    github.com/hashicorp/boundary/internal/cmd/commands/database.(*InitCommand).Run(0xc0005ae000, {0xc000132030, 0xc0002857a0, 0xc000285788})
            /go/src/github.com/hashicorp/boundary/internal/cmd/commands/database/init.go:175 +0x4a
    github.com/mitchellh/cli.(*CLI).Run(0xc0002b2c80)
            /go/pkg/mod/github.com/mitchellh/cli@v1.1.2/cli.go:262 +0x5f8
    github.com/hashicorp/boundary/internal/cmd.RunCustom({0xc000132010, 0x60, 0x0}, 0x0)
            /go/src/github.com/hashicorp/boundary/internal/cmd/main.go:186 +0x9d6
    github.com/hashicorp/boundary/internal/cmd.Run(...)
            /go/src/github.com/hashicorp/boundary/internal/cmd/main.go:92
    main.main()
            /go/src/github.com/hashicorp/boundary/cmd/boundary/main.go:13 +0xc9
2022-04-18 11:03:10 -04:00
Timothy Messier 9aa2d4cd84 test(session): Speed up some tests around dead worker cleanup
This removes or reduces the time that is waited in a number of tests by
allowing the grace period time be a configuration option on the
connection repository.
2022-03-15 13:51:15 -04:00
Timothy Messier 79670180a7 refact(session): Move domain logic of Worker Status into domain service
This creates a domain service function `session.WorkerStatusReport`. The
service performs two functions:

1. Checks the status for all of the reported sessions, returning a
   report of the sessions that are in a "non-active" state, i.e.
   "cacneling" or "terminated".
2. Looks for any "orphaned" session connections, i.e. connections that
   are active but were not reported by the worker. These connections are
   marked as closed.

This also removes the "ShouldCloseConnectionsOnWorker" logic, as this
was determined to not be a possible state, and was unnecessary.
2022-03-15 13:51:15 -04:00
Timothy Messier cdb035f5fc test(worker_service): Add baseline tests for Status
This adds tests for the Status method of the WorkerService grpc service
that is exposed by controller.
2022-03-15 12:11:31 -04:00
Timothy Messier 4de6464978 refact(session): Make CloseDeadConnectionsForWorker more testable
The query for CloseDeadConnectionsForWorker includes a time comparison
to exclude results that are too close to the current time. This is done
to account for a delay in reporting by the worker. However, since the
delay was hardcoded in the query, it made it difficult to test.

This moves the delay duration into a parameter that is set on the
repository. The amount of the delay can be set at repository creation
time using the new WithWorkerStateDelay option. This defaults to the
previously hardcoded amount.

This will allow tests to control the delay to exercise this
functionality fully.
2022-03-15 12:11:31 -04:00
Timothy Messier e0603534c0 lint(session): Whitespace and missing ; in sql queries 2022-03-15 12:11:31 -04:00
Timothy Messier abb02d80d0 Merge pull request #1904 from hashicorp/tmessi-multiarc-postgres-image
chore(dbtest): Build test database docker image for arm64
fix(makefile): Update docker-build-dev to use correct target
2022-03-11 13:56:39 -05:00
Timothy Messier 761acd37b8 fix(makefile): Update docker-build-dev to use correct target
When the make targets where updated to switch from `make dev` to
`make build`, the dependency for the `docker-build-dev` target was not
updated.

See: b53e4d4c3e
2022-03-11 13:55:23 -05:00
Timothy Messier 839f9efcfb chore(dbtest): Build test database docker image for arm64
This adds a new makefile target to build and publish the test database
docker image for multiple architectures. It will create images for:

- linux/amd64
- linux/arm64

The target uses docker buildx to build the images. To build the images:

    docker buildx create --driver docker-container --use
    make docker-buildx
    docker buildx rm

See: https://docs.docker.com/buildx/working-with-buildx/
2022-03-11 13:55:23 -05:00
Timothy Messier bdb98d508e fix(genapi): Sort slice in removeDups template function (#1889)
The removeDups template function converts a slice into a map and
back into a slice in order to leverage the map keys to remove
duplicates. However, since the iteration order over a map is not
specified it would be possible to get different orders for multiple runs
of `make api`. While this would not have an impact on any functionality,
it is causing sporadic failures for the new make-gen-deltas CI job.

See: https://go.dev/ref/spec#For_statements
Ref: d57603022a
2022-03-04 11:44:41 -05:00
Timothy Messier 59d754e85f chore: Prep for next version 2022-02-17 14:58:13 -05:00
Timothy Messier 3446a0af39 chore(website): Update version to 0.7.5 2022-02-17 14:54:46 -05:00
Timothy Messier a2dc9dfd40 fix(build): Use POSIX compatible comparison
In CI were errors/warnings like:

    ./scripts/plugins.sh: 7: [: windowsx: unexpected operator

This comparison is compatible with more versions of bash and other
shells and should prevent these messages.
2022-02-17 11:15:36 -05:00
Timothy Messier 44d269fdbd fix(build): Include .exe suffix when building plugins for Windows (#1867)
When moving to the new CRT build process, this was missed from the older
build scripts. When building the plugins for Windows, if the files do
not have the `.exe` suffix, boundary fails with errors like the
following:

    Error initializing controller: error creating aws host plugin: error fetching host plugin rpc client: exec:
    "C:\\Users\\alice\\AppData\\Local\\Temp\\441718622\\boundary-plugin-host-aws": file does not exist
2022-02-17 10:48:15 -05:00
Timothy Messier 60bbadd125 chore: Set next version to 0.7.5 (#1847) 2022-02-09 16:12:53 -05:00
Timothy Messier 8557442370 ci: Add plugin compile step (#1840)
Some OS build steps were not compiling the plugins before compiling the
boundary binary. This resulted in binaries that did not have plugins
included, and would result in an error when starting a boundary server.
2022-02-02 17:29:29 -05:00
Timothy Messier cf0a95f260 Merge pull request #1820 from hashicorp/tmessi-fix-docker-build-dev
Replace XC_OSARCH with GOOS and GOARCH
2022-01-13 08:55:26 -05:00
Timothy Messier 0c3218ec3e docs(website): Update cross-compiling notes
This replaces references to XC_OSARCH with GOOS and GOARCH.

See: 1c8e0ed1e1
2022-01-13 08:54:50 -05:00
Timothy Messier 36664d433b chore(makefile): Fix docker-build-dev target
This target is updated to set GOOS and GOARCH instead of XC_OSARCH since
the build script was updated to use these environment variables for
cross-compiling.

See: 1c8e0ed1e1
2022-01-13 08:54:50 -05:00
Timothy Messier 27ebfa1125 Merge pull request #1796 from hashicorp/llb-credential-type-mapping
This allows users to set the type of credential that a credential
library will provide.

A User Password credential type and an Unspecified credential type are included
with the expectation that additional credential types will be added in the
future. This change also adds the credential type attribute to existing
credential libraries and sets it to Unspecified. The credential type can
only be set when a credential library is created.

The vault credential library includes functionality for converting a
Vault Secret into a User Password Credential. This mapping is enabled by
default, however, the user can override the attributes used for this
mapping.
2021-12-17 14:03:58 -05:00
Timothy Messier cc3bd20d2c Merge pull request #1756 from hashicorp/tmessi-target-refactors
Additional refactors to target domain and controller service packages for subtype registration.
2021-12-03 10:46:23 -05:00
Timothy Messier 0cfd8279b0 fix(controller/targets): Fix creation of credential libraries
The arg order was incorrect for ingress/egress credentials.

Ref: 2cc58ff901
Blame: 36f1ae75f7
2021-12-03 10:19:29 -05:00
Timothy Messier 533b434d1a refact(controller/targets): Move tcp functionality into subpackage
This follows a similar pattern as the target domain package, providing a
subpackage for the tcp target functionality, allowing this to be
pluggable.
2021-12-03 10:19:29 -05:00
Timothy Messier c9b99306e1 refact(target): Add NewFunc to registry
This adds a new requirement onto subtypes to register a NewFunc.
Previously the subtypes where implementing this function anyway, but the
target package was not including them in the registry. This resulted in
packages that use the target package needing to import the subtypes
directly, which we want to avoid.

This refactor will require the subtypes to register their NewFunc which
can then be used by `target.New` so packages that need to create targets
can do so by only using the target package.

This also updates the tcp subpackage to register a NewFunc.
2021-12-03 10:19:29 -05:00
Timothy Messier 1ae388438f feat(subtypes): Add function to provide all known prefixes 2021-12-03 10:19:29 -05:00
Timothy Messier 34d9842f85 fix(testing/docker): Correctly reset IFS (#1754) 2021-12-02 12:13:07 -05:00
Timothy Messier a404b5e365 Merge pull request #1753 from hashicorp/tmessi-sdk-api-test-ci
ci: Run sdk and api tests in ci
2021-12-02 07:52:37 -05:00
Timothy Messier 0a4df95fdd ci: Run sdk and api tests in ci
This adds new makefile targets and configuration to run the tests in the
api and sdk modules. These do not run by default since `go test ./...`
does not cross module boundaries.
2021-12-02 07:27:54 -05:00
Timothy Messier 0bc9e30aa6 chore(makefile): Mark all phony targets as PHONY
Some phony targets where not included in the single .PHONY line, this
switches to marking targets as PHONY just before the target is defined,
which makes it easier to ensure the targets are correctly marked as
phony.
2021-12-01 16:49:42 -05:00
Timothy Messier e6a8704a60 fix(docker): Add missing packages to dev docker image (#1713)
Trying to run the docker image built with `make docker-build-dev` would
result in an error at startup:

    standard_init_linux.go:228: exec user process caused: no such file or directory

This was due to the dev docker image lacking `dumb-init` which is used
by `docker-entrypoint.sh`.

This commit updates the dev dockerfile to add dumb-init. It also adds
additional packages so that the dev image aligns with the release image.
2021-11-17 07:28:58 -05:00
Timothy Messier 242e353f18 fix(schema): Prevent duplicate versions per edition (#1670)
This should help prevent issues like the one fixed in
f2ad4de554.

A version for a particular edition should only exist once, previously
which ever file was read last for a version would be included, which
would lead to some migrations not running.
2021-11-05 14:57:10 -04:00
Timothy Messier ee88e863a3 Merge branch 'tmessi-docker-test-config' (#1652) 2021-11-03 07:45:24 -04:00
Timothy Messier 1a24a0fc2f feat(sqltest): Make container name configurable 2021-11-03 07:44:51 -04:00
Timothy Messier 35a7c4f6e7 feat(dbtest): Make test container name configurable 2021-11-03 07:44:51 -04:00
Timothy Messier decc3ec2cf test(targets): Change test to not depend on response order (#1653)
This test started failing when the order of the list response changed.
Since the order does not matter, this test was updated to not depend on
the order.
2021-11-02 15:38:37 -04:00
Timothy Messier f53772519c Merge branch 'tmessi-target-egress-api-cli' (#1648) 2021-11-02 10:25:48 -04:00
Timothy Messier 7d7d8af694 feat(cli): Add support for egress credentials for targets command 2021-11-01 13:33:54 -04:00
Timothy Messier 1da403a2d2 feat(api): Add support for egress credentials for targets endpoint 2021-11-01 13:33:54 -04:00
Timothy Messier 36f1ae75f7 feat(sdk): Add support for egress credentials to target service 2021-11-01 13:33:54 -04:00
Timothy Messier 66a1b996d0 Merge branch 'tmessi-target-egress' (#1594) 2021-10-29 10:30:27 -04:00
Timothy Messier 1b7cfb1704 feat(target): Add support for credential library validation
Target subtypes must now implement another repository hook to validate
any CredentialLibraries that are being added/set. This allows for
subtypes to determine the valid set of CredentialLibraries.

For tcp.Targets only CredentialLibaries with
credential.ApplicationPurpose are allowed. If any other purpose is
provided an error is returned.
2021-10-29 10:01:52 -04:00
Timothy Messier 2cc58ff901 refact(target): Change repository to take CredentialLibraries
This change removes the hard-coded credential purpose for the Credential
Libraries. It also moves the logic of creating CredentialLibraries from
CredentialSources out of the repository and into the targets.Service.
This refactor will allow for additional credential purposes to be
supported in both the service and the repository.
2021-10-29 10:01:52 -04:00
Timothy Messier 4ccdfd7b7e Merge branch 'tmessi-target-remove-unused-code' (#1631) 2021-10-26 08:45:37 -04:00
Timothy Messier 24c6c329fe chore(target): Remove unused option support from repo Create
For the target Repository's Create method, the options of
WithHostSources and WithCredentialSources where never used by the
targets.Service. As such the repository does not need to support these
options.

See: 51812ff779
2021-10-26 08:20:15 -04:00
Timothy Messier b5fbf9608e refact(target): Remove old TargetType (#1618)
Now that subtypes are registered via sub-packages, this TargetType is
not needed and should not be used. This removes it and updates the
target.Repository and targets.Service to use the updated code.

This was missed in eac433f7ff.
2021-10-20 08:35:33 -04:00
Timothy Messier 55ba24499a Merge branch 'tmessi-target-refact' (#1573) 2021-10-19 14:11:38 -04:00
Timothy Messier 02b2291375 feat(subtypes): Make Registry thread-safe 2021-10-19 10:44:51 -04:00
Timothy Messier eac433f7ff refact(target): Move tcp into subpackage
This moves all of the tcp target functionality into a tcp package. It
also establishes a Register function in the target package to allow
specific target types to be registered at initilazation time. When
registering, a target type needs to provide its Subtype, as well as some
RepositoryHooks that are used by the target Repository.
2021-10-19 10:44:51 -04:00
Timothy Messier 51812ff779 docs(target): Mark additional fields as output only (#1609)
When creating or updating a target, the following fields should have
been marked as output only:

- host_set_ids
- host_source_ids
- application_credential_source_ids
- application_credential_library_ids

This updates the protobuf and generated files including the swagger file
used by the docs site to correctly mark these are output only.

Fixes #1588
2021-10-19 09:37:32 -04:00
Timothy Messier 65f72ce3d0 Merge branch 'tmessi-hooks' (#1593) 2021-10-15 14:24:20 -04:00
Timothy Messier 4b6a16034e chore: Add ci job to trigger update to enterprise 2021-10-15 14:03:26 -04:00
Timothy Messier b9a393d10b chore: Add pre-push hook 2021-10-15 14:03:26 -04:00
Timothy Messier b0b8375dc6 Merge branch 'tmessi-migration-editions' 2021-10-11 08:37:07 -04:00
Timothy Messier 06e6ab6c57 build: Fix build to support switch to embed for migrations
With the refactor to the schema package, and the switch to use embed,
the sql files need to be included in CI when compiling the boundary
binary.
2021-10-08 06:50:26 -04:00
Timothy Messier e3f7c263b0 refactor(sqltest): Update init script to support migration editions
This updates the docker image used for tests to support the new location
for sql migration files and the concept of editions. It continues to
process the old paths for now if the new directory does not exist, so
that the same image can be used during the transition.
2021-10-08 06:50:26 -04:00
Timothy Messier 2143940a4a refactor(dbtest): Support new paths for migration files
This updates the docker image used for tests to support the new location
for sql migration files and the concept of editions. It continues to
process the old paths for now if the new directory does not exist, so
that the same image can be used during the transition.
2021-10-08 06:50:26 -04:00
Timothy Messier 8caaf3e076 refactor(schema): Add support for migration editions
This refactors the schema package and subpackages to support editions.
An Edition is a collection of sql migrations. A given boundary binary
can have multiple migration editions. The `schema.Manager` is updated to
apply the necessary migrations in the correct order, leveraging an
Edition's priority to determine the order in which the separate Editions
are applied.

The sql migration files are now nested under a directory for the
edition.

This also switches from the generated code to using embed, which
eliminates the need for the `make migrations` target and the generated
code. As such this commit removes the target and generated code.

See:
    https://pkg.go.dev/embed
2021-10-08 06:50:26 -04:00
Timothy Messier 111f3906e8 ci: Consolidate some circle configuration with executors (#1578) 2021-10-05 15:15:08 -04:00
Timothy Messier 88b3c8358c feat(cmd): Include version metadata in output (#1560)
If the VersionMetadata is set, include it in the output of the `boundary
version` subcommand.
2021-09-23 12:22:20 -04:00
Timothy Messier 21e61d362e Merge branch 'tmessi-wh-credentials' 2021-09-16 10:09:57 -04:00
Timothy Messier 99d0d2f682 wh: Add wh_credential_dimension and bridge tables
This adds new dimension table to record credential information. Since a
session can have multiple credentials, the wh_session_accumulating_fact
is is linked to the credential_dimensions via bridge tables,
wh_credential_group and wh_credential_group_membership. When a session
is inserted, the credental group and credential dimensions will be
upserted. If the group changed in any way, a new group is inserted along
with all of the corresponding credentials.
2021-09-16 08:53:11 -04:00
Timothy Messier 30736b3bcd Merge branch 'tmessi/faster-testing' 2021-09-10 08:08:02 -04:00
Timothy Messier 2ee1d4e6e4 refactor: Make docker pacakge an internal package of cmd/base
The docker package and its StartDbInDocker function should only be used
by the `boundary dev` command now. So moving it into an internal package
of `base` will prevent it from being use for tests accidentally, while
still allowing it to be used for `boundary dev`.
2021-09-09 13:42:01 -04:00
Timothy Messier ecdcf72e0e ci: Update Makefile with new targets for testing
This updates the test-ci target to startup the test database container
first, wait for it to be ready, and then start running the tests.

It also creates some new targets for local devs. Prior to running any
tests either via `make test` or `go test`, the database should be
started with:

    make test-database-up

It can take a few seconds for the database to fully initialize, the
status can be checked with:

    docker logs -f boundary-sql-tests

This database can be stopped and destroyed with:

    make test-database-down

In general it should only need to be restarted when new migrations are
added. But it might also be necessary to restart if some tests fail in
an unexpected way and fail to do cleanup steps.
2021-09-09 13:42:01 -04:00
Timothy Messier 75388f727a test: Refactor to use dbtest package instead of docker
This swaps the test initialization to use the dbtest package so each
test will get a fresh database created from a template database, instead
of a completely new docker container.
2021-09-09 13:42:01 -04:00
Timothy Messier af5d1af568 test: Add dbtest package
This is modeled after the internal/docker package to make it easy to use as a
replacement. Instead of creating a new docker container for each test,
it will create a new database in an existing database container, using a
template database as a source. This assumes that the template database
exists and already has the schema migrations run against it.

The default template is `boundary_template` which should already have
all migrations applied. However, some tests require an empty database to
test the migration code. In these cases the `template1` template
database should be used, ie:

    dbtest.StartWithTemplate("postgres", dbtest.WithTemplate("template1"))
2021-09-09 13:42:00 -04:00
Timothy Messier c6cb7c8512 chore: Define custom docker image for tests
This images is built from the official postgres docker image, but with
updates to optimize the test execution:

- A config file for postgres to increase the performance of the
  test server.
- An initialization script to create a template database with all
  migrations run against it.

There are new make targets to build and publish this docker image.
The image can be pulled with:

    docker pull hashicorpboundary/postgres:13-alpine

To use this image for tests start the container:

    make -C internal/db/docker database-up
2021-09-09 13:42:00 -04:00
Timothy Messier 06ce257cb8 Merge branch 'tmessi/wh-refactors' 2021-08-30 15:45:09 -04:00
Timothy Messier 90e2c871f0 refactor(wh): Remove host prefix from wh_user_dimension org fields
These fields are being refactored so they conform with the new
wh_credential_dimension. This will inform Business Intelligence tools
that these attributes conform across dimensions.
2021-08-30 14:25:30 -04:00
Timothy Messier 026f09a9a8 refactor(wh): Rename primary and foreign key columns
The tables in the operational part of the Boundary database (meaning
non-warehouse tables) suffix primary key columns and foreign key columns
with `_id`. Many of these columns appear in the warehouse dimension and
fact tables as normal attributes, not primary keys or foreign keys. To
disambiguate ID columns from operational tables, the primary key column
for dimension tables will be renamed from `id` to `key` and the foreign
key columns in the fact tables will be renamed to change the suffix from
`_id` to `_key`.
2021-08-30 14:25:30 -04:00
Timothy Messier c8bf1917f5 db: Refactor test setup for pre-populated data
Now when initializing the test database for sql tests,
it will load the colors persona data into the database. This will
provide a data set that tests can use without needing to call
`wtt_load`.

The main motivation is to allow for a separation of setup and test
execution that requires crossing a transaction boundary. The pgTap tests
are required to exectue as a single transaction, so that the rollback
can reset the state, and each test can be isolated. However, can cause
issues with some test senarios, particuarly with the use of some times
releated functions like `current_timestamp` and `now` which return the
time that the current transaction started. This creates an issue if a
test relies on some setup that sets a time via `now`, then an update
that expects a new time via `now`.

See: https://www.postgresql.org/docs/13/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
2021-08-30 14:25:30 -04:00
Timothy Messier 0f19009cea feat(wh): Add oidc related columns to wh_user_dimension (#1455)
This adds new columns to the wh_user_dimension to provide additional
data from OIDC that does not apply to Password Auth.

Note: Given the specifics of the data, it is possible these columns may
be used by other auth methods in the future, hence the lack of `oidc` in
the column names.

The specific columns are:

- auth_method_external_id
    For OIDC this is the Issuer
- auth_account_external_id
    For OIDC this is the Subject
- auth_account_full_name
    For OIDC this is the account's Full Name, and can be `None`.
- auth_account_email
    For OIDC this is the account's Email, and can be `None`.

For all of these new columns, they will be `Not Applicable` if the auth
method is Password.
2021-08-11 18:45:14 -04:00
Timothy Messier 624bdbf0c2 test(db): Add baseline tests for wh_user_dimension (#1454)
This sets up the configuration for running a new suite of tests that are
written in sql, to test the sql logic implemented in plpgsql functions
and triggers. It is primarily designed to provides tests for the data
warehouse functionality that is implemented purely in sql.

The infrastructure to run these tests leverages docker. It creates one
docker container using the `library/postgres` image and provisions the
database with the boundary sql migrations and test helper functions.  A
separate docker container is run that has the pgtap extension and
pg_prove cli to execute the tests.

As noted, pgtap is used for the tests. This postgresql extension
provides a number of helpful assertion functions to make writing sql
tests easier. It also, along with the pg_prove cli, provides readable
test output.

Along with the new testing infrastructure this commit establishes a
baseline of tests for the wh_user_dimension:

- Unit tests for individual views and functions:
    - whx_user_dimension_source
    - whx_user_dimension_target
    - wh_upsert_user
- Integration tests for that verify that the wh_user_dimension gets
  populated correctly when sessions are inserted or updated. This
  ensures that:
    - the trigger runs on session insert
    - the trigger results in the correct changes to the
      wh_user_dimension.

This commit provides a `Makefile` to run the tests locally that provides
support for:

- Setting the postgres docker image to easily test multiple versions.
- Passing through options to pg_prove
- Passing the test list to run individual tests
- Additional targets to separately startup the database image to quickly
  re-run tests while developing new tests.

Lastly configures circleci to run this test suite as a matrix build
in parallel with the other tests. The matrix build tests multiple
versions of postgres:

- latest
- 13-alpine
- 12-alpine
- 11-alpine

See:
    https://pgtap.org/
2021-08-11 13:25:32 -04:00