Commit Graph
47 Commits
Author SHA1 Message Date
Hugo Vieira 8ab9ffbcac refact(cmd): Encapsulate some functionality on Command and Server
This commit extracts 3 separate pieces of functionality into their own
function/method:

- Extracts the database opening with the intention to have a function
  that performs all that functionality but returns the created database
  object rather than setting it to the Server structure.
- Extracts database validation logic, to provide a common code path for
  upcoming functionality.
- Expose schema manager on the Command struct as well as providing
  common functions to acquire shared lock/close.
2022-09-12 17:55:32 +01:00
Timothy Messier 79866a287f feat(schema): Add support for migration hooks
This adds the ability to define hooks that will run prior to a schema
migration. The hooks should only be used when a migration would fail due
to data being in an invalid state, likely due to a bug in the previous
schema definition. For example if a column was missing a constraint, and
a new migration is attempting to add the constraint, there might already
be values that violate the new constraint. In such cases, we would want
the user to make a decision to address the data, and need to provide
them with details about what data is problematic in case they want to
manually address the problem. To help the user, if there is a sane way
to address the data, we should provide an option to automatically
"repair" the data, allowing the migration to continue. However, this
still should be an explicit opt-in from the user, and we need to clearly
describe what the repair option would do to the user so they understand
the consequences of opting in.

To accomplish this each migration can be provided a hook that contains a
CheckFunc, RepairFunc, and RepairDescription. These functions must
operate at the point-in-time of the migration immediately preceding the
current migration, as as such they should not use and domain packages or
repositories, instead they should use direct sql with the sql library.
The description is used to explain what the RepairFunc will do.

Hooks should be defined in `internal/db/schema/migrations/oss/oss.go`
and registered with the schema edition.

See the example in `internal/db/schema/manager_example_test.go` for more
details.
2022-08-22 12:15:20 -07:00
Louis Ruch dcccaf1bcf bug(cmd): Ensure RunShutdownFuncs is called when an early error occurs (#2333)
* bug(cmd): Ensure RunShutdownFuncs is called when an early error occurs
2022-08-08 09:13:47 -07:00
Jeff Mitchell 9a4545e59e Fix eventing and worker name setup (#2204)
* Don't automatically create worker names, as this is now invalid for
  PKI workers
* Fix a check in dev that clears out name/description in exactly the
  wrong cases
* Change eventing setup to use a hostname-based ID instead of the name
  (which could change on every start anyways)
2022-06-15 20:01:03 -04:00
Johan Brandhorst-Satzkorn b20939ecb4 fix(cmd): Fix build error (#2107)
This seems to have been missed when #2094 was
reviewed and merged.

Blame: ec608b79da
2022-05-25 15:40:36 -04:00
Johan Brandhorst-Satzkorn ec608b79da fix(cmd): Respect DB max open connections (#2094)
Both the init and migrate commands were ignoring
the configured max_open_connections database
setting. This fix ensures that both commands
respect the limits.
2022-05-23 08:21:15 -04:00
Jeff Mitchell 1be55b50c7 Pull up Server to top level of Init command (#1959)
* Pull up Server to top level of Init command

Init was using a local server variable but not passing in the existing
command, resulting in the context being lost. This caused the command to
fail to run since the changes to add logging to KMS plugins were
introduced.

This also fixes a couple of places that were not using the global const
value for config KMS.

* Fix test compilation
2022-04-06 16:40:47 -04:00
Jeff Mitchell e596daf34d Add hclog adapter and gating to eventer (#1915)
This contains to related things:

1. An adapter allowing an hclog interface to take in information and send them to the eventer
2. A gate on the eventer, which is the analogue to the behavior prior to eventing where we'd ensure logs were not printed prior to the startup information. Without this, plugin logs using the hclog adapter will start showing up too early.
2022-03-16 17:25:34 -04:00
Jeff Mitchell 7eb29261b2 Update to go-kms-wrapping version 2, and plugin-based KMS (#1901) 2022-03-16 17:04:07 -04:00
Jeff Mitchell 1c8e0ed1e1 Add scaffolding for external host plugins and convert aws/azure over (#1581) 2021-10-14 11:56:08 -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
Jim 8d6dee09a9 refact: Add db.DB wrapper and refact all test fixtures to use it. (#1535)
* refact: Changes required for gorm v2

* refact: Add db.DB wrapper and refact all test fixtures to use it

Stop leaking the gorm abstraction within our unit tests.

* refact: Migrate direct calls to pq to pgx driver

The refactor will remove the remaining direct dependencies on
the pq driver which has been deprecated in favor of the pgx
driver.

It includes the addition of common.SqlOpen which is a wrapper around
sql.Open, which is needed to deal with the driver name changing from
"postgres" to "pgx" but in our code base the dialect and driver are
synonyms.
2021-09-30 09:17:27 -04:00
Jim 136ac00b49 refact: Changes required for gorm v2 (#1528) 2021-09-30 08:47:34 -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
Jeff Mitchell e9a8ede0d6 Move wrapper package back to SDK (#1511)
TF uses this, so SDK is a decent place for it. It doesn't create
dependencies between it and API.
2021-09-08 12:15:42 -04:00
Jeff Mitchell 081de3cf79 Migrate sdk/recovery to api/ and sdk/wrapper to internal (#1507)
* `recovery` is only used by the API (and the main module, for decryption)
* `wrapper` is only used by the CLI right now

Moving these brings them closer to the code that uses them, and makes
the SDK package a bit more clear in terms of functionality.
2021-09-07 22:13:19 -04:00
s-christoffandJim 6b78108ecf Update primary error functions to take a context, deprecate old functions (#1358)
* add new error funcs which take a ctx and deprecate existing funcs

* use context where available when writing error events

* remove circular internal/errors pkg dep

* suppress some chatty errors using errors.WithoutEvent()

* convert auth oidc funcs to take context where needed to write events

Co-authored-by: Jim <jlambert@hashicorp.com>
2021-07-29 20:52:56 -04:00
Jim 11124794bf Events: add node for formatting/filtering cloudevents (#1390) 2021-07-25 17:40:54 -04:00
Jeff Mitchell ed6c59a053 Update the rest of the shared libs locations 2021-07-14 17:50:15 -07:00
Jeff Mitchell 44329d4ff9 Repoint mlock import 2021-07-14 17:33:23 -07:00
Jeff Mitchell 2cbcf9a563 Update usage of shared-secure-libs (#1393) 2021-07-12 21:06:22 -04:00
Jim 1daa3ebefe integrate events into the servers (#1355) 2021-07-08 15:50:25 -04:00
Jeff Mitchell 9c945b7021 Migrate ParseAddress to shared-secure-libs (#1313) 2021-06-15 13:35:29 -04:00
Jeff Mitchell c22631fbca Fix boundary database init respecting format flag (#1204)
The output was ready for json format but the flag wasn't included.
2021-05-05 11:49:06 -04:00
Michael Gaffney ecc9d6d649 Run make fmt 2021-05-03 13:38:29 -04:00
Todd Knight 5d17bd9eec Error on boundary database migrate if the db hasn't been initialized (#1184) 2021-05-03 08:55:37 -07:00
dd0f34bc35 Add new OIDC auth method. (#1090)
Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com>
Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
2021-04-08 20:54:32 -04:00
Jeff Mitchell b05ed0bf65 If the database is already initialized, use 0 as the return value (#1033)
This matches the migrations code, which treats the operation as
idempotent.
2021-03-25 17:53:11 -04:00
Jeff Mitchell 3b452cb503 Fix initial user ID not being shown in some cases during init 2021-03-04 21:08:22 -05:00
Jeff Mitchell 9649a19d23 Update CLI error codes to be consistent with connect (#976) 2021-03-04 20:05:17 -05:00
Todd Knight 57d4bf2bfd Removing dev migration feature and checks (#892) 2021-01-28 19:28:31 -07:00
Todd Knight 955ae41215 Support upgrading from old migration table name (#889) 2021-01-28 14:30:08 -07:00
Todd Knight 1f9fcad1cd Adding Migrate Command (#872) 2021-01-25 14:43:50 -07:00
Todd Knight 595a86508e Fix lockup when initalizing database. (#875) 2021-01-20 18:10:45 -07:00
Todd Knight ec6151d174 Organize DB Schema Migration Code and DB Init Checks (#842)
Create Schema Manager and propagate contexts into the DB calls downstream.
Add checks at controller startup and database init for correct schema version and schema migration dirty bit being set.
2021-01-19 10:40:41 -07:00
Michael GaffneyandJeff Mitchell 94cb79bbdd See how Boundary would look with gofumpt applied (#853)
* See how Boundary would look with https://github.com/mvdan/gofumpt applied

Results of running `gofumpt -w -s .`

* Update tools file and Makefile for gofumpt

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
2021-01-07 10:02:32 -05:00
Louis Ruch dbc796759b ICU-934/Verify controller config block (#851)
* Verify controller config block

* update changelog
2021-01-06 10:41:38 -08:00
Jeff Mitchell 833f29e352 Switch connection limit for default target to -1 (#814)
This makes the initial testing workflow less confusing for users
2020-12-09 16:05:48 -05:00
Todd Knight f6e50006fc Generate postgres.gen.go using schema version directory structure (#808)
* Reorganize the db migration .sql scripts into individual schema version directories and generate the sql httpfs fakeFile accordingly.

* Created a /dev schema version directory to hold db schema updates that have not been finalized.

* Add an 'allow-development-migrations' flag to allow `boundary database init` to be executed even when there are schema updates in /dev.
2020-12-04 21:32:27 -07:00
Jim af6ef1b687 Refactor existing sentinel errors (#774) 2020-11-05 16:54:03 -05:00
Jim 547ae7c802 Fix database init when locale isn't english (#736)
* use IsMissingTableError(error)

* update changelog
2020-10-20 21:13:01 -04:00
Jeff Mitchell fa700dc002 Add account ID templating (#518)
* Remove default role and create via the same mechanism as other initial resources
2020-10-01 10:51:54 -04:00
Jeff Mitchell 41a3c66ea1 Add names to init output (#428) 2020-09-24 12:54:40 -04:00
Jeff Mitchell 7fcbffbe88 Remove not-set value. (#427)
I don't think the conditions exist here that necessitated it being
introduced into Vault, but I do sometimes see a baffling condition where
the address coming from the flag is empty. I don't think we need this so
take it out.
2020-09-24 12:19:00 -04:00
Jeff Mitchell 31fe9292b3 Instantiate default resources (#425) 2020-09-24 03:31:26 -04:00
Jeff Mitchell 38ce9d9eac Combine controller and worker commands (#415) 2020-09-23 01:23:10 -04:00
Jeff Mitchell dd06615c2e Add database initialization command (#400) 2020-09-21 20:25:16 -04:00