Commit Graph
202 Commits
Author SHA1 Message Date
Hugo 41b1b5b4b7 feat(db): Introduce migrations for ssh targets (#2960)
Adds the schema for ssh targets. This also changes the target listing
func to not error out when it encounters a target with an unknown type.
Instead, it now ignores it and continues to the next one.
2023-02-21 16:31:22 -05:00
Johan Brandhorst-Satzkorn 3c29308673 chore: Add license headers to all files 2023-02-03 15:54:27 -08:00
Timothy Messier 6a41bf1237 feat(wh): Support vault ssh certificate credentials
This expands the wh_credential_dimension to include fields for the new
vault ssh certificate credential library.
2023-02-02 17:43:17 +00:00
Danielle 3a78a74571 feat(vault): Support Issuing SSH Cert Credentials
Allows the new credential library type to be pulled from the db and used
for issuing ssh certificate type credentials. The ssh cert library
interfaces with vault's ssh secrets engine to either issu certificates
directly from vault, or to generate them within boundary and have vault
sign them as a certificate authority for authentication.

See:
  https://developer.hashicorp.com/vault/api-docs/secret/ssh#sign-ssh-key
  https://developer.hashicorp.com/vault/api-docs/secret/ssh#generate-certificate-and-key
2023-02-02 17:43:16 +00:00
HaotianandTimothy Messier 823b8cdfc6 feat(vault): Add CRUDL methods for ssh certificate cred library (#2765)
This defines a new credential library type for ssh certificates.
It adds new repository methods to support CRUDL of the new ssh
certificate credential library.

Co-authored-by: Timothy Messier <tim.messier@gmail.com>
2023-02-02 17:43:16 +00:00
Johan Brandhorst-Satzkorn 55259029f1 Add job run cleaner (#2866)
* chore: remove duplicate import

* feat: Add job run cleaner

The new job cleans job runs older than a configured interval.
Configure the job to clean jobs older than 1 minute.
2023-01-31 20:41:33 -05:00
Irena Rindos 2e3fd041ef Target worker filters migration fix (#2859) 2023-01-31 08:38:32 -05:00
Timothy Messier e2248c1360 fix(wh): Associate session fact with credential dimensions (#2787)
The wh_upsert_credential_group function was incorrectly attempting to
update the session connection fact table. There are a couple problems
with this:

1. At the time that this runs, there would be no session connection facts
   for this session.
2. This function is meant to update the session fact table, there is a
   separate function that associates the credential group with the
   session connection facts.

This also fixes another bug that was causing expired rows of the
credential dimension to be included in the group membership. And finally
it fixes a typo in the function name.
2023-01-13 11:24:32 -05:00
Damian Debkowski a8ee18e177 fix(db): target address relabel migration id (#2769) 2023-01-09 14:00:28 -08:00
Damian Debkowski 0dbe18e453 fix(db): remove migration test 59_01
This test uses the target domain repository code to test the ingress
& egress worker filter. With our changes we have updated the target
domain repository logic to fetch the target address. When this migration
test is invoked, the target_address table does not exist and the domain
code will always return an error making this test invalid.
2023-01-09 15:39:55 +00:00
Damian Debkowski 3dd4b1c63d feat(db): Support a direct address association to a Target 2023-01-09 15:39:55 +00:00
Johan Brandhorst-Satzkorn eb113b5c9e fix(db): Reorder migrations (#2688)
Migration numbers need to be consistent between version upgrades.
The migrations for the key lifecycle management were merged
into v0.11.1 as number 56, but are currently 58 in main.
This reorders them down to 56, fixing an issue when
migrating from 0.11.1 to main.
2022-12-08 13:40:14 -05:00
Irena Rindos 834a2a88f7 feat(targets): Addition of egress and ingress worker filters (#2654)
* feat(targets): Addition of egress and ingress worker filters
2022-11-30 15:23:37 -05:00
Haotian 96a630905f formatting consistency for 'create function' statements (#2620) 2022-11-18 11:04:34 -08:00
Johan Brandhorst-Satzkorn 8908dccf6d Forward port some release fixes (#2631)
* fix(worker): Verify contents of loaded session (#2629)

* fix(worker): Verify contents of loaded session

Previously, it was possible for an empty private key to be used
when the session had no user or project associated with it.
The new checks guarantee that we will fail gracefully in these
cases.

* Check against len instead of nil

* Add CHANGELOG

* fix(session): Always invoke all parts of session cancel trigger

The session cancelation trigger would not set the key_id to null
appropriately if another one of the fields on the session was
already null, since that case statement would be matched first.
The new structure matches all statements, in case any of them have
special logic (such as in the project case).
2022-11-17 18:21:20 -05:00
edd323b73a Key Rotation/Destruction (#2477) (#2607)
* Key Rotation/Destruction (#2477)

* fix: Correct kms.CreateKeys comment

This method does not return anything.

* feat(kms): Add new ListKeys method

The new ListKeys method wraps the underlying KMS wrapper,
returning all the keys in the scope specified.

* feat(scopes): Add new scope actions for key management

Adds list-keys, rotate-keys and revoke-keys actions for scopes.

* feat(scopes): Add ListKeys API endpoint

This new endpoint lists all keys in a scope

* feat(api): Add ListKeys to Scopes client

This has to be a custom function because it is a custom action
and doesn't map well to any of the existing templates, or
generalises well in a way that would make it reasonable
to create a new template.

* feat(cli): Add new scopes list-keys command

* add RotateKeys function to the kms repository

* Add Rotate Keys Endpoint to Scopes Api (#2360)

* add rotate keys endpoint

* add tests for RotateKeys endpoint

* remove that one comment I forgot about

* addressing more PR comments

* Add Rotate Keys CLI Command (#2395)

* add cli command and client

* add bats tests

* fix some info text and pr comments

* write a new rotate keys description

* Add Missing DEK Foreign Keys (#2408)

* add missing fks

* mark key as nullable in gorm

* update tests to use a new wrapper with a real key_id

* fix formatting in test and add keys for auth_token test

* replace key values

* revert postgres_40_01_test.go

* style: reformat sql for readability

* refactor: change type of key_id columns to kms_private_id

* Store key_id and scope_id with oplog entries, re-type columns referencing data key version (#2431)

* fix(db): Correct types of data key version referencers

* fix(oplog): Fix missing error handling

* feat(oplog): Store key_id and scope_id with oplog entries

This migration truncates all existing oplog entries, as
migrating existing data would have been complex and
likely unnecessary.

* Update view references

* Always delete oplog entries when dropping keys

* Fix rebase issues

* Fix sql tests

* Add schema for new kms destruction jobs (#2479)

* feat: Add schema for new kms destruction jobs

The schema lets us manage destruction jobs per-table
while providing a guarantee that only one run is running
at a time.

* Apply suggestions from code review

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

* Fix table reference and tests

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

* update domain, api, and cli to all include key versions in outputs (#2472)

* update domain, api, and cli to all include key versions in outputs

* fix go sum

* add migration to fix immutable error

* fix final test issue as well as make gen issue

* rebase and fix

* address johan pr comments

* make gen, didn't realize comments were included

* update migrations based on new migration 55 file 03

* Move migrations to 56

* feat: Add key version rewrapping function registry (#2478)

The new RegisterTableRewrapFn can be used by a domain
to register a callback to use when rewrapping data in a
specific table name.

* feat(kms): Add scopeId to RewrapFn (#2539)

This makes it much easier for rewrap functions to look up
the correct wrapper and limit the number of rows searched.

* Update Root Cert Proto Definition (#2542)

* update root cert proto definition to properly identify public_key as the table primary key

* add the test fix as well

* Rewrap Functions for Encrypted Tables (#2532)

* add oidc rewrap

* add argon2 config rewrap

* add auth token rewrapping

* add worker auth cert rewrapping

* check the err

* add username password credential rewrapping

* add ssh private key credential rewrapping

* add vault client certificate rewrap function

* add host catalog secret rewrap function

* cleanup a little

* add host vault token rewrap function

* add session credential rewrap function

* add session rewrap function

* add worker auth rewrap function

* update test to include full assert gamut

* add session rewrap function TEST

* bring all tests up to current standards, make more readable, and include full assert gamut

* rework all rewrap functions to utilize scope id

* update comments, queries, sql refs, etc, in response to PR comments

* forgot a comment

* remove hmac updates and fix a couple comments again

* Rewrapping Registered Tables Test (#2555)

* add the registered table test as well as the two missing rewrap functions

* address pr comments, add db r/w conversions, cmp.diff, sql comment, remove (now) faulty immutable test

* Add ability to list key version destruction jobs, recurring jobs and destroying key versions (#2498)

* feat(kms): Add ability to list data key version destruction jobs

* feat(scopes): Add ListKeyVersionDestructionJobs

* feat(cli): Add list-key-version-destruction-jobs

* feat(kms): Add recurring job that performs table rewrapping

The new recurring job runs for each job table with a registered
rewrapping callback. It attempts to become the running run and
start its rewrapping, gracefully handling sudden interruptions
by resuming it's work if it finds evidence of sudden interruption.

* feat(kms): Add recurring job for destroying key versions

The new job monitors the database for data key version destruction
jobs that have finished rewrapping all its data, performing
the final data key version revocation.

* feat(kms): Add DestroyKeyVersion

DestroyKeyVersion immediately destroys a key version
if it is a root key version or a data key version
which encrypts no data. If the data key version
encrypts data which needs to be rewrapped, it
queues an asynchronous job to complete the rewrapping
operation.

* feat(scopes): Add DestroyKeyVersion API endpoint

* feat(cli): Add scopes destroy-key-version CLI command

* Ensure all secret updates include key ID (#2556)

* feat(all): Ensure all secret updates include key ID

When updating a secret, it is paramount that the key ID
is also updated, as it is the only means we have of ensuring
that we only destroy keys once there is no more data
associated with the key.

* Remove fix to session repository for now

This breaks the current private key derivation method

* add new encrypt/decrypt funcs and made necessary proto changes (#2557)

* add new encrypt/decrypt funcs and made necessary proto changes

* address all PR comments

* fix test panic

* add param checking to rewraps

* fix(schema): Correctly organize migrations again

* Review comments part 1

* Review comments part 2

* Review comments part 3

* Store cert private key, encrypt tofu token (#2583)

* fix(session): store cert private key, encrypt tofu token

Previously, we would derive a session certificate private key from
the session key used in each project, and not store the key. We
would also encrypt the tofu token with the database key but not
store a reference to this key in the database.

This change fixes this by replacing our key derivation with a key
generation step, and instead store the generated key, encrypted,
in the database. We also ensure that any new tofu tokens are
encrypted with the same key.

To handle existing sessions, we lazily rewrite the sessions whenever
a user lists them. There is a minor risk that a user could end up
destroying the database key that encrypts the tofu token before
that session has been rewrapped, but this is going to be rare and
temporary.

* feat(session): Allow the random source for secrets to be configured

* Review comments

* Minor fixes

* More minor fixes

* More small fixes

Co-authored-by: Danielle Miu <dani.miu@hashicorp.com>
Co-authored-by: Danielle <29378233+DanielleMiu@users.noreply.github.com>
Co-authored-by: Michael Gaffney <mike@gaffney.cc>
Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>

* fix(session): Unset session key ID when scope is deleted

Unsetting the key ID allows the session to live beyond the lifetime of
the scope, while allowing the scope to cascade delete its keys.

* fix(migrations): Rewrite migration 56 tests

These tests can no longer use the normal test helpers
as they try to use the new oplog table structure, so we
have to manually write all the interactions.

* fix(migrations): Rename migration 58 file name

This was the name used in the release branch, update
it to the new migration number.

* fix(e2e): Add some comments and debug to kms tests

* fix(session): Handle empty project and user IDs in read

When a project or user is deleted, the session is automatically
canceled and the respective field on the session is unset.
LookupSession did not handle this case gracefully, and would
error on decryption in this state. Skip decrypting sessions that
do not have either a user or project to avoid this error. The
decrypted values are not used for a canceled session.

* Fix worker test

* Increase test timeout

Co-authored-by: Danielle Miu <dani.miu@hashicorp.com>
Co-authored-by: Danielle <29378233+DanielleMiu@users.noreply.github.com>
Co-authored-by: Michael Gaffney <mike@gaffney.cc>
Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
2022-11-16 18:17:28 -05:00
Haotian d97d34adc4 refactor(db): applies consistent formatting to 'comment on' statements 2022-11-15 10:26:26 -08:00
Michael Gaffney f114e20c6d docs(db): fix comments on database domain types
Fixes the comments on the wt_scope_id, wt_user_id, and wt_role_id domain
types.
2022-10-26 08:27:38 -04:00
Michael Gaffney ed4b00303a docs(db): fix comments on kms database tables
Fixes the comments on the kms_data_key and kms_data_key_version tables.
2022-10-26 08:19:43 -04:00
Michael Gaffney c9cfb0e564 docs(db): fix comments on oidc database tables
Fixes the comments on the auth_oidc_method and auth_oidc_account tables.
2022-10-26 08:01:14 -04:00
Michael Gaffney 3241c9a411 docs(db): fix comments on database functions
Fixes the comments on functions wt_add_seconds, wt_add_seconds_to_now,
wt_sub_seconds, and wt_sub_seconds_from_now which were the tragic
victims of a copypasta error.
2022-10-26 06:34:36 -04:00
Johan Brandhorst-Satzkorn f57454b6b9 Rewrite interface{} to any (#2535)
* chore: Rewrite interface{} to any

* Add ignore revs
2022-10-25 19:29:38 -04:00
Todd fa39fe5b0f Delete the base auth account when a concrete auth account is deleted (#2528) 2022-10-11 16:59:52 -07:00
Irena Rindos 4493dfd527 use prior and current worker auth keys (#2495)
* use prior and current worker auth keys
2022-09-26 11:23:08 -04:00
Timothy Messier a2ef14283b fix(org): Address bug that prevented deleting an org (#2465)
The schema changes introduced in 0.10.2 introduced a bug where an org
could not be deleted if there was a session for an org scoped user. It
would result in an error like:

    scope.(Service).deleteFromRepo: unable to delete scope: \
        iam.(Repository).DeleteScope: failed for o_VkNy46KwfS: \
        iam.(Repository).delete: db.DoTx: iam.(Repository).delete: \
        db.Delete: insert or update on table "session" violates foreign key constraint "target_fkey": integrity violation: error #1003

A worker around would be to first delete all projects in the org, then
finally delete the org.

This fix adds a regression test to the sqltests and updates several
constraints on the session table to be deferrable. Since the org delete
is a single transaction, this allows all of the necessary resources to
be deleted before attempting to enforce these constrains.

See: https://www.postgresql.org/docs/current/sql-set-constraints.html
Blame: 3a28ab614
2022-09-19 09:47:52 -04:00
Damian Debkowski 546c5dc5be feat: static json credentials (#2423) 2022-09-16 15:00:04 -07:00
Irena Rindos 821d8317dc address op state review feedback (#2453)
* address op state review feedback
2022-09-16 09:13:37 -04:00
Jeff Mitchell 53b5e532d5 Remove deprecated methods/fields on targets (#2393) 2022-09-15 09:20:08 -04:00
Irena Rindos fc0ead73e6 feat(workers): worker operational state (#2427)
* feat(workers): worker operational state
2022-09-12 16:10:03 -04:00
Jeff Mitchell 9002930d65 Adapt shared lock skip logic to dbswap branch (#2437) 2022-09-12 17:55:32 +01:00
Hugo Vieira 621f8a9ff2 fix(schema): Database connection not cleanly closed
This commit introduces closing the Schema Manager's underlying driver
connection. We were only releasing the shared lock but not actually
cleaning up the db connection and relied on the fact that the process
would exit to do that for us.
2022-09-12 17:55:32 +01:00
Irena Rindos 18dff62b7b Merge BYOW GA branch to main (#2398)
* feat(workers): Add ability to read and reinitialize cert authority (#2312)

* feat(workers): Return Release Version on worker list and read (#2377)

* feat(cli): Read and reinitialize worker certificate authority (#2387)
2022-09-08 13:19:21 -04:00
Timothy Messier 2fbdcf6ce0 feat(session): Use permissions for limiting list results
The session repository can now be passed an optional set of permissions.
The permissions are used to restrict results from the repository.
Currently this only impacts the List method. This enabled the sessions
service to use a single query to retrieve sessions and replaces the
previous behavior where the session service would first request all
sessions for a given set of scopes, evaluate the permissions, and then
request sessions based on a set of session ids.
2022-09-07 17:53:39 +00:00
Louis Ruch d7c4c648ec bug(vault): Correctly handle credential stores with expired tokens (#2399)
* bug(vault): Correctly handle credential stores with expired tokens

Boundary makes use of a database view to perform CRUD operations on
Vault credential stores and libraries. This view did not include
credential stores with tokens that have expired in Vault, causing
errors when attempting to perform any action against them.
2022-09-06 07:50:15 -07:00
Jeff MitchellandIrena Rindos 01fb949d0b Add controller-led worker auth flow (#2413)
This adds an action to the API that allows pulling out an activation
token that can be given to a worker in its config (directly or via env
or file). The worker can pass this along with its normal request in
place of its normal nonce and the server will automatically accept it.

Co-authored-by: Irena Rindos <irenarindos@users.noreply.github.com>
2022-09-02 14:32:41 -04:00
Damian Debkowski 3f70644978 fix(db): update host_plugin_set to set project_id value (#2410) 2022-08-30 16:37:16 -07:00
Johan Brandhorst-Satzkorn aef9073fa6 Upgrade to Go 1.19 (#2347) 2022-08-25 12:12:24 -04:00
Danielle 07a4082aa1 Add SQL Migration 05 From go-kms-wrapping (#2371)
* adding sql migration 05 from go-kms-wrapping

* rename file from 05 to 01 to match boundary standards

* move key rewrap to folder 47
2022-08-25 12:06:43 -04:00
Johan Brandhorst-Satzkorn d709b97e18 fix(schema): Panic with error rather than function (#2391) 2022-08-24 20:42:21 -04:00
Louis Ruch 929a385fdb fix: move 'drop target_all_subtypes' after whx views 2022-08-24 09:33:37 -07:00
Damian Debkowski 27e9f775be feat: add initial migration hook 2022-08-22 12:15:20 -07: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 d01f374490 bug(db): Fix credential purpose migration (#2351)
* bug(db): Fix credential purpose migration
2022-08-11 10:41:48 -07:00
Michael Gaffney a6d9c228aa Merge branch 'mgaffney-greppable-sql' 2022-08-10 18:25:31 -04:00
Louis Ruch 7fafadd70b db: Add credential_sha256 to session_credentials (#2339)
* db: Add credential_sha256 to session_credentials
2022-08-08 18:54:42 -07:00
Michael Gaffney ac6f14a37f style(sql): make migrations more greppable 2022-08-08 18:17:57 -04:00
02dd28f587 Add support for SSH private key passphrases (#2331)
This adds support for encrypted SSH keys via passphrase.

Co-authored-by: Louis Ruch <louisruch@gmail.com>
Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
2022-08-08 15:15:03 -04:00
irenarindos 4908aba546 feat(vault): Add unimplemented worker filter support to OSS 2022-07-25 11:50:27 -04:00
Louis RuchandJeff Mitchell a17e973712 feat(credentials): Refactor credential purposes (#2260)
* feat(credentials): Refactor credential purposes

 * Application credentials have been refactored to Brokered credentials
 * Egress credentials have been refactored to Injected Application
credentials

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
2022-07-19 15:16:24 -07:00
Louis Ruch ef5ac07f02 Add ssh_private_key support for Vault libraries and targets (#2263)
* Add support for ssh_private_key credential type in Vault libraries

* Add support for ssh_private_key credential type

* Support jsonpointer for Vault library mapping overrides
2022-07-19 10:31:53 -07:00