Commit Graph
91 Commits
Author SHA1 Message Date
Michael Gaffney 194b3af678 chore: exclude storage protobuf files from API linting (#2254) 2022-07-11 17:23:09 -04:00
Michael Gaffney 2fabfd99e5 docs: add database indexes under performance in contributing guide (#1881) 2022-03-02 08:00:37 -05:00
Michael Gaffney 67bad4cd6e Update Go version to 1.17.5 (#1789) 2021-12-14 11:58:34 -05:00
Michael Gaffney 72d4d6d205 fix(sql): Remove warning from create_time trigger (#1751)
Raising a warning in the default trigger used for setting the value in
create_time columns creates unnecessary noise in the PostgreSQL log
files.

Closes #1744
2021-12-01 11:05:19 -05:00
Michael Gaffney c361e6ec22 fix(warehouse): Add primary key to credential group membership table (#1636) 2021-10-26 05:20:34 -04:00
Michael Gaffney e9d3cebd45 feat(credential): Add specific credential types (#1525)
This adds interfaces for the following credential types:
- Username and password
- Username and private key
- Certificate and private key

It also adds the following types for redacting secret data:
- Password
- PrivateKey
2021-09-14 14:11:42 -04:00
Michael Gaffney 5f88243ddc Fix db migration that adds support for OIDC in the data warehouse (#1471)
Four new columns were added to the `wh_user_dimension` table to support
OIDC. The data type for the columns was originally `wh_dim_text` which
is a domain type with a `not null` restriction. Adding the new columns
caused the migration to fail if the `wh_user_dimension` table had any
rows in it because the existing rows would violate the `not null`
restriction.

Closes #1469
2021-08-18 22:18:51 -04:00
Michael Gaffney ef051135b2 Add data warehouse changes for OIDC to the Changelog (#1465) 2021-08-16 13:21:40 -04:00
Michael Gaffney d4fc2efa53 Move base interfaces of the domain into a boundary package (#1415) 2021-07-26 14:03:15 -04:00
Michael Gaffney 8890b97b6f Update docs for minimum value of max_open_connections (#1387)
Closes #1374
2021-07-08 15:41:01 -07:00
Michael Gaffney a9c2674395 Document dependency on pgcrypto (#1385)
Closes #823
2021-07-08 16:57:05 -04:00
Michael Gaffney 28f48df026 Add documentation for credentials to website (#1356) 2021-06-25 15:31:10 -04:00
df35699c4e Integrate with Vault to retrieve and manage per session credentials (#1308)
* Fix down migrations

* Udpates due to merge

* Sentinel values only have to be greater than 0

* Create credential related sdk structs and methods.

* Post merge interface updating.

* Removing scratch code that was not cleaned up.

* updates

* Convert client certificate and client certificate keys into pem blocks and validate.

* Add newline at end of file.

* Faster check for "s" at the end of a resource name when generating from templates.

* make fmt

* updates

* Add dynamic credentials to a session

* Refactor: move contents of file

* updates

* Updates

* Add InvalidDynamicCredential error

* Assign credentials

* Allow updating client certificates seperate from the client certificate key.

* Replace application purpose string with enum value

* PR feedback / fix go test .

* Delete dead code

* Use common view

* Refactor: extract interface and rename method

* Refactor: move code to eliminate privPurpLibrary

* Add comment to requestMap

* Refactor: do not export methods on an unexported struct

* Update internal/db/schema/migrations/postgres/10/03_vault_credential.up.sql

Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>

* Add comments to credential Purpose constants

* Reorder switch statements to handle errors first

* PR feedback

* update

* fix merge

* Organizing the scheduler code and extract the individual store creation test helper function.

* Run 'make fmt'

* Create certificate when creating store.  Allow vault address to be passed in as option

* Refactor: rename database views and associated structs

This change renames two database views and associated go structs to use
a consistent naming pattern. Views ending in 'private' contain encrypted
credentials needed for connecting to Vault. Views ending in 'public'
mirror the 'private' views but do not include any encrypted values.

This change does not include any changes to functionality or behavior.

* Adding SAD target operations for credential libraries to the SDK.

* Add status field and enumeration table for credential status

* Refactor: rename Status to TokenStatus

* Add status to vault credentials

* Creating the template for the CLI and helper functions.

* Add private database view for vault credentials

* Add scope_id to view and cleanup TODO comment

* Reformat embedded sql queries

* Add vault client helpers

* updates

* white space

* Add LookupLease test

* CLI commands for Store work.  Renamed fields in proto w/ vault prefix.

* Test issue credentials with client TLS

* Add additional checks to vault ping

* Add an error for vault token capabilities and create a VaultToken error kind

* Add support for working with Vault policies

* Use Vault 1.7.2 for testing

* Add testing helper for creating a vault client with a non-root token

* Fix Vault renew lease test

The Vault renew lease endpoint accepts an optional duration parameter
for requesting the number of seconds to extend the lease by. However,
Vault is not required to honor this request.

* Add a var for the required capabilities of a boundary Vault token

* Enhance the test helper for adding a policy to Vault

* Allow the test role in postgresql to revoke credentials

* Remove out of date comments

* Enhance Vault test helpers for the database secrets engine

* Reformat comments

* Add a method for getting the capabilities of the current Vault token

* Add revoke lease to internal Vault client

* Reformat: combine err return line with check for nil line

* Remove redundant checks in test code

Remove checks in test code that are redundant with checks in the test
harness.

* Refactor CreateToken test helper to return the secret and the token

* Fix build failures caused by signature change in vault.CreateToken

* Fix Vault version and Vault API link in comments

* ran `make gen` after merging from mgaffney-vault.

* Remove Vault prefix from attribute fields in API, create a base CLI option for adding field prefixes. format now uses that prefix for error reporting.

* Template now allows attaching attribute field prefixes.

* Credential store uses PrefixAttributeFieldErrorsWithSubactionPrefix.

* Fixing naming of vault flags and helper flags.

* Updating more references to generated api methods.

* Make the capabilities String method more readable

* Add comment outlining PrintApiError usage of Options.

* Refactor test to move declarations closer to first use

* Fix comment

* Implement revoke method on vault repository

* Tests now verify certs, CA, and tokens, addresses can be updated in a store.

* Added test for creating store with pk/cert in same field.

* Allo updating certificates seperate from private key.  Only contact backing vault service when updating token.

* Fixing bad tests and removing unused code.

* Adding tests for various ways of updating tokens.

* Add private credential

* Add token revocation job and cred renewal/revocation job

* Regen after merge.

* Fixing field mask related merge error.

* Create Library CLI. Removes vault prefix from path. Adds a WithoutCleanup testOption for vault.

* Set all credentials to revoked when a token is revoked

* Fixing missed renaming update.

* fix copy/paste error.

* Fixing code generation errors after merge.

* make gen after merge.

* Update internal/cmd/commands/credentialstorescmd/vault_funcs.go

Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>

* Update internal/cmd/commands/credentialstorescmd/vault_funcs.go

Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>

* Update internal/cmd/commands/credentialstorescmd/vault_funcs.go

Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>

* Refactor: move migrations from 10 to 12

* Removing logic from transaction.

* wrapping client errors in the calling op for CredentialStore's client() method.

* Redact token

* redact client key

* updates

* Add trigger to revoke credentials when session is canceled or terminated

* Fixing some help text for some flags.

* Add ability to load values from files (file://) or environment variables (env://).

* Updating comments

* fix bad merge

* feedback

* Adding issued credentials to sessions.

* Error on capabilities

* updates

* Expose NewVaulTestServer

* Add godoc

* Adding generated SessionCredential struct for API.

* Progress on building handler test for Authorize Session.

* feedback

* Update policies

* Add 'revoke' as a status for Vault Tokens

* Add delete_time to vault credential store

* Create dynamic credentials at session creation time.

* Tests pass with credentials attached to AuthorizedSession result.

* Only call issue if there are credentials to issue.

* Fixing output only issues. Adding type to credential library.

* Fix test to clear un/pw generated.  confirm generated un/pw changes from 1 authorize session call to another.

* Update lookupTokenError

* Add delete_time to private credential store

* Refactor: move private store to separate file

* Fixing tests for AuthorizeSession and verifying error cases.

* Only create the credential repo if there are credentials to issue.

* Rename Library field to CredentialLibrary.

* Fixing missing change of Library to CredentialLibrary.

* Removing Default SDK functions for fields which are required and update CLI to match.

* Replace resource specific id variables with "id" and the input parmater for paths to be just a single string and the resource name as it should show up in the path.

* Soft delete vault credential stores

* Prevent new SQL functions from silently overwriting existing functions

* Rename "Hmac" to "HMAC" in the human readable cli response table.

* Fix tests

* Add vault database cleanup jobs

* Add ability to set the token period in the vault test harness

* updates

* Add not_null_columns func test

* remove unused struct

* Up no output timeout

* Validate current vault token on addr update

* Fix client cert change test

* add cert test

* Update revocation job where

* Fix comment

* Use Vault's default port in CLI help strings

* Remove down migrations

* Increase migration file numbers by 1

* Run make migrations

* Move migrations from 12 to 10

* Increase Circle CI timeout for acceptance tests

* Fix spelling mistake in error messages

* ASD cmds for Target and returning credentials to AuthSession request (#1338)

* Add Add/Set/Remove commands for libraries on Targets.  Return credentials on AuthorizeSession request.

Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>

Co-authored-by: Louis Ruch <louisruch@gmail.com>
Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com>
Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
2021-06-22 22:26:26 -04:00
Michael Gaffney 094bdcdd2b protobuf: remove unused imports (#1267)
This removes unused imports in the protobuf files which are reported as
warnings by the protoc compiler.
2021-06-02 14:59:36 -04:00
Michael Gaffney 21033a6174 Refactor: multiple rename to fix the spelling of subtype (#1227)
The definition of 'subtype' is 'a secondary or subordinate type'. The
'T' should not be capitalized (unless it is referring to a type of
submarine, which its not).
2021-05-17 15:36:45 -04:00
Michael Gaffney 48340da733 workflow: add automatic label for SQL files (#1187) 2021-05-03 10:59:19 -04:00
Michael Gaffney ea0e2e5df4 Add tests for common.BuildUpdatePaths (#1143) 2021-04-18 11:00:38 -04:00
Michael Gaffney 5855930921 Renumber migrations in the '2/' directory to start at 01 (#1114) 2021-04-14 11:47:21 -04:00
Michael Gaffney d3146992f1 Errors: add Code and Kind for external system errors (#1080) 2021-04-07 14:50:00 -04:00
Michael Gaffney aafbada3ae Remove calls to t.Helper() from test methods (not helpers) (#1063) 2021-04-02 19:40:51 -04:00
Michael Gaffney c141a050e5 Document Postgres permission requirements (#871)
* Add semantic line feeds

* Document Postgres permission requirements

Closes #823
2021-01-15 17:32:28 -05: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
Michael Gaffney b7139920a1 Docs: small fixes to the Accounts and Groups pages (#641) 2020-10-12 18:18:17 -04:00
Michael Gaffney 73884aa6d3 Docs: add content to Domain Model - Overview page (#640) 2020-10-12 18:15:36 -04:00
Michael Gaffney 64915e6034 Docs: add content to Domain Model - Sessions page (#631) 2020-10-12 16:44:08 -04:00
Michael Gaffney d509baa153 Docs: add content to Domain Model - Targets page (#625) 2020-10-11 20:46:25 -04:00
Michael Gaffney be81616cb8 Docs: add content to Domain Model - Host Sets page (#624) 2020-10-11 20:02:50 -04:00
Michael Gaffney 363810aaf8 Docs: add content to Domain Model - Hosts page (#623) 2020-10-11 19:01:35 -04:00
Michael Gaffney e87edd9ae3 Docs: add content to Domain Model - Host Catalogs page (#622) 2020-10-11 17:21:27 -04:00
Michael Gaffney caf7a47ff7 Docs: add content to Domain Model - Scopes page (#621) 2020-10-11 16:45:15 -04:00
Michael Gaffney e232ea24f2 Docs: add content to Domain Model - Roles page (#620) 2020-10-11 16:15:26 -04:00
Michael Gaffney 7e9d2ed896 Docs: add content to Domain Model - Users page (#619) 2020-10-11 15:34:39 -04:00
Michael Gaffney 6724c527a6 Docs: add content to Domain Model - Groups page (#618) 2020-10-11 15:05:15 -04:00
Michael Gaffney c20aa2ebf6 Docs: fix links in Accounts page (#617) 2020-10-11 14:21:04 -04:00
Michael Gaffney 0bf8f81189 Docs: add content to Domain Model - Authentication Methods page (#616)
* Docs: add content to Domain Model - Authentication Methods page

* Docs: order references alphabetically
2020-10-11 14:19:01 -04:00
Michael Gaffney e25c58ce8e Docs: add content to Domain Model - Accounts page (#615) 2020-10-11 12:47:45 -04:00
Michael Gaffney b340a0f9ee Docs: remove pages from domain model section (#612) 2020-10-10 17:00:45 -04:00
Michael Gaffney 1ac3660dca Docs: add domain model diagram and update meta data in domain model pages (#611)
* Docs: add domain model diagram

* Docs: fix meta data in domain model pages

* Docs: add Sessions to domain model
2020-10-10 16:40:06 -04:00
Michael Gaffney 0a957e080d Docs: add semantic line breaks to domain model docs (#592)
* Docs: add semantic line breaks to domain model docs

No content has been changed.

* Fix semantic line break
2020-10-09 13:22:26 -07:00
Michael Gaffney a9e806b673 Data warehouse (#475)
* Define initial warehouse schema

* Add session id as the primary key to the session accumulating fact table

* Insert a row to use instead of nulls in the time and date dimensions

* Add missing attributes and a partial index

* Rename files

* Refactor: move fact table to a separate migration

* Add domain types for the warehouse

* Add session connection transaction fact table

* Change columns to match ingress data types

* Add views for host dimension ingress

* Create source and target views for the host and user dimensions

* Generate random ID for dimension table primary key

* Formatting changes

* Add current dimension id to target views

* Implement upsert function for host dimension

* Use domain types for upsert function parameters

* Fix indentation

* Add wh_public_id domain type

* Fix value of type columns when the other columns are null

* Implement upsert function for user dimension

* Add warehouse domain types for timestamps and text fields

* Move fact table migrations to a higher number

* Add functions for getting the current date and current time IDs

* Rename backend to endpoint in column names

* Rename fact tables

The fact tables are actually accumulating fact tables not transactional
fact tables.

* Add default value to connection_authorized_time column

* Update session fact table

* Add session_max_seconds, session_connection_limit, and default_port to wh_host_dimension

* Move session table above connection table

* Add after insert trigger to session table for warehouse ingress

* Add fk from connection warehouse table to session warehouse table

* Implement insert trigger for session connections

* Update warehouse for a user having multiple auth accounts

* Rename warehouse columns to be consistent with operational tables

* Add connection specific columns to the connection fact table

* Update session calculations in warehouse

* Rename functions and formatting changes

* Rename session columns to match names of session states

* Implement warehouse triggers for session and connection state changes

* Run 'make migrations'

* Use a static start and end date for the warehouse date dimension

* Document warehouse functions

* Remove outdated TODO comments

* Add TODO comments for additional dimensions and fact table columns
2020-09-30 14:09:40 -04:00
Michael Gaffney 36d465476c Name all the check constraints in the database (#410)
* Name all of the check constraints

* Run 'make migrations'
2020-09-22 14:44:21 -04:00
Michael Gaffney f0c84de49c Disambiguate auth_account scope_id by adding iam_user_scope_id column (#407) 2020-09-22 13:30:11 -04:00
Michael Gaffney d52fb81e68 Change the default max session for a target to 8 hours (#392)
* Change the default max session for a target to 8 hours

* Run 'make migrations'
2020-09-21 12:12:18 -04:00
Michael Gaffney 4ae3a52056 Define session database schema (#322)
* Define session database schema

* Update comments

* Add insert trigger for session state

* Add canceling state and update foreign keys to 'set null' on delete
2020-09-03 10:49:27 -04:00
Michael Gaffney 58dec98ea2 Rename table from servers to server (#307) 2020-08-26 13:15:12 -04:00
Michael Gaffney 9ca8a4ec20 Host set members (#301)
* Update host set member test

* Add ListSetMembers method signature and doc

* Move repository methods for host set members to new file

* Add TestSetMembers

* Implement ListSetMembers

* Return hosts from ListSetMembers

* Implement AddSetMembers

* Implement DeleteSetMembers

* Use sql.QueryContext not sql.Query

* Implement SetSetMembers

* Refactor: extract getHosts method

* Refactor: extract createMembers method

* Refactor: extract common functions

* Return correct count of changed

In SetSetMembers, retrieving the current list of hosts in the set
happens after the transaction to modify the set has completed. This
retrieval can result in an error but the number of modified rows is not
effected.

* Make list set members an unexported method

* Get hosts within the same transaction as mutations of the set

* Return hosts of set from LookupSet method

* Return hosts of set from UpdateSet method

* Remove listSetMembers

* Fix merge conflict

* Add NOTE and TODOs about using new pattern in "SetMembers" methods
2020-08-26 12:31:18 -04:00
Michael Gaffney de162c5533 Replace and remove ErrNilParameter with ErrInvalidParameter (#295) 2020-08-25 12:18:14 -04:00
Michael Gaffney 14dd7b49b2 Add method signatures for host set operations (#291)
* Add method signatures for host set operations

* Rename ReplaceSetMembers to SetSetMembers
2020-08-20 17:53:58 -04:00
Michael Gaffney b24fc185a7 Export TestSets helper function (#292) 2020-08-20 15:13:12 -04:00
Michael Gaffney 3a3cdd7219 Static host set repository methods (#289)
* Implement CreateSet

* Implement UpdateSet

* Implement LookupSet

* Implement ListSets

* Implement DeleteSet

* Remove unused parameter from test helper function

* Update to use new kms structure

* Remove unused parameter for test helper function

* Fix resource-type string for host set
2020-08-20 13:56:52 -04:00
Michael Gaffney a413ad7b84 Static Host: Lookup, List and Delete (#283)
* Implement LookupHost

* Implement ListHosts

* Implement DeleteHost
2020-08-19 14:14:14 -04:00
Michael Gaffney 041e1f9fd3 Update host (#278)
* Add IsNotNullError function to db package

* Let the database handle default values not gorm

* Implement UpdateHost

* Remove unnecessary clone
2020-08-18 16:50:26 -04:00
Michael Gaffney e18cdc52b3 Create host (#276)
* Change testHostCatalog methods to be like other resource test methods

* Implement CreateHost

* Make allocHost return a pointer to a Host
2020-08-17 17:06:31 -04:00
Michael Gaffney 7d133878be Add base types for host catalog, host set, and host (#272)
* Move static host migrations to higher number

* Add wt_host_address domain type

* Add base tables for host catalog, host set, and host

* Reformat create trigger statements

* Add subtype triggers for host catalog, host set, and host

* Remove wt_host_address domain type

* Rename columns in host_set_member

* Add delete trigger functions for base types

* Add delete after triggers to static host subtypes

* Add protobufs for host base types
2020-08-17 11:00:41 -04:00
Michael Gaffney 7ac4be51c0 Refactor static host package (#263)
* Refactor: inline tablename constants

* Refactor: move functionality to new files
2020-08-13 14:00:15 -04:00
Michael Gaffney 6f886976e4 Add not null constraint to wt_version domain (#254) 2020-08-11 14:15:19 -04:00
Michael GaffneyandJeff Mitchell a7c467bd68 Password - UpdateAccount and SetPassword (#248)
* Implement UpdateAccount

* Implement SetPassword

* Add tests for duplicate user names

* Fix imports broken after product rename

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
2020-08-11 10:12:36 -04:00
Michael Gaffney bdb31cf8b5 Bump deps (#245) 2020-08-08 10:49:43 -04:00
Michael Gaffney 7fefd5e2fe Change password (#237)
* Implement ChangePassword

* Refactor: extract authenticate method

* Update tests to verify oplog entries

* More refactoring

* Remove extraneous clones

* More refactoring
2020-08-06 13:03:42 -04:00
Michael Gaffney 5ceb335466 Rehash credential during authentication if config has change (#234) 2020-07-31 14:42:22 -04:00
Michael GaffneyandTodd Knight 6c679a9939 Add password authentication using Argon2 (#227)
* Add argon2 credentials

* Verify oplog in tests

* Refactor: rename field

* Update internal/auth/password/repository_account.go

Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com>

* Add inline comments to SQL query to doc mapping to structure

* Refactor: move authentication query to query.go file

* Replace immutable_create_time_func with immutable_columns

Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com>
2020-07-31 11:18:41 -04:00
Michael Gaffney 87492816cb Replace immutable_create_time_func with immutable_columns (#231) 2020-07-30 16:43:11 -04:00
Michael Gaffney 5e8179c6fb Allow lookupAfterWrite for resources with Private Ids (#229) 2020-07-30 13:44:14 -04:00
Michael Gaffney c163d790a4 Add configuration settings for Argon2 password KDF (#217)
* Bump generated proto code

* Add argon2 conf sql and proto files

* Add generated code for argon2 conf

* Add Resources for Argon2 configuration

* Add get and set Configuration to repository

* Add current config reference to AuthMethod

* Fix authmethod_test

* Fix TestAccount_New

* Add WithConfiguration to options

* Add sql views for current configuration

* Fix SetTableName

* Remove duplicate testAccounts function

* Make tests clearer

* Fix comment

* Rename test variable

* Use NewPrivateId function for private Ids

* Refactor: rename public_id to private_id for password_conf and password_credential

* Remove bad comment

* Check if embedded argon2 configuration is nil

* Add checks around the WithConfiguration option

* Use spaces not tabs in proto file

* Add doc to explain choice of oplog ticket

* Verify oplog in test
2020-07-29 07:58:19 -04:00
Michael Gaffney 76abd4f3b4 Update comments to use "base type" instead of "abstract" (#222) 2020-07-28 09:17:23 -04:00
Michael Gaffney 7897c1cf52 Add base resources for password authentication (#213)
* Add base SQL and protobuf files

* Add options and public Ids

* Add AuthMethod and Account resources

* Add repository

* Add CreateAuthMethod to repository

* Add CreateAccount method to repository

* Remove redundant foreign keys

* Document relationships between iam and auth tables

* Document relationships between auth and auth_password tables

* Add documentation for subtype triggers

* Use wt_scope_id domain type for scope_id

* Refactor: move test helper function

* Remove check from SetTableName

* Remove check from another SetTableName

* Use org scope in tests

* Remove handling of CreateTime and UpdateTime from docs
2020-07-24 10:23:35 -04:00
Michael Gaffney e03a0ff9d7 Simplify SetTableName pattern (#214) 2020-07-23 17:58:41 -04:00
Michael Gaffney 799242fce4 Bump deps and run 'make gen' (#212) 2020-07-22 17:00:22 -04:00
Michael Gaffney ebf69bbd27 Fix error string for lookupAfterWrite (#208)
The following error string was the end result of an error in lookupAfterWrite:
  `set password configuration: update: lookup error lookup after write: failed record not found`

The error string with this change applied would be:
  `set password configuration: update: lookup after write: record not found`
2020-07-20 17:20:22 -04:00
Michael Gaffney d69588131c Fix for panic in db.setFieldsToNil (#155) 2020-06-28 16:55:57 -04:00
Michael Gaffney c110c86ee5 Add function to check if db error is a check constraint violation (#142) 2020-06-23 18:00:50 -04:00
Michael Gaffney 6908f7a7a2 Use standard column names (#138) 2020-06-22 13:54:55 -04:00
Michael Gaffney 1023c90729 Enforce auth_account to iam_user plus iam_scope constraints (#137) 2020-06-21 13:16:03 -04:00
Michael Gaffney 0ebb38bbe5 auth method schema (#131)
* Rename iam migrations to 06

* Add base tables for auth methods and auth accounts

* Add triggers for auth_method and auth_account subtypes
2020-06-19 13:10:05 -04:00
Michael Gaffney 2d650b241d Fix down migrations (#120)
* Fix iam down migrations

* Fix '03_db' down migrations

* Fix oplog down migrations

* Fix domain down migrations

* Run make gen
2020-06-13 07:20:40 -04:00
Michael Gaffney 4f30983c14 Bump deps and run make gen (#115) 2020-06-11 10:08:54 -04:00
Michael Gaffney ce166c0bdf Use dbassert package (#114)
Removes direct dependency on gorm in tests.
2020-06-10 09:06:41 -04:00
Michael Gaffney cce06c2cc3 Do not explicitly call the embedded store.HostCatalog (#88) 2020-06-02 07:53:35 -04:00
Michael Gaffney 5bdd8a46ea Extract timestamp scanners into reusable package (#91)
* Refactor: move Timestamp from static/store to db/timestamp

* Refactor: convert remaining Timestamps to timestamp.Timestamp

* Use new db timestamp
2020-06-01 11:46:50 -04:00
Michael Gaffney 9eaf8afb6f Rename db.IsUnique to db.IsUniqueError (#90) 2020-06-01 09:54:02 -04:00
Michael Gaffney 4f3f9ed222 Check for nil in embedded HostCatalog (#89) 2020-06-01 09:53:47 -04:00
Michael Gaffney 6d123d91bb Fix comment for trigger (#92) 2020-05-29 14:51:22 -04:00
0c7f6da936 Static Host Catalog (#51)
* database: add wt_public_id domain type

* static-hosts: add migrations

* Rename migrations

* migrations: add description column and fix foreign keys

* Add protobuf for static host

* Add HostCatalog and HostSet

* Add Options

* Add foreign key constraint

* Add package doc

* Add copied scanner code

* Add NewHostCatalog with tests

* Override default table name for static host catalog

* WIP: save static host catalog to database

* WIP: Print db url for debugging

* Add iam test helper function

* Make gorm default to null for names and descriptions

* Add foreign key constraint from host catalog to scope

* Names are not needed for the test org and project

* Avoid an ordering dependency in down migrations

* Use wt_timestamp

* Add check constraint on host address column

* Add Host

* Add HostSet

* Add HostSetMember

* Test a HostSetMember can be written to the database

* Move the getters and setters for table name to a new file

The TableName methods are needed by gorm and the SetTableName methods
are for oplog. Moving them to a new file so related functionality is in
the same file.

* Add repository

* Add NewRepository

* Close connection before cleanup of database

* Add comments to protobuf file and regenerate

* Define repository methods for HostCatalog

* Assign PublicId when resource is inserted into the database

* Wrap a nil parameter error

* Add oplog tickets for static host types

* WIP: first cut at CreateCatalog

* CreateHostCatalog: more tests

* Detect unique constraint violation

* Use const for PublicId prefixes

* Use PostgreSQL error name instead of error code

* Add TODO comments

* Fix comments

* Use PublicId not PublicID

* Refactor: move error variables from host/static to db

The error variables defined in host/static are generic and can be reused
by other packages.

* Create a new repository for each test

* Validate CreateCatalog returns a new HostCatalog

* Do not modify the HostCatalog passed in

* Implement UpdateCatalog

* Minor cleanup to make folds work

* Implement LookupCatalog

* Refactor: extract allocCatalog function

* Add comment

* Refactor: extract newCatalogMetadata function

* Make error strings more consistent

* Move database specific error check to internal/db package

* Change signature of DeleteCatalog and update docs

* Implement DeleteCatalog

* Make error strings more consistent

* Add examples

* Update docs

* Add package level doc and example for repository

* No need for using reflect.DeepEqual

* Remove redundant comment

* Clarify ErrMultipleRecords results in the transaction being rolled back

* Remove redundant error checks

* Remove unnecessary check

* Return early instead of using nested 'else' statements

* Update and Delete must return a row count

* catch err on defers (#82)

Co-authored-by: Jim Lambert <jimlambrt@Jims-MBP-3.home>

* Remove 'if assert' pattern

* Use assert package in test helper function

* Add test for updating a non existent catalog

* Use a single assert when a specific error is expected

* Use assert package when it clarifies the check

* Catch errors in cleanup functions

* Update comments in protobuf file

* Update doc for UpdateCatalog to reflect the new behavior

* Add common error values for field mask errors

* Require a field mask when calling update methods

* Add TODO for removing direct call to gorm

* Export Public ID prefixes

* Add db timestamp guards

* Remove unused option

Co-authored-by: Jim <jlambert@hashicorp.com>
Co-authored-by: Jim Lambert <jimlambrt@Jims-MBP-3.home>
2020-05-27 18:16:43 -04:00
Michael Gaffney c9ad86c7ba Refactor: move error variables from host/static to db (#68)
The error variables defined in host/static are generic and can be reused
by other packages.
2020-05-20 16:23:22 -04:00
Michael Gaffney fad302a36d Run make migrations (#61) 2020-05-16 19:53:13 -04:00
Michael Gaffney 3d614dd732 Run migrations in a transaction (#60) 2020-05-16 13:26:57 -04:00
Michael Gaffney 477a47897e Add wt_timestamp type to database (#52)
* Add wt_timestamp type to database

* Swap the order of domains and oplog migrations

All migrations should use the new 'wt_timestamp' domain type for
timestamps.

* Remove dead code

* Add down migration for wt_timestamp
2020-05-13 10:40:57 -04:00
Michael Gaffney 8d7f24268c Return url of test database (#48)
It is helpful to connect to a database when tests have failed.
2020-05-12 15:49:37 -04:00
Michael Gaffney 98cd37da97 Rename test files to match the name of the file they test (#43)
Rename test files to follow the convention of 'foo.go' and
'foo_test.go'.
2020-05-11 16:01:49 -04:00
Michael Gaffney 8824a6f7f9 database: add wt_public_id domain type (#30) 2020-05-06 08:29:13 -04:00
Michael Gaffney 5e5a56cac0 Refactor names to avoid stutter (#1)
Since client code uses the package name as a prefix when referring to
the package contents, the names for those contents need not repeat the
package name.

- Rename base.BaseCommand to base.Command
- Rename base.BaseServer to base.Server
- Rename config.DevConfig() to config.Dev()
- Rename config.LoadConfigFile() to config.LoadFile()
- Rename config.NewConfig() to config.New()
- Rename config.ParseConfig() to config.Parse()
- Rename controller.ControllerCommand to controller.Command
- Rename controller.NewController() to controller.New()
- Rename dev.DevCommand to dev.Command
- Rename listener.ListenerFactory to listener.Factory
- Rename listener.NewListener() to listener.New()
- Rename version.GetVersion() to version.Get()
- Rename version.VersionInfo to version.Info

See:
- https://golang.org/doc/effective_go.html#package-names
- https://blog.golang.org/package-names#TOC_3.
- https://github.com/golang/go/wiki/CodeReviewComments#package-names
2020-03-10 15:48:04 -04:00